Skip to content

Commit

Permalink
Refactor to DRY up test fixture data into helper file
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Aug 27, 2019
1 parent 0ac48a0 commit 9c3e5c0
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`TemplateSelectorItem Basic rendering renders with required props 1`] = `
<button
className="template-selector-item__label"
id="1-test-template"
id="13-test-template"
onClick={[Function]}
onMouseEnter={[Function]}
type="button"
Expand All @@ -29,7 +29,7 @@ exports[`TemplateSelectorItem Basic rendering renders with required props 1`] =
exports[`TemplateSelectorItem Dynamic previews renders in dynamic preview mode 1`] = `
<button
className="template-selector-item__label"
id="1-test-template"
id="13-test-template"
onClick={[Function]}
onMouseEnter={[Function]}
type="button"
Expand All @@ -54,7 +54,7 @@ exports[`TemplateSelectorItem Dynamic previews renders in dynamic preview mode 1
"noTopSpacing": false,
"textTransform": "",
},
"clientId": "2",
"clientId": "1",
"innerBlocks": Array [],
"isValid": true,
"name": "core/paragraph",
Expand All @@ -71,7 +71,7 @@ exports[`TemplateSelectorItem Dynamic previews renders in dynamic preview mode 1
"noTopSpacing": false,
"textTransform": "",
},
"clientId": "3",
"clientId": "2",
"innerBlocks": Array [],
"isValid": true,
"name": "core/paragraph",
Expand All @@ -88,7 +88,7 @@ exports[`TemplateSelectorItem Dynamic previews renders in dynamic preview mode 1
"noTopSpacing": false,
"textTransform": "",
},
"clientId": "4",
"clientId": "3",
"innerBlocks": Array [],
"isValid": true,
"name": "core/paragraph",
Expand All @@ -105,7 +105,7 @@ exports[`TemplateSelectorItem Dynamic previews renders in dynamic preview mode 1
"noTopSpacing": false,
"textTransform": "",
},
"clientId": "5",
"clientId": "4",
"innerBlocks": Array [],
"isValid": true,
"name": "core/paragraph",
Expand All @@ -124,7 +124,7 @@ exports[`TemplateSelectorItem Dynamic previews renders in dynamic preview mode 1
"noTopSpacing": false,
"textTransform": "",
},
"clientId": "6",
"clientId": "5",
"innerBlocks": Array [],
"isValid": true,
"name": "core/paragraph",
Expand All @@ -141,7 +141,7 @@ exports[`TemplateSelectorItem Dynamic previews renders in dynamic preview mode 1
"noTopSpacing": false,
"textTransform": "",
},
"clientId": "7",
"clientId": "6",
"innerBlocks": Array [],
"isValid": true,
"name": "core/paragraph",
Expand All @@ -158,7 +158,7 @@ exports[`TemplateSelectorItem Dynamic previews renders in dynamic preview mode 1
"noTopSpacing": false,
"textTransform": "",
},
"clientId": "8",
"clientId": "7",
"innerBlocks": Array [],
"isValid": true,
"name": "core/paragraph",
Expand All @@ -175,7 +175,7 @@ exports[`TemplateSelectorItem Dynamic previews renders in dynamic preview mode 1
"noTopSpacing": false,
"textTransform": "",
},
"clientId": "9",
"clientId": "8",
"innerBlocks": Array [],
"isValid": true,
"name": "core/paragraph",
Expand All @@ -194,7 +194,7 @@ exports[`TemplateSelectorItem Dynamic previews renders in dynamic preview mode 1
"noTopSpacing": false,
"textTransform": "",
},
"clientId": "10",
"clientId": "9",
"innerBlocks": Array [],
"isValid": true,
"name": "core/paragraph",
Expand All @@ -211,7 +211,7 @@ exports[`TemplateSelectorItem Dynamic previews renders in dynamic preview mode 1
"noTopSpacing": false,
"textTransform": "",
},
"clientId": "11",
"clientId": "10",
"innerBlocks": Array [],
"isValid": true,
"name": "core/paragraph",
Expand All @@ -228,7 +228,7 @@ exports[`TemplateSelectorItem Dynamic previews renders in dynamic preview mode 1
"noTopSpacing": false,
"textTransform": "",
},
"clientId": "12",
"clientId": "11",
"innerBlocks": Array [],
"isValid": true,
"name": "core/paragraph",
Expand All @@ -245,7 +245,7 @@ exports[`TemplateSelectorItem Dynamic previews renders in dynamic preview mode 1
"noTopSpacing": false,
"textTransform": "",
},
"clientId": "13",
"clientId": "12",
"innerBlocks": Array [],
"isValid": true,
"name": "core/paragraph",
Expand All @@ -269,7 +269,7 @@ exports[`TemplateSelectorItem Dynamic previews renders in dynamic preview mode 1
exports[`TemplateSelectorItem Static previews renders in static preview mode by default 1`] = `
<button
className="template-selector-item__label"
id="1-test-template"
id="13-test-template"
onClick={[Function]}
onMouseEnter={[Function]}
type="button"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* External dependencies
*/
import { uniqueId, range } from 'lodash';

export const templatesFixture = [
{
slug: 'template-1',
title: 'Template 1',
preview: 'https://via.placeholder.com/350x150',
previewAlt: 'Testing alt',
},
{
slug: 'template-2',
title: 'Template 2',
preview: 'https://via.placeholder.com/300x250',
previewAlt: 'Testing alt 2',
},
{
slug: 'template-3',
title: 'Template 3',
preview: 'https://via.placeholder.com/500x200',
previewAlt: 'Testing alt 3',
},
];

export const blocksByTemplatesFixture = templatesFixture.reduce( ( acc, curr ) => {
acc[ curr.slug ] = range( 4 ).map( () => {
return {
clientId: uniqueId(),
name: 'core/paragraph',
isValid: true,
attributes: {
align: 'left',
content:
'Visitors will want to know who is on the other side of the page. Use this space to write about yourself, your site, your business, or anything you want. Use the testimonials below to quote others, talking about the same thing – in their own words.',
dropCap: false,
fontWeight: '',
textTransform: '',
noBottomSpacing: false,
noTopSpacing: false,
coblocks: [],
},
innerBlocks: [],
originalContent:
'<p style="text-align:left;">Visitors will want to know who is on the other side of the page. Use this space to write about yourself, your site, your business, or anything you want. Use the testimonials below to quote others, talking about the same thing – in their own words.</p>',
};
} );
return acc;
}, {} );
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* External dependencies
*/
import { uniqueId, range } from 'lodash';
import { uniqueId } from 'lodash';
import { shallow } from 'enzyme';
import { templatesFixture, blocksByTemplatesFixture } from './helpers/templates-blocks-helpers';
import { TemplateSelectorControl } from '../template-selector-control';

describe( 'TemplateSelectorControl', () => {
Expand All @@ -11,60 +12,14 @@ describe( 'TemplateSelectorControl', () => {
vertical: 'Business',
};

const templates = [
{
slug: 'template-1',
title: 'Template 1',
preview: 'https://via.placeholder.com/350x150',
previewAlt: 'Testing alt',
},
{
slug: 'template-2',
title: 'Template 2',
preview: 'https://via.placeholder.com/300x250',
previewAlt: 'Testing alt 2',
},
{
slug: 'template-3',
title: 'Template 3',
preview: 'https://via.placeholder.com/500x200',
previewAlt: 'Testing alt 3',
},
];

const blocksByTemplates = templates.reduce( ( acc, curr ) => {
acc[ curr.slug ] = range( 4 ).map( () => {
return {
clientId: uniqueId(),
name: 'core/paragraph',
isValid: true,
attributes: {
align: 'left',
content:
'Visitors will want to know who is on the other side of the page. Use this space to write about yourself, your site, your business, or anything you want. Use the testimonials below to quote others, talking about the same thing – in their own words.',
dropCap: false,
fontWeight: '',
textTransform: '',
noBottomSpacing: false,
noTopSpacing: false,
coblocks: [],
},
innerBlocks: [],
originalContent:
'<p style="text-align:left;">Visitors will want to know who is on the other side of the page. Use this space to write about yourself, your site, your business, or anything you want. Use the testimonials below to quote others, talking about the same thing – in their own words.</p>',
};
} );
return acc;
}, {} );

describe( 'Basic rendering', () => {
it( 'renders with required props', () => {
const wrapper = shallow(
<TemplateSelectorControl
label="Select a Template..."
instanceId={ uniqueId() }
templates={ templates }
blocksByTemplates={ blocksByTemplates }
templates={ templatesFixture }
blocksByTemplates={ blocksByTemplatesFixture }
siteInformation={ siteInformation }
/>
);
Expand All @@ -77,7 +32,7 @@ describe( 'TemplateSelectorControl', () => {
<TemplateSelectorControl
label="Select a Template..."
instanceId={ uniqueId() }
blocksByTemplates={ blocksByTemplates }
blocksByTemplates={ blocksByTemplatesFixture }
/>
);

Expand All @@ -90,7 +45,7 @@ describe( 'TemplateSelectorControl', () => {
label="Select a Template..."
instanceId={ uniqueId() }
templates={ 'evil stuff here' }
blocksByTemplates={ blocksByTemplates }
blocksByTemplates={ blocksByTemplatesFixture }
/>
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/**
* External dependencies
*/
import { uniqueId, omit, range } from 'lodash';
import { uniqueId, omit } from 'lodash';
import { shallow } from 'enzyme';
import TemplateSelectorItem from '../template-selector-item';
import { blocksByTemplatesFixture } from './helpers/templates-blocks-helpers';

describe( 'TemplateSelectorItem', () => {
const requiredProps = {
Expand All @@ -13,52 +14,6 @@ describe( 'TemplateSelectorItem', () => {
staticPreviewImg: 'https://somepreviewimage.jpg',
};

const templates = [
{
slug: 'template-1',
title: 'Template 1',
preview: 'https://via.placeholder.com/350x150',
previewAlt: 'Testing alt',
},
{
slug: 'template-2',
title: 'Template 2',
preview: 'https://via.placeholder.com/300x250',
previewAlt: 'Testing alt 2',
},
{
slug: 'template-3',
title: 'Template 3',
preview: 'https://via.placeholder.com/500x200',
previewAlt: 'Testing alt 3',
},
];

const blocksByTemplates = templates.reduce( ( acc, curr ) => {
acc[ curr.slug ] = range( 4 ).map( () => {
return {
clientId: uniqueId(),
name: 'core/paragraph',
isValid: true,
attributes: {
align: 'left',
content:
'Visitors will want to know who is on the other side of the page. Use this space to write about yourself, your site, your business, or anything you want. Use the testimonials below to quote others, talking about the same thing – in their own words.',
dropCap: false,
fontWeight: '',
textTransform: '',
noBottomSpacing: false,
noTopSpacing: false,
coblocks: [],
},
innerBlocks: [],
originalContent:
'<p style="text-align:left;">Visitors will want to know who is on the other side of the page. Use this space to write about yourself, your site, your business, or anything you want. Use the testimonials below to quote others, talking about the same thing – in their own words.</p>',
};
} );
return acc;
}, {} );

describe( 'Basic rendering', () => {
it( 'renders with required props', () => {
const wrapper = shallow( <TemplateSelectorItem { ...requiredProps } /> );
Expand Down Expand Up @@ -158,7 +113,7 @@ describe( 'TemplateSelectorItem', () => {
<TemplateSelectorItem
{ ...requiredProps }
useDynamicPreview={ true }
blocks={ blocksByTemplates }
blocks={ blocksByTemplatesFixture }
/>
);

Expand Down

0 comments on commit 9c3e5c0

Please sign in to comment.