-
-
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
base: master
Are you sure you want to change the base?
18 translation version name in title bar #1979
Conversation
Sefaria/Sefaria-Playwright-Tests#18 TODO: Decide if we want to test for default translation title.
Issue noted for Hebrew sources - no default translation is selected.
@saengel , this one isn't quite ready to merge. I'm wondering about your opinion on the file translation-version-name-appears-in-title.spec.ts, and the commented out tests. Do you want me to test for the existence of a default translation title? This will fail for Hebrew source language texts, as the default translation isn't selected in the translation side bar. |
Hi @b-w-cole - thank you again! Another fantastic PR - much appreciated! I think for Hebrew source language texts, let's keep them commented out for now. Let me know when it's ready for a review. |
Hi @saengel ! Sorry for the long wait. I tweaked the Hebrew source language tests to be their own separate test, as the logic needs to be slightly different. However, I noticed a quirk with the Hebrew Interface / Hebrew Source translations.
I would expect the Hebrew translation title to appear in the translation title. Also the source text switches itself to Bilingual. I will switch this test parameter to Shocken's translation for now and recommit. |
Also allowing default translation validations to be skipped for Hebrew language source texts
Hi @saengel , I was able to consolidate the English and Hebrew tests with a little rearranging. Additionally, I added bilingual support. |
Issue: Tests time out on assertions looking for text in the wrong language Solution: Clearing the cookies resets the cookie-setting process and allows language cookies to be refreshed for each context.
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.
Hi @b-w-cole - overall looks really great! Some tricky cases you had to figure out here, and appreciate how you found a way... even when there were unexpected edge cases.
I left a few comments, mostly for us to discuss (curious to hear your thoughts as well). We can go from there. As always, great work!
await page.getByRole('radiogroup', {name: 'Language'}).locator(`${sourceLanguageToggle}`).click() | ||
|
||
// Locating the source text segment, then verifying translation | ||
await expect(page.locator('div.segmentNumber').first().locator('..').locator('p')).toContainText(`${expectedSourceText}`) |
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.
We had discussed focusing on testing user-facing attributes (reference to the playwright docs here) versus locators, you had mentioned that you try to do that as much as possible - unless the case necessitates locators. I'm assuming this is a case you needed locators, do you mind elaborating on why? Will help me better understand how we're able to test our code.
(And, if this happens to be a case that can be rewritten to test user-facing attributes, that would be great as well!)
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.
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.
I was able to condense this to await expect(page.getByRole('region').locator('.segmentText span').last()).toContainText("expectedText")
, as well as remove some other locators, but I can only go so far, as I need to pinpoint exactly where the text is showing up. There's not really roles associated with the divs and spans for text, so I use the CSS locators instead. I could use getByText(), but if I do that, I cannot test.
Additionally, I was able to simplify the process for changing source language and remove those locators. **Edit: In the photo, I simplified further and now we're back to locators. :/ **
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.
Hello! On this topic again, I took another look at this, and found that the best way is with the locator pointing to div classes. I tried to use sensible CSS classes where it is clearer what the locator is pointing to.
I am also submitting a correction to the commit I submitted a week ago. I was thinking about it at the time that
await expect(page.getByRole('link', {name: currentlySelectedText}).locator('..')).toContainText(defaultTranslation!)
would be appropriate for translation-version-name-appears-in-title.spec.ts, but I'd like to change it. While the test passes, it doesn't flow very well through the DOM. Also, it is not at all recommended by the course I'm taking, so there it is that.
Instead, I would like to change this line to be:
await expect(page.locator('div.version-with-preview-title-line').filter({ hasText: currentlySelectedText })).toContainText(translationName!)
It flows much more naturally in the DOM, looking through the document for all version title lines containing 'Currently Selected' and checking if this also contains the translation we want.
What do you think?
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.
Hi Brandon, thank you for the thoughtful explanations and revisions here. I think this improvement is great. Again, we try to prefer user-facing attributes as much as possible - but sometimes we need to rely on locators and that should be fine. Thank you for these improvements.
|
||
// Checking out the second part of the text, if 'Bilingual' is selected | ||
if(`${sourceLanguage}` === 'Bilingual'){ | ||
await expect(page.locator('div.segmentNumber').first().locator('..').locator('p span').last()).toContainText(`${expectedBilingualText}`) |
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.
Same question here in terms of using a locator.
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.
Thanks for keeping me on track with these. I'm continuing to learn, and you're helping me out. There's more I'd like to simplify in this for sure. I'll let you know.
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!
|
||
// Navigate to the Translations sidebar by clicking on the text title | ||
//Clicks on בראשית א׳ / Genesis I | ||
await page.locator('h1').click() |
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.
Same comment throughout this file regarding locator use - I didn't comment in each location, just a general curiosity to see if it's possible to rewrite any of these.
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.
Hmm... I can change it to await page.getByRole('heading').first().click()
. This still works, and it is using best practices. What do you think?
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.
I think that would be great, thank you for the suggestion!
await page.waitForSelector('h3') | ||
|
||
// 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 being default Masoretic |
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.
Can we rewrite to say "due to the Hebrew text not displaying a version title". That might be a more accurate description of what's going on in terms of site functionality (even if the root reason behind it is what you described here, for Tanakh texts at least)
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.
Sure thing! I will make this change.
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.
Great, thank you!
// TODO: 4th translation, handling Hebrew Interface translations in Hebrew. For example: 'חומש רש״י, רבי שרגא זילברשטיין' should appear in the translation title as written. | ||
const translationNames = ['The Schocken Bible, Everett Fox, 1995 ©', '«Да» project'] | ||
|
||
// Utilizing the traditional for-loop as there are async issues with foreach |
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.
Helpful comment! Thank you!
await changeLanguage(page, language); | ||
langCookies = await context.cookies(); | ||
} | ||
// If a cookie already has contents, clear it so that the language cookie can be reset |
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.
This is great, thank you again for the efforts to figure this out!
// Hebrew Interface and Hebrew Source | ||
{interfaceLanguage: 'Hebrew', interfaceLanguageToggle: LANGUAGES.HE, | ||
sourceLanguage: 'Hebrew', sourceLanguageToggle: SOURCE_LANGUAGES.HE, | ||
expectedSourceText: 'רֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃', expectedBilingualText: '', expectedInterfaceText: 'מקורות' }, |
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.
Not a super huge deal (especially since copy and paste with Hebrew text into most IDEs can be really finicky) but the first letter of the verse (the ב) is missing in every instance of Hebrew expectedSourceText
. Is it possible to add it in for clarity? Just so it makes more sense to people reading the tests.
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.
Oh shoot, sorry about that! It is fixed.
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.
Perfect, no worries!
sourceLanguage: 'Hebrew', sourceLanguageToggle: SOURCE_LANGUAGES.HE, | ||
expectedSourceText: 'רֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃', expectedBilingualText: '', expectedInterfaceText: 'Texts' } | ||
|
||
].forEach(({interfaceLanguage, interfaceLanguageToggle, sourceLanguage, sourceLanguageToggle, expectedSourceText, expectedBilingualText, expectedInterfaceText}) => { |
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!
} | ||
|
||
// Validate Hebrew interface language is still toggled | ||
const textLink = page.locator('a.textLink').first() |
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.
Maybe consider renaming to interfaceTextLink
for clarity?
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.
That makes sense to me.
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.
Ok great!
await expect(page.locator('div.version-with-preview-title-line', {hasText: defaultTranslation!}).getByRole('link')).toHaveText(`${currentlySelected}`) | ||
} | ||
|
||
// TODO: 4th translation, handling Hebrew Interface translations in Hebrew. For example: 'חומש רש״י, רבי שרגא זילברשטיין' should appear in the translation title as written. |
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.
Do we need to leave this TODO
here? Remind me what's outstanding (I thought we were skipping this case, due to the lack of version title being displayed)
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.
Nope, great catch!
Description
A test to cover this test case: Sefaria/Sefaria-Playwright-Tests#18
Includes:
Code Changes
The following changes were made to the files below
Notes
Issue noted with Hebrew sources - the translation title doesn't appear by default. Such cases are commented out in the test parameters.