created the home button to go back to the main page when done with current pad, also tried to make a test

This commit is contained in:
harshil05133 2025-02-17 04:27:09 -05:00
parent 1e5b302a79
commit 60e19bc281
9 changed files with 69 additions and 0 deletions

View file

@ -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',

View file

@ -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;

View file

@ -0,0 +1,9 @@
.homeicon-exit:before {
content: "\2302";
margin-right: 5px;
}
.homeicon:hover{
background-color: grey;
}

View file

@ -74,6 +74,9 @@
.buttonicon-showusers:before {
content: "\e835";
}
.buttonicon-showusers:before {
content: "\e835";
}
.buttonicon-savedRevision:before {
content: "\e856";
}

View file

@ -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');

View file

@ -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']");

View file

@ -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/');
});

View file

@ -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
*

View file

@ -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
});
});