Skip to content

Commit 27cb57c

Browse files
committed
test(e2e): add tests for custom fields and custom resolvers
1 parent c0a0ba5 commit 27cb57c

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
describe(`custom-fields`, () => {
2+
beforeEach(() => {
3+
cy.visit("/custom-fields").waitForRouteChange()
4+
})
5+
6+
it(`custom-fields: custom field`, () => {
7+
cy.get(`[data-cy-id="field"] [data-cy-value]`).should(
8+
`have.text`,
9+
`customFieldValue`
10+
)
11+
})
12+
13+
it(`custom-fields: custom resolver`, () => {
14+
cy.get(`[data-cy-id="resolver"] [data-cy-value]`).should(
15+
`have.text`,
16+
`customResolverResult`
17+
)
18+
})
19+
})

e2e-tests/contentful/gatsby-node.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
exports.onCreateNode = ({ node, actions }) => {
2+
const { createNodeField } = actions
3+
4+
if (node.internal.type === "ContentfulContentTypeText") {
5+
createNodeField({
6+
node,
7+
name: "customField",
8+
value: "customFieldValue",
9+
})
10+
}
11+
}
12+
13+
exports.createSchemaCustomization = ({ actions, schema }) => {
14+
const { createTypes } = actions
15+
16+
const typeDefs = `
17+
type ContentfulContentTypeTextFields {
18+
customField: String!
19+
}
20+
type ContentfulContentTypeText {
21+
fields: ContentfulContentTypeTextFields!
22+
}
23+
`
24+
25+
createTypes(typeDefs)
26+
}
27+
28+
exports.createResolvers = ({ createResolvers }) => {
29+
createResolvers({
30+
ContentfulContentTypeText: {
31+
customResolver: {
32+
type: 'String!',
33+
resolve(source, args, context, info) {
34+
return "customResolverResult"
35+
},
36+
},
37+
},
38+
})
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { graphql } from "gatsby"
2+
import * as React from "react"
3+
4+
import Layout from "../components/layout"
5+
6+
const CustomFieldsPage = ({ data }) => {
7+
const {
8+
contentfulContentTypeText
9+
} = data
10+
return (
11+
<Layout>
12+
<h2>Custom Field:</h2>
13+
<div data-cy-id="field">
14+
<p data-cy-value>{contentfulContentTypeText.fields.customField}</p>
15+
</div>
16+
<h2>Custom Resolver:</h2>
17+
<div data-cy-id="resolver">
18+
<p data-cy-value>{contentfulContentTypeText.customResolver}</p>
19+
</div>
20+
</Layout>
21+
)
22+
}
23+
24+
export default CustomFieldsPage
25+
26+
export const pageQuery = graphql`
27+
query TextQuery {
28+
contentfulContentTypeText {
29+
fields {
30+
customField
31+
}
32+
customResolver
33+
}
34+
}
35+
`

e2e-tests/contentful/src/pages/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ const IndexPage = () => (
5959
<li>
6060
<Link to="/ssr">SSR</Link>
6161
</li>
62+
<li>
63+
<Link to="/custom-fields">Custom Fields &amp; Resolver</Link>
64+
</li>
6265
</ul>
6366
</Layout>
6467
)

0 commit comments

Comments
 (0)