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

Add unit tests for ProjectsExistWrapper #3817

Merged
merged 1 commit into from Jan 6, 2020

Conversation

vikram-raj
Copy link
Member

@openshift-ci-robot openshift-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 20, 2019
@openshift-ci-robot openshift-ci-robot added the component/dev-console Related to dev-console label Dec 20, 2019
@vikram-raj vikram-raj changed the title Add unit test for ProjectsExistWrapper Add unit tests for ProjectsExistWrapper Dec 20, 2019
import * as _ from 'lodash';
import ProjectsExistWrapper from '../ProjectsExistWrapper';

const projects: any = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you create an interface for this object instead of using any?

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be the project prop using React.ComponentProps of the ProjectsExistsWrapper

hintBlock = 'Select a way to create an application, component or service from one of the options.',
}) => {
const activeNamespace = getActiveNamespace();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are using getActiveNamespace() here which directly hooks into the redux store variable and gives back the result? This is not a correct convention to use redux state and console code does it wrong. We should always use connect to get the values from redux state.

Copy link
Contributor

Choose a reason for hiding this comment

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

The old code was correct. Please revert changes to this file.

Comment on lines 54 to 55
name: 'cvogt',
selfLink: '/apis/project.openshift.io/v1/projects/cvogt',
Copy link
Contributor

Choose a reason for hiding this comment

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

Better if we use some test names & avoid any real usernames

Comment on lines 13 to 17
const wrapper = shallow(
<ProjectsExistWrapper title="Topology" projects={projects}>
{}
</ProjectsExistWrapper>,
);
Copy link
Member

Choose a reason for hiding this comment

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

nit: we can have this in beforeEach

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not used exactly the same in every test.

Copy link
Member Author

Choose a reason for hiding this comment

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

@invincibleJai It is different for each test. That is why I define it for each test.

hintBlock = 'Select a way to create an application, component or service from one of the options.',
}) => {
const activeNamespace = getActiveNamespace();
Copy link
Contributor

Choose a reason for hiding this comment

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

The old code was correct. Please revert changes to this file.

it('should render projects exist wrapper component', () => {
const wrapper = shallow(
<ProjectsExistWrapper title="Topology" projects={projects}>
{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove.

Copy link
Member Author

Choose a reason for hiding this comment

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

children is the required prop for ProjectsExistWrapper.

Comment on lines 13 to 17
const wrapper = shallow(
<ProjectsExistWrapper title="Topology" projects={projects}>
{}
</ProjectsExistWrapper>,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not used exactly the same in every test.

{}
</ProjectsExistWrapper>,
);
expect(wrapper).toBeTruthy();
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a useful test because I don't think this could ever fail.

import * as _ from 'lodash';
import ProjectsExistWrapper from '../ProjectsExistWrapper';

const projects: any = {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be the project prop using React.ComponentProps of the ProjectsExistsWrapper

{}
</ProjectsExistWrapper>,
);
expect(wrapper.find('LoadingBox').exists()).toBeTruthy();
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the component constructor and not a string.
find(LoadingBox)

</ProjectsExistWrapper>,
);
const hintBlock = shallow(wrapper.props().hintBlock);
expect(wrapper.find('ODCEmptyState').exists()).toBeTruthy();
Copy link
Contributor

Choose a reason for hiding this comment

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

This test should end on this line. The rest is testing static markup.

];
const wrapper = shallow(
<ProjectsExistWrapper title="Topology" projects={data}>
{() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a constant here and in the assertion below.

}}
</ProjectsExistWrapper>,
);
expect(wrapper.contains(<span>Child component</span>)).toBeTruthy();
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be more specific and assert that the only contents is the given children.

});

it('should show loading box', () => {
const data = _.cloneDeep(projects);
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be better to define default project props in beforeEach and have necessary overrides in each test case.

projects.loaded = false;
const wrapper = shallow(
<ProjectsExistWrapper title="Topology" projects={projects}>
{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you rendering an empty block of children instead of using a self closing tag? What's the point of {}

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 fixed it. I was thinking of something else.

{}
</ProjectsExistWrapper>,
);
const hintBlock = shallow(wrapper.props().hintBlock);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a useful test as you are testing another component other than the ProjectExistsWrapper and it is also not a conditional prop value.

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 just wanted to test the empty state here. If we have no projects then it should render the empty state.

Copy link
Contributor

Choose a reason for hiding this comment

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

If there are no projects assert presence of ODCEmptyState.

Avoid asserting the markup of a component not owned by the component you are testing. Your unit test becomes dependent on the implementation details of another component which is bad.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed this. Now, checking for only ODCEmptyState is present if no project it present.

@invincibleJai
Copy link
Member

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 24, 2019
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Dec 26, 2019
@invincibleJai
Copy link
Member

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 2, 2020
@andrewballantyne
Copy link
Contributor

/kind cleanup

@openshift-ci-robot openshift-ci-robot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Jan 2, 2020
Copy link
Contributor

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

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

/assign
/retest

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewballantyne, invincibleJai, vikram-raj

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 6, 2020
@openshift-merge-robot openshift-merge-robot merged commit 91fb810 into openshift:master Jan 6, 2020
@spadgett spadgett added this to the v4.4 milestone Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. component/dev-console Related to dev-console component/kubevirt Related to kubevirt-plugin kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants