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 13 commits into
base: master
Choose a base branch
from

Conversation

b-w-cole
Copy link

Description

A test to cover this test case: Sefaria/Sefaria-Playwright-Tests#18

Includes:

  • Parameterized tests for all Interface and Source language combinations
  • Abstracted source language function for this and future purposes
  • New Global variable for source language selection, pointing to DOM locators.

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.

@b-w-cole
Copy link
Author

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

@saengel
Copy link
Contributor

saengel commented Aug 1, 2024

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

@b-w-cole
Copy link
Author

b-w-cole commented Aug 9, 2024

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.

  1. Load Hebrew Interface and Source text
  2. Navigate to Translations
  3. Select 'חומש רש״י, רבי שרגא זילברשטיין'
  4. 'The Rashi chumash by Rabbi Shraga Silverstein' (in English) will appear in the translation title.

I would expect the Hebrew translation title to appear in the translation title.
image

Also the source text switches itself to Bilingual.
image

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
@b-w-cole
Copy link
Author

b-w-cole commented Aug 9, 2024

Hi @saengel , I was able to consolidate the English and Hebrew tests with a little rearranging. Additionally, I added bilingual support.

b-w-cole and others added 2 commits August 9, 2024 17:06
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.
Copy link
Contributor

@saengel saengel left a 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}`)
Copy link
Contributor

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!)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I see. What I was doing here was using the "Pick Locator" tool in VSCode. Let me see if I can neaten it up.
image

Copy link
Author

@b-w-cole b-w-cole Oct 10, 2024

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. :/ **

image


// 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}`)
Copy link
Contributor

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.

Copy link
Author

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.

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!


// Navigate to the Translations sidebar by clicking on the text title
//Clicks on בראשית א׳ / Genesis I
await page.locator('h1').click()
Copy link
Contributor

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.

Copy link
Author

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?

Copy link
Contributor

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
Copy link
Contributor

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)

Copy link
Author

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.

Copy link
Contributor

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
Copy link
Contributor

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
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!

// Hebrew Interface and Hebrew Source
{interfaceLanguage: 'Hebrew', interfaceLanguageToggle: LANGUAGES.HE,
sourceLanguage: 'Hebrew', sourceLanguageToggle: SOURCE_LANGUAGES.HE,
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.

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.

Copy link
Author

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.

Copy link
Contributor

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}) => {
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!

}

// Validate Hebrew interface language is still toggled
const textLink = page.locator('a.textLink').first()
Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Contributor

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.
Copy link
Contributor

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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, great catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants