Skip to content

Commit

Permalink
test(e2e): add tests for custom fields and custom resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed Oct 13, 2023
1 parent c0a0ba5 commit 27cb57c
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
19 changes: 19 additions & 0 deletions e2e-tests/contentful/cypress/integration/delivery/custom-fields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe(`custom-fields`, () => {
beforeEach(() => {
cy.visit("/custom-fields").waitForRouteChange()
})

it(`custom-fields: custom field`, () => {
cy.get(`[data-cy-id="field"] [data-cy-value]`).should(
`have.text`,
`customFieldValue`
)
})

it(`custom-fields: custom resolver`, () => {
cy.get(`[data-cy-id="resolver"] [data-cy-value]`).should(
`have.text`,
`customResolverResult`
)
})
})
39 changes: 39 additions & 0 deletions e2e-tests/contentful/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
exports.onCreateNode = ({ node, actions }) => {
const { createNodeField } = actions

if (node.internal.type === "ContentfulContentTypeText") {
createNodeField({
node,
name: "customField",
value: "customFieldValue",
})
}
}

exports.createSchemaCustomization = ({ actions, schema }) => {
const { createTypes } = actions

const typeDefs = `
type ContentfulContentTypeTextFields {
customField: String!
}
type ContentfulContentTypeText {
fields: ContentfulContentTypeTextFields!
}
`

createTypes(typeDefs)
}

exports.createResolvers = ({ createResolvers }) => {
createResolvers({
ContentfulContentTypeText: {
customResolver: {
type: 'String!',
resolve(source, args, context, info) {
return "customResolverResult"
},
},
},
})
}
35 changes: 35 additions & 0 deletions e2e-tests/contentful/src/pages/custom-fields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { graphql } from "gatsby"
import * as React from "react"

import Layout from "../components/layout"

const CustomFieldsPage = ({ data }) => {
const {
contentfulContentTypeText
} = data
return (
<Layout>
<h2>Custom Field:</h2>
<div data-cy-id="field">
<p data-cy-value>{contentfulContentTypeText.fields.customField}</p>
</div>
<h2>Custom Resolver:</h2>
<div data-cy-id="resolver">
<p data-cy-value>{contentfulContentTypeText.customResolver}</p>
</div>
</Layout>
)
}

export default CustomFieldsPage

export const pageQuery = graphql`
query TextQuery {
contentfulContentTypeText {
fields {
customField
}
customResolver
}
}
`
3 changes: 3 additions & 0 deletions e2e-tests/contentful/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const IndexPage = () => (
<li>
<Link to="/ssr">SSR</Link>
</li>
<li>
<Link to="/custom-fields">Custom Fields &amp; Resolver</Link>
</li>
</ul>
</Layout>
)
Expand Down

0 comments on commit 27cb57c

Please sign in to comment.