Skip to content

Commit

Permalink
feat(gatsby): enable local themes (#15856)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherBiscardi authored and sidharthachatterjee committed Oct 29, 2019
1 parent c2ed766 commit bd85555
Show file tree
Hide file tree
Showing 35 changed files with 342 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
/* global cy */

describe(`Components`, () => {
it(`can be added by themes`, () => {
cy.visit(`/shadowed`).waitForRouteChange()
cy.getTestElement(`date`).contains(`6/28/1993`)
describe(`can be added by themes`, () => {
it(`installed theme`, () => {
cy.visit(`/shadowed`).waitForRouteChange()
cy.getTestElement(`date`).contains(`6/28/1993`)
})
it(`local theme`, () => {
cy.visit(`/shadowed-local`).waitForRouteChange()
cy.getTestElement(`header`).contains(
`This is component to test shadowing of local theme`
)
})
})
it(`added by themes can be shadowed`, () => {
cy.visit(`/shadowed`).waitForRouteChange()
cy.getTestElement(`time`).contains(`2:39:07 PM`)
describe(`added by themes can be shadowed`, () => {
it(`installed theme`, () => {
cy.visit(`/shadowed`).waitForRouteChange()
cy.getTestElement(`time`).contains(`2:39:07 PM`)
})
it(`local theme`, () => {
cy.visit(`/shadowed-local`).waitForRouteChange()
cy.getTestElement(`pre`).contains(`This is in main site`)
cy.getTestElement(`pre`).should(
`not.contain`,
`This is in gatsby-theme-local`
)
})
})
})
29 changes: 21 additions & 8 deletions e2e-tests/themes/development-runtime/cypress/integration/pages.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
/* global cy */

describe(`Pages`, () => {
it(`can be added by themes`, () => {
cy.visit(`/about`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Blog Title Placeholder`)
describe(`can be added by themes`, () => {
it(`installed theme`, () => {
cy.visit(`/about`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Blog Title Placeholder`)
})
it(`local theme`, () => {
cy.visit(`/page-from-local`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Page from local theme`)
})
})
it(`added by themes can be shadowed`, () => {
cy.visit(`/contact`).waitForRouteChange()
cy.getTestElement(`title`).contains(
`A title since the theme didn't have one`
)
describe(`added by themes can be shadowed`, () => {
it(`installed theme`, () => {
cy.visit(`/contact`).waitForRouteChange()
cy.getTestElement(`title`).contains(
`A title since the theme didn't have one`
)
})

it(`local theme`, () => {
cy.visit(`/page-from-local-overwrite`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Overwritten page from local theme`)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
/* global cy */

describe(`Site Metadata`, () => {
it(`can be added by themes`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Blog Title Placeholder`)
describe(`can be added by themes`, () => {
it(`installed theme`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Blog Title Placeholder`)
})
it(`local theme`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`description`).contains(`Description placeholder`)
})
})
it(`added by themes can be overridden`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`author`).contains(`Sidhartha Chatterjee`)
describe(`added by themes can be overridden`, () => {
it(`installed theme`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`author`).contains(`Sidhartha Chatterjee`)
})
it(`local theme`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`social_twitter`).contains(`chatsidhartha`)
})
})
})
5 changes: 4 additions & 1 deletion e2e-tests/themes/development-runtime/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module.exports = {
siteMetadata: {
author: `Sidhartha Chatterjee`,
social: {
twitter: `chatsidhartha`,
},
},
plugins: [`gatsby-theme-about`],
plugins: [`gatsby-theme-about`, `gatsby-theme-local`],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
siteMetadata: {
description: `Description placeholder`,
social: {
twitter: `twitter placeholder`,
},
},
plugins: [
{
resolve: `gatsby-plugin-page-creator`,
options: {
path: `${__dirname}/src/pages`,
},
},
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// no-op
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "gatsby-theme-local"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react"
import ToBeShadowed from "./to-be-shadowed"

export default () => (
<>
<header data-testid="header">
This is component to test shadowing of local theme
</header>
<pre data-testid="pre">
<ToBeShadowed />
</pre>
</>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from "react"

export default () => <>This is in gatsby-theme-local</>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from "react"

export default () => <h1 data-testid="title">Page from local theme</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from "react"

export default () => <h1 data-testid="title">Page from local theme</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from "react"

export default () => <>This is in main site</>
6 changes: 6 additions & 0 deletions e2e-tests/themes/development-runtime/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export default ({ data }) => (
<>
<p data-testid="title">{data.site.siteMetadata.title}</p>
<p data-testid="author">{data.site.siteMetadata.author}</p>
<p data-testid="description">{data.site.siteMetadata.description}</p>
<p data-testid="social_twitter">{data.site.siteMetadata.social.twitter}</p>
</>
)

Expand All @@ -14,6 +16,10 @@ export const pageQuery = graphql`
siteMetadata {
title
author
description
social {
twitter
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from "react"

export default () => (
<h1 data-testid="title">Overwritten page from local theme</h1>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from "react"

import LocalShadowingComponent from "../../plugins/gatsby-theme-local/src/components/shadowing-local"

export default () => <LocalShadowingComponent />
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
/* global cy */

describe(`Components`, () => {
it(`can be added by themes`, () => {
cy.visit(`/shadowed`).waitForRouteChange()
cy.getTestElement(`date`).contains(`6/28/1993`)
describe(`can be added by themes`, () => {
it(`installed theme`, () => {
cy.visit(`/shadowed`).waitForRouteChange()
cy.getTestElement(`date`).contains(`6/28/1993`)
})
it(`local theme`, () => {
cy.visit(`/shadowed-local`).waitForRouteChange()
cy.getTestElement(`header`).contains(
`This is component to test shadowing of local theme`
)
})
})
it(`added by themes can be shadowed`, () => {
cy.visit(`/shadowed`).waitForRouteChange()
cy.getTestElement(`time`).contains(`2:39:07 PM`)
describe(`added by themes can be shadowed`, () => {
it(`installed theme`, () => {
cy.visit(`/shadowed`).waitForRouteChange()
cy.getTestElement(`time`).contains(`2:39:07 PM`)
})
it(`local theme`, () => {
cy.visit(`/shadowed-local`).waitForRouteChange()
cy.getTestElement(`pre`).contains(`This is in main site`)
cy.getTestElement(`pre`).should(
`not.contain`,
`This is in gatsby-theme-local`
)
})
})
})
29 changes: 21 additions & 8 deletions e2e-tests/themes/production-runtime/cypress/integration/pages.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
/* global cy */

describe(`Pages`, () => {
it(`can be added by themes`, () => {
cy.visit(`/about`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Blog Title Placeholder`)
describe(`can be added by themes`, () => {
it(`installed theme`, () => {
cy.visit(`/about`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Blog Title Placeholder`)
})
it(`local theme`, () => {
cy.visit(`/page-from-local`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Page from local theme`)
})
})
it(`added by themes can be shadowed`, () => {
cy.visit(`/contact`).waitForRouteChange()
cy.getTestElement(`title`).contains(
`A title since the theme didn't have one`
)
describe(`added by themes can be shadowed`, () => {
it(`installed theme`, () => {
cy.visit(`/contact`).waitForRouteChange()
cy.getTestElement(`title`).contains(
`A title since the theme didn't have one`
)
})

it(`local theme`, () => {
cy.visit(`/page-from-local-overwrite`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Overwritten page from local theme`)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
/* global cy */

describe(`Site Metadata`, () => {
it(`can be added by themes`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Blog Title Placeholder`)
describe(`can be added by themes`, () => {
it(`installed theme`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Blog Title Placeholder`)
})
it(`local theme`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`description`).contains(`Description placeholder`)
})
})
it(`added by themes can be overridden`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`author`).contains(`Sidhartha Chatterjee`)
describe(`added by themes can be overridden`, () => {
it(`installed theme`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`author`).contains(`Sidhartha Chatterjee`)
})
it(`local theme`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`social_twitter`).contains(`chatsidhartha`)
})
})
})
5 changes: 4 additions & 1 deletion e2e-tests/themes/production-runtime/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module.exports = {
siteMetadata: {
author: `Sidhartha Chatterjee`,
social: {
twitter: `chatsidhartha`,
},
},
plugins: [`gatsby-theme-about`],
plugins: [`gatsby-theme-about`, `gatsby-theme-local`],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
siteMetadata: {
description: `Description placeholder`,
social: {
twitter: `twitter placeholder`,
},
},
plugins: [
{
resolve: `gatsby-plugin-page-creator`,
options: {
path: `${__dirname}/src/pages`,
},
},
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// no-op
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "gatsby-theme-local"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react"
import ToBeShadowed from "./to-be-shadowed"

export default () => (
<>
<header data-testid="header">
This is component to test shadowing of local theme
</header>
<pre data-testid="pre">
<ToBeShadowed />
</pre>
</>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from "react"

export default () => <>This is in gatsby-theme-local</>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from "react"

export default () => <h1 data-testid="title">Page from local theme</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from "react"

export default () => <h1 data-testid="title">Page from local theme</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from "react"

export default () => <>This is in main site</>
6 changes: 6 additions & 0 deletions e2e-tests/themes/production-runtime/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export default ({ data }) => (
<>
<p data-testid="title">{data.site.siteMetadata.title}</p>
<p data-testid="author">{data.site.siteMetadata.author}</p>
<p data-testid="description">{data.site.siteMetadata.description}</p>
<p data-testid="social_twitter">{data.site.siteMetadata.social.twitter}</p>
</>
)

Expand All @@ -14,6 +16,10 @@ export const pageQuery = graphql`
siteMetadata {
title
author
description
social {
twitter
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from "react"

export default () => (
<h1 data-testid="title">Overwritten page from local theme</h1>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from "react"

import LocalShadowingComponent from "../../plugins/gatsby-theme-local/src/components/shadowing-local"

export default () => <LocalShadowingComponent />

0 comments on commit bd85555

Please sign in to comment.