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
Conversation
import * as _ from 'lodash'; | ||
import ProjectsExistWrapper from '../ProjectsExistWrapper'; | ||
|
||
const projects: any = { |
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.
Can you create an interface for this object instead of using any?
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 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(); |
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.
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.
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 old code was correct. Please revert changes to this file.
name: 'cvogt', | ||
selfLink: '/apis/project.openshift.io/v1/projects/cvogt', |
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.
Better if we use some test names & avoid any real usernames
const wrapper = shallow( | ||
<ProjectsExistWrapper title="Topology" projects={projects}> | ||
{} | ||
</ProjectsExistWrapper>, | ||
); |
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.
nit: we can have this in beforeEach
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.
It's not used exactly the same in every test.
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.
@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(); |
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 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}> | ||
{} |
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.
Remove.
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.
children
is the required prop for ProjectsExistWrapper
.
const wrapper = shallow( | ||
<ProjectsExistWrapper title="Topology" projects={projects}> | ||
{} | ||
</ProjectsExistWrapper>, | ||
); |
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.
It's not used exactly the same in every test.
{} | ||
</ProjectsExistWrapper>, | ||
); | ||
expect(wrapper).toBeTruthy(); |
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 a useful test because I don't think this could ever fail.
import * as _ from 'lodash'; | ||
import ProjectsExistWrapper from '../ProjectsExistWrapper'; | ||
|
||
const projects: any = { |
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 should be the project prop using React.ComponentProps of the ProjectsExistsWrapper
{} | ||
</ProjectsExistWrapper>, | ||
); | ||
expect(wrapper.find('LoadingBox').exists()).toBeTruthy(); |
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.
Use the component constructor and not a string.
find(LoadingBox)
</ProjectsExistWrapper>, | ||
); | ||
const hintBlock = shallow(wrapper.props().hintBlock); | ||
expect(wrapper.find('ODCEmptyState').exists()).toBeTruthy(); |
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 test should end on this line. The rest is testing static markup.
]; | ||
const wrapper = shallow( | ||
<ProjectsExistWrapper title="Topology" projects={data}> | ||
{() => { |
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.
Use a constant here and in the assertion below.
}} | ||
</ProjectsExistWrapper>, | ||
); | ||
expect(wrapper.contains(<span>Child component</span>)).toBeTruthy(); |
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 should be more specific and assert that the only contents is the given children.
}); | ||
|
||
it('should show loading box', () => { | ||
const data = _.cloneDeep(projects); |
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.
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}> | ||
{} |
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.
Why are you rendering an empty block of children instead of using a self closing tag? What's the point of {}
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 fixed it. I was thinking of something else.
{} | ||
</ProjectsExistWrapper>, | ||
); | ||
const hintBlock = shallow(wrapper.props().hintBlock); |
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 is not a useful test as you are testing another component other than the ProjectExistsWrapper and it is also not a conditional prop value.
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 just wanted to test the empty state here. If we have no projects then it should render the empty state.
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.
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.
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.
Fixed this. Now, checking for only ODCEmptyState
is present if no project it present.
/lgtm |
/lgtm |
/kind cleanup |
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.
/assign
/retest
[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 |
Task - https://issues.redhat.com/browse/ODC-2594