Skip to content
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
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions e2e-tests/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export const LANGUAGES = {
'HE': 'hebrew',
}

export const SOURCE_LANGUAGES = {
'EN': 'Show English Text',
'HE': 'Show Hebrew Text',
'BI': 'Show English & Hebrew Text'
}

export const cookieObject = {
"name": "interfaceLang",
"value": DEFAULT_LANGUAGE,
Expand Down
67 changes: 67 additions & 0 deletions e2e-tests/tests/interface-language-is-sticky.spec.ts
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}) => {
Copy link
Contributor

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!

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 e2e-tests/tests/translation-version-name-appears-in-title.spec.ts
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!)
}
})
});
40 changes: 33 additions & 7 deletions e2e-tests/utils.ts
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';

Expand All @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Expand Down Expand Up @@ -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";
}
Loading