-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: build out tests for testing exercise (#34)
* Add test setup to project with basic test Co-authored-by: Steven Hicks <steven.j.hicks@gmail.com> Co-authored-by: Tanjie McMeans <tanjie.mcmeans@artsymail.com> * Set up test environment and basic test for Exercise 3 Co-authored-by: Steven Hicks <steven.j.hicks@gmail.com> Co-authored-by: Pavlos Vinieratos <pvinis@gmail.com> * yey tests Co-authored-by: Anna Carey <anna@annajcarey.com> Co-authored-by: Steven Hicks <steven.j.hicks@gmail.com> * remove unused deps * add next back Co-authored-by: Anna Carey <anna@annajcarey.com> Co-authored-by: Steven Hicks <steven.j.hicks@gmail.com> * chore: capture Artist3Heading.spec.tsx completed state (and ignore it from jest) Co-authored-by: Anna Carey <anna.carey@artsymail.com> Co-authored-by: Tanjie McMeans <tanjie.mcmeans@artsymail.com> Co-authored-by: Pavlos Vinieratos <pvinis@gmail.com> Co-authored-by: Anna Carey <anna@annajcarey.com>
- Loading branch information
1 parent
cab4ba2
commit 96ef0b8
Showing
8 changed files
with
3,029 additions
and
85 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,4 +1,15 @@ | ||
{ | ||
"presets": ["@babel/preset-react"], | ||
"presets": [ | ||
"@babel/preset-react", | ||
"@babel/preset-typescript", | ||
[ | ||
"next/babel", | ||
{ | ||
"preset-env": { | ||
"modules": "commonjs" | ||
} | ||
} | ||
] | ||
], | ||
"plugins": ["relay"] | ||
} |
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,5 @@ | ||
module.exports = { | ||
// clearMocks: true, | ||
testEnvironment: "jsdom", | ||
testPathIgnorePatterns: ["/node_modules/", "/completed/"], | ||
} |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from "react" | ||
import { render } from "@testing-library/react" | ||
import { QueryRenderer } from "react-relay" | ||
import { MockPayloadGenerator, createMockEnvironment } from "relay-test-utils" | ||
import { graphql } from "relay-runtime" | ||
import { | ||
Artist3Heading, | ||
Artist3HeadingFragmentContainer, | ||
Artist3HeadingProps, | ||
} from "./Artist3Heading" | ||
import { Artist3HeadingTestQuery } from "./__generated__/Artist3HeadingTestQuery.graphql" | ||
|
||
it("Artist3Heading (silly)", () => { | ||
const props: Artist3HeadingProps = { | ||
artist: { | ||
name: "Andy Warhol", | ||
birthYear: 123, | ||
" $refType": "Artist3Heading_artist", | ||
}, | ||
} | ||
|
||
const { queryAllByText } = render(<Artist3Heading {...props} />) | ||
|
||
const header = queryAllByText("Andy Warhol") | ||
expect(header).toHaveLength(1) | ||
}) | ||
|
||
it("Artist3Heading", () => { | ||
const mockEnvironment = createMockEnvironment() | ||
|
||
const { queryAllByText } = render( | ||
<QueryRenderer<Artist3HeadingTestQuery> | ||
environment={mockEnvironment} | ||
query={graphql` | ||
query Artist3HeadingTestQuery($artistID: ID!) { | ||
artist(id: $artistID) { | ||
...Artist3Heading_artist | ||
} | ||
} | ||
`} | ||
variables={{ artistID: "wow" }} | ||
render={({ props }) => { | ||
if (!props || !props.artist) { | ||
return <div>Loading</div> | ||
} | ||
return <Artist3HeadingFragmentContainer artist={props.artist} /> | ||
}} | ||
/> | ||
) | ||
|
||
mockEnvironment.mock.resolveMostRecentOperation(operation => | ||
MockPayloadGenerator.generate(operation, { | ||
Artist: () => ({ | ||
name: "Andy Warhol", | ||
birthYear: 123, | ||
}), | ||
}) | ||
) | ||
|
||
const header = queryAllByText("Andy Warhol") | ||
expect(header).toHaveLength(1) | ||
}) |
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
131 changes: 131 additions & 0 deletions
131
src/exercises/03-Testing-Queries/__generated__/Artist3HeadingTestQuery.graphql.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
src/exercises/03-Testing-Queries/completed/Artist3Heading.spec.tsx
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,62 @@ | ||
// import React from "react" | ||
// import { render } from "@testing-library/react" | ||
// import { QueryRenderer } from "react-relay" | ||
// import { MockPayloadGenerator, createMockEnvironment } from "relay-test-utils" | ||
// import { graphql } from "relay-runtime" | ||
// import { | ||
// Artist3Heading, | ||
// Artist3HeadingFragmentContainer, | ||
// Artist3HeadingProps, | ||
// } from "./Artist3Heading" | ||
// import { Artist3HeadingTestQuery } from "./__generated__/Artist3HeadingTestQuery.graphql" | ||
|
||
// it("Artist3Heading (silly)", () => { | ||
// const props: Artist3HeadingProps = { | ||
// artist: { | ||
// name: "Andy Warhol", | ||
// birthYear: 123, | ||
// " $refType": "Artist3Heading_artist", | ||
// }, | ||
// } | ||
|
||
// const { queryAllByText } = render(<Artist3Heading {...props} />) | ||
|
||
// const header = queryAllByText("Andy Warhol") | ||
// expect(header).toHaveLength(1) | ||
// }) | ||
|
||
// it("Artist3Heading", () => { | ||
// const mockEnvironment = createMockEnvironment() | ||
|
||
// const { queryAllByText } = render( | ||
// <QueryRenderer<Artist3HeadingTestQuery> | ||
// environment={mockEnvironment} | ||
// query={graphql` | ||
// query Artist3HeadingTestQuery($artistID: ID!) { | ||
// artist(id: $artistID) { | ||
// ...Artist3Heading_artist | ||
// } | ||
// } | ||
// `} | ||
// variables={{ artistID: "wow" }} | ||
// render={({ props }) => { | ||
// if (!props || !props.artist) { | ||
// return <div>Loading</div> | ||
// } | ||
// return <Artist3HeadingFragmentContainer artist={props.artist} /> | ||
// }} | ||
// /> | ||
// ) | ||
|
||
// mockEnvironment.mock.resolveMostRecentOperation(operation => | ||
// MockPayloadGenerator.generate(operation, { | ||
// Artist: () => ({ | ||
// name: "Andy Warhol", | ||
// birthYear: 123, | ||
// }), | ||
// }) | ||
// ) | ||
|
||
// const header = queryAllByText("Andy Warhol") | ||
// expect(header).toHaveLength(1) | ||
// }) |
Oops, something went wrong.