Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinjude committed Oct 5, 2022
1 parent 82d04e3 commit 7e965be
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 28 deletions.
@@ -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()

Expand All @@ -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)
})
})
})

This file was deleted.

@@ -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)
})
})
})
33 changes: 33 additions & 0 deletions 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`)
})
})
25 changes: 25 additions & 0 deletions 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 }

0 comments on commit 7e965be

Please sign in to comment.