Skip to content
This repository was archived by the owner on Mar 27, 2018. It is now read-only.

Commit b2336b5

Browse files
committed
test(drupal-page): add initial tests for DrupalPage
1 parent 8ba0d63 commit b2336b5

File tree

3 files changed

+163
-0
lines changed

3 files changed

+163
-0
lines changed

src/components/DrupalPage.test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import DrupalPage from './DrupalPage';
2+
import React from 'react';
3+
import renderer from 'react-test-renderer';
4+
import site from '../utils/site';
5+
import waitForHnData from '../utils/waitForHnData';
6+
import { mapper } from '../utils/tests';
7+
8+
jest.mock('../utils/site', () => {
9+
return require('../utils/tests').mockSite();
10+
});
11+
12+
jest.mock('util-deprecate', () => jest.fn((func) => func));
13+
console.log = console.warn = console.error = jest.fn((message) => { throw new Error(message); });
14+
15+
beforeEach(() => {
16+
site.getData.mockRestore();
17+
});
18+
19+
describe('DrupalPage', async () => {
20+
21+
test('with required props', async () => {
22+
const component = (
23+
<DrupalPage
24+
mapper={mapper}
25+
url={'/'}
26+
/>
27+
);
28+
29+
expect(renderer.create(component).toJSON()).toMatchSnapshot();
30+
31+
expect(renderer.create(
32+
await waitForHnData(component)
33+
).toJSON()).toMatchSnapshot();
34+
});
35+
36+
test('with all props', async () => {
37+
const component = (
38+
<DrupalPage
39+
mapper={mapper}
40+
url={'/'}
41+
layout={'div'}
42+
layoutProps={{'testLayoutProp': true}}
43+
renderWhileLoadingData={true}
44+
pageProps={{'testPageProp': true}}
45+
/>
46+
);
47+
48+
expect(renderer.create(component).toJSON()).toMatchSnapshot();
49+
50+
expect(renderer.create(
51+
await waitForHnData(component)
52+
).toJSON()).toMatchSnapshot();
53+
54+
});
55+
});
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`DrupalPage with all props 1`] = `
4+
<div
5+
loadingData={true}
6+
page={null}
7+
testLayoutProp={true}
8+
url={null}
9+
/>
10+
`;
11+
12+
exports[`DrupalPage with all props 2`] = `
13+
<div
14+
loadingData={false}
15+
page={
16+
Object {
17+
"__hn": Object {
18+
"entity": Object {
19+
"bundle": "unique_bundle",
20+
"type": "unique_type",
21+
},
22+
},
23+
}
24+
}
25+
testLayoutProp={true}
26+
url="/"
27+
>
28+
<div
29+
bundle="unique_type__unique_bundle"
30+
className="MyCustomMapperComponent"
31+
entity={
32+
Object {
33+
"__hn": Object {
34+
"entity": Object {
35+
"bundle": "unique_bundle",
36+
"type": "unique_type",
37+
},
38+
},
39+
}
40+
}
41+
index={0}
42+
page={
43+
Object {
44+
"__hn": Object {
45+
"entity": Object {
46+
"bundle": "unique_bundle",
47+
"type": "unique_type",
48+
},
49+
},
50+
}
51+
}
52+
paragraph={
53+
Object {
54+
"__hn": Object {
55+
"entity": Object {
56+
"bundle": "unique_bundle",
57+
"type": "unique_type",
58+
},
59+
},
60+
}
61+
}
62+
testPageProp={true}
63+
/>
64+
</div>
65+
`;
66+
67+
exports[`DrupalPage with required props 1`] = `null`;
68+
69+
exports[`DrupalPage with required props 2`] = `
70+
<div
71+
bundle="unique_type__unique_bundle"
72+
className="MyCustomMapperComponent"
73+
entity={
74+
Object {
75+
"__hn": Object {
76+
"entity": Object {
77+
"bundle": "unique_bundle",
78+
"type": "unique_type",
79+
},
80+
},
81+
}
82+
}
83+
index={0}
84+
page={
85+
Object {
86+
"__hn": Object {
87+
"entity": Object {
88+
"bundle": "unique_bundle",
89+
"type": "unique_type",
90+
},
91+
},
92+
}
93+
}
94+
paragraph={
95+
Object {
96+
"__hn": Object {
97+
"entity": Object {
98+
"bundle": "unique_bundle",
99+
"type": "unique_type",
100+
},
101+
},
102+
}
103+
}
104+
/>
105+
`;

src/utils/tests.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export function mockSite() {
2424
getData = jest.fn(() => {
2525
return entity;
2626
});
27+
getPage = jest.fn(async () => {
28+
return uuid;
29+
})
2730
}
2831
return new SiteMock();
2932
}

0 commit comments

Comments
 (0)