Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for ProjectsExistWrapper
- Loading branch information
1 parent
f625b90
commit 8cf732e
Showing
2 changed files
with
74 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
frontend/packages/dev-console/src/components/__tests__/ProjectsExistWrapper.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import * as React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import * as _ from 'lodash'; | ||
import ProjectsExistWrapper from '../ProjectsExistWrapper'; | ||
|
||
const projects: any = { | ||
data: [], | ||
loaded: true, | ||
}; | ||
|
||
describe('ProjectsExistWrapper', () => { | ||
it('should render projects exist wrapper component', () => { | ||
const wrapper = shallow( | ||
<ProjectsExistWrapper title="Topology" projects={projects}> | ||
{} | ||
</ProjectsExistWrapper>, | ||
); | ||
expect(wrapper).toBeTruthy(); | ||
}); | ||
|
||
it('should show loading box', () => { | ||
const data = _.cloneDeep(projects); | ||
data.loaded = false; | ||
const wrapper = shallow( | ||
<ProjectsExistWrapper title="Topology" projects={data}> | ||
{} | ||
</ProjectsExistWrapper>, | ||
); | ||
expect(wrapper.find('LoadingBox').exists()).toBeTruthy(); | ||
}); | ||
|
||
it('should show empty state hint block', () => { | ||
const wrapper = shallow( | ||
<ProjectsExistWrapper title="Topology" projects={projects}> | ||
{} | ||
</ProjectsExistWrapper>, | ||
); | ||
const hintBlock = shallow(wrapper.props().hintBlock); | ||
expect(wrapper.find('ODCEmptyState').exists()).toBeTruthy(); | ||
expect(hintBlock.find('h2.co-hint-block__title').contains('No projects exist')).toBeTruthy(); | ||
expect( | ||
hintBlock | ||
.find('.co-hint-block__body p') | ||
.contains( | ||
'Select one of the following options to create an application, component or service. As part of the creation process a project and application will be created.', | ||
), | ||
).toBeTruthy(); | ||
}); | ||
|
||
it('should return children when project exist', () => { | ||
const data = _.cloneDeep(projects); | ||
data.data = [ | ||
{ | ||
name: 'cvogt', | ||
selfLink: '/apis/project.openshift.io/v1/projects/cvogt', | ||
uid: '3afaa628-fde7-4afa-8800-281b7b11f4bf', | ||
resourceVersion: '91841', | ||
creationTimestamp: '2019-12-19T16:08:38Z', | ||
}, | ||
]; | ||
const wrapper = shallow( | ||
<ProjectsExistWrapper title="Topology" projects={data}> | ||
{() => { | ||
return <span>Child component</span>; | ||
}} | ||
</ProjectsExistWrapper>, | ||
); | ||
expect(wrapper.contains(<span>Child component</span>)).toBeTruthy(); | ||
}); | ||
}); |