1
- /**
2
- * Copyright (c) 2021 GraphQL Contributors.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import { ExplorerContext , SchemaContext } from '@graphiql/react' ;
9
1
import {
10
2
// @ts -expect-error
11
3
fireEvent ,
12
4
render ,
13
5
} from '@testing-library/react' ;
14
6
import { GraphQLNamedType } from 'graphql' ;
15
- import React from 'react' ;
16
7
8
+ import { SchemaContext } from '../../../schema' ;
9
+ import { ExplorerContext } from '../../context' ;
10
+ import { TypeDocumentation } from '../type-documentation' ;
17
11
import {
18
- ExampleSchema ,
12
+ ExampleEnum ,
19
13
ExampleQuery ,
14
+ ExampleSchema ,
20
15
ExampleUnion ,
21
- ExampleEnum ,
22
- } from '../../__tests__/ExampleSchema' ;
23
- import TypeDoc from '../TypeDoc' ;
16
+ } from './example-schema' ;
24
17
import { mockExplorerContextValue , unwrapType } from './test-utils' ;
25
18
26
- function TypeDocWithContext ( props : { type : GraphQLNamedType } ) {
19
+ function TypeDocumentationWithContext ( props : { type : GraphQLNamedType } ) {
27
20
return (
28
21
< SchemaContext . Provider
29
22
value = { {
@@ -40,15 +33,17 @@ function TypeDocWithContext(props: { type: GraphQLNamedType }) {
40
33
name : unwrapType ( props . type ) . name ,
41
34
def : props . type ,
42
35
} ) } >
43
- < TypeDoc />
36
+ < TypeDocumentation />
44
37
</ ExplorerContext . Provider >
45
38
</ SchemaContext . Provider >
46
39
) ;
47
40
}
48
41
49
42
describe ( 'TypeDoc' , ( ) => {
50
43
it ( 'renders a top-level query object type' , ( ) => {
51
- const { container } = render ( < TypeDocWithContext type = { ExampleQuery } /> ) ;
44
+ const { container } = render (
45
+ < TypeDocumentationWithContext type = { ExampleQuery } /> ,
46
+ ) ;
52
47
const description = container . querySelectorAll (
53
48
'.graphiql-markdown-description' ,
54
49
) ;
@@ -66,7 +61,9 @@ describe('TypeDoc', () => {
66
61
} ) ;
67
62
68
63
it ( 'renders deprecated fields when you click to see them' , ( ) => {
69
- const { container } = render ( < TypeDocWithContext type = { ExampleQuery } /> ) ;
64
+ const { container } = render (
65
+ < TypeDocumentationWithContext type = { ExampleQuery } /> ,
66
+ ) ;
70
67
let cats = container . querySelectorAll ( '.doc-category-item' ) ;
71
68
expect ( cats ) . toHaveLength ( 3 ) ;
72
69
@@ -83,14 +80,18 @@ describe('TypeDoc', () => {
83
80
} ) ;
84
81
85
82
it ( 'renders a Union type' , ( ) => {
86
- const { container } = render ( < TypeDocWithContext type = { ExampleUnion } /> ) ;
83
+ const { container } = render (
84
+ < TypeDocumentationWithContext type = { ExampleUnion } /> ,
85
+ ) ;
87
86
expect ( container . querySelector ( '.doc-category-title' ) ) . toHaveTextContent (
88
87
'possible types' ,
89
88
) ;
90
89
} ) ;
91
90
92
91
it ( 'renders an Enum type' , ( ) => {
93
- const { container } = render ( < TypeDocWithContext type = { ExampleEnum } /> ) ;
92
+ const { container } = render (
93
+ < TypeDocumentationWithContext type = { ExampleEnum } /> ,
94
+ ) ;
94
95
expect ( container . querySelector ( '.doc-category-title' ) ) . toHaveTextContent (
95
96
'values' ,
96
97
) ;
@@ -101,7 +102,7 @@ describe('TypeDoc', () => {
101
102
102
103
it ( 'shows deprecated enum values on click' , ( ) => {
103
104
const { getByText, container } = render (
104
- < TypeDocWithContext type = { ExampleEnum } /> ,
105
+ < TypeDocumentationWithContext type = { ExampleEnum } /> ,
105
106
) ;
106
107
const showBtn = getByText ( 'Show deprecated values...' ) ;
107
108
expect ( showBtn ) . toBeInTheDocument ( ) ;
0 commit comments