Skip to content

Commit

Permalink
feat(testing): path recognition for urls
Browse files Browse the repository at this point in the history
  • Loading branch information
akiva10b committed May 6, 2024
1 parent bc13116 commit 9f6bfc1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
36 changes: 18 additions & 18 deletions e2e-tests/tests/banner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import {test, expect} from '@playwright/test';
import {goToPageWithLang, sleep} from "../utils";
import {goToPageWithLang, getPathAndParams} from "../utils";
import {LANGUAGES} from '../globals'

test('Banner links exist - English', async ({ context }) => {
Expand All @@ -14,34 +14,34 @@ test('Banner links exist - English', async ({ context }) => {

// Testing Sefaria logo
await page.getByRole('link', { name: 'Sefaria Logo' }).click();
expect(page.url()).toBe("https://www.sefaria.org/texts")
expect(getPathAndParams(page.url())).toBe("/texts")

// Testing Texts link
await page.getByRole('banner').getByRole('link', { name: 'Texts' }).click();
expect(page.url()).toBe("https://www.sefaria.org/texts")
expect(getPathAndParams(page.url())).toBe("/texts")

// Testing Topics link
await page.getByRole('banner').getByRole('link', { name: 'Topics' }).click();
expect(page.url()).toBe("https://www.sefaria.org/topics")
expect(getPathAndParams(page.url())).toBe("/topics")

// Testing Community link
await page.getByRole('banner').getByRole('link', { name: 'Community' }).click();
expect(page.url()).toContain("https://www.sefaria.org/community")
expect(getPathAndParams(page.url())).toContain("/community")

// Testing Sign-up
// This will end up on the page referenced by the previous "test", which is Community
await page.getByRole('banner').getByRole('link', { name: 'Sign up' }).click();
expect(page.url()).toBe("https://www.sefaria.org/register?next=%2Fcommunity")
expect(getPathAndParams(page.url())).toBe("/register?next=%2Fcommunity")

// Testing log in link
const page2 = await goToPageWithLang(context,'/texts',LANGUAGES.EN);
await page2.getByRole('banner').getByRole('link', { name: 'Log in' }).click();
expect(page2.url()).toBe("https://www.sefaria.org/login?next=%2Ftexts")
expect(getPathAndParams(page2.url())).toBe("/login?next=%2Ftexts")
await page2.close();

// Testing Help link
await page.getByRole('banner').getByRole('link', { name: 'Help' }).click();
expect(page.url()).toBe("https://www.sefaria.org/collections/sefaria-faqs")
expect(getPathAndParams(page.url())).toBe("/collections/sefaria-faqs")

const page1Promise = page.waitForEvent('popup');
await page.getByRole('banner').getByRole('link', { name: 'Donate' }).click();
Expand All @@ -55,16 +55,16 @@ test('Banner links exist - Hebrew', async ({ context }) => {

const page = await goToPageWithLang(context, '/', LANGUAGES.HE);
await page.getByRole('link', { name: 'Sefaria Logo' }).click();
expect(page.url()).toBe("https://www.sefaria.org.il/texts")
expect(getPathAndParams(page.url())).toBe("/texts")

await page.getByRole('banner').getByRole('link', { name: 'מקורות' }).click();
expect(page.url()).toBe("https://www.sefaria.org.il/texts")
expect(getPathAndParams(page.url())).toBe("/texts")

await page.getByRole('banner').getByRole('link', { name: 'נושאים' }).click();
expect(page.url()).toBe("https://www.sefaria.org.il/topics")
expect(getPathAndParams(page.url())).toBe("/topics")

await page.getByRole('banner').getByRole('link', { name: 'קהילה' }).click();
expect(page.url()).toContain("https://www.sefaria.org.il/community")
expect(page.url()).toContain("/community")

//look for and click Donate, while waiting for the page to pop up
const page1Promise = page.waitForEvent('popup');
Expand All @@ -84,21 +84,21 @@ test('Banner links exist - Hebrew', async ({ context }) => {
await page.getByPlaceholder('חיפוש').press('Enter');
await page.getByText('תוצאות עבור').click();
await page.getByRole('heading', { name: 'תוצאות עבור ״Love״' }).click();
expect(page.url()).toBe('https://www.sefaria.org.il/search?q=Love&tab=text&tvar=1&tsort=relevance&svar=1&ssort=relevance')
expect(getPathAndParams(page.url())).toBe('/search?q=Love&tab=text&tvar=1&tsort=relevance&svar=1&ssort=relevance')

// Testing Login
const page2 = await goToPageWithLang(context, '/', LANGUAGES.HE);
await page2.getByRole('banner').getByRole('link', { name: 'התחברות'}).click();
expect(page2.url()).toBe("https://www.sefaria.org.il/login?next=%2Ftexts")
expect(getPathAndParams(page2.url())).toBe("/login?next=%2Ftexts")
page2.close()

// Testing Sign-up
await page.getByRole('banner').getByRole('link', { name: 'להרשמה' }).click();
expect(page.url()).toBe("https://www.sefaria.org.il/register?next=%2Fsearch%3Fq%3DLove%26tab%3Dtext%26tvar%3D1%26tsort%3Drelevance%26svar%3D1%26ssort%3Drelevance");
expect(getPathAndParams(page.url())).toBe("/register?next=%2Fsearch%3Fq%3DLove%26tab%3Dtext%26tvar%3D1%26tsort%3Drelevance%26svar%3D1%26ssort%3Drelevance");

// Testing Help link
await page.getByRole('banner').getByRole('link', { name: 'עזרה' }).click();
expect(page.url()).toBe("https://www.sefaria.org.il/collections/%D7%A9%D7%90%D7%9C%D7%95%D7%AA-%D7%A0%D7%A4%D7%95%D7%A6%D7%95%D7%AA-%D7%91%D7%A1%D7%A4%D7%A8%D7%99%D7%90");
expect(getPathAndParams(page.url())).toBe("/collections/%D7%A9%D7%90%D7%9C%D7%95%D7%AA-%D7%A0%D7%A4%D7%95%D7%A6%D7%95%D7%AA-%D7%91%D7%A1%D7%A4%D7%A8%D7%99%D7%90");

});

Expand All @@ -124,10 +124,10 @@ test('Banner - Search, Keyboard, and Language toggle works for English site', as
await page.getByRole('cell', { name: 'א', exact: true }).click();

await page.locator('#panel-0').getByRole('link', { name: 'עברית' }).click()
expect(page.url()).toBe("https://www.sefaria.org.il/texts");
expect(getPathAndParams(page.url())).toBe("/texts");

await page.getByRole('list').getByRole('link', { name: 'English' }).click();
expect(page.url()).toBe("https://www.sefaria.org.il/translations/en");
expect(getPathAndParams(page.url())).toBe("/translations/en");


});
5 changes: 5 additions & 0 deletions e2e-tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@ export const goToPageWithUser = async (context: BrowserContext, url: string, use
await newPage.goto(url);
return newPage;
}

export const getPathAndParams = (url: string) => {
const urlObj = new URL(url);
return urlObj.pathname + urlObj.search;
}

0 comments on commit 9f6bfc1

Please sign in to comment.