From bfc0b467045675ae0dee4a5f77c2b2e76219ff37 Mon Sep 17 00:00:00 2001 From: engelhartrueben Date: Thu, 3 Oct 2024 09:36:37 -0400 Subject: [PATCH 1/4] Refactor "Renders for campaign with null creator, doesn't include created by" away from enzyme and onto React Testing Library --- __test__/containers/CampaignList.test.js | 38 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/__test__/containers/CampaignList.test.js b/__test__/containers/CampaignList.test.js index 069f7d710..ffe729b77 100644 --- a/__test__/containers/CampaignList.test.js +++ b/__test__/containers/CampaignList.test.js @@ -31,9 +31,9 @@ describe("CampaignList", () => { }; const mutations = { - createCampaign: () => {}, - archiveCampaigns: () => {}, - unarchiveCampaign: () => {} + createCampaign: () => { }, + archiveCampaigns: () => { }, + unarchiveCampaign: () => { } }; describe("Campaign list for campaign with null creator", () => { @@ -71,15 +71,27 @@ describe("CampaignList", () => { // when test("Renders for campaign with null creator, doesn't include created by", () => { StyleSheetTestUtils.suppressStyleInjection(); - const wrapper = mount( - - ); - const text = wrapper.text(); - expect(text.includes("Created by")).toBeFalsy(); - expect(text.includes("Yes on A")).toBeTruthy(); - expect(text).toMatch(/Archive/); - expect(text).toMatch(/1202/); - expect(text).toMatch(/1101/); + act(() => { + render( + + ); + }); + + const cells = screen.getAllByRole('cell'); + + expect(cells.length).toBe(7); + // campaign ID cell + expect(cells[1].textContent).toContain("1"); + // campaign info cell + expect(cells[2].textContent).toContain("Yes on A"); + // campaign info cell - lack of "created by" due to creator = null + expect(cells[2].textContent).not.toContain("Created by"); + // unassigned contacts + expect(cells[3].textContent).toContain("1101"); + // unmessaged contacts + expect(cells[4].textContent).toContain("1202"); + // archive + expect(cells[5].textContent).toBe("Archive"); }); }); @@ -152,7 +164,7 @@ describe("CampaignList", () => { } } }, - refetch: () => {} + refetch: () => { } }; test("Timezone column is displayed when timezone is current sort", async () => { From 5988c162d53af4ee466cfe65df45890d53243890 Mon Sep 17 00:00:00 2001 From: engelhartrueben Date: Thu, 3 Oct 2024 09:41:47 -0400 Subject: [PATCH 2/4] Refactor "Renders for campaign with creator, includes created by" away from enzyme and onto React Testing Libary --- __test__/containers/CampaignList.test.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/__test__/containers/CampaignList.test.js b/__test__/containers/CampaignList.test.js index ffe729b77..70327ca16 100644 --- a/__test__/containers/CampaignList.test.js +++ b/__test__/containers/CampaignList.test.js @@ -126,14 +126,17 @@ describe("CampaignList", () => { // when test("Renders for campaign with creator, includes created by", () => { StyleSheetTestUtils.suppressStyleInjection(); - const wrapper = mount( - - ); - expect( - wrapper.containsMatchingElement( - — Created by Lorem Ipsum - ) - ).toBeTruthy(); + act(() => { + render( + + ); + }); + + const cells = screen.getAllByRole('cell'); + + expect(cells.length).toBe(7); + // campaign info cell + expect(cells[2].textContent).toBe("Campaign — Created by Lorem Ipsum"); }); }); From e5307968abb0b11b5a89550953cda883a34572c2 Mon Sep 17 00:00:00 2001 From: engelhartrueben Date: Thu, 3 Oct 2024 09:43:17 -0400 Subject: [PATCH 3/4] remove enzyme from imports --- __test__/containers/CampaignList.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/__test__/containers/CampaignList.test.js b/__test__/containers/CampaignList.test.js index 70327ca16..c088ddd75 100644 --- a/__test__/containers/CampaignList.test.js +++ b/__test__/containers/CampaignList.test.js @@ -2,7 +2,6 @@ * @jest-environment jsdom */ import React from "react"; -import { mount } from "enzyme"; import { act } from "react-dom/test-utils"; import { render, From 4a5829899cea07ea626b5683854c202c80896520 Mon Sep 17 00:00:00 2001 From: engelhartrueben Date: Thu, 3 Oct 2024 09:43:47 -0400 Subject: [PATCH 4/4] prettier --- __test__/containers/CampaignList.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/__test__/containers/CampaignList.test.js b/__test__/containers/CampaignList.test.js index c088ddd75..b2a384f00 100644 --- a/__test__/containers/CampaignList.test.js +++ b/__test__/containers/CampaignList.test.js @@ -130,7 +130,6 @@ describe("CampaignList", () => { ); }); - const cells = screen.getAllByRole('cell'); expect(cells.length).toBe(7);