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: CollectionControl #13656

Merged
merged 3 commits into from
Apr 5, 2021
Merged

Conversation

yardz
Copy link
Contributor

@yardz yardz commented Mar 16, 2021

SUMMARY

Tests for CollectionControl component

TEST PLAN

No behavior changes. All tests must pass.


test('Should render', () => {
render(<CollectionControl {...defaultProps} />);
expect(screen.getByTestId('CollectionControl')).toBeInTheDocument();
Copy link
Member

Choose a reason for hiding this comment

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

Just a tip, if you can't assign any reasonable role to the container component, you can always access it using:

const { container } = render(<CollectionControl {...defaultProps} />);
expect(container).toBeInTheDocument();

😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know, but I avoid using const {container} = render() as much as possible. I find it more reliable to use screen methods. I've had some problems with containers, so I avoid them whenever is possible.

Copy link
Member

Choose a reason for hiding this comment

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

I'm curious what sort of problems you were running into there that might be worth avoiding them for. I like @michael-s-molina 's implementation - it's clean, and it makes less noise in the DOM.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rusackas It was not in this specific case. But in the past I've had problems that container had a very different result than screen. As screen is theoretically the HTML that will be rendered in the browser, I prefer to use it. Any change in behavior or configuration will not change the test result. That way I'm sure the test is right.

I only use container when I'm doing unit tests, and even in these cases I avoid it as much as possible.

Copy link
Member

@michael-s-molina michael-s-molina Mar 26, 2021

Choose a reason for hiding this comment

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

@yardz I don't know if in the past the implementation was different. Nowadays it's very similar. It will be different when we specify a container for render that is not the default.

Screen Shot 2021-03-26 at 11 32 38 AM

Screen Shot 2021-03-26 at 11 33 05 AM

Kent C. Dodds in his excellent article Common mistakes with React Testing Library recommends using screen whenever possible to avoid destructuring.

Screen Shot 2021-03-26 at 11 34 01 AM

I also think we should always use screen. That being said, in the case where we CANNOT find a satisfactory role/text/placeholder for our top component and we just want to test that the div has rendered, both test-id or container are valid options. Since both options are not accessible, I prefer the one where we don't leave fingerprints in the component's code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very nice post, several tips!

Well, I don't think that adding this test-id has any negative side effects at any level so the discussion comes down to "use or not the test-id." When it comes down to that it seems to me more like a discussion of "taste" than of "good practices".

If you think this is a block for the merge I can change it.

Copy link
Member

Choose a reason for hiding this comment

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

@yardz For me, it's not a blocker as indicated by the ✔️.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have not seen it haha

@codecov
Copy link

codecov bot commented Mar 22, 2021

Codecov Report

Merging #13656 (33f15c6) into master (df5fb5a) will decrease coverage by 0.13%.
The diff coverage is 78.39%.

❗ Current head 33f15c6 differs from pull request most recent head 134e298. Consider uploading reports for the commit 134e298 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #13656      +/-   ##
==========================================
- Coverage   77.35%   77.22%   -0.14%     
==========================================
  Files         918      934      +16     
  Lines       46652    47414     +762     
  Branches     5723     5921     +198     
==========================================
+ Hits        36087    36614     +527     
- Misses      10429    10658     +229     
- Partials      136      142       +6     
Flag Coverage Δ
cypress 56.03% <50.95%> (-0.54%) ⬇️
javascript 63.64% <71.59%> (+0.58%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...erset-frontend/src/SqlLab/components/SqlEditor.jsx 56.01% <ø> (ø)
...et-frontend/src/SqlLab/components/TableElement.jsx 88.37% <ø> (ø)
superset-frontend/src/chart/chartReducer.ts 66.19% <ø> (+1.81%) ⬆️
...ontend/src/common/hooks/usePrevious/usePrevious.ts 100.00% <ø> (ø)
...ontend/src/components/CertifiedIconWithTooltip.tsx 54.54% <0.00%> (-5.46%) ⬇️
...rset-frontend/src/components/ErrorMessage/types.ts 100.00% <ø> (ø)
...et-frontend/src/components/TableView/TableView.tsx 96.42% <ø> (ø)
...et-frontend/src/dashboard/actions/nativeFilters.ts 60.00% <ø> (-4.11%) ⬇️
...end/src/dashboard/components/StickyVerticalBar.tsx 100.00% <ø> (ø)
...end/src/dashboard/components/dnd/DragDroppable.jsx 97.29% <ø> (ø)
... and 175 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update df5fb5a...134e298. Read the comment docs.

Copy link
Member

@geido geido left a comment

Choose a reason for hiding this comment

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

LGTM except for a nit and Michael's comments

@rusackas
Copy link
Member

rusackas commented Apr 5, 2021

/testenv up

Copy link
Member

@rusackas rusackas left a comment

Choose a reason for hiding this comment

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

LGTM

@pkdotson pkdotson merged commit 555d7bb into apache:master Apr 5, 2021
@yardz yardz deleted the test-CollectionControl branch April 5, 2021 19:11
@github-actions
Copy link
Contributor

github-actions bot commented Apr 5, 2021

@rusackas Ephemeral environment spinning up at http://54.191.3.22:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

lyndsiWilliams pushed a commit to preset-io/superset that referenced this pull request Apr 7, 2021
* Tests for CollectionControl

* add role to icon

* applying factory to props
allanco91 pushed a commit to allanco91/superset that referenced this pull request May 21, 2021
* Tests for CollectionControl

* add role to icon

* applying factory to props
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.2.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels test:component 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants