-
Notifications
You must be signed in to change notification settings - Fork 115
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
MNT Use React Testing Library #1052
MNT Use React Testing Library #1052
Conversation
2b15a72
to
93a0c67
Compare
93a0c67
to
38730c2
Compare
|
||
test('AbstractAction renders a DropdownItem', () => { | ||
const { container } = render(<AbstractAction {...makeProps()}/>); | ||
expect(container.querySelector('.dropdown-item')).not.toBeNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original test explicitly checked for 1 item. We should do the same here, if we only expect one item. I think this is important because there's no other way for us to detect duplicate buttons (behat won't flag it, for example)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also applies with many other assertions throughout this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not doing
test('ArchiveAction renders the wrapped component', () => { | ||
const { container } = render(<ActionComponent {...makeProps()}/>); | ||
expect(container.querySelector('button.element-editor__actions-archive').textContent).toBe('Archive'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems more like a mashup of "renders a button" and "renders the title and class" - what it isn't is "renders the wrapped component" since renders the wrapped component would be checking if the div is there.
I don't think it's worth checking for the wrapped component, but if you are gonna have a test for it, you'll need to add a css class or ID to the div and check that the div is rendered.
The button, class, and title checking tests can be mixed together, but the name of the test needs to make it clear that that's what we're testing for - and it should include the length === 1 check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This applies in other test files as well (e.g. for publish action)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not doing
|
||
test('Summary should render an image if the fileUrl prop is provided', () => { | ||
const { container } = render(<Summary {...makeProps()}/>); | ||
expect(container.querySelector('.element-editor-summary__thumbnail-image')).not.toBeNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's important here to check for an actual img
element here, since we want to check an image is actually rendered in the DOM. Bonus points for validating the correct src
even though the original didn't do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably thumbnail-image is an img
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can be explicit instead of presuming - this is meant to be a test of what the user experiences, isn't it? It feels important to validate that the user is experiencing an image, and not just some random DOM element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not doing
client/src/components/HistoricElementView/tests/HistoricElementView-test.js
Show resolved
Hide resolved
expect(link.textContent).toEqual('Block history'); | ||
}); | ||
}); | ||
test('HistoricElementView render ', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The space at the end there makes me wonder if you had meant to do some more work on this one (either come up with a more descriptive title or split this back out into the individual well-described tests from the original)?
If not, then this is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not doing
@GuySartorelli Rather than respond to all of the feedback individually, I've responded below to some common types of feedback below. This is applicable to all the other PRs because the same patterns of things will show up many times so I'm highlighting them now before all the other peer review is done. This means I'll be leaving lots of your individual pieces of feedback unanswered Using querySelectorAll() + .length
|
38730c2
to
aa558a9
Compare
Using querySelectorAll() + .length .toHaveLenth(n) rather than querySelector() + .not.toBeNull();The fact is, Please either change these tests to use
These aren't behat tests - they're a much lower level set of tests checking smaller "units" of functionality for individual components. We have the opportunity to test things here that we wouldn't test in behat and I don't think we should look at end-to-end tests for a measure of how we write our unit tests. Missing assertions e.g. original test tested a prop value, or a state value. The new test doesn't test this.Please reply to the individual comments for these - this is far too big a blanket, it's impossible for me to know which things I've flagged are covered by this and which you either didn't notice or forgot, etc. Test title is non-descriptiveThe test titles are important, as they describe what is being tested and therefore give developers a clue as to how the test should behave. If a test starts failing suddenly, the name of the test can be an important clue for what needs to change so that the test passes while still testing what it is meant to test. In the cases where I have flagged the name of a test, these are either scenarios where the new test does not test the same thing as the old test, or where the test is new, or where the title is duplicated (two tests with the same title). In all of the scenarios above, I think it is fair for me to expect a title that is descriptive of what the test is doing, since in these cases it's not just a one-to-one match with the old tests. Things such as "value passed to makeProps() is already in default props", we can could the value of "key", etcI would like to know if these were done intentionally, and if it's desirable to do it this way, since that will help me know in the future if these are intentional patterns that should be followed or if they were simply left as they are because it's not worth the effort to change. But I won't request any more changes or information about this so that we can avoid some ping pong on them. |
At this point there's a vast number of these assertions to fix (there's 2x other issues containing multiple PRs each). I'd rather programmatically fix everything in one go then have to fix everything individually. If you want this done then please raise a new card to do everything in one go after all the PRs are merged.
OK. I'll reply 'Not doing' to the things I'm not doing. This may seem like I'm just being lazy, though there's over 10,000 lines added so far in all the PRs so I'm genuinely concerned about getting burnt-out here by too many minor changes being asked for in peer review.
Again, there's far too many to change at this point. When I was transcribing these tests I don't really know what a lot of the tests were really doing other than usually testing a class method. So I usually just copy paste the old test title and use that. At this point I really don't know what the tests do as I would transcribe a test and then move on to the next. You probably have just as good an idea what these tests do just by looking at the PR. If you feel these need to be fixed, please raise a new card and it can be done retrospectively, though I doubt this will every get prioritized because it's simply too low value and because it's simply a long and boring task that I doubt anyone will want to do.
Maybe? Maybe at the time I thought it would make the tests easier to read? In all instances though stuff like this is of trivial importance and should be ignored. |
aa558a9
to
deb0a73
Compare
I've raised silverstripe/.github#43 for the outstanding changes. I'll action it. |
Issue silverstripe/silverstripe-admin#1419