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

test(dark-light-modes): reusable test code #934

Merged
merged 37 commits into from
Jan 28, 2025

Conversation

max-umain
Copy link
Collaborator

@max-umain max-umain commented Dec 18, 2024

Describe pull-request

This PR introduces reusable test code, that allows for easily generating tests for any component, based on their existing tests and dynamically modifying mode (lightmode, darkmode) and mode variant (primary, secondary).

In this PR I have also applied this dynamic test for almost all components, so now they have screenshot tests for modes and mode variants.

Issue Linking:

The following tickets are addressed in this PR

How to test

Provide detailed steps for testing, including any necessary setup.

  1. Go to the root directory of tegel
  2. Run npm run test

Checklist before submission

  • I have added unit tests for my changes (if applicable)
  • All existing tests pass
  • I have updated the documentation (if applicable)
  • Not breaking production behavior
  • Behavior available in storybook with documented descriptions (if applicable)
  • npm run build-all without errors

Suggested test steps

  • Browser testing (Chrome, Safari, Firefox)
  • Keyboard operability
  • Interactive elements have labels.
  • Storybook controls
  • Design/controls/props is aligned with other components
  • Dark/light mode and variants
  • Input fields – values should be displayed properly
  • Events

Screenshots

None

Additional context

How to use the reusable test code

In .e2e.ts test files, extract the tests within the test.describe.parallel that have a toHaveScreenshot and put them below one of the following

testConfigurations.withModeVariants.forEach((config) => {
  test.describe.parallel(getTestDescribeText(config, testDescription), () => {
    test.beforeEach(async ({ page }) => {
      await setupPage(page, config, componentTestPath, componentName);
    });

or

testConfigurations.basic.forEach((config) => {
  test.describe.parallel(getTestDescribeText(config, testDescription), () => {
    test.beforeEach(async ({ page }) => {
      await setupPage(page, config, componentTestPath, componentName);
    });

and make sure to close the functions with curly braces and parentheses. Also insert code from existing (if there is any) test.beforeEach to this one, and also removing the page.goto lines in every test in the file.

Copy link
Contributor

github-actions bot commented Dec 18, 2024

Playwright test results

passed  789 passed
skipped  1 skipped

Details

stats  790 tests across 134 suites
duration  2 minutes, 18 seconds
commit  c25c1a5

Skipped tests

src/components/table/table/test/expandable-row-autocollapse/expandable-row-autocollapse.e2e.ts › tds-table-expandable-row-autoCollapse › NEEDS FIXING: expanding one row collapses the others when autoCollapse is true

Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-934.d3fazya28914g3.amplifyapp.com

Copy link
Contributor

@nathalielindqvist nathalielindqvist left a comment

Choose a reason for hiding this comment

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

Going through all of the new screenshots PRs that have been posted using this reusable code as a base, it seems like there are still residual tests in light mode (specifically primary light mode if the component has mode variants) that produce duplicates of screenshots. This has happened all throughout the PRs. Before moving forward with this idea I think it would be good to align on how we want to tackle this problem, if we want to remove the original tests entirely or if this script should be tweaked to not produce results in (primary) light mode. Or, if there is another way to go about this and still get the result of dark mode tests. Having a larger discussion within the dev group sounds like a good idea to me.

@max-umain max-umain force-pushed the test/reusable-code-for-tests branch from 451a8ac to e3b8ced Compare January 14, 2025 13:30
@max-umain max-umain changed the title test: add testConfiguration file with reusable test code test: tests with mode and mode variants using reusable test code Jan 16, 2025
@max-umain max-umain marked this pull request as ready for review January 17, 2025 08:42
@max-umain max-umain force-pushed the test/reusable-code-for-tests branch from b20d19b to a9db16b Compare January 17, 2025 16:03
@max-umain max-umain force-pushed the test/reusable-code-for-tests branch from a9db16b to 3852406 Compare January 20, 2025 08:40
Copy link
Contributor

@theJohnnyMe theJohnnyMe left a comment

Choose a reason for hiding this comment

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

Changes in PR are touching too large amount of files to provide detailed code review. However, idea of having configuration file and less lines of code to test both dark and light mode and its submodes looks good to me.

Looking in some components we could further optimize this by just taking screenshots using "beforeEach" trick done here and moving other logic outside - for example checking if disabled cursor is disabled. That would be a step in next improvement.

Overall great work!

@theJohnnyMe theJohnnyMe changed the title test: tests with mode and mode variants using reusable test code test(dark-light-modes): reusable test code Jan 20, 2025
@theJohnnyMe
Copy link
Contributor

I have updated the title of PR, just a bit shorter.

@max-umain
Copy link
Collaborator Author

Changes in PR are touching too large amount of files to provide detailed code review. However, idea of having configuration file and less lines of code to test both dark and light mode and its submodes looks good to me.

I think the idea was that everything in this PR has been merged from other PRs that has been approved, so I don't think any of the files in this PR are necessary to review as they have already been approved, except for testConfiguration.ts

Copy link
Collaborator

@ckrook ckrook left a comment

Choose a reason for hiding this comment

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

Have went through every sub-pr before they where merge into this larger PR, and it looked good to me.

@max-umain max-umain merged commit 245b73f into develop Jan 28, 2025
4 checks passed
@max-umain max-umain deleted the test/reusable-code-for-tests branch January 28, 2025 08:19
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.

5 participants