-
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.
test(e2e): add tests for custom fields and custom resolvers
- Loading branch information
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
e2e-tests/contentful/cypress/integration/delivery/custom-fields.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,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` | ||
) | ||
}) | ||
}) |
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,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" | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
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,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 | ||
} | ||
} | ||
` |
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