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

Incremental UI Tests #3 #82

Merged
merged 17 commits into from
Jan 10, 2021
Merged

Incremental UI Tests #3 #82

merged 17 commits into from
Jan 10, 2021

Conversation

aradmargalit
Copy link
Collaborator

@aradmargalit aradmargalit commented Jan 3, 2021

Review #81 first! Once that's done, change this base branch to react-ts (or whatever the mainline is at that point).

🚨 Important! This fixes a legitimate bug with goBack vs. back. Apparently there's an incompatibility between react-router-dom and history@5, so I downgraded to 4. Here's the literature on that

This also fixes a silly bug where the reduxRender wouldn't properly nest Routes in a <Switch />

image

expect(screen.getByText(/Delete this Draft/)).toBeDefined();
});

it('deletes a draft from Redux when the delete button is clicked', async () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is where userEvent as a library is really nice. I think this test is really easy to understand, and mirrors how a user would interact with the table. What do you think?

Copy link
Owner

Choose a reason for hiding this comment

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

This is really nice, great demonstration of the value of that library! I imagine writing this test otherwise would be so complicated that I would have probably suggested we forget automating it (and just test manually)

userEvent.click(screen.getByText(/Delete this Draft/));

// Wait for antd to render the confirm modal, then click Yes
await waitFor(() => screen.getByText('Yes'));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In theory, you could combine lines 69 and 70, but according to Kent himself, it's an antipattern:

waitFor is intended for things that have a non-deterministic amount of time between the action you performed and the assertion passing. Because of this, the callback can be called (or checked for errors) a non-deterministic number of times and frequency (it's called both on an interval as well as when there are DOM mutations). So this means that your side-effect could run multiple times!

visible={props.visible}
onCancel={props.onClose}
footer={props.footer}
destroyOnClose
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is the only line that changed. Keeping the modal in the DOM is wasteful and confuses the test runner

Copy link
Owner

Choose a reason for hiding this comment

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

TIL
Thanks!

Base automatically changed from inc-ui-test-2 to react-ts January 10, 2021 02:31
expect(screen.getByText(/Delete this Draft/)).toBeDefined();
});

it('deletes a draft from Redux when the delete button is clicked', async () => {
Copy link
Owner

Choose a reason for hiding this comment

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

This is really nice, great demonstration of the value of that library! I imagine writing this test otherwise would be so complicated that I would have probably suggested we forget automating it (and just test manually)

visible={props.visible}
onCancel={props.onClose}
footer={props.footer}
destroyOnClose
Copy link
Owner

Choose a reason for hiding this comment

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

TIL
Thanks!

@eshedmargalit eshedmargalit merged commit 298148e into react-ts Jan 10, 2021
@eshedmargalit eshedmargalit deleted the inc-ui-test-3 branch January 10, 2021 02:45
eshedmargalit added a commit that referenced this pull request Apr 15, 2021
* App tests

* Add scaffolding for useIsMounted

* Ignore .js, .jsx, and other CRA files

* Action creator tests

* renderCommaSepList tests

* removeMiddleAuthorsTest

* shortenAuthors test

* shortenTableString

* getTagColor test

* isDOI test

* markdown test

* shhhh is okay

* self review feedback

* DraftsRedux test

* Woohoo! A Redux test

* finish drafts tests

Co-authored-by: Eshed Margalit <eshedmargalit@users.noreply.github.com>
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