33 */
44import React from "react" ;
55import { mount } from "enzyme" ;
6+ import { render , screen , waitForElementToBeRemoved , waitFor , cleanup } from "@testing-library/react" ;
7+ import userEvent from "@testing-library/user-event"
68import { AdminCampaignList } from "../../src/containers/AdminCampaignList" ;
7- import { TIMEZONE_SORT } from "../../src/components/AdminCampaignList/SortBy" ;
89import { StyleSheetTestUtils } from "aphrodite" ;
10+ import { act } from 'react-dom/test-utils' ;
11+
12+ // https://github.com/Khan/aphrodite/issues/62#issuecomment-267026726
13+ beforeEach ( ( ) => {
14+ StyleSheetTestUtils . suppressStyleInjection ( ) ;
15+ } ) ;
16+ afterEach ( ( ) => {
17+ StyleSheetTestUtils . clearBufferAndResumeStyleInjection ( ) ;
18+ cleanup ( )
19+ } ) ;
920
1021describe ( "CampaignList" , ( ) => {
1122 const params = {
1223 adminPerms : true ,
13- organizationId : 77
24+ organizationId : '77'
1425 } ;
1526
1627 const mutations = {
@@ -110,19 +121,21 @@ describe("CampaignList", () => {
110121
111122 describe ( "Campaign list sorting" , ( ) => {
112123 const campaignWithCreator = {
113- id : 1 ,
124+ id : '1' ,
125+ title : 'test' ,
114126 creator : {
115127 displayName : "Lorem Ipsum"
116128 } ,
117129 completionStats : { } ,
118130 organization : {
119131 id : 1
120- }
132+ } ,
133+ timezone : "US/Eastern"
121134 } ;
122135
123136 const data = {
124137 organization : {
125- id : 1 ,
138+ id : '1' ,
126139 cacheable : 2 ,
127140 campaigns : {
128141 campaigns : [ campaignWithCreator ] ,
@@ -132,26 +145,46 @@ describe("CampaignList", () => {
132145 total : 1
133146 }
134147 }
135- }
148+ } ,
149+ refetch : ( ) => { }
136150 } ;
137151
138- test ( "Timezone column is displayed when timezone is current sort" , ( ) => {
152+ test ( "Timezone column is displayed when timezone is current sort" , async ( ) => {
139153 StyleSheetTestUtils . suppressStyleInjection ( ) ;
140- const wrapper = mount (
141- < AdminCampaignList data = { data } mutations = { mutations } params = { params } />
142- ) ;
143- wrapper . setState ( {
144- sortBy : TIMEZONE_SORT . value
145- } ) ;
146- expect ( wrapper . containsMatchingElement ( "Timezone" ) ) . toBeTruthy ( ) ;
154+ act ( ( ) => {
155+ render (
156+ < AdminCampaignList data = { data } mutations = { mutations } params = { params } />
157+ ) ;
158+ } )
159+
160+ act ( ( ) => {
161+ userEvent . click (
162+ screen . getByRole (
163+ 'button' ,
164+ { name : / s o r t : c r e a t e d , n e w e s t / i}
165+ ) , { skipHover : true } ) ;
166+ } )
167+
168+ act ( ( ) => {
169+ userEvent . click (
170+ screen . getByRole (
171+ 'option' ,
172+ { name : / s o r t : t i m e z o n e / i}
173+ ) , { skipHover : true } ) ;
174+ } )
175+
176+ await waitFor ( ( ) => expect ( screen . getByRole ( 'columnheader' , { name : / t i m e z o n e / i} ) ) . toBeTruthy ( ) ) ;
147177 } ) ;
148178
149179 test ( "Timezone column is hidden when it isn't the current sort" , ( ) => {
150180 StyleSheetTestUtils . suppressStyleInjection ( ) ;
151- const wrapper = mount (
152- < AdminCampaignList data = { data } mutations = { mutations } params = { params } />
153- ) ;
154- expect ( wrapper . containsMatchingElement ( "Timezone" ) ) . toBeFalsy ( ) ;
181+ act ( ( ) => {
182+ render (
183+ < AdminCampaignList data = { data } mutations = { mutations } params = { params } />
184+ ) ;
185+ } )
186+ const timezoneButton = screen . queryByText ( 'columnheader' , { name : / t i m e z o n e / i } ) ;
187+ expect ( timezoneButton ) . toBeNull ( ) ;
155188 } ) ;
156189 } ) ;
157190} ) ;
0 commit comments