From 57a0d99dc851fed6ca6610967231ba3e39b14954 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 9 Aug 2023 09:39:48 +0100 Subject: [PATCH] Improve randomString mock for better snapshots (#11375) --- jest.config.ts | 4 +- test/components/structures/RoomView-test.tsx | 5 - .../structures/SpaceHierarchy-test.tsx | 5 - .../__snapshots__/RoomView-test.tsx.snap | 8 +- .../SpaceHierarchy-test.tsx.snap | 18 +-- .../views/beacon/BeaconListItem-test.tsx | 5 - .../views/beacon/DialogSidebar-test.tsx | 5 - .../views/beacon/ShareLatestLocation-test.tsx | 5 - .../BeaconListItem-test.tsx.snap | 2 +- .../__snapshots__/DialogSidebar-test.tsx.snap | 2 +- .../ShareLatestLocation-test.tsx.snap | 2 +- .../ManageRestrictedJoinRuleDialog-test.tsx | 7 -- .../views/dialogs/ServerPickerDialog-test.tsx | 5 - ...nageRestrictedJoinRuleDialog-test.tsx.snap | 4 +- .../ServerPickerDialog-test.tsx.snap | 2 +- .../views/elements/AppTile-test.tsx | 5 - .../views/elements/LabelledCheckbox-test.tsx | 7 -- .../__snapshots__/AppTile-test.tsx.snap | 2 +- .../LabelledCheckbox-test.tsx.snap | 8 +- .../views/location/LocationShareMenu-test.tsx | 5 - .../LocationShareMenu-test.tsx.snap | 4 +- .../views/messages/MLocationBody-test.tsx | 7 -- .../__snapshots__/MLocationBody-test.tsx.snap | 12 +- .../polls/pollHistory/PollHistory-test.tsx | 5 - .../polls/pollHistory/PollListItem-test.tsx | 5 - .../pollHistory/PollListItemEnded-test.tsx | 5 - .../__snapshots__/PollHistory-test.tsx.snap | 4 +- .../__snapshots__/PollListItem-test.tsx.snap | 2 +- .../PollListItemEnded-test.tsx.snap | 2 +- .../right_panel/RoomSummaryCard-test.tsx | 5 - .../RoomSummaryCard-test.tsx.snap | 2 +- .../views/settings/FontScalingPanel-test.tsx | 7 -- .../views/settings/Notifications-test.tsx | 5 - .../views/settings/ThemeChoicePanel-test.tsx | 7 -- .../FontScalingPanel-test.tsx.snap | 4 +- .../devices/FilteredDeviceListHeader-test.tsx | 5 - .../FilteredDeviceListHeader-test.tsx.snap | 4 +- .../notifications/Notifications2-test.tsx | 19 --- .../Notifications2-test.tsx.snap | 108 +++++++++--------- .../user/AppearanceUserSettingsTab-test.tsx | 5 - .../tabs/user/SessionManagerTab-test.tsx | 5 - .../tabs/user/SidebarUserSettingsTab-test.tsx | 6 - .../AppearanceUserSettingsTab-test.tsx.snap | 4 +- .../SessionManagerTab-test.tsx.snap | 2 +- .../SidebarUserSettingsTab-test.tsx.snap | 20 ++-- .../SpaceSettingsVisibilityTab-test.tsx | 5 - test/{globalSetup.js => globalSetup.ts} | 0 test/{setupTests.js => setupTests.ts} | 22 +++- test/utils/oidc/authorize-test.ts | 2 + 49 files changed, 133 insertions(+), 256 deletions(-) rename test/{globalSetup.js => globalSetup.ts} (100%) rename test/{setupTests.js => setupTests.ts} (53%) diff --git a/jest.config.ts b/jest.config.ts index 818a164ddd..d7f00f194e 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -21,9 +21,9 @@ import type { Config } from "jest"; const config: Config = { testEnvironment: "jsdom", testMatch: ["/test/**/*-test.[jt]s?(x)"], - globalSetup: "/test/globalSetup.js", + globalSetup: "/test/globalSetup.ts", setupFiles: ["jest-canvas-mock"], - setupFilesAfterEnv: ["/test/setupTests.js"], + setupFilesAfterEnv: ["/test/setupTests.ts"], moduleNameMapper: { "\\.(gif|png|ttf|woff2)$": "/__mocks__/imageMock.js", "\\.svg$": "/__mocks__/svg.js", diff --git a/test/components/structures/RoomView-test.tsx b/test/components/structures/RoomView-test.tsx index 8a9e385e8b..3d3fab4482 100644 --- a/test/components/structures/RoomView-test.tsx +++ b/test/components/structures/RoomView-test.tsx @@ -67,11 +67,6 @@ import { WidgetType } from "../../../src/widgets/WidgetType"; import WidgetStore from "../../../src/stores/WidgetStore"; import { ViewRoomErrorPayload } from "../../../src/dispatcher/payloads/ViewRoomErrorPayload"; -// Fake random strings to give a predictable snapshot for IDs -jest.mock("matrix-js-sdk/src/randomstring", () => ({ - randomString: () => "abdefghi", -})); - const RoomView = wrapInMatrixClientContext(_RoomView); describe("RoomView", () => { diff --git a/test/components/structures/SpaceHierarchy-test.tsx b/test/components/structures/SpaceHierarchy-test.tsx index 685fbc7d0d..5e414f5111 100644 --- a/test/components/structures/SpaceHierarchy-test.tsx +++ b/test/components/structures/SpaceHierarchy-test.tsx @@ -30,11 +30,6 @@ import MatrixClientContext from "../../../src/contexts/MatrixClientContext"; import DMRoomMap from "../../../src/utils/DMRoomMap"; import SettingsStore from "../../../src/settings/SettingsStore"; -// Fake random strings to give a predictable snapshot for checkbox IDs -jest.mock("matrix-js-sdk/src/randomstring", () => ({ - randomString: () => "abdefghi", -})); - describe("SpaceHierarchy", () => { describe("showRoom", () => { let client: MatrixClient; diff --git a/test/components/structures/__snapshots__/RoomView-test.tsx.snap b/test/components/structures/__snapshots__/RoomView-test.tsx.snap index c0a2989f96..3a65706ef0 100644 --- a/test/components/structures/__snapshots__/RoomView-test.tsx.snap +++ b/test/components/structures/__snapshots__/RoomView-test.tsx.snap @@ -54,7 +54,7 @@ exports[`RoomView for a local room in state CREATING should match the snapshot 1
renders 1`] = ` class="mx_Checkbox mx_Checkbox_hasKind mx_Checkbox_kind_solid" >