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

[RW-12615][risk=no] Converted admin-user-profile.spec.tsx #8602

Merged
merged 20 commits into from
Jun 14, 2024
Merged

Conversation

evrii
Copy link
Collaborator

@evrii evrii commented Jun 12, 2024


PR checklist

  • I have included an issue ID or "no ticket" in the PR title as outlined in CONTRIBUTING.md.
  • I have included a risk tag of the form [risk=no|low|moderate|severe] in the PR title as outlined in CONTRIBUTING.md.
  • I have manually tested this change and my testing process is described above.
  • This change includes appropriate automated tests, and I have documented any behavior that cannot be tested with code.
  • I have added explanatory comments where the logic is not obvious.
  • One or more of the following is true:
    • This change is intended to complete a JIRA story, so I have checked that all AC are met for that story.
    • This change fixes a bug, so I have ensured the steps to reproduce are in the Jira ticket or provided above.
    • This change impacts deployment safety (e.g. removing/altering APIs which are in use), so I have documented the impacts in the description.
    • This change includes a new feature flag, so I have created and linked new JIRA tickets to (a) turn on the feature flag and (b) remove it later.
    • This change modifies the UI, so I have taken screenshots or recordings of the new behavior and notified the PO and UX designer in Slack.
    • This change modifies API behavior, so I have run the relevant E2E tests locally because API changes are not covered by our PR checks.
    • None of the above apply to this change.

@evrii evrii changed the title Convert a few tests. [RW-12615][risk=no] Converted admin-user-profile.spec.tsx Jun 13, 2024
@evrii evrii marked this pull request as ready for review June 13, 2024 19:39
@evrii evrii requested a review from jmthibault79 June 13, 2024 19:42
return divs.at(2).text();
const getDropdown = (containerTestId: string): HTMLSelectElement => {
const container = screen.getByTestId(containerTestId);
return within(container).getByRole('combobox', { hidden: true });
Copy link
Collaborator

Choose a reason for hiding this comment

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

interesting! I think you, me, and Neha all have different ways of accessing dropdowns. We should probably consolidate them when we migrate to Terra-UI's version.

Copy link
Collaborator Author

@evrii evrii Jun 14, 2024

Choose a reason for hiding this comment

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

I agree. I believe that consolidation will be key. I think the problem is compounded by the fact that I believe that there are currently two or three types of drop downs.


expect(findTextInput(wrapper, 'contactEmail').props().value).toEqual(
BROAD_ADDR_1
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like to keep this check, to show that value changed in the course of the test

screen.getByRole('button', {
name: /save/i,
})
);
});

it('should not allow updating both email and institution if they match each other', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

please update the name of this test

Copy link
Collaborator

Choose a reason for hiding this comment

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

(remove "not")

expect(tableRows.length).toEqual(orderedAccessModules.length);
const table = screen.getByTestId('access-module-table');
const rows = within(table).getAllByRole('row');
rows.shift(); // remove the header row
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you know why this was not necessary before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The previous version (line 520) is doing a css selector tbody tr[role="row"] so it was only getting the rows in the body of the table. Since css selectors are not the preferred way of selecting within RTL, I am relying on getAllByRole('row'); which gets all the rows in the table (header and body). Since that is the case, we need to remove the first row since it is from the previously unaccounted for header row.

As an aside, there is a long open issue in the testing library that calls for a more intuitive way of testing tables:
testing-library/dom-testing-library#583

).exists()
).toBeTruthy();
const table = screen.getByTestId('access-module-table');
within(table).getByText(`requires eRA Commons for ${tiers} access`, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

while not strictly necessary, I believe the best practice is to still use an expect() here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree. I wrestled with this for a while, but I think you're right, because it makes our assertions more explicit:
https://kentcdodds.com/blog/common-mistakes-with-react-testing-library#using-get-variants-as-assertions

@evrii evrii merged commit 94522da into main Jun 14, 2024
21 checks passed
@evrii evrii deleted the eric/RW-12615 branch June 14, 2024 17:07
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.

2 participants