-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
275b356
commit 30e22a1
Showing
22 changed files
with
394 additions
and
13 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
e2e-tests/development-runtime/cypress/integration/slices/slice-via-create-page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
33
e2e-tests/development-runtime/cypress/integration/slices/slices.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
"author": "Dustin Schau <[email protected]>", | ||
"dependencies": { | ||
"babel-plugin-search-and-replace": "^1.1.0", | ||
"gatsby": "next", | ||
"gatsby": "^4.23.0-alpha-preview-slices.78", | ||
"gatsby-image": "next", | ||
"gatsby-plugin-image": "next", | ||
"gatsby-plugin-less": "next", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React, { useContext } from "react" | ||
import { ContextForSlices } from "../context-for-slices" | ||
|
||
// Use as a Slice | ||
function Footer({ framework, lang, sliceContext: { framework: frameworkViaContext }}) { | ||
const { posts } = useContext(ContextForSlices) | ||
|
||
return ( | ||
<footer | ||
style={{ | ||
marginTop: `10px`, | ||
fontSize: `12px`, | ||
}} | ||
> | ||
<span data-testid="footer-slice-context-value">{frameworkViaContext}</span> | ||
<span data-testid="footer-static-text">Built with {` `}</span> | ||
<span data-testid="footer-props">{`${framework}${lang}`}</span> | ||
{` `}Posts Count: <span data-testid="footer-context-derieved-value">{`${posts.length}`}</span> | ||
</footer> | ||
) | ||
} | ||
|
||
export default Footer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
e2e-tests/development-runtime/src/components/recipe-author.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from "react" | ||
|
||
// Use as a Slice | ||
function RecipeAuthor({ sliceContext: { name } }) { | ||
return ( | ||
<div> | ||
Written by{" "} | ||
<span data-testid="recipe-author-name" style={{ fontWeight: "bold" }}> | ||
{name} | ||
</span> | ||
</div> | ||
) | ||
} | ||
|
||
export default RecipeAuthor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from "react" | ||
|
||
const ContextForSlices = React.createContext() | ||
|
||
const ContextForSlicesProvider = ({ children }) => { | ||
const contextValue = { | ||
posts: [ | ||
{ | ||
title: "My first blog post", | ||
content: "This is my first blog post", | ||
}, | ||
{ | ||
title: "My second blog post", | ||
content: "This is my second blog post", | ||
}, | ||
], | ||
} | ||
return ( | ||
<ContextForSlices.Provider value={contextValue}> | ||
{children} | ||
</ContextForSlices.Provider> | ||
) | ||
} | ||
|
||
export { ContextForSlices, ContextForSlicesProvider } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from "react" | ||
import { Slice } from "gatsby" | ||
import Layout from "../components/layout" | ||
|
||
const Recipe = ({ pageContext: { description, name } }) => { | ||
return ( | ||
<Layout> | ||
<h1 data-testid="recipe-name">{name}</h1> | ||
<p data-testid="recipe-description">{description}</p> | ||
<Slice alias="author" /> | ||
</Layout> | ||
) | ||
} | ||
|
||
export default Recipe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
e2e-tests/production-runtime/cypress/integration/slices/slice-via-create-page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
33
e2e-tests/production-runtime/cypress/integration/slices/slices.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.