Repository navigation
feat(e2e,playwright):migrate common components help button tests - #51628
ojeytonwilliams merged 7 commits into
Conversation
|
👀 Review this PR in a CodeSee Review Map |
|
Hi 👋 , |
Ahmadkashif
left a comment
There was a problem hiding this comment.
Thank you so much for your time and effort to improve this @Fahdkassim
This is a solid effort from your side.
|
@ojeytonwilliams @Fahdkassim @naomi-lgbt @raisedadead I have some insights to share based on this part of our codebase. This PR by @Fahdkassim appears to be a 1:1 correlation in playwright for what we had for cypress, for the same component. I suggest the following:
file: e2e/lib/testUtils/helpButton.tsx export const testHelpButton = async (page: Page) => {
const helpButton = page.getByTestId('get-help-dropdown');
await expect(helpButton).toBeVisible();
await helpButton.click();
await expect(page.getByTestId('get-hint')).toBeVisible();
await expect(page.getByTestId('ask-for-help')).toBeVisible();
await expect(page.getByTestId('watch-a-video')).toBeVisible();
}Keeping this in mind, the actual e2e test looks something like this: import { test, expect, type Page } from '@playwright/test';
import { testHelpButton } from './lib/testUtils/helpButton';
test.describe('help-button tests for a page with three links', () => {
let page: Page;
// visit the page with the video link
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
await page.goto(
'/learn/responsive-web-design/basic-html-and-html5/say-hello-to-html-elements'
);
});
test.afterAll(async () => {
await page.close();
});
test('should render the button, menu and the three links when video is available', async () => {
await testHelpButton(page);
// continue using this function across all relevant e2e tests, where ever the React component is being reused, we test it with this one call.
})What do you think fellas? |
|
Definitely a fan of DRYing out the tests. |
Do you mean never write e2e tests for these? If yes, I agree. This is unrelated, but the thing is, our unit testing (jest) for the components is severely lacking and is mostly an after-thought. |
|
I agree that we use e2e tests in situations where unit tests would be preferred, but I don't see the case for reusable tests like There is a case for DRYing out any kind of setup, though. If we have multiple tests that need to start from the same state, it can be helpful to DRY out the steps to reach that state so that it's easier to maintain. |
|
In terms of deriving best practices for others to follow, what do you guys suggest should be the way forward? A, either we never test such UI in e2e tests, OR |
…he playwright config file to read the env variables feat(e2e) pulled in main and resolved conflicts
…efactored the code for the tests to assert the visibility of the elements through the playwright test id
6071757 to
fbfdfdb
Compare
…the test file and called it in all the test blocks
|
I don't want to be overly dogmatic, since it's quite subjective, but B) sounds the best to me. Also, I wouldn't say anything is off-limits when it comes to e2e testing, it's just that we don't want the tests to be flaky or slow. So, as long as the e2e tests are reliable and fast, that's good enough for me. |
|
I've improved the code in the test file by implementing a DRY approach. I've created a reusable function that is now called in every test block within the file. This enhancement allows us to efficiently test multiple pages without duplicating the code. Additionally, I've placed the reusable function at the top of the file. If you'd prefer, I can also organise this function in a separate file within a directory like 'e2e/lib/testUtils.' Let me know your preference. |
|
Changes applied |
ojeytonwilliams
left a comment
There was a problem hiding this comment.
Thanks @Fahdkassim, this is very clean and easy to read!
LGTM 👍
Ahmadkashif
left a comment
There was a problem hiding this comment.
Approving this, as we now have a consensus on how to move forward.
Thanks for your time @Fahdkassim @ojeytonwilliams @raisedadead 👍
|
Awesome 🙂 . I guess if there are no more blockers this PR should be merged 🚀 |
|
Yep, it's all good. Thanks everyone! |

Checklist:
mainbranch of freeCodeCamp.Closes #XXXXX