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 #4 #83

Merged
merged 13 commits into from
Jan 10, 2021
Merged

Incremental UI Tests #4 #83

merged 13 commits into from
Jan 10, 2021

Conversation

aradmargalit
Copy link
Collaborator

Review #82 first! Then rebase this and merge.
image


it('renders Infinity per Week', () => {
render(<FrequencyChart reviews={reviews} />);
expect(screen.getAllByText('Infinity')).toBeDefined();
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 expect this will change once glue gets merged in -- happy to update once that's ready, but this test will be a good canary in that coalmine.

expect(screen.getByText(displayName)).toBeDefined();
});

// TODO EM: I think this should be a <Link /> so that it's easier to test.
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'm getting weird errors about how href based navigation isn't supported in JSDOM

Copy link
Owner

Choose a reason for hiding this comment

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

I have no complaints about moving all href -> Link

Should I commit that on this branch before merging?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nah, I made an issue for it
#84

@@ -20,7 +20,7 @@ export default function MinimalStatBoxView({ userDisplayName, reviews }: Minimal
);

// destructure if not null, or set all to undefined
const { numReviews, ppwString, ppwColor } = getReviewStats(reviews) || {};
const { numReviews, ppwString, ppwColor } = getReviewStats(reviews);
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 couldn't find any way that the || {} would ever trigger. Can you?

Copy link
Owner

Choose a reason for hiding this comment

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

Hmm no, I think what you have is safe.
The reviews arg is typed to be Review[] so TS compiler would've complained if there were a valid route to passing undefined or null instead, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That was my thinking as well, yeah

@@ -135,7 +135,7 @@ export default function PaperSearchBarView({
<div>
<br />
{searchArea}
{loading ? <Spin className="searchResult loading-spinner" /> : searchRender}
{loading ? <Spin data-testid="paper-searchbar-spinner" className="searchResult loading-spinner" /> : searchRender}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

using data-testid should really be a last resort since it's an accessibility code smell. But in this case, it's antds component, so I'm just tagging it so I can check for it in tests.

Base automatically changed from inc-ui-test-3 to react-ts January 10, 2021 02:45
Copy link
Owner

@eshedmargalit eshedmargalit left a comment

Choose a reason for hiding this comment

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

This PR moved me from "tests are nice but mostly just an extra safety step to catch corner cases" to "wow, I can actually program my entire manual check workflow into an automated test suite, it's lit 🔥 "

Thanks so much for your work on this and #81, #82 !

Comment on lines +42 to +45
it('renders about 1 per week', () => {
render(<FrequencyChart reviews={reviews} />);
expect(screen.getAllByText('1')).toBeDefined();
});
Copy link
Owner

Choose a reason for hiding this comment

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

Question: it seems like the test criteria in this test and the preceding test are pretty vague, i.e.,

  • screen.getAllByText('1')) doesn't really test that ppw = 1
  • If ppw = 4.01, for example, both tests pass (but shouldn't)

Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, good point. It's partially because react testing library can't search for text across HTML elements, which makes searching for the full string hard. Let's open an issue to clean these up later.


describe('with a logged-in user', () => {
it('redirects to the dashboard', () => {
const initialState = { ...getBlankInitialState(), user: { ...blankUser, display: 'Piranesi' } };
Copy link
Owner

Choose a reason for hiding this comment

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

Hmm. This passes because technically a User is present and it does redirect. But display isn't a valid attribute of User and it wouldn't show their name correctly (should be displayName).

I guess this test doesn't actually test that the displayName works as expected, so maybe okay?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah that was just a typo, let me push a fix before we merge

it('shows the information icon with information on hover', async () => {
renderWithRouterRedux(<MenuBarRedux />);

userEvent.hover(screen.getByLabelText('info-circle'));
Copy link
Owner

Choose a reason for hiding this comment

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

Very cool!

expect(screen.getByText(displayName)).toBeDefined();
});

// TODO EM: I think this should be a <Link /> so that it's easier to test.
Copy link
Owner

Choose a reason for hiding this comment

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

I have no complaints about moving all href -> Link

Should I commit that on this branch before merging?

@@ -20,7 +20,7 @@ export default function MinimalStatBoxView({ userDisplayName, reviews }: Minimal
);

// destructure if not null, or set all to undefined
const { numReviews, ppwString, ppwColor } = getReviewStats(reviews) || {};
const { numReviews, ppwString, ppwColor } = getReviewStats(reviews);
Copy link
Owner

Choose a reason for hiding this comment

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

Hmm no, I think what you have is safe.
The reviews arg is typed to be Review[] so TS compiler would've complained if there were a valid route to passing undefined or null instead, right?

import NotFound from './NotFound';

describe('<NotFound />', () => {
it('shows a stupid compass lol?', () => {
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 cyber-bullying

Let's hire Re'em to make a 404 page

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Jokes aside, I think that'd be a really nice gesture


it('the second one redirects to the form page', () => {
renderWithRouterRedux(<PaperSearchBar />, { redirectTo: '/form' });
userEvent.click(screen.getAllByText(/Create Manual Entry/)[1]);
Copy link
Owner

Choose a reason for hiding this comment

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

Okay nice, I was wondering how this would get resolved 👀

@eshedmargalit eshedmargalit merged commit b212687 into react-ts Jan 10, 2021
@eshedmargalit eshedmargalit deleted the inc-ui-test-4 branch January 10, 2021 20:48
eshedmargalit pushed a commit that referenced this pull request Apr 15, 2021
* shhhh is okay

* self review feedback

* Basic FrequencyChart tests

* Login tests

* MenuBar tests

* test todos

* Remove impossible conclusion

* safe assertion, I hope

* NotFound test

* bare bones paper search

* more paper search tests

* whoo, that should be it!

* display --> displayName
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