Skip to content

Commit b67906b

Browse files
Merge pull request #2473 from StateVoicesNational/re/archives
#2473 Archive Issue
2 parents 2b8c7c5 + 4bc59a3 commit b67906b

File tree

5 files changed

+471
-305
lines changed

5 files changed

+471
-305
lines changed

__test__/containers/CampaignList.test.js

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,31 @@
33
*/
44
import React from "react";
55
import { 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";
814
import { 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+
1027
describe("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: /sort: created, newest/i }),
173+
{ skipHover: true }
174+
);
145175
});
146-
expect(wrapper.containsMatchingElement("Timezone")).toBeTruthy();
176+
177+
act(() => {
178+
userEvent.click(
179+
screen.getByRole("option", { name: /sort: timezone/i }),
180+
{ skipHover: true }
181+
);
182+
});
183+
184+
await waitFor(() =>
185+
expect(
186+
screen.getByRole("columnheader", { name: /timezone/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: /timezone/i
204+
});
205+
expect(timezoneButton).toBeNull();
155206
});
156207
});
157208
});

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@
182182
},
183183
"devDependencies": {
184184
"@babel/eslint-parser": "^7.24.7",
185+
"@testing-library/dom": "^10.4.0",
186+
"@testing-library/react": "^12.1.5",
187+
"@testing-library/user-event": "^12.1.5",
185188
"babel-jest": "^29.3.1",
186189
"babel-preset-es2017": "^6.24.1",
187190
"cypress": "^13.11.0",

0 commit comments

Comments
 (0)