-
-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
18 translation version name in title bar #1979
Open
b-w-cole
wants to merge
14
commits into
Sefaria:master
Choose a base branch
from
b-w-cole:18-translation-version-name-in-title-bar
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3e60399
Validate interface language is sticky when source language changes
b-w-cole 170d3ce
Merge branch 'master' into sticky-interface-and-source-language
b-w-cole c120aa6
Parameterized tests for brevity
b-w-cole 622d4c7
Initial Commit of Translation Version Name in Title Bar
b-w-cole 353d8e9
Testing for default source language only
b-w-cole f1136b2
Neatening parameters
b-w-cole 0197eed
Updating Interface language test
b-w-cole acb07a8
Expanding test to include different sources, plus utils addition
b-w-cole 018f556
Expanding tests to handle bilingual source texts
b-w-cole 0bb0ec0
Updated test with new global params
b-w-cole b953eaf
Solving issue with flakey tests by clearing cookies for each test
b-w-cole e5131aa
chore(testing): add ip control for bilingual tests
akiva10b e1d1f38
Cleaned up tests to read more naturally
b-w-cole 111ef61
Improving a locator for better DOM flow and readibility
b-w-cole File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import {test, expect} from '@playwright/test'; | ||
import {goToPageWithLang, isIsraelIp, changeLanguageOfText} from "../utils"; | ||
import {LANGUAGES, SOURCE_LANGUAGES} from '../globals' | ||
|
||
const interfaceTextHE = 'מקורות'; | ||
const interfaceTextEN = 'Texts'; | ||
const sourceTextHE = 'בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃'; | ||
const sourceTextEN = 'When God began to create'; | ||
|
||
[ | ||
// Hebrew Interface and English Source | ||
{interfaceLanguage: 'Hebrew', interfaceLanguageToggle: LANGUAGES.HE, | ||
sourceLanguage: 'English', sourceLanguageToggle: SOURCE_LANGUAGES.EN, | ||
expectedSourceText: sourceTextEN, expectedBilingualText: '', expectedInterfaceText: interfaceTextHE }, | ||
|
||
// Hebrew Interface and Bilingual Source | ||
{interfaceLanguage: 'Hebrew', interfaceLanguageToggle: LANGUAGES.HE, | ||
sourceLanguage: 'Bilingual', sourceLanguageToggle: SOURCE_LANGUAGES.BI, | ||
expectedSourceText: sourceTextHE, expectedBilingualText: sourceTextEN, expectedInterfaceText: interfaceTextHE }, | ||
|
||
// Hebrew Interface and Hebrew Source | ||
{interfaceLanguage: 'Hebrew', interfaceLanguageToggle: LANGUAGES.HE, | ||
sourceLanguage: 'Hebrew', sourceLanguageToggle: SOURCE_LANGUAGES.HE, | ||
expectedSourceText: sourceTextHE, expectedBilingualText: '', expectedInterfaceText: interfaceTextHE }, | ||
|
||
// English Interface and English Source | ||
{interfaceLanguage: 'English', interfaceLanguageToggle: LANGUAGES.EN, | ||
sourceLanguage: 'English', sourceLanguageToggle: SOURCE_LANGUAGES.EN, | ||
expectedSourceText: sourceTextEN, expectedBilingualText: '', expectedInterfaceText: interfaceTextEN }, | ||
|
||
// English Interface and Bilingual Source | ||
{interfaceLanguage: 'English', sinterfaceLanguageToggle: LANGUAGES.EN, | ||
sourceLanguage: 'Bilingual', sourceLanguageToggle: SOURCE_LANGUAGES.BI, | ||
expectedSourceText: sourceTextHE, expectedBilingualText: sourceTextEN, expectedInterfaceText: interfaceTextEN }, | ||
|
||
// English Interface and Hebrew Source | ||
{interfaceLanguage: 'English', interfaceLanguageToggle: LANGUAGES.EN, | ||
sourceLanguage: 'Hebrew', sourceLanguageToggle: SOURCE_LANGUAGES.HE, | ||
expectedSourceText: sourceTextHE, expectedBilingualText: '', expectedInterfaceText: interfaceTextEN } | ||
|
||
].forEach(({interfaceLanguage, interfaceLanguageToggle, sourceLanguage, sourceLanguageToggle, expectedSourceText, expectedBilingualText, expectedInterfaceText}) => { | ||
test(`${interfaceLanguage} Interface Language with ${sourceLanguage} Source`, async ({ context }) => { | ||
|
||
// Navigating to Bereshit with selected Interface Language, Hebrew or English | ||
const page = await goToPageWithLang(context,'/Genesis.1', interfaceLanguageToggle) | ||
|
||
// Change the source language of the text | ||
await changeLanguageOfText(page, sourceLanguageToggle) | ||
|
||
// Locating the source text segment, then verifying translation | ||
await expect(page.locator('.segmentText span').first()).toContainText(expectedSourceText) | ||
|
||
// Checking out the second part of the text, if 'Bilingual' is selected | ||
if(sourceLanguage === 'Bilingual'){ | ||
await expect(page.locator('.segmentText .contentSpan.en').first()).toContainText(expectedBilingualText) | ||
const isIL = await isIsraelIp(page); | ||
if (isIL) { | ||
expectedInterfaceText = interfaceTextHE; | ||
} | ||
} | ||
|
||
// Validate the Hebrew interface language is still toggled | ||
const interfaceTextLink = page.locator('a.textLink').first() | ||
await expect(interfaceTextLink).toHaveText(expectedInterfaceText) | ||
|
||
}) | ||
}) |
81 changes: 81 additions & 0 deletions
81
e2e-tests/tests/translation-version-name-appears-in-title.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import {test, expect} from '@playwright/test'; | ||
import {goToPageWithLang, changeLanguageOfText} from "../utils"; | ||
import {LANGUAGES, SOURCE_LANGUAGES} from '../globals' | ||
|
||
[ | ||
// Hebrew Interface and Hebrew Source | ||
{interfaceLanguage: 'Hebrew', interfaceLanguageToggle: LANGUAGES.HE, | ||
sourceLanguage: 'Hebrew', sourceLanguageToggle: SOURCE_LANGUAGES.HE, | ||
translationsText: 'תרגומים', selectText: 'בחירה', currentlySelectedText: 'נוכחי'}, | ||
|
||
// Hebrew Interface and Bilingual Source | ||
{interfaceLanguage: 'Hebrew', interfaceLanguageToggle: LANGUAGES.HE, | ||
sourceLanguage: 'Bilingual', sourceLanguageToggle: SOURCE_LANGUAGES.BI, | ||
translationsText: 'תרגומים', selectText: 'בחירה', currentlySelectedText: 'נוכחי'}, | ||
|
||
// Hebrew Interface and English Source | ||
{interfaceLanguage: 'Hebrew', interfaceLanguageToggle: LANGUAGES.HE, | ||
sourceLanguage: 'English', sourceLanguageToggle: SOURCE_LANGUAGES.EN, | ||
translationsText: 'תרגומים', selectText: 'בחירה', currentlySelectedText: 'נוכחי'}, | ||
|
||
// English Interface and English Source | ||
{interfaceLanguage: 'English', interfaceLanguageToggle: LANGUAGES.EN, | ||
sourceLanguage: 'English', sourceLanguageToggle: SOURCE_LANGUAGES.EN, | ||
translationsText: 'Translations', selectText: 'Select', currentlySelectedText: 'Currently Selected'}, | ||
|
||
// English Interface and English Source | ||
{interfaceLanguage: 'English', interfaceLanguageToggle: LANGUAGES.EN, | ||
sourceLanguage: 'Bilingual', sourceLanguageToggle: SOURCE_LANGUAGES.BI, | ||
translationsText: 'Translations', selectText: 'Select', currentlySelectedText: 'Currently Selected'}, | ||
|
||
// English Interface and Hebrew Source | ||
{interfaceLanguage: 'English', interfaceLanguageToggle: LANGUAGES.EN, | ||
sourceLanguage: 'Hebrew', sourceLanguageToggle: SOURCE_LANGUAGES.HE, | ||
translationsText: 'Translations', selectText: 'Select', currentlySelectedText: 'Currently Selected'} | ||
|
||
].forEach(({interfaceLanguage, interfaceLanguageToggle, sourceLanguage, sourceLanguageToggle, translationsText, currentlySelectedText, selectText}) => { | ||
test(`${interfaceLanguage} - translation name appears in title for ${sourceLanguage} source text`, async ({ context }) => { | ||
// Navigate to Bereshit in specified Interface Language | ||
const page = await goToPageWithLang(context,'/Genesis.1', interfaceLanguageToggle) | ||
|
||
// Change the Source Language of the text | ||
await changeLanguageOfText(page, sourceLanguageToggle) | ||
|
||
// Navigate to the Translations sidebar by clicking on the text title | ||
//Clicks on בראשית א׳ / Genesis I | ||
await page.getByRole('heading').first().click() | ||
|
||
// Click on Translations | ||
await page.getByRole('link', {name: translationsText}).click() | ||
|
||
// Wait for Translations side-bar to load by waiting for 'Translations' header | ||
await page.waitForSelector('h3') | ||
|
||
// Retain the translation name locator | ||
const selectedTranslationName = page.locator('span.readerTextVersion') | ||
|
||
// Check if the default translation in the title matches the selected translation | ||
// NOTE: We are skipping checking for the default translation here, due to the Hebrew text not displaying a version title | ||
if(sourceLanguage !== 'Hebrew'){ | ||
const defaultTranslation = await selectedTranslationName.textContent() | ||
|
||
// Check that "Currently Selected / נוכחי" has the default translation next to it by pointing to the version title div | ||
await expect(page.locator('div.version-with-preview-title-line').filter({ hasText: currentlySelectedText })).toContainText(defaultTranslation!) | ||
|
||
} | ||
|
||
const translationNames = ['The Schocken Bible, Everett Fox, 1995 ©', '«Да» project'] | ||
|
||
for(let translationName of translationNames){ | ||
// "Select" another translation. | ||
// The "Select" link is the sibling of the translation in the DOM | ||
await page.getByText(translationName).locator('..').getByText(selectText).click() | ||
|
||
// Validate selected translation is reflected in title | ||
await expect(selectedTranslationName).toContainText(translationName) | ||
|
||
// Validate that the currently selected translation is the one we want by pointing to the version title div | ||
await expect(page.locator('div.version-with-preview-title-line').filter({ hasText: currentlySelectedText })).toContainText(translationName!) | ||
} | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import {DEFAULT_LANGUAGE, LANGUAGES, testUser} from './globals' | ||
import {DEFAULT_LANGUAGE, LANGUAGES, SOURCE_LANGUAGES, testUser} from './globals' | ||
import {BrowserContext} from 'playwright-core'; | ||
import type { Page } from 'playwright-core'; | ||
|
||
|
@@ -23,13 +23,16 @@ export const changeLanguage = async (page: Page, language: string) => { | |
} | ||
|
||
export const goToPageWithLang = async (context: BrowserContext, url: string, language=DEFAULT_LANGUAGE) => { | ||
if (!langCookies.length) { | ||
const page: Page = await context.newPage(); | ||
await page.goto(''); | ||
await changeLanguage(page, language); | ||
langCookies = await context.cookies(); | ||
} | ||
// If a cookie already has contents, clear it so that the language cookie can be reset | ||
if (langCookies.length) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great, thank you again for the efforts to figure this out! |
||
await context.clearCookies() | ||
} | ||
const page: Page = await context.newPage(); | ||
await page.goto(''); | ||
await changeLanguage(page, language); | ||
langCookies = await context.cookies(); | ||
await context.addCookies(langCookies); | ||
|
||
// this is a hack to get the cookie to work | ||
const newPage: Page = await context.newPage(); | ||
await newPage.goto(url); | ||
|
@@ -65,4 +68,27 @@ export const goToPageWithUser = async (context: BrowserContext, url: string, use | |
export const getPathAndParams = (url: string) => { | ||
const urlObj = new URL(url); | ||
return urlObj.pathname + urlObj.search; | ||
} | ||
|
||
export const changeLanguageOfText = async (page: Page, sourceLanguage: string) => { | ||
// Clicking on the Source Language toggle | ||
await page.getByAltText('Toggle Reader Menu Display Settings').click() | ||
|
||
// Selecting Source Language | ||
await page.getByLabel(sourceLanguage, {exact: true}).click() | ||
|
||
} | ||
|
||
export const getCountryByIp = async (page: Page) => { | ||
const data = await page.evaluate(() => { | ||
return fetch('https://ipapi.co/json/') | ||
.then(response => response.json()) | ||
.then(data => data) | ||
}) | ||
return data.country; | ||
} | ||
|
||
export const isIsraelIp = async (page: Page) => { | ||
const country = await getCountryByIp(page); | ||
return country === "IL"; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for using
forEach
again, makes a big difference!