-
Notifications
You must be signed in to change notification settings - Fork 631
/
Copy pathdetails.spec.tsx
69 lines (62 loc) · 2.18 KB
/
details.spec.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { Provider } from 'react-redux';
import * as Router from 'react-router-dom';
import { mount, ReactWrapper } from 'enzyme';
import store from '@console/internal/redux';
import { DetailsPage, DetailsPageProps } from '@console/internal/components/factory/details';
import { PodModel, ConfigMapModel } from '@console/internal/models';
import { referenceForModel } from '@console/internal/module/k8s';
import { Firehose } from '@console/internal/components/utils';
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: jest.fn(),
useLocation: jest.fn(),
}));
describe(DetailsPage.displayName, () => {
let wrapper: ReactWrapper<DetailsPageProps>;
beforeEach(() => {
// Need full mount with redux store since this is a redux-connected component
jest.spyOn(Router, 'useParams').mockReturnValue({ ns: 'default' });
jest.spyOn(Router, 'useLocation').mockReturnValue({ pathname: '' });
wrapper = mount(
<DetailsPage
name="test-name"
namespace="default"
kind={referenceForModel(PodModel)}
pages={[]}
kindObj={PodModel}
/>,
{
wrappingComponent: ({ children }) => (
<Provider store={store}>
<Router.BrowserRouter>{children}</Router.BrowserRouter>
</Provider>
),
},
);
});
it('renders a `Firehose` using the given props', () => {
expect(wrapper.find<any>(Firehose).props().resources[0]).toEqual({
kind: referenceForModel(PodModel),
name: 'test-name',
namespace: 'default',
isList: false,
prop: 'obj',
});
});
it('adds extra resources to `Firehose` if provided in props', () => {
const resources = [
{
kind: referenceForModel(ConfigMapModel),
name: 'test-configmap',
namespace: 'kube-system',
isList: false,
prop: 'configMap',
},
];
wrapper = wrapper.setProps({ resources, kindObj: ConfigMapModel });
expect(wrapper.find<any>(Firehose).props().resources.length).toEqual(resources.length + 1);
resources.forEach((resource, i) => {
expect(wrapper.find<any>(Firehose).props().resources[i + 1]).toEqual(resource);
});
});
});