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

1967 component tests content view #2169

Merged
merged 13 commits into from
Nov 27, 2019
Merged

Conversation

Mogge
Copy link
Member

@Mogge Mogge commented Nov 8, 2019

🍰 Pullrequest

Issues

Todo

  • There is a lot of repeating code, that can be condensed.

Copy link
Member

@mattwr18 mattwr18 left a comment

Choose a reason for hiding this comment

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

hey @Mogge, I really love your thoroughness in testing here, but I would love it if you could break these tests into common set up in beforeEach blocks, followed by it blocks with one expectation, only more if unable to test some outcome without multiple.

.attributes('to'),
).toBe('/post-menu-delete')
items.at(1).trigger('click')
expect(openModalSpy).toHaveBeenCalledWith('delete')
Copy link
Member

Choose a reason for hiding this comment

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

As we talked about briefly on Discord @Mogge, please try to avoid multiple expectations in the same it block... sometimes, it's kinda unavoidable, but in this case, I think it's not.

you can add a beforeEach inside describe contribution, which handles similar set up, then have one expectation per it block, describing what you are testing with the expect

.attributes('to'),
).toBe('/comment-menu-delete')
items.at(1).trigger('click')
expect(openModalSpy).toHaveBeenCalledWith('delete')
Copy link
Member

Choose a reason for hiding this comment

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

same as 👆

Copy link
Member Author

@Mogge Mogge Nov 13, 2019

Choose a reason for hiding this comment

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

I reduced the expectations to only one per it block. Now I am only checking that the methods are called correctly, and skipped all the tests of text, number of items etc.

.attributes('to'),
).toBe('/report-contribution-title')
items.at(0).trigger('click')
expect(openModalSpy).toHaveBeenCalledWith('report')
Copy link
Member

Choose a reason for hiding this comment

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

instead of setting up the method openModal as a spy, can we set up $store.commit as a mock, and check that is called with specific data?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried, but it is getting very complicated because y also have to mount the Modal component. I think we have to rely on the tests of the Modal component that the commits are called correctly (which as far as I can see is the case). I ensure in the tests of ContentMenu that the parameters are passed to Modal correctly.

Copy link
Member

Choose a reason for hiding this comment

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

I can see that, and as we discussed today, you are testing it up to one point, and there are other tests that take it further!!

@Mogge
Copy link
Member Author

Mogge commented Nov 13, 2019

I do not have a good feeling with using .at(number) to grab the menu items I want to test. This can end up in some painful work when new items are added. Can we find some convention to pass a properly defined class to the items, which has the only purpose to identify the item in the tests? Is there a way to add these classes only if we are testing? Does a component somehow know if it is tested or running in production?

@mattwr18
Copy link
Member

hey @Mogge can we pair on this? it would be nice to get it merged in, no?

@mattwr18
Copy link
Member

when can we pair on this @Mogge ... I seem to not be available when you are and vice versa...

@Mogge Mogge force-pushed the 1967-Component-Tests-ContentView branch from c1d3fb0 to 317b335 Compare November 27, 2019 10:19
@Mogge
Copy link
Member Author

Mogge commented Nov 27, 2019

As .filter returns an WrapperArray object, I have to chose the first with .at(0) to have an wrapper object to trigger the click. I do not understand how the example in ContributionForm.spec.js can work. How can you trigger a click on an WrapperArray?

@cypress
Copy link

cypress bot commented Nov 27, 2019



Test summary

48 0 0 0


Run details

Project Human-Connection
Status Passed
Commit b2f2783
Started Nov 27, 2019 2:18 PM
Ended Nov 27, 2019 2:33 PM
Duration 14:41 💡
OS Linux Ubuntu Linux - 16.04
Browser Chromium 78

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

Copy link
Member

@mattwr18 mattwr18 left a comment

Choose a reason for hiding this comment

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

great job! thanks for adding some filter() to make it more likely the tests won't break if someone adds a link!!!

.attributes('to'),
).toBe('/report-contribution-title')
items.at(0).trigger('click')
expect(openModalSpy).toHaveBeenCalledWith('report')
Copy link
Member

Choose a reason for hiding this comment

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

I can see that, and as we discussed today, you are testing it up to one point, and there are other tests that take it further!!

@mattwr18 mattwr18 merged commit 5d80eca into master Nov 27, 2019
@mattwr18 mattwr18 deleted the 1967-Component-Tests-ContentView branch November 27, 2019 17:03
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.

🤖 [TESTS] Add component tests for ContentMenu
2 participants