Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 57a0d99

Browse files
authored
Improve randomString mock for better snapshots (#11375)
1 parent c3574c2 commit 57a0d99

File tree

49 files changed

+133
-256
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+133
-256
lines changed

jest.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import type { Config } from "jest";
2121
const config: Config = {
2222
testEnvironment: "jsdom",
2323
testMatch: ["<rootDir>/test/**/*-test.[jt]s?(x)"],
24-
globalSetup: "<rootDir>/test/globalSetup.js",
24+
globalSetup: "<rootDir>/test/globalSetup.ts",
2525
setupFiles: ["jest-canvas-mock"],
26-
setupFilesAfterEnv: ["<rootDir>/test/setupTests.js"],
26+
setupFilesAfterEnv: ["<rootDir>/test/setupTests.ts"],
2727
moduleNameMapper: {
2828
"\\.(gif|png|ttf|woff2)$": "<rootDir>/__mocks__/imageMock.js",
2929
"\\.svg$": "<rootDir>/__mocks__/svg.js",

test/components/structures/RoomView-test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ import { WidgetType } from "../../../src/widgets/WidgetType";
6767
import WidgetStore from "../../../src/stores/WidgetStore";
6868
import { ViewRoomErrorPayload } from "../../../src/dispatcher/payloads/ViewRoomErrorPayload";
6969

70-
// Fake random strings to give a predictable snapshot for IDs
71-
jest.mock("matrix-js-sdk/src/randomstring", () => ({
72-
randomString: () => "abdefghi",
73-
}));
74-
7570
const RoomView = wrapInMatrixClientContext(_RoomView);
7671

7772
describe("RoomView", () => {

test/components/structures/SpaceHierarchy-test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
3030
import DMRoomMap from "../../../src/utils/DMRoomMap";
3131
import SettingsStore from "../../../src/settings/SettingsStore";
3232

33-
// Fake random strings to give a predictable snapshot for checkbox IDs
34-
jest.mock("matrix-js-sdk/src/randomstring", () => ({
35-
randomString: () => "abdefghi",
36-
}));
37-
3833
describe("SpaceHierarchy", () => {
3934
describe("showRoom", () => {
4035
let client: MatrixClient;

test/components/structures/__snapshots__/RoomView-test.tsx.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ exports[`RoomView for a local room in state CREATING should match the snapshot 1
5454
</div>
5555
</div>
5656
<div
57-
aria-describedby="mx_TooltipTarget_abdefghi"
57+
aria-describedby="mx_TooltipTarget_vY7Q4uEh"
5858
class="mx_LegacyRoomHeader_topic mx_RoomTopic"
5959
dir="auto"
6060
tabindex="0"
@@ -147,7 +147,7 @@ exports[`RoomView for a local room in state ERROR should match the snapshot 1`]
147147
</div>
148148
</div>
149149
<div
150-
aria-describedby="mx_TooltipTarget_abdefghi"
150+
aria-describedby="mx_TooltipTarget_vY7Q4uEh"
151151
class="mx_LegacyRoomHeader_topic mx_RoomTopic"
152152
dir="auto"
153153
tabindex="0"
@@ -337,7 +337,7 @@ exports[`RoomView for a local room in state NEW should match the snapshot 1`] =
337337
</div>
338338
</div>
339339
<div
340-
aria-describedby="mx_TooltipTarget_abdefghi"
340+
aria-describedby="mx_TooltipTarget_vY7Q4uEh"
341341
class="mx_LegacyRoomHeader_topic mx_RoomTopic"
342342
dir="auto"
343343
tabindex="0"
@@ -606,7 +606,7 @@ exports[`RoomView for a local room in state NEW that is encrypted should match t
606606
</div>
607607
</div>
608608
<div
609-
aria-describedby="mx_TooltipTarget_abdefghi"
609+
aria-describedby="mx_TooltipTarget_vY7Q4uEh"
610610
class="mx_LegacyRoomHeader_topic mx_RoomTopic"
611611
dir="auto"
612612
tabindex="0"

test/components/structures/__snapshots__/SpaceHierarchy-test.tsx.snap

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ exports[`SpaceHierarchy <SpaceHierarchy /> renders 1`] = `
117117
class="mx_Checkbox mx_Checkbox_hasKind mx_Checkbox_kind_solid"
118118
>
119119
<input
120-
id="checkbox_abdefghi"
120+
id="checkbox_vY7Q4uEh9K"
121121
tabindex="0"
122122
type="checkbox"
123123
/>
124124
<label
125-
for="checkbox_abdefghi"
125+
for="checkbox_vY7Q4uEh9K"
126126
>
127127
<div
128128
class="mx_Checkbox_background"
@@ -198,12 +198,12 @@ exports[`SpaceHierarchy <SpaceHierarchy /> renders 1`] = `
198198
class="mx_Checkbox mx_Checkbox_hasKind mx_Checkbox_kind_solid"
199199
>
200200
<input
201-
id="checkbox_abdefghi"
201+
id="checkbox_38QgU2Pomx"
202202
tabindex="-1"
203203
type="checkbox"
204204
/>
205205
<label
206-
for="checkbox_abdefghi"
206+
for="checkbox_38QgU2Pomx"
207207
>
208208
<div
209209
class="mx_Checkbox_background"
@@ -280,12 +280,12 @@ exports[`SpaceHierarchy <SpaceHierarchy /> renders 1`] = `
280280
class="mx_Checkbox mx_Checkbox_hasKind mx_Checkbox_kind_solid"
281281
>
282282
<input
283-
id="checkbox_abdefghi"
283+
id="checkbox_wKpa6hpi3Y"
284284
tabindex="-1"
285285
type="checkbox"
286286
/>
287287
<label
288-
for="checkbox_abdefghi"
288+
for="checkbox_wKpa6hpi3Y"
289289
>
290290
<div
291291
class="mx_Checkbox_background"
@@ -365,7 +365,7 @@ exports[`SpaceHierarchy <SpaceHierarchy /> renders 1`] = `
365365
Join
366366
</div>
367367
<div
368-
aria-describedby="mx_TooltipTarget_abdefghi"
368+
aria-describedby="mx_TooltipTarget_EetmBG4y"
369369
class="mx_TextWithTooltip_target"
370370
tabindex="0"
371371
>
@@ -374,12 +374,12 @@ exports[`SpaceHierarchy <SpaceHierarchy /> renders 1`] = `
374374
>
375375
<input
376376
disabled=""
377-
id="checkbox_abdefghi"
377+
id="checkbox_VCeEefiPqp"
378378
tabindex="-1"
379379
type="checkbox"
380380
/>
381381
<label
382-
for="checkbox_abdefghi"
382+
for="checkbox_VCeEefiPqp"
383383
>
384384
<div
385385
class="mx_Checkbox_background"

test/components/views/beacon/BeaconListItem-test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ import {
2828
makeRoomWithBeacons,
2929
} from "../../../test-utils";
3030

31-
// Fake random strings to give a predictable snapshot for IDs
32-
jest.mock("matrix-js-sdk/src/randomstring", () => ({
33-
randomString: () => "abdefghi",
34-
}));
35-
3631
describe("<BeaconListItem />", () => {
3732
// 14.03.2022 16:15
3833
const now = 1647270879403;

test/components/views/beacon/DialogSidebar-test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ import {
2727
mockClientMethodsUser,
2828
} from "../../../test-utils";
2929

30-
// Fake random strings to give a predictable snapshot for IDs
31-
jest.mock("matrix-js-sdk/src/randomstring", () => ({
32-
randomString: () => "abdefghi",
33-
}));
34-
3530
describe("<DialogSidebar />", () => {
3631
const defaultProps: ComponentProps<typeof DialogSidebar> = {
3732
beacons: [],

test/components/views/beacon/ShareLatestLocation-test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ import ShareLatestLocation from "../../../../src/components/views/beacon/ShareLa
2121
import { copyPlaintext } from "../../../../src/utils/strings";
2222
import { flushPromises } from "../../../test-utils";
2323

24-
// Fake random strings to give a predictable snapshot for IDs
25-
jest.mock("matrix-js-sdk/src/randomstring", () => ({
26-
randomString: () => "abdefghi",
27-
}));
28-
2924
jest.mock("../../../../src/utils/strings", () => ({
3025
copyPlaintext: jest.fn().mockResolvedValue(undefined),
3126
}));

test/components/views/beacon/__snapshots__/BeaconListItem-test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ exports[`<BeaconListItem /> when a beacon is live and has locations renders beac
3232
class="mx_BeaconListItem_interactions"
3333
>
3434
<div
35-
aria-describedby="mx_TooltipTarget_abdefghi"
35+
aria-describedby="mx_TooltipTarget_vY7Q4uEh"
3636
tabindex="0"
3737
>
3838
<a

test/components/views/beacon/__snapshots__/DialogSidebar-test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ exports[`<DialogSidebar /> renders sidebar correctly with beacons 1`] = `
6262
class="mx_BeaconListItem_interactions"
6363
>
6464
<div
65-
aria-describedby="mx_TooltipTarget_abdefghi"
65+
aria-describedby="mx_TooltipTarget_vY7Q4uEh"
6666
tabindex="0"
6767
>
6868
<a

test/components/views/beacon/__snapshots__/ShareLatestLocation-test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`<ShareLatestLocation /> renders share buttons when there is a location 1`] = `
44
<DocumentFragment>
55
<div
6-
aria-describedby="mx_TooltipTarget_abdefghi"
6+
aria-describedby="mx_TooltipTarget_vY7Q4uEh"
77
tabindex="0"
88
>
99
<a

test/components/views/dialogs/ManageRestrictedJoinRuleDialog-test.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ import ManageRestrictedJoinRuleDialog from "../../../../src/components/views/dia
2323
import SpaceStore from "../../../../src/stores/spaces/SpaceStore";
2424
import DMRoomMap from "../../../../src/utils/DMRoomMap";
2525

26-
// Fake random strings to give a predictable snapshot
27-
jest.mock("matrix-js-sdk/src/randomstring", () => {
28-
return {
29-
randomString: () => "abdefghi",
30-
};
31-
});
32-
3326
describe("<ManageRestrictedJoinRuleDialog />", () => {
3427
const userId = "@alice:server.org";
3528
const mockClient = getMockClientWithEventEmitter({

test/components/views/dialogs/ServerPickerDialog-test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ import SdkConfig from "../../../../src/SdkConfig";
2323
import { flushPromises } from "../../../test-utils";
2424
import { ValidatedServerConfig } from "../../../../src/utils/ValidatedServerConfig";
2525

26-
// Fake random strings to give a predictable snapshot for IDs
27-
jest.mock("matrix-js-sdk/src/randomstring", () => ({
28-
randomString: () => "abdefghi",
29-
}));
30-
3126
describe("<ServerPickerDialog />", () => {
3227
const defaultServerConfig = {
3328
hsUrl: "https://matrix.org",

test/components/views/dialogs/__snapshots__/ManageRestrictedJoinRuleDialog-test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ exports[`<ManageRestrictedJoinRuleDialog /> should list spaces which are not par
107107
class="mx_Checkbox mx_Checkbox_hasKind mx_Checkbox_kind_solid"
108108
>
109109
<input
110-
id="checkbox_abdefghi"
110+
id="checkbox_vY7Q4uEh9K"
111111
type="checkbox"
112112
/>
113113
<label
114-
for="checkbox_abdefghi"
114+
for="checkbox_vY7Q4uEh9K"
115115
>
116116
<div
117117
class="mx_Checkbox_background"

test/components/views/dialogs/__snapshots__/ServerPickerDialog-test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ exports[`<ServerPickerDialog /> should render dialog 1`] = `
5656
class="mx_StyledRadioButton_content"
5757
>
5858
<div
59-
aria-describedby="mx_TooltipTarget_abdefghi"
59+
aria-describedby="mx_TooltipTarget_vY7Q4uEh"
6060
class="mx_TextWithTooltip_target mx_Login_underlinedServerName"
6161
tabindex="0"
6262
>

test/components/views/elements/AppTile-test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ jest.mock("../../../../src/stores/OwnProfileStore", () => ({
6161
},
6262
}));
6363

64-
// Fake random strings to give a predictable snapshot
65-
jest.mock("matrix-js-sdk/src/randomstring", () => ({
66-
randomString: () => "abdefghi",
67-
}));
68-
6964
describe("AppTile", () => {
7065
let cli: MatrixClient;
7166
let r1: Room;

test/components/views/elements/LabelledCheckbox-test.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ import React from "react";
1919

2020
import LabelledCheckbox from "../../../../src/components/views/elements/LabelledCheckbox";
2121

22-
// Fake random strings to give a predictable snapshot for checkbox IDs
23-
jest.mock("matrix-js-sdk/src/randomstring", () => {
24-
return {
25-
randomString: () => "abdefghi",
26-
};
27-
});
28-
2922
describe("<LabelledCheckbox />", () => {
3023
type CompProps = React.ComponentProps<typeof LabelledCheckbox>;
3124
const getComponent = (props: CompProps) => <LabelledCheckbox {...props} />;

test/components/views/elements/__snapshots__/AppTile-test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ exports[`AppTile for a pinned widget should render permission request 1`] = `
276276
<span>
277277
Using this widget may share data
278278
<div
279-
aria-describedby="mx_TooltipTarget_abdefghi"
279+
aria-describedby="mx_TooltipTarget_vY7Q4uEh"
280280
class="mx_TextWithTooltip_target mx_TextWithTooltip_target--helpIcon"
281281
tabindex="0"
282282
>

test/components/views/elements/__snapshots__/LabelledCheckbox-test.tsx.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ exports[`<LabelledCheckbox /> should render with byline of "this is a byline" 1`
1010
>
1111
<input
1212
checked=""
13-
id="checkbox_abdefghi"
13+
id="checkbox_vY7Q4uEh9K"
1414
type="checkbox"
1515
/>
1616
<label
17-
for="checkbox_abdefghi"
17+
for="checkbox_vY7Q4uEh9K"
1818
>
1919
<div
2020
class="mx_Checkbox_background"
@@ -53,11 +53,11 @@ exports[`<LabelledCheckbox /> should render with byline of undefined 1`] = `
5353
>
5454
<input
5555
checked=""
56-
id="checkbox_abdefghi"
56+
id="checkbox_vY7Q4uEh9K"
5757
type="checkbox"
5858
/>
5959
<label
60-
for="checkbox_abdefghi"
60+
for="checkbox_vY7Q4uEh9K"
6161
>
6262
<div
6363
class="mx_Checkbox_background"

test/components/views/location/LocationShareMenu-test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ jest.mock("../../../../src/Modal", () => ({
7070
ModalManagerEvent: { Opened: "opened" },
7171
}));
7272

73-
// Fake random strings to give a predictable snapshot for IDs
74-
jest.mock("matrix-js-sdk/src/randomstring", () => ({
75-
randomString: () => "abdefghi",
76-
}));
77-
7873
describe("<LocationShareMenu />", () => {
7974
const userId = "@ernie:server.org";
8075
const mockClient = getMockClientWithEventEmitter({

test/components/views/location/__snapshots__/LocationShareMenu-test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ exports[`<LocationShareMenu /> with live location disabled goes to labs flag scr
2626
class="mx_SettingsFlag_label"
2727
>
2828
<div
29-
id="mx_LabelledToggleSwitch_abdefghi"
29+
id="mx_LabelledToggleSwitch_vY7Q4uEh9K38"
3030
>
3131
Enable live location sharing
3232
</div>
3333
</span>
3434
<div
3535
aria-checked="false"
3636
aria-disabled="false"
37-
aria-labelledby="mx_LabelledToggleSwitch_abdefghi"
37+
aria-labelledby="mx_LabelledToggleSwitch_vY7Q4uEh9K38"
3838
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_enabled"
3939
role="switch"
4040
tabindex="0"

test/components/views/messages/MLocationBody-test.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ import { TILE_SERVER_WK_KEY } from "../../../../src/utils/WellKnownUtils";
3232
import { makeLocationEvent } from "../../../test-utils/location";
3333
import { getMockClientWithEventEmitter } from "../../../test-utils";
3434

35-
// Fake random strings to give a predictable snapshot
36-
jest.mock("matrix-js-sdk/src/randomstring", () => {
37-
return {
38-
randomString: () => "abdefghi",
39-
};
40-
});
41-
4235
describe("MLocationBody", () => {
4336
const mapOptions = { container: {} as unknown as HTMLElement, style: "" };
4437
describe("<MLocationBody>", () => {

0 commit comments

Comments
 (0)