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: write tests for user management #1316

Merged
merged 14 commits into from
Oct 26, 2023
Merged

Conversation

QAComet
Copy link
Contributor

@QAComet QAComet commented Oct 3, 2023

No description provided.

package-lock.json Outdated Show resolved Hide resolved
@barinali barinali changed the title test: create tests for admin pages test: write tests for user management Oct 5, 2023
@QAComet
Copy link
Contributor Author

QAComet commented Oct 9, 2023

@barinali here's the problem + possible solutions for the current snackbar logic

Snackbar closing

Test case

Consider the following test case:

  1. We create a user
  2. We delete this user
  3. We try and create a user with the first user's email address

In this test case, we want to test for an associated snackbar message
telling us if the action was successful or not. Let's assume we just
use

await page.snackbar.waitFor({ state: 'visible' })

If we run this check after creating a user, and then after deleting
the user, the

await page.snackbar.waitFor({ state: 'visible' })

could be executed before the second snackbar message is created. This
will create an erroenous check. Moreover, if we want to validate the
message type, and execute

page.getSnackbar()

before the second snackbar is on the page, it will return the properties
of the snackbar message from step 1. If step 2 fails, and the test
erroneously thinks it hasn't, this is a big issue!

Also, because we don't control when each step in the tests run, we might
run into other race conditions and have false positive/false negative
test runs.

Solutions

  1. close the snackbar after verifying its data
  2. add in a special data- tag, such as data-type to each of the snackbar
    messages, so we have a way to tag these message types. For example, on
    the CreateUser page we could have something like
    enqueueSnackbar(formatMessage('createUser.successfullyCreated'), {
      variant: 'success',
      SnackbarProps: {
        'data-test': 'createUser.successfullyCreated'
      }
    });
    this way we can call something like
    const msg = page.getByTestId("createUser.successfullyCreated');
    await msg.waitFor({ state: 'visible' });
  3. Something else?

Note that we cannot reliably depend on looking at the count of snackbar messages, since this is non-deterministic between test runs, machines, etc.

Also note that 1+2 are probably the ideal solution, since

@QAComet QAComet force-pushed the admin-panel branch 5 times, most recently from abd2cfd to 79f7033 Compare October 26, 2023 02:33
@barinali barinali merged commit 463e690 into automatisch:main Oct 26, 2023
7 checks passed
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.

None yet

2 participants