17
17
* under the License.
18
18
*/
19
19
import React from 'react' ;
20
- import { shallow } from 'enzyme' ;
21
- import { Provider } from 'react-redux' ;
22
20
import { Store } from 'redux' ;
23
- import * as SupersetUI from '@superset-ui/core' ;
24
- import { styledMount as mount } from 'spec/helpers/theming' ;
21
+ import { render } from 'spec/helpers/testing-library' ;
25
22
import {
26
23
CHART_RENDERING_SUCCEEDED ,
27
24
CHART_UPDATE_SUCCEEDED ,
@@ -36,123 +33,105 @@ import { sliceId } from 'spec/fixtures/mockChartQueries';
36
33
import { dashboardFilters } from 'spec/fixtures/mockDashboardFilters' ;
37
34
import { dashboardWithFilter } from 'spec/fixtures/mockDashboardLayout' ;
38
35
36
+ jest . mock (
37
+ 'src/dashboard/components/FiltersBadge/DetailsPanel' ,
38
+ ( ) =>
39
+ ( { children } : { children : React . ReactNode } ) =>
40
+ < div data-test = "mock-details-panel" > { children } </ div > ,
41
+ ) ;
42
+
39
43
const defaultStore = getMockStoreWithFilters ( ) ;
40
44
function setup ( store : Store = defaultStore ) {
41
- return mount (
42
- < Provider store = { store } >
43
- < FiltersBadge chartId = { sliceId } />
44
- </ Provider > ,
45
- ) ;
45
+ return render ( < FiltersBadge chartId = { sliceId } /> , { store } ) ;
46
46
}
47
47
48
- describe ( 'FiltersBadge' , ( ) => {
49
- // there's this bizarre "active filters" thing
50
- // that doesn't actually use any kind of state management.
51
- // Have to set variables in there.
52
- buildActiveFilters ( {
53
- dashboardFilters,
54
- components : dashboardWithFilter ,
55
- } ) ;
56
-
57
- beforeEach ( ( ) => {
58
- // shallow rendering in enzyme doesn't propagate contexts correctly,
59
- // so we have to mock the hook.
60
- // See https://medium.com/7shifts-engineering-blog/testing-usecontext-react-hook-with-enzyme-shallow-da062140fc83
61
- jest
62
- . spyOn ( SupersetUI , 'useTheme' )
63
- . mockImplementation ( ( ) => SupersetUI . supersetTheme ) ;
64
- } ) ;
48
+ // there's this bizarre "active filters" thing
49
+ // that doesn't actually use any kind of state management.
50
+ // Have to set variables in there.
51
+ buildActiveFilters ( {
52
+ dashboardFilters,
53
+ components : dashboardWithFilter ,
54
+ } ) ;
65
55
66
- describe ( 'for dashboard filters' , ( ) => {
67
- it ( "doesn't show number when there are no active filters" , ( ) => {
68
- const store = getMockStoreWithFilters ( ) ;
69
- // start with basic dashboard state, dispatch an event to simulate query completion
70
- store . dispatch ( {
71
- type : CHART_UPDATE_SUCCEEDED ,
72
- key : sliceId ,
73
- queriesResponse : [
74
- {
75
- status : 'success' ,
76
- applied_filters : [ ] ,
77
- rejected_filters : [ ] ,
78
- } ,
79
- ] ,
80
- dashboardFilters,
81
- } ) ;
82
- const wrapper = shallow (
83
- < Provider store = { store } >
84
- < FiltersBadge chartId = { sliceId } /> ,
85
- </ Provider > ,
86
- ) ;
87
- expect ( wrapper . find ( '[data-test="applied-filter-count"]' ) ) . not . toExist ( ) ;
56
+ describe ( 'for dashboard filters' , ( ) => {
57
+ test ( 'does not show number when there are no active filters' , ( ) => {
58
+ const store = getMockStoreWithFilters ( ) ;
59
+ // start with basic dashboard state, dispatch an event to simulate query completion
60
+ store . dispatch ( {
61
+ type : CHART_UPDATE_SUCCEEDED ,
62
+ key : sliceId ,
63
+ queriesResponse : [
64
+ {
65
+ status : 'success' ,
66
+ applied_filters : [ ] ,
67
+ rejected_filters : [ ] ,
68
+ } ,
69
+ ] ,
70
+ dashboardFilters,
88
71
} ) ;
72
+ const { queryByTestId } = setup ( store ) ;
73
+ expect ( queryByTestId ( 'applied-filter-count' ) ) . not . toBeInTheDocument ( ) ;
74
+ } ) ;
89
75
90
- it ( 'shows the indicator when filters have been applied' , ( ) => {
91
- const store = getMockStoreWithFilters ( ) ;
92
- // start with basic dashboard state, dispatch an event to simulate query completion
93
- store . dispatch ( {
94
- type : CHART_UPDATE_SUCCEEDED ,
95
- key : sliceId ,
96
- queriesResponse : [
97
- {
98
- status : 'success' ,
99
- applied_filters : [ { column : 'region' } ] ,
100
- rejected_filters : [ ] ,
101
- } ,
102
- ] ,
103
- dashboardFilters,
104
- } ) ;
105
- store . dispatch ( { type : CHART_RENDERING_SUCCEEDED , key : sliceId } ) ;
106
- const wrapper = setup ( store ) ;
107
- expect ( wrapper . find ( 'DetailsPanelPopover' ) ) . toExist ( ) ;
108
- expect (
109
- wrapper . find ( '[data-test="applied-filter-count"] .current' ) ,
110
- ) . toHaveText ( '1' ) ;
111
- expect ( wrapper . find ( 'WarningFilled' ) ) . not . toExist ( ) ;
76
+ test ( 'shows the indicator when filters have been applied' , ( ) => {
77
+ const store = getMockStoreWithFilters ( ) ;
78
+ // start with basic dashboard state, dispatch an event to simulate query completion
79
+ store . dispatch ( {
80
+ type : CHART_UPDATE_SUCCEEDED ,
81
+ key : sliceId ,
82
+ queriesResponse : [
83
+ {
84
+ status : 'success' ,
85
+ applied_filters : [ { column : 'region' } ] ,
86
+ rejected_filters : [ ] ,
87
+ } ,
88
+ ] ,
89
+ dashboardFilters,
112
90
} ) ;
91
+ store . dispatch ( { type : CHART_RENDERING_SUCCEEDED , key : sliceId } ) ;
92
+ const { getByTestId } = setup ( store ) ;
93
+ expect ( getByTestId ( 'applied-filter-count' ) ) . toHaveTextContent ( '1' ) ;
94
+ expect ( getByTestId ( 'mock-details-panel' ) ) . toBeInTheDocument ( ) ;
113
95
} ) ;
96
+ } ) ;
114
97
115
- describe ( 'for native filters' , ( ) => {
116
- it ( "doesn't show number when there are no active filters" , ( ) => {
117
- const store = getMockStoreWithNativeFilters ( ) ;
118
- // start with basic dashboard state, dispatch an event to simulate query completion
119
- store . dispatch ( {
120
- type : CHART_UPDATE_SUCCEEDED ,
121
- key : sliceId ,
122
- queriesResponse : [
123
- {
124
- status : 'success' ,
125
- applied_filters : [ ] ,
126
- rejected_filters : [ ] ,
127
- } ,
128
- ] ,
129
- } ) ;
130
- store . dispatch ( { type : CHART_RENDERING_SUCCEEDED , key : sliceId } ) ;
131
- const wrapper = setup ( store ) ;
132
- expect ( wrapper . find ( '[data-test="applied-filter-count"]' ) ) . not . toExist ( ) ;
98
+ describe ( 'for native filters' , ( ) => {
99
+ test ( 'does not show number when there are no active filters' , ( ) => {
100
+ const store = getMockStoreWithNativeFilters ( ) ;
101
+ // start with basic dashboard state, dispatch an event to simulate query completion
102
+ store . dispatch ( {
103
+ type : CHART_UPDATE_SUCCEEDED ,
104
+ key : sliceId ,
105
+ queriesResponse : [
106
+ {
107
+ status : 'success' ,
108
+ applied_filters : [ ] ,
109
+ rejected_filters : [ ] ,
110
+ } ,
111
+ ] ,
133
112
} ) ;
113
+ store . dispatch ( { type : CHART_RENDERING_SUCCEEDED , key : sliceId } ) ;
114
+ const { queryByTestId } = setup ( store ) ;
115
+ expect ( queryByTestId ( 'applied-filter-count' ) ) . not . toBeInTheDocument ( ) ;
116
+ } ) ;
134
117
135
- it ( 'shows the indicator when filters have been applied' , ( ) => {
136
- const store = getMockStoreWithNativeFilters ( ) ;
137
- // start with basic dashboard state, dispatch an event to simulate query completion
138
- store . dispatch ( {
139
- type : CHART_UPDATE_SUCCEEDED ,
140
- key : sliceId ,
141
- queriesResponse : [
142
- {
143
- status : 'success' ,
144
- applied_filters : [ { column : 'region' } ] ,
145
- rejected_filters : [ ] ,
146
- } ,
147
- ] ,
148
- } ) ;
149
- store . dispatch ( { type : CHART_RENDERING_SUCCEEDED , key : sliceId } ) ;
150
- const wrapper = setup ( store ) ;
151
- expect ( wrapper . find ( 'DetailsPanelPopover' ) ) . toExist ( ) ;
152
- expect (
153
- wrapper . find ( '[data-test="applied-filter-count"] .current' ) ,
154
- ) . toHaveText ( '1' ) ;
155
- expect ( wrapper . find ( 'WarningFilled' ) ) . not . toExist ( ) ;
118
+ test ( 'shows the indicator when filters have been applied' , ( ) => {
119
+ const store = getMockStoreWithNativeFilters ( ) ;
120
+ // start with basic dashboard state, dispatch an event to simulate query completion
121
+ store . dispatch ( {
122
+ type : CHART_UPDATE_SUCCEEDED ,
123
+ key : sliceId ,
124
+ queriesResponse : [
125
+ {
126
+ status : 'success' ,
127
+ applied_filters : [ { column : 'region' } ] ,
128
+ rejected_filters : [ ] ,
129
+ } ,
130
+ ] ,
156
131
} ) ;
132
+ store . dispatch ( { type : CHART_RENDERING_SUCCEEDED , key : sliceId } ) ;
133
+ const { getByTestId } = setup ( store ) ;
134
+ expect ( getByTestId ( 'applied-filter-count' ) ) . toHaveTextContent ( '1' ) ;
135
+ expect ( getByTestId ( 'mock-details-panel' ) ) . toBeInTheDocument ( ) ;
157
136
} ) ;
158
137
} ) ;
0 commit comments