Skip to content
This repository has been archived by the owner on Dec 21, 2021. It is now read-only.

More frontend tests #56

Merged
merged 37 commits into from Sep 14, 2018
Merged

More frontend tests #56

merged 37 commits into from Sep 14, 2018

Conversation

woosie10
Copy link
Contributor

@woosie10 woosie10 commented Sep 3, 2018

No description provided.

@woosie10 woosie10 changed the title [WIP] More frontend tests More frontend tests Sep 12, 2018
let wrapper;

beforeEach(() => {
props = {
Copy link
Contributor

Choose a reason for hiding this comment

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

there is an issue with react-dropzone that is generating an error:
react-dropzone/react-dropzone#554

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

it('should render to right', () => {
wrapper.setProps({ menuOffsetDirection: 'right' });
expect(wrapper.find('.menu').prop('style')).toHaveProperty('left', -30);
expect(wrapper.find('.menu').prop('style')).toHaveProperty('right', undefined);
Copy link
Contributor

Choose a reason for hiding this comment

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

these two expect expressions could be merged into one like in this example:

 expect(wrapper.find('.video-stream img').prop('style')).toEqual({width: 600,height:450})

Copy link
Contributor

Choose a reason for hiding this comment

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

As we discussed, this would not be a good idea in this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a recommendation to use .toBeUndefined() when checking for undefined.
https://jestjs.io/docs/en/expect#tobeundefined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

it('should not propagate click', () => {
wrapper.simulate('click', mockClickEvent);
expect(mockClickEvent.stopPropagation).toBeCalled();
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

We agreed on the following:
-Use .toHaveLength() to check for element existence, because it also checks if it exists only once.
-In the future, use .hasClass() where applicable. It's not worth the effort to rewrite anything for this now.
-Use .prop('disabled') to check for disabled status, instead of .find([disabled])
-Use toBe() when not comparing objects.
-Use .prop('key') instead of .props().key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

it('should call onSubmitHandler when form is submitted', () => {
wrapper.simulate('submit', mockClickEvent);
expect(props.onSubmitHandler).toHaveBeenCalled();
expect(wrapper.state().submitted).toEqual(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

I propose to use state() as we agreed in the case of props().
state('key') instead of state().key

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

import * as React from 'react';
import { shallow } from 'enzyme';
import { UnmountClosed } from 'react-collapse';
Copy link
Contributor

Choose a reason for hiding this comment

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

This import should be a few lines below in the component list.

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 normally put external imports at the top, then our components under // components. react-collapse is an external import.

wrapper.find('.label').simulate('click', mockClickEvent);
expect(wrapper.find('.visible')).toHaveLength(1);
wrapper.find('.label').simulate('click', mockClickEvent);
expect(wrapper.find('.visible').exists()).toEqual(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason here for having 2 different patterns to check for the existence of an element with this class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not, the first checks that it's open, the the second checks that it's closed

Copy link
Contributor

@ImreBognarUltimaker ImreBognarUltimaker left a comment

Choose a reason for hiding this comment

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

Please take a look at the comments.

@ImreBognarUltimaker
Copy link
Contributor

Everything looks good.

@woosie10 woosie10 merged commit e8a85be into master Sep 14, 2018
@woosie10 woosie10 deleted the more-frontend-test branch September 14, 2018 09:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants