diff --git a/src/node/utils/toolbar.ts b/src/node/utils/toolbar.ts index f0ef45479..119181e33 100644 --- a/src/node/utils/toolbar.ts +++ b/src/node/utils/toolbar.ts @@ -241,6 +241,12 @@ module.exports = { embed: defaultButtonAttributes('embed'), showusers: defaultButtonAttributes('showusers'), + gohome:{ + command: 'gohome', + localizationId: 'pad.toolbar.gohome.title', + class: 'homeicon homeicon-exit', + }, + timeslider_export: { command: 'import_export', localizationId: 'timeslider.toolbar.exportlink.title', diff --git a/src/static/css/pad.css b/src/static/css/pad.css index 5ef192509..027877e23 100644 --- a/src/static/css/pad.css +++ b/src/static/css/pad.css @@ -12,6 +12,7 @@ @import url("pad/gritter.css"); @import url("pad/loadingbox.css"); @import url("pad/form.css"); +@import url("pad/home.css"); html { font-size: 15px; diff --git a/src/static/css/pad/home.css b/src/static/css/pad/home.css new file mode 100644 index 000000000..811a22a29 --- /dev/null +++ b/src/static/css/pad/home.css @@ -0,0 +1,9 @@ +.homeicon-exit:before { + content: "\2302"; + margin-right: 5px; +} + +.homeicon:hover{ + background-color: grey; +} + diff --git a/src/static/css/pad/icons.css b/src/static/css/pad/icons.css index eb1016dca..dd17f45eb 100644 --- a/src/static/css/pad/icons.css +++ b/src/static/css/pad/icons.css @@ -74,6 +74,9 @@ .buttonicon-showusers:before { content: "\e835"; } +.buttonicon-showusers:before { + content: "\e835"; +} .buttonicon-savedRevision:before { content: "\e856"; } diff --git a/src/static/js/pad_editbar.ts b/src/static/js/pad_editbar.ts index d98174fe5..a3097c4d7 100644 --- a/src/static/js/pad_editbar.ts +++ b/src/static/js/pad_editbar.ts @@ -387,6 +387,11 @@ exports.padeditbar = new class { $('#myusernameedit').trigger('focus'); }); + this.registerCommand('gohome', () => { + console.log('Go Home button clicked'); + window.location.href = '/'; + }); + this.registerCommand('embed', () => { this.setEmbedLinks(); this.toggleDropDown('embed'); diff --git a/src/tests/frontend-new/helper/padHelper.ts b/src/tests/frontend-new/helper/padHelper.ts index f52cd0a35..28673feed 100644 --- a/src/tests/frontend-new/helper/padHelper.ts +++ b/src/tests/frontend-new/helper/padHelper.ts @@ -20,6 +20,10 @@ export const toggleUserList = async (page: Page) => { await page.locator("button[data-l10n-id='pad.toolbar.showusers.title']").click() } +export const leavePad = async (page: Page) => { + await page.locator("button[data-l10n-id='pad.toolbar.gohome.title']").click(); +} + export const setUserName = async (page: Page, userName: string) => { await page.waitForSelector('[class="popup popup-show"]') await page.click("input[data-l10n-id='pad.userlist.entername']"); diff --git a/src/tests/frontend-new/specs/leavePadTests.ts b/src/tests/frontend-new/specs/leavePadTests.ts new file mode 100644 index 000000000..497bcdd3f --- /dev/null +++ b/src/tests/frontend-new/specs/leavePadTests.ts @@ -0,0 +1,16 @@ +import { test, expect } from '@playwright/test'; // Assuming Playwright is being used +import { leavePad } from '../helper/padHelper'; // Import the exitPad function + +test('should exit the pad and return to the homepage', async ({ page }) => { + // Open a new pad (this can use helper.newPad() if it exists) + await page.goto('http://localhost:9001/p/test-' + Date.now()); // Or use helper.newPad() + + // Ensure the page is loaded + await page.waitForLoadState('domcontentloaded'); + + // Click the exit button using the exitPad function + await leavePad(page); + + // Verify that the page has navigated to the homepage + await expect(page).toHaveURL('http://localhost:9001/'); +}); \ No newline at end of file diff --git a/src/tests/frontend/helper/ui.ts b/src/tests/frontend/helper/ui.ts index 69e6b7d40..3c35aa154 100644 --- a/src/tests/frontend/helper/ui.ts +++ b/src/tests/frontend/helper/ui.ts @@ -85,6 +85,21 @@ helper.toggleUserList = async () => { await helper.waitForPromise(() => !isVisible); }; +helper.homeButton = () => helper.padChrome$("button[data-l10n-id='pad.toolbar.gohome.title']"); + +helper.leavePad = async () => { + const button = helper.homeButton(); + button.trigger('click'); + await helper.waitForPromise(() => window.location.pathname === '/'); +}; + +helper.newPad = async (page: Page) => { + // create a new pad before each test run + const padId = "FRONTEND_TESTS"+randomUUID(); + await page.goto('http://localhost:9001/p/'+padId); + await page.waitForSelector('iframe[name="ace_outer"]'); + return padId; +} /** * Gets the user name input field * diff --git a/src/tests/frontend/specs/leavePadTest.js b/src/tests/frontend/specs/leavePadTest.js new file mode 100644 index 000000000..4d0652052 --- /dev/null +++ b/src/tests/frontend/specs/leavePadTest.js @@ -0,0 +1,10 @@ +describe("Leave Pad Functionality", function () { + beforeEach(async function () { + await helper.newPad(); // Open a new pad before each test + }); + + it("should leave the pad and go back to the homepage", async function () { + await helper.leavePad(); // Clicks the exit button + expect(window.location.pathname).toBe("/"); // Confirms we are on the homepage + }); +});