1
1
import React from 'react' ;
2
- import { render , screen } from '@testing-library/react' ;
2
+ import { render , screen , act } from '@testing-library/react' ;
3
3
import '@testing-library/jest-dom' ;
4
- import DatasetTable from './index ' ;
4
+ import DataTableStateWrapper from './DataTableStateWrapper ' ;
5
5
import * as resource from "../../tests/fixtures/resource.json" ;
6
6
import * as distribution from "../../tests/fixtures/distribution.json" ;
7
+ import { DataTableContext } from '../../templates/Dataset' ;
7
8
8
9
describe ( '<DatasetTableTab />' , ( ) => {
9
- test ( "Renders correctly" , ( ) => {
10
+ window . scrollTo = jest . fn ( ) ;
11
+ beforeEach ( ( ) => {
10
12
resource . setSort = jest . fn ( ) ;
13
+ } )
14
+ test ( "Renders correctly" , ( ) => {
11
15
render (
12
- < DatasetTable
13
- resource = { resource }
14
- distribution = { distribution . distribution [ 0 ] }
15
- rootUrl = { "test/api/" }
16
- /> )
16
+ < DataTableContext . Provider value = { {
17
+ resource : resource ,
18
+ distribution : distribution . distribution [ 0 ] ,
19
+ rootUrl : "test/api/"
20
+ } } >
21
+ < DataTableStateWrapper />
22
+ </ DataTableContext . Provider >
23
+ )
17
24
18
25
expect ( screen . getByText ( "Data filters: none" ) ) . toBeInTheDocument ( ) ;
19
26
expect ( screen . getByRole ( "table" ) ) . toBeInTheDocument ( ) ;
20
27
expect ( screen . getByRole ( "navigation" ) ) . toHaveClass ( "ds-c-pagination" ) ;
21
28
} ) ;
22
29
test ( "Renders data dictionary info banner if prop is provided" , ( ) => {
23
- resource . setSort = jest . fn ( ) ;
24
30
render (
25
- < DatasetTable
26
- resource = { resource }
27
- distribution = { distribution . distribution [ 0 ] }
28
- rootUrl = { "test/api/" }
29
- dataDictionaryBanner = { true }
30
- /> )
31
+ < DataTableContext . Provider value = { {
32
+ resource : resource ,
33
+ distribution : distribution . distribution [ 0 ] ,
34
+ rootUrl : "test/api/" ,
35
+ dataDictionaryBanner : true
36
+ } } >
37
+ < DataTableStateWrapper />
38
+ </ DataTableContext . Provider >
39
+ )
31
40
expect ( screen . getByText ( 'Click on the "Data Dictionary" tab above for full column definitions' ) ) . toBeInTheDocument ( ) ;
32
41
} ) ;
33
42
test ( "Does not render data dictionary info banner if prop is not provided" , ( ) => {
34
- resource . setSort = jest . fn ( ) ;
35
43
render (
36
- < DatasetTable
37
- resource = { resource }
38
- distribution = { distribution . distribution [ 0 ] }
39
- rootUrl = { "test/api/" }
40
- /> )
44
+ < DataTableContext . Provider value = { {
45
+ resource : resource ,
46
+ distribution : distribution . distribution [ 0 ] ,
47
+ rootUrl : "test/api/"
48
+ } } >
49
+ < DataTableStateWrapper />
50
+ </ DataTableContext . Provider >
51
+ )
41
52
expect ( screen . queryByText ( 'Click on the "Data Dictionary" tab above for full column definitions' ) ) . not . toBeInTheDocument ( ) ;
42
53
} ) ;
54
+ test ( "Renders controls if prop is provided" , ( ) => {
55
+ render (
56
+ < DataTableContext . Provider value = { {
57
+ resource : resource ,
58
+ distribution : distribution . distribution [ 0 ] ,
59
+ rootUrl : "test/api/" ,
60
+ datasetTableControls : true
61
+ } } >
62
+ < DataTableStateWrapper />
63
+ </ DataTableContext . Provider >
64
+ )
65
+
66
+ expect ( screen . queryAllByText ( "Manage Columns" ) ) . toHaveLength ( 2 ) ;
67
+ expect ( screen . queryByText ( "Full Screen" ) ) . toBeInTheDocument ( ) ;
68
+ } )
69
+ test ( "State is synchronized between regular and full screen mode" , async ( ) => {
70
+ render (
71
+ < DataTableContext . Provider value = { {
72
+ resource : resource ,
73
+ distribution : distribution . distribution [ 0 ] ,
74
+ rootUrl : "test/api/" ,
75
+ datasetTableControls : true
76
+ } } >
77
+ < DataTableStateWrapper />
78
+ </ DataTableContext . Provider >
79
+ )
80
+ // Is there a better way to do this test because every step seems to need an act
81
+ await act ( async ( ) => {
82
+ await screen . queryAllByText ( "Manage Columns" ) [ 0 ] . click ( ) ;
83
+ } ) ;
84
+ await act ( async ( ) => {
85
+ await screen . getByRole ( 'checkbox' , { name : "Select all" } ) . click ( )
86
+ } )
87
+ await act ( async ( ) => {
88
+ await screen . getByRole ( 'button' , { name : 'Save' } ) . click ( ) ;
89
+ } )
90
+ await act ( async ( ) => {
91
+ await screen . getByRole ( 'button' , { name : 'Full Screen mode - Opens in a dialog' } ) . click ( ) ;
92
+ } )
93
+ await act ( async ( ) => {
94
+ await screen . queryAllByText ( "Manage Columns" ) [ 1 ] . click ( ) ;
95
+ } ) ;
96
+ expect ( screen . getByRole ( 'checkbox' , { name : "Select all" } ) ) . not . toBeChecked ( ) ;
97
+ } , 10000 )
43
98
} ) ;
0 commit comments