33 */
44import React from "react" ;
55import { mount } from "enzyme" ;
6- import { AdminCampaignList } from "../../src/containers/AdminCampaignList" ;
7- import { TIMEZONE_SORT } from "../../src/components/AdminCampaignList/SortBy" ;
6+ import { act } from "react-dom/test-utils" ;
7+ import {
8+ render ,
9+ screen ,
10+ waitFor ,
11+ cleanup
12+ } from "@testing-library/react" ;
13+ import userEvent from "@testing-library/user-event" ;
814import { StyleSheetTestUtils } from "aphrodite" ;
915
16+ import { AdminCampaignList } from "../../src/containers/AdminCampaignList" ;
17+
18+ // https://github.com/Khan/aphrodite/issues/62#issuecomment-267026726
19+ beforeEach ( ( ) => {
20+ StyleSheetTestUtils . suppressStyleInjection ( ) ;
21+ } ) ;
22+ afterEach ( ( ) => {
23+ StyleSheetTestUtils . clearBufferAndResumeStyleInjection ( ) ;
24+ cleanup ( ) ;
25+ } ) ;
26+
1027describe ( "CampaignList" , ( ) => {
1128 const params = {
1229 adminPerms : true ,
13- organizationId : 77
30+ organizationId : "77"
1431 } ;
1532
1633 const mutations = {
@@ -110,19 +127,21 @@ describe("CampaignList", () => {
110127
111128 describe ( "Campaign list sorting" , ( ) => {
112129 const campaignWithCreator = {
113- id : 1 ,
130+ id : "1" ,
131+ title : "test" ,
114132 creator : {
115133 displayName : "Lorem Ipsum"
116134 } ,
117135 completionStats : { } ,
118136 organization : {
119137 id : 1
120- }
138+ } ,
139+ timezone : "US/Eastern"
121140 } ;
122141
123142 const data = {
124143 organization : {
125- id : 1 ,
144+ id : "1" ,
126145 cacheable : 2 ,
127146 campaigns : {
128147 campaigns : [ campaignWithCreator ] ,
@@ -132,26 +151,58 @@ describe("CampaignList", () => {
132151 total : 1
133152 }
134153 }
135- }
154+ } ,
155+ refetch : ( ) => { }
136156 } ;
137157
138- test ( "Timezone column is displayed when timezone is current sort" , ( ) => {
158+ test ( "Timezone column is displayed when timezone is current sort" , async ( ) => {
139159 StyleSheetTestUtils . suppressStyleInjection ( ) ;
140- const wrapper = mount (
141- < AdminCampaignList data = { data } mutations = { mutations } params = { params } />
142- ) ;
143- wrapper . setState ( {
144- sortBy : TIMEZONE_SORT . value
160+ act ( ( ) => {
161+ render (
162+ < AdminCampaignList
163+ data = { data }
164+ mutations = { mutations }
165+ params = { params }
166+ />
167+ ) ;
168+ } ) ;
169+
170+ act ( ( ) => {
171+ userEvent . click (
172+ screen . getByRole ( "button" , { name : / s o r t : c r e a t e d , n e w e s t / i } ) ,
173+ { skipHover : true }
174+ ) ;
145175 } ) ;
146- expect ( wrapper . containsMatchingElement ( "Timezone" ) ) . toBeTruthy ( ) ;
176+
177+ act ( ( ) => {
178+ userEvent . click (
179+ screen . getByRole ( "option" , { name : / s o r t : t i m e z o n e / i } ) ,
180+ { skipHover : true }
181+ ) ;
182+ } ) ;
183+
184+ await waitFor ( ( ) =>
185+ expect (
186+ screen . getByRole ( "columnheader" , { name : / t i m e z o n e / i } )
187+ ) . toBeTruthy ( )
188+ ) ;
147189 } ) ;
148190
149191 test ( "Timezone column is hidden when it isn't the current sort" , ( ) => {
150192 StyleSheetTestUtils . suppressStyleInjection ( ) ;
151- const wrapper = mount (
152- < AdminCampaignList data = { data } mutations = { mutations } params = { params } />
153- ) ;
154- expect ( wrapper . containsMatchingElement ( "Timezone" ) ) . toBeFalsy ( ) ;
193+ act ( ( ) => {
194+ render (
195+ < AdminCampaignList
196+ data = { data }
197+ mutations = { mutations }
198+ params = { params }
199+ />
200+ ) ;
201+ } ) ;
202+ const timezoneButton = screen . queryByText ( "columnheader" , {
203+ name : / t i m e z o n e / i
204+ } ) ;
205+ expect ( timezoneButton ) . toBeNull ( ) ;
155206 } ) ;
156207 } ) ;
157208} ) ;
0 commit comments