Skip to content

Commit

Permalink
add redux page multi-component test --build-all
Browse files Browse the repository at this point in the history
  • Loading branch information
jbolda committed Sep 26, 2017
1 parent 6c1e622 commit 2cefaeb
Show file tree
Hide file tree
Showing 2 changed files with 257 additions and 0 deletions.
167 changes: 167 additions & 0 deletions packages/gatsby/src/redux/__tests__/__snapshots__/pages.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,45 @@ Array [
]
`;

exports[`Add pages allows you to add multiple pages each with multiple components 1`] = `
Array [
Object {
"component": Array [
"/whatever/index.js",
"/morewhatever/index.js",
],
"componentChunkName": Array [
"component---whatever-index-js",
"component---morewhatever-index-js",
],
"context": Object {},
"internalComponentName": "ComponentHi",
"jsonName": "hi.json",
"path": "/hi/",
"pluginCreatorId": "test",
"pluginCreator___NODE": "test",
"updatedAt": 1482363367071,
},
Object {
"component": Array [
"/whatever/index.js",
"/pizza/index.js",
],
"componentChunkName": Array [
"component---whatever-index-js",
"component---pizza-index-js",
],
"context": Object {},
"internalComponentName": "ComponentHiHotpizza",
"jsonName": "hi-hotpizza.json",
"path": "/hi/hotpizza/",
"pluginCreatorId": "test",
"pluginCreator___NODE": "test",
"updatedAt": 1482363367071,
},
]
`;

exports[`Add pages allows you to add pages 1`] = `
Object {
"payload": Object {
Expand Down Expand Up @@ -131,8 +170,114 @@ Array [
]
`;

exports[`Add pages allows you to add pages with context when using multiple components 1`] = `
Object {
"payload": Object {
"component": Array [
"/whatever/index.js",
"/differentwhatever/index.js",
],
"componentChunkName": Array [
"component---whatever-index-js",
"component---differentwhatever-index-js",
],
"context": Object {
"id": 123,
},
"internalComponentName": "ComponentHi",
"jsonName": "hi.json",
"path": "/hi/",
"pluginCreatorId": "test",
"pluginCreator___NODE": "test",
"updatedAt": 1482363367071,
},
"plugin": Object {
"id": "test",
"name": "test",
},
"traceId": undefined,
"type": "CREATE_PAGE",
}
`;

exports[`Add pages allows you to add pages with context when using multiple components 2`] = `
Array [
Object {
"component": Array [
"/whatever/index.js",
"/differentwhatever/index.js",
],
"componentChunkName": Array [
"component---whatever-index-js",
"component---differentwhatever-index-js",
],
"context": Object {
"id": 123,
},
"internalComponentName": "ComponentHi",
"jsonName": "hi.json",
"path": "/hi/",
"pluginCreatorId": "test",
"pluginCreator___NODE": "test",
"updatedAt": 1482363367071,
},
]
`;

exports[`Add pages allows you to add pages with multiple components 1`] = `
Object {
"payload": Object {
"component": Array [
"/whatever/index.js",
"/morewhatever/index.js",
],
"componentChunkName": Array [
"component---whatever-index-js",
"component---morewhatever-index-js",
],
"context": Object {},
"internalComponentName": "ComponentHi",
"jsonName": "hi.json",
"path": "/hi/",
"pluginCreatorId": "test",
"pluginCreator___NODE": "test",
"updatedAt": 1482363367071,
},
"plugin": Object {
"id": "test",
"name": "test",
},
"traceId": undefined,
"type": "CREATE_PAGE",
}
`;

exports[`Add pages allows you to add pages with multiple components 2`] = `
Array [
Object {
"component": Array [
"/whatever/index.js",
"/morewhatever/index.js",
],
"componentChunkName": Array [
"component---whatever-index-js",
"component---morewhatever-index-js",
],
"context": Object {},
"internalComponentName": "ComponentHi",
"jsonName": "hi.json",
"path": "/hi/",
"pluginCreatorId": "test",
"pluginCreator___NODE": "test",
"updatedAt": 1482363367071,
},
]
`;

exports[`Add pages allows you to delete paths 1`] = `Array []`;

exports[`Add pages allows you to delete paths that have multiple components 1`] = `Array []`;

exports[`Add pages allows you to update existing pages (based on path) 1`] = `
Array [
Object {
Expand All @@ -152,3 +297,25 @@ Array [
},
]
`;

exports[`Add pages allows you to update existing pages with multiple components (based on path) 1`] = `
Array [
Object {
"component": Array [
"/whateven/index.js",
"/supercereal/index.js",
],
"componentChunkName": Array [
"component---whateven-index-js",
"component---supercereal-index-js",
],
"context": Object {},
"internalComponentName": "ComponentHi",
"jsonName": "hi.json",
"path": "/hi/",
"pluginCreatorId": "test",
"pluginCreator___NODE": "test",
"updatedAt": 1482363367071,
},
]
`;
90 changes: 90 additions & 0 deletions packages/gatsby/src/redux/__tests__/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,94 @@ describe(`Add pages`, () => {
expect(state).toMatchSnapshot()
expect(state.length).toEqual(0)
})

it(`allows you to add pages with multiple components`, () => {
const action = actions.createPage(
{
path: `/hi/`,
component: [`/whatever/index.js`, `/morewhatever/index.js`],
},
{ id: `test`, name: `test` }
)
const state = reducer(undefined, action)
expect(action).toMatchSnapshot()
expect(state).toMatchSnapshot()
})

it(`allows you to add pages with context when using multiple components`, () => {
const action = actions.createPage(
{
path: `/hi/`,
component: [`/whatever/index.js`, `/differentwhatever/index.js`],
context: {
id: 123,
},
},
{ id: `test`, name: `test` }
)
const state = reducer(undefined, action)
expect(action).toMatchSnapshot()
expect(state).toMatchSnapshot()
})

it(`allows you to add multiple pages each with multiple components`, () => {
const action = actions.createPage(
{
path: `/hi/`,
component: [`/whatever/index.js`, `/morewhatever/index.js`],
},
{ id: `test`, name: `test` }
)
const action2 = actions.createPage(
{
path: `/hi/hotpizza/`,
component: [`/whatever/index.js`, `/pizza/index.js`],
},
{ id: `test`, name: `test` }
)
let state = reducer(undefined, action)
state = reducer(state, action2)
expect(state).toMatchSnapshot()
expect(state.length).toEqual(2)
})

it(`allows you to update existing pages with multiple components (based on path)`, () => {
const action = actions.createPage(
{
path: `/hi/`,
component: [`/something/index.js`, `/morewhatever/index.js`],
},
{ id: `test`, name: `test` }
)

// Change the component
const action2 = actions.createPage(
{
path: `/hi/`,
component: [`/whateven/index.js`, `/supercereal/index.js`],
},
{ id: `test`, name: `test` }
)

let state = reducer(undefined, action)
state = reducer(state, action2)
expect(state).toMatchSnapshot()
expect(state.length).toEqual(1)
})

it(`allows you to delete paths that have multiple components`, () => {
const action = actions.createPage(
{
path: `/hi/`,
component: [`/ohhey/index.js`, `/goodbye/index.js`],
},
{ name: `test` }
)
const action2 = actions.deletePage({ path: `/hi/` })

let state = reducer(undefined, action)
state = reducer(state, action2)
expect(state).toMatchSnapshot()
expect(state.length).toEqual(0)
})
})

0 comments on commit 2cefaeb

Please sign in to comment.