From 7e965be6b65ae61a07fe3c411e8bb0ed1f30c51e Mon Sep 17 00:00:00 2001 From: Jude Agboola Date: Wed, 5 Oct 2022 08:19:25 +0100 Subject: [PATCH] initial --- .../slices/slice-via-create-page.js | 8 ++--- .../cypress/integration/slices copy/slices.js | 24 -------------- .../slices/slice-via-create-page.js | 25 ++++++++++++++ .../cypress/integration/slices/slices.js | 33 +++++++++++++++++++ .../production-runtime/shared-data/slices.js | 25 ++++++++++++++ 5 files changed, 87 insertions(+), 28 deletions(-) delete mode 100644 e2e-tests/production-runtime/cypress/integration/slices copy/slices.js create mode 100644 e2e-tests/production-runtime/cypress/integration/slices/slice-via-create-page.js create mode 100644 e2e-tests/production-runtime/cypress/integration/slices/slices.js create mode 100644 e2e-tests/production-runtime/shared-data/slices.js diff --git a/e2e-tests/development-runtime/cypress/integration/slices/slice-via-create-page.js b/e2e-tests/development-runtime/cypress/integration/slices/slice-via-create-page.js index 7a1eeb1a5f9d8..3e0b4cd6cecb5 100644 --- a/e2e-tests/development-runtime/cypress/integration/slices/slice-via-create-page.js +++ b/e2e-tests/development-runtime/cypress/integration/slices/slice-via-create-page.js @@ -1,11 +1,11 @@ -import { allRecipes } from "../../../shared-data/slices" +import { allRecipes, allRecipeAuthors } from "../../../shared-data/slices" /** - * Test behaviour when a slice created and passed as a `slices` option via createPage + * Test behaviour when a slice is created and passed `slices` option to createPage */ describe("Slice passed via createPage", () => { - it("Created pages should have correct values", () => { + it("Pages created with slices mapping have correct content", () => { allRecipes.forEach(recipe => { cy.visit(`recipe/${recipe.id}`).waitForRouteChange() @@ -19,7 +19,7 @@ describe("Slice passed via createPage", () => { cy.getTestElement(`recipe-author-name`) .invoke(`text`) - .should(`contain`, recipe.author.name) + .should(`contain`, allRecipeAuthors.find(author => recipe.authorId === author.id).name) }) }) }) diff --git a/e2e-tests/production-runtime/cypress/integration/slices copy/slices.js b/e2e-tests/production-runtime/cypress/integration/slices copy/slices.js deleted file mode 100644 index 95ddda996a45b..0000000000000 --- a/e2e-tests/production-runtime/cypress/integration/slices copy/slices.js +++ /dev/null @@ -1,24 +0,0 @@ -describe(`Slices`, () => { - beforeEach(() => { - cy.visit(`/`).waitForRouteChange() - }) - - it(`Slice content show on screen`, () => { - cy.getTestElement(`footer-static-text`) - .invoke(`text`) - .should(`contain`, `Built with`) - }) - - it(`Slice can take in props`, () => { - cy.getTestElement(`footer-props`) - .invoke(`text`) - .should(`contains`, `Gatsbyjs`) - }) - - it(`Slice can consume a context wrapped in WrapRootElement`, () => { - cy.getTestElement(`footer-context-derieved-value`) - .invoke(`text`) - .should(`contain`, `2`) - }) -}) - \ No newline at end of file diff --git a/e2e-tests/production-runtime/cypress/integration/slices/slice-via-create-page.js b/e2e-tests/production-runtime/cypress/integration/slices/slice-via-create-page.js new file mode 100644 index 0000000000000..3e0b4cd6cecb5 --- /dev/null +++ b/e2e-tests/production-runtime/cypress/integration/slices/slice-via-create-page.js @@ -0,0 +1,25 @@ +import { allRecipes, allRecipeAuthors } from "../../../shared-data/slices" + +/** + * Test behaviour when a slice is created and passed `slices` option to createPage + */ + +describe("Slice passed via createPage", () => { + it("Pages created with slices mapping have correct content", () => { + allRecipes.forEach(recipe => { + cy.visit(`recipe/${recipe.id}`).waitForRouteChange() + + cy.getTestElement(`recipe-name`) + .invoke(`text`) + .should(`contain`, recipe.name) + + cy.getTestElement(`recipe-description`) + .invoke(`text`) + .should(`contain`, recipe.description) + + cy.getTestElement(`recipe-author-name`) + .invoke(`text`) + .should(`contain`, allRecipeAuthors.find(author => recipe.authorId === author.id).name) + }) + }) +}) diff --git a/e2e-tests/production-runtime/cypress/integration/slices/slices.js b/e2e-tests/production-runtime/cypress/integration/slices/slices.js new file mode 100644 index 0000000000000..5e2ec4156b110 --- /dev/null +++ b/e2e-tests/production-runtime/cypress/integration/slices/slices.js @@ -0,0 +1,33 @@ +/** + * Test basic Slices API behaviour like context, props, .... + */ + +describe(`Slices`, () => { + beforeEach(() => { + cy.visit(`/`).waitForRouteChange() + }) + + it(`Slice content show on screen`, () => { + cy.getTestElement(`footer-static-text`) + .invoke(`text`) + .should(`contain`, `Built with`) + }) + + it(`Slice recieves context passed via createSlice`, () => { + cy.getTestElement(`footer-slice-context-value`) + .invoke(`text`) + .should(`contain`, `Gatsby`) + }) + + it(`Slice can take in props`, () => { + cy.getTestElement(`footer-props`) + .invoke(`text`) + .should(`contains`, `Gatsbyjs`) + }) + + it(`Slice can consume a context wrapped in WrapRootElement`, () => { + cy.getTestElement(`footer-context-derieved-value`) + .invoke(`text`) + .should(`contain`, `2`) + }) +}) diff --git a/e2e-tests/production-runtime/shared-data/slices.js b/e2e-tests/production-runtime/shared-data/slices.js new file mode 100644 index 0000000000000..651111121772e --- /dev/null +++ b/e2e-tests/production-runtime/shared-data/slices.js @@ -0,0 +1,25 @@ +const allRecipes = [ + { + id: "r1", + name: "Jollof Rice", + description: + "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).", + authorId: "a-1", + }, + { + id: "r2", + name: "Ewa Agoyin", + description: + "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).", + authorId: "a-2", + }, +] + +const allRecipeAuthors = [ + { id: "a-1", name: "Jude" }, + { id: "a-2", name: "Ty" }, +] + +const framework = "Gatsby" + +module.exports = { allRecipes, allRecipeAuthors, framework }