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

Commit

Permalink
fix(async-mapper): add tests for asyncMapper in DrupalPage
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Wensink committed Mar 18, 2018
1 parent 45e1fda commit 7a214a0
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 57 deletions.
7 changes: 5 additions & 2 deletions src/components/DrupalPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,13 @@ class DrupalPage extends Component {
}

DrupalPage.propTypes = {
asyncMapper: PropTypes.bool,
asyncMapper: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.oneOfType([PropTypes.shape(), PropTypes.func]),
]),
layout: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
layoutProps: PropTypes.shape(),
mapper: PropTypes.oneOfType([PropTypes.shape(), PropTypes.func]).isRequired,
mapper: PropTypes.oneOfType([PropTypes.shape(), PropTypes.func]),
pageProps: PropTypes.shape(),
renderWhileLoadingData: PropTypes.bool,
url: PropTypes.string.isRequired,
Expand Down
39 changes: 38 additions & 1 deletion src/components/DrupalPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import renderer from 'react-test-renderer';
import site from '../utils/site';
import waitForHnData from '../utils/waitForHnData';
import { mapper } from '../utils/tests';
import { asyncMapper, mapper } from '../utils/tests';

jest.mock('../utils/site', () => {
return require('../utils/tests').mockSite();
Expand Down Expand Up @@ -47,4 +47,41 @@ describe('DrupalPage', async () => {
renderer.create(await waitForHnData(component)).toJSON(),
).toMatchSnapshot();
});

test('with asyncMapper', async () => {
const component = (
<DrupalPage
asyncMapper={asyncMapper}
url={'/'}
layoutProps={{ testLayoutProp: true }}
renderWhileLoadingData={true}
pageProps={{ testPageProp: true }}
/>
);

expect(renderer.create(component).toJSON()).toMatchSnapshot();

expect(
renderer.create(await waitForHnData(component)).toJSON(),
).toMatchSnapshot();
});

test('with asyncMapper as boolean (deprecated)', async () => {
const component = (
<DrupalPage
asyncMapper
mapper={asyncMapper}
url={'/'}
layoutProps={{ testLayoutProp: true }}
renderWhileLoadingData={true}
pageProps={{ testPageProp: true }}
/>
);

expect(renderer.create(component).toJSON()).toMatchSnapshot();

expect(
renderer.create(await waitForHnData(component)).toJSON(),
).toMatchSnapshot();
});
});
80 changes: 80 additions & 0 deletions src/components/__snapshots__/DrupalPage.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,86 @@ exports[`DrupalPage with all props 2`] = `
</div>
`;

exports[`DrupalPage with asyncMapper 1`] = `null`;

exports[`DrupalPage with asyncMapper 2`] = `
<div
bundle="unique_type_1__unique_bundle_1"
className="MyCustomMapperComponent"
entity={
Object {
"__hn": Object {
"entity": Object {
"bundle": "unique_bundle_1",
"type": "unique_type_1",
},
},
}
}
page={
Object {
"__hn": Object {
"entity": Object {
"bundle": "unique_bundle_1",
"type": "unique_type_1",
},
},
}
}
paragraph={
Object {
"__hn": Object {
"entity": Object {
"bundle": "unique_bundle_1",
"type": "unique_type_1",
},
},
}
}
testPageProp={true}
/>
`;

exports[`DrupalPage with asyncMapper as boolean (deprecated) 1`] = `null`;

exports[`DrupalPage with asyncMapper as boolean (deprecated) 2`] = `
<div
bundle="unique_type_1__unique_bundle_1"
className="MyCustomMapperComponent"
entity={
Object {
"__hn": Object {
"entity": Object {
"bundle": "unique_bundle_1",
"type": "unique_type_1",
},
},
}
}
page={
Object {
"__hn": Object {
"entity": Object {
"bundle": "unique_bundle_1",
"type": "unique_type_1",
},
},
}
}
paragraph={
Object {
"__hn": Object {
"entity": Object {
"bundle": "unique_bundle_1",
"type": "unique_type_1",
},
},
}
}
testPageProp={true}
/>
`;

exports[`DrupalPage with required props 1`] = `null`;

exports[`DrupalPage with required props 2`] = `
Expand Down
54 changes: 0 additions & 54 deletions src/components/__snapshots__/EntityMapper.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -54,60 +54,6 @@ exports[`EntityMapper asyncMapper as boolean (deprecated) 2`] = `
/>
`;

exports[`EntityMapper asyncMapper as boolean 1`] = `
<div
bundle="unique_type_1__unique_bundle_1"
className="MyCustomMapperComponent"
entity={
Object {
"__hn": Object {
"entity": Object {
"bundle": "unique_bundle_1",
"type": "unique_type_1",
},
},
}
}
paragraph={
Object {
"__hn": Object {
"entity": Object {
"bundle": "unique_bundle_1",
"type": "unique_type_1",
},
},
}
}
/>
`;

exports[`EntityMapper asyncMapper as boolean 2`] = `
<div
bundle="unique_type_1__unique_bundle_1"
className="MyCustomMapperComponent"
entity={
Object {
"__hn": Object {
"entity": Object {
"bundle": "unique_bundle_1",
"type": "unique_type_1",
},
},
}
}
paragraph={
Object {
"__hn": Object {
"entity": Object {
"bundle": "unique_bundle_1",
"type": "unique_type_1",
},
},
}
}
/>
`;

exports[`EntityMapper non-existing entity 1`] = `null`;

exports[`EntityMapper non-existing entity 2`] = `null`;
Expand Down

0 comments on commit 7a214a0

Please sign in to comment.