From 4eba451176bb682c7746e07b2fe62eace2e11403 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 22 Mar 2022 00:44:03 -0600 Subject: [PATCH 1/5] Actually fix the space panel not working (#8111) --- res/css/structures/_LeftPanel.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/res/css/structures/_LeftPanel.scss b/res/css/structures/_LeftPanel.scss index f663d5a70bb..4186beab258 100644 --- a/res/css/structures/_LeftPanel.scss +++ b/res/css/structures/_LeftPanel.scss @@ -37,6 +37,7 @@ $roomListCollapsedWidth: 68px; display: flex; flex-direction: row; flex: 1; + height: 100%; // ensure space panel is still scrollable with an outer wrapper .mx_LeftPanel_wrapper--user { background-color: $roomlist-bg-color; From 6639b60dfd11da2a7712fe915b926d08d38292d0 Mon Sep 17 00:00:00 2001 From: Germain Date: Tue, 22 Mar 2022 08:25:39 +0000 Subject: [PATCH 2/5] Only consider is_falling_back when threads is enabled (#8083) Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- src/utils/Reply.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/Reply.ts b/src/utils/Reply.ts index 7c5d92fc46e..3d62bb946c0 100644 --- a/src/utils/Reply.ts +++ b/src/utils/Reply.ts @@ -22,6 +22,7 @@ import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread"; import { PERMITTED_URL_SCHEMES } from "../HtmlUtils"; import { makeUserPermalink, RoomPermalinkCreator } from "./permalinks/Permalinks"; import { RecursivePartial } from "../@types/common"; +import SettingsStore from "../settings/SettingsStore"; export function getParentEventId(ev: MatrixEvent): string | undefined { if (!ev || ev.isRedacted()) return; @@ -178,7 +179,10 @@ export function shouldDisplayReply(event: MatrixEvent): boolean { } const relation = event.getRelation(); - if (relation?.rel_type === THREAD_RELATION_TYPE.name && relation?.is_falling_back) { + if (SettingsStore.getValue("feature_thread") && + relation?.rel_type === THREAD_RELATION_TYPE.name && + relation?.is_falling_back + ) { return false; } From 2bf1d2b287c3d4ea2ab8cc023efbf538bfe37f76 Mon Sep 17 00:00:00 2001 From: Germain Date: Tue, 22 Mar 2022 09:23:55 +0000 Subject: [PATCH 3/5] Change stable threads dialog copy (#8099) --- src/components/structures/MatrixChat.tsx | 20 ++++++++++---------- src/i18n/strings/en_EN.json | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 4d1efe81889..203c26cd7bb 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -1465,24 +1465,24 @@ export default class MatrixChat extends React.PureComponent { setTimeout(() => { if (SettingsStore.getValue("feature_thread") && SdkConfig.get("show_labs_settings")) { Modal.createDialog(InfoDialog, { - title: _t("Threads are no longer experimental! 🎉"), + title: _t("Threads Approaching Beta 🎉"), description: <>

- { _t("We’ve recently introduced key stability " - + "improvements for Threads, which also means " - + "phasing out support for experimental Threads.") } + { _t("We're getting closer to releasing a public Beta for Threads.") }

- { _t("All thread events created during the " - + "experimental period will now be rendered in " - + "the room timeline and displayed as replies. " - + "This is a one-off transition. Threads are now " - + "part of the Matrix specification.") } + { _t("As we prepare for it, we need to make some changes: threads created " + + "before this point will be displayed as regular replies.", + {}, { + "strong": sub => { sub }, + }) }

- { _t("Thank you for helping us testing Threads!") } + { _t("This will be a one-off transition, as threads are now part " + + "of the Matrix specification.") }

, + button: _t("Got it"), onFinished: () => { localStorage.setItem("mx_seen_feature_thread_experimental", "true"); }, diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 08332fecdab..6b94b7a85df 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -3098,10 +3098,10 @@ "Failed to forget room %(errCode)s": "Failed to forget room %(errCode)s", "Unable to copy room link": "Unable to copy room link", "Unable to copy a link to the room to the clipboard.": "Unable to copy a link to the room to the clipboard.", - "Threads are no longer experimental! 🎉": "Threads are no longer experimental! 🎉", - "We’ve recently introduced key stability improvements for Threads, which also means phasing out support for experimental Threads.": "We’ve recently introduced key stability improvements for Threads, which also means phasing out support for experimental Threads.", - "All thread events created during the experimental period will now be rendered in the room timeline and displayed as replies. This is a one-off transition. Threads are now part of the Matrix specification.": "All thread events created during the experimental period will now be rendered in the room timeline and displayed as replies. This is a one-off transition. Threads are now part of the Matrix specification.", - "Thank you for helping us testing Threads!": "Thank you for helping us testing Threads!", + "Threads Approaching Beta 🎉": "Threads Approaching Beta 🎉", + "We're getting closer to releasing a public Beta for Threads.": "We're getting closer to releasing a public Beta for Threads.", + "As we prepare for it, we need to make some changes: threads created before this point will be displayed as regular replies.": "As we prepare for it, we need to make some changes: threads created before this point will be displayed as regular replies.", + "This will be a one-off transition, as threads are now part of the Matrix specification.": "This will be a one-off transition, as threads are now part of the Matrix specification.", "New search beta available": "New search beta available", "We're testing a new search to make finding what you want quicker.\n": "We're testing a new search to make finding what you want quicker.\n", "Signed Out": "Signed Out", From abc225d3c60e8542ad976bc36c6ea5ed9e4facaa Mon Sep 17 00:00:00 2001 From: Kerry Date: Tue, 22 Mar 2022 11:32:35 +0100 Subject: [PATCH 4/5] Unit test tsc fixes part 15 (#8104) * fix ts issues in MPollBody test Signed-off-by: Kerry Archibald * fix ts issues in PollCreateDialog Signed-off-by: Kerry Archibald * fix settings components Signed-off-by: Kerry Archibald * fix DateSeparator Signed-off-by: Kerry Archibald * fix loosies Signed-off-by: Kerry Archibald * update tsconfig Signed-off-by: Kerry Archibald --- .../views/elements/AppTile-test.tsx | 14 +- .../views/elements/PollCreateDialog-test.tsx | 58 +- .../views/messages/DateSeparator-test.tsx | 15 +- .../views/messages/MLocationBody-test.tsx | 2 +- .../views/messages/MPollBody-test.tsx | 160 +- .../__snapshots__/DateSeparator-test.tsx.snap | 138 +- .../__snapshots__/MPollBody-test.tsx.snap | 3986 ++++++++--------- .../views/settings/FontScalingPanel-test.tsx | 4 +- .../views/settings/KeyboardShortcut-test.tsx | 5 +- .../views/settings/Notifications-test.tsx | 26 +- .../views/settings/ThemeChoicePanel-test.tsx | 4 +- .../FontScalingPanel-test.tsx.snap | 500 +-- .../ThemeChoicePanel-test.tsx.snap | 196 +- .../views/spaces/QuickThemeSwitcher-test.tsx | 4 +- .../SpaceSettingsVisibilityTab-test.tsx | 11 +- tsconfig.json | 10 +- 16 files changed, 2379 insertions(+), 2754 deletions(-) diff --git a/test/components/views/elements/AppTile-test.tsx b/test/components/views/elements/AppTile-test.tsx index d10ca20bc28..7f035131a3f 100644 --- a/test/components/views/elements/AppTile-test.tsx +++ b/test/components/views/elements/AppTile-test.tsx @@ -114,6 +114,10 @@ describe("AppTile", () => { await RightPanelStore.instance.onReady(); }); + beforeEach(() => { + jest.spyOn(SettingsStore, "getValue").mockRestore(); + }); + it("tracks live tiles correctly", () => { expect(AppTile.isLive("1", "r1")).toEqual(false); @@ -196,7 +200,7 @@ describe("AppTile", () => { it("distinguishes widgets with the same ID in different rooms", async () => { // Set up right panel state const realGetValue = SettingsStore.getValue; - SettingsStore.getValue = (name, roomId) => { + jest.spyOn(SettingsStore, 'getValue').mockImplementation((name, roomId) => { if (name === "RightPanel.phases") { if (roomId === "r1") { return { @@ -212,7 +216,7 @@ describe("AppTile", () => { return null; } return realGetValue(name, roomId); - }; + }); // Run initial render with room 1, and also running lifecycle methods const renderer = TestRenderer.create( @@ -232,7 +236,7 @@ describe("AppTile", () => { expect(AppTile.isLive("1", "r1")).toBe(true); expect(AppTile.isLive("1", "r2")).toBe(false); - SettingsStore.getValue = (name, roomId) => { + jest.spyOn(SettingsStore, "getValue").mockImplementation((name, roomId) => { if (name === "RightPanel.phases") { if (roomId === "r2") { return { @@ -248,7 +252,7 @@ describe("AppTile", () => { return null; } return realGetValue(name, roomId); - }; + }); // Wait for RPS room 2 updates to fire const rpsUpdated2 = waitForRps("r2"); // Switch to room 2 @@ -266,8 +270,6 @@ describe("AppTile", () => { expect(AppTile.isLive("1", "r1")).toBe(false); expect(AppTile.isLive("1", "r2")).toBe(true); - - SettingsStore.getValue = realGetValue; }); it("preserves non-persisted widget on container move", async () => { diff --git a/test/components/views/elements/PollCreateDialog-test.tsx b/test/components/views/elements/PollCreateDialog-test.tsx index 7ac68ccf3ba..779b68e16bb 100644 --- a/test/components/views/elements/PollCreateDialog-test.tsx +++ b/test/components/views/elements/PollCreateDialog-test.tsx @@ -26,16 +26,15 @@ import { M_TEXT, PollStartEvent, } from 'matrix-events-sdk'; -import { IContent, MatrixEvent } from 'matrix-js-sdk/src/models/event'; +import { MatrixEvent } from 'matrix-js-sdk/src/models/event'; import { - wrapInMatrixClientContext, findById, - stubClient, + getMockClientWithEventEmitter, } from '../../../test-utils'; import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; -import _PollCreateDialog from "../../../../src/components/views/elements/PollCreateDialog"; -const PollCreateDialog = wrapInMatrixClientContext(_PollCreateDialog); +import PollCreateDialog from "../../../../src/components/views/elements/PollCreateDialog"; +import MatrixClientContext from '../../../../src/contexts/MatrixClientContext'; // Fake date to give a predictable snapshot const realDateNow = Date.now; @@ -51,9 +50,21 @@ afterAll(() => { }); describe("PollCreateDialog", () => { + const mockClient = getMockClientWithEventEmitter({ + sendEvent: jest.fn().mockResolvedValue({ event_id: '1' }), + }); + + beforeEach(() => { + mockClient.sendEvent.mockClear(); + }); + it("renders a blank poll", () => { const dialog = mount( , + { + wrappingComponent: MatrixClientContext.Provider, + wrappingComponentProps: { value: mockClient }, + }, ); expect(dialog.html()).toMatchSnapshot(); }); @@ -207,9 +218,6 @@ describe("PollCreateDialog", () => { }); it("displays a spinner after submitting", () => { - stubClient(); - MatrixClientPeg.get().sendEvent = jest.fn(() => Promise.resolve()); - const dialog = mount( , ); @@ -223,21 +231,6 @@ describe("PollCreateDialog", () => { }); it("sends a poll create event when submitted", () => { - stubClient(); - let sentEventContent: IContent = null; - MatrixClientPeg.get().sendEvent = jest.fn( - ( - _roomId: string, - _threadId: string, - eventType: string, - content: IContent, - ) => { - expect(M_POLL_START.matches(eventType)).toBeTruthy(); - sentEventContent = content; - return Promise.resolve(); - }, - ); - const dialog = mount( , ); @@ -246,6 +239,8 @@ describe("PollCreateDialog", () => { changeValue(dialog, "Option 2", "A2"); dialog.find("button").simulate("click"); + const [, , eventType, sentEventContent] = mockClient.sendEvent.mock.calls[0]; + expect(M_POLL_START.matches(eventType)).toBeTruthy(); expect(sentEventContent).toEqual( { [M_TEXT.name]: "Q\n1. A1\n2. A2", @@ -275,21 +270,6 @@ describe("PollCreateDialog", () => { }); it("sends a poll edit event when editing", () => { - stubClient(); - let sentEventContent: IContent = null; - MatrixClientPeg.get().sendEvent = jest.fn( - ( - _roomId: string, - _threadId: string, - eventType: string, - content: IContent, - ) => { - expect(M_POLL_START.matches(eventType)).toBeTruthy(); - sentEventContent = content; - return Promise.resolve(); - }, - ); - const previousEvent: MatrixEvent = new MatrixEvent( PollStartEvent.from( "Poll Q", @@ -312,6 +292,8 @@ describe("PollCreateDialog", () => { changeKind(dialog, M_POLL_KIND_UNDISCLOSED.name); dialog.find("button").simulate("click"); + const [, , eventType, sentEventContent] = mockClient.sendEvent.mock.calls[0]; + expect(M_POLL_START.matches(eventType)).toBeTruthy(); expect(sentEventContent).toEqual( { "m.new_content": { diff --git a/test/components/views/messages/DateSeparator-test.tsx b/test/components/views/messages/DateSeparator-test.tsx index 574a22289d7..89987114b1c 100644 --- a/test/components/views/messages/DateSeparator-test.tsx +++ b/test/components/views/messages/DateSeparator-test.tsx @@ -16,17 +16,18 @@ limitations under the License. import React from "react"; import { mount } from "enzyme"; +import { mocked } from "jest-mock"; import sdk from "../../../skinned-sdk"; -import * as TestUtils from "../../../test-utils"; import { formatFullDateNoTime } from "../../../../src/DateUtils"; import SettingsStore from "../../../../src/settings/SettingsStore"; import { UIFeature } from "../../../../src/settings/UIFeature"; +import MatrixClientContext from "../../../../src/contexts/MatrixClientContext"; +import { getMockClientWithEventEmitter } from "../../../test-utils"; jest.mock("../../../../src/settings/SettingsStore"); -const _DateSeparator = sdk.getComponent("views.messages.DateSeparator"); -const DateSeparator = TestUtils.wrapInMatrixClientContext(_DateSeparator); +const DateSeparator = sdk.getComponent("views.messages.DateSeparator"); describe("DateSeparator", () => { const HOUR_MS = 3600000; @@ -45,8 +46,12 @@ describe("DateSeparator", () => { } } + const mockClient = getMockClientWithEventEmitter({}); const getComponent = (props = {}) => - mount(); + mount(, { + wrappingComponent: MatrixClientContext.Provider, + wrappingComponentProps: { value: mockClient }, + }); type TestCase = [string, number, string]; const testCases: TestCase[] = [ @@ -106,7 +111,7 @@ describe("DateSeparator", () => { describe('when feature_jump_to_date is enabled', () => { beforeEach(() => { - (SettingsStore.getValue as jest.Mock) = jest.fn((arg) => { + mocked(SettingsStore).getValue.mockImplementation((arg) => { if (arg === "feature_jump_to_date") { return true; } diff --git a/test/components/views/messages/MLocationBody-test.tsx b/test/components/views/messages/MLocationBody-test.tsx index c9b4bb2f496..67c274ef9ea 100644 --- a/test/components/views/messages/MLocationBody-test.tsx +++ b/test/components/views/messages/MLocationBody-test.tsx @@ -222,7 +222,7 @@ describe("MLocationBody", () => { describe("isSelfLocation", () => { it("Returns true for a full m.asset event", () => { - const content = makeLocationContent("", 0); + const content = makeLocationContent("", '0'); expect(isSelfLocation(content)).toBe(true); }); diff --git a/test/components/views/messages/MPollBody-test.tsx b/test/components/views/messages/MPollBody-test.tsx index 69cf16ab477..b2c39ece21b 100644 --- a/test/components/views/messages/MPollBody-test.tsx +++ b/test/components/views/messages/MPollBody-test.tsx @@ -16,8 +16,7 @@ limitations under the License. import React from "react"; import { mount, ReactWrapper } from "enzyme"; -import { Callback, IContent, MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix"; -import { ISendEventResponse } from "matrix-js-sdk/src/@types/requests"; +import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix"; import { Relations } from "matrix-js-sdk/src/models/relations"; import { RelatedRelations } from "matrix-js-sdk/src/models/related-relations"; import { @@ -30,8 +29,8 @@ import { M_TEXT, POLL_ANSWER, } from "matrix-events-sdk"; +import { MockedObject } from "jest-mock"; -import * as TestUtils from "../../../test-utils"; import sdk from "../../../skinned-sdk"; import { UserVote, @@ -42,19 +41,26 @@ import { } from "../../../../src/components/views/messages/MPollBody"; import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; import { IBodyProps } from "../../../../src/components/views/messages/IBodyProps"; +import { getMockClientWithEventEmitter } from "../../../test-utils"; +import MatrixClientContext from "../../../../src/contexts/MatrixClientContext"; const CHECKED = "mx_MPollBody_option_checked"; -const _MPollBody = sdk.getComponent("views.messages.MPollBody"); -const MPollBody = TestUtils.wrapInMatrixClientContext(_MPollBody); +const MPollBody = sdk.getComponent("views.messages.MPollBody"); -MatrixClientPeg.matrixClient = { - getUserId: () => "@me:example.com", - sendEvent: () => Promise.resolve({ "event_id": "fake_send_id" }), -}; -setRedactionAllowedForMeOnly(MatrixClientPeg.matrixClient); +const mockClient = getMockClientWithEventEmitter({ + getUserId: jest.fn().mockReturnValue("@me:example.com"), + sendEvent: jest.fn().mockReturnValue(Promise.resolve({ "event_id": "fake_send_id" })), + getRoom: jest.fn(), +}); + +setRedactionAllowedForMeOnly(mockClient); describe("MPollBody", () => { + beforeEach(() => { + mockClient.sendEvent.mockClear(); + }); + it("finds no votes if there are none", () => { expect( allVotes( @@ -110,13 +116,12 @@ describe("MPollBody", () => { ]), ]); - const matrixClient = TestUtils.createTestClient(); - setRedactionAllowedForMeOnly(matrixClient); + setRedactionAllowedForMeOnly(mockClient); expect( pollEndTs( { getRoomId: () => "$room" } as MatrixEvent, - matrixClient, + mockClient, endRelations, ), ).toBe(12); @@ -132,13 +137,12 @@ describe("MPollBody", () => { ]), ]); - const matrixClient = TestUtils.createTestClient(); - setRedactionAllowedForMeOnly(matrixClient); + setRedactionAllowedForMeOnly(mockClient); expect( pollEndTs( { getRoomId: () => "$room" } as MatrixEvent, - matrixClient, + mockClient, endRelations, ), ).toBe(13); @@ -460,7 +464,7 @@ describe("MPollBody", () => { const votes = []; const ends = []; const body = newMPollBody(votes, ends, answers); - expect(body.html()).toBe(""); + expect(body.html()).toBeNull(); }); it("renders the first 20 answers if 21 were given", () => { @@ -530,110 +534,47 @@ describe("MPollBody", () => { }); it("sends a vote event when I choose an option", () => { - const receivedEvents = []; - MatrixClientPeg.matrixClient.sendEvent = ( - roomId: string, - eventType: string, - content: IContent, - txnId?: string, - callback?: Callback, - ): Promise => { - receivedEvents.push({ roomId, eventType, content, txnId, callback }); - return Promise.resolve({ "event_id": "fake_tracked_send_id" }); - }; - const votes = []; const body = newMPollBody(votes); clickRadio(body, "wings"); - expect(receivedEvents).toEqual([ - expectedResponseEvent("wings"), - ]); + expect(mockClient.sendEvent).toHaveBeenCalledWith(...expectedResponseEventCall("wings")); }); it("sends only one vote event when I click several times", () => { - const receivedEvents = []; - MatrixClientPeg.matrixClient.sendEvent = ( - roomId: string, - eventType: string, - content: IContent, - txnId?: string, - callback?: Callback, - ): Promise => { - receivedEvents.push({ roomId, eventType, content, txnId, callback }); - return Promise.resolve({ "event_id": "fake_tracked_send_id" }); - }; - const votes = []; const body = newMPollBody(votes); clickRadio(body, "wings"); clickRadio(body, "wings"); clickRadio(body, "wings"); clickRadio(body, "wings"); - expect(receivedEvents).toEqual([ - expectedResponseEvent("wings"), - ]); + expect(mockClient.sendEvent).toHaveBeenCalledWith( + ...expectedResponseEventCall("wings"), + ); }); it("sends no vote event when I click what I already chose", () => { - const receivedEvents = []; - MatrixClientPeg.matrixClient.sendEvent = ( - roomId: string, - eventType: string, - content: IContent, - txnId?: string, - callback?: Callback, - ): Promise => { - receivedEvents.push({ roomId, eventType, content, txnId, callback }); - return Promise.resolve({ "event_id": "fake_tracked_send_id" }); - }; - const votes = [responseEvent("@me:example.com", "wings")]; const body = newMPollBody(votes); clickRadio(body, "wings"); clickRadio(body, "wings"); clickRadio(body, "wings"); clickRadio(body, "wings"); - expect(receivedEvents).toEqual([]); + expect(mockClient.sendEvent).not.toHaveBeenCalled(); }); it("sends several events when I click different options", () => { - const receivedEvents = []; - MatrixClientPeg.matrixClient.sendEvent = ( - roomId: string, - eventType: string, - content: IContent, - txnId?: string, - callback?: Callback, - ): Promise => { - receivedEvents.push({ roomId, eventType, content, txnId, callback }); - return Promise.resolve({ "event_id": "fake_tracked_send_id" }); - }; - const votes = []; const body = newMPollBody(votes); clickRadio(body, "wings"); clickRadio(body, "italian"); clickRadio(body, "poutine"); - expect(receivedEvents).toEqual([ - expectedResponseEvent("wings"), - expectedResponseEvent("italian"), - expectedResponseEvent("poutine"), - ]); + expect(mockClient.sendEvent).toHaveBeenCalledTimes(3); + expect(mockClient.sendEvent).toHaveBeenCalledWith(...expectedResponseEventCall("wings")); + expect(mockClient.sendEvent).toHaveBeenCalledWith(...expectedResponseEventCall("italian")); + expect(mockClient.sendEvent).toHaveBeenCalledWith(...expectedResponseEventCall("poutine")); }); it("sends no events when I click in an ended poll", () => { - const receivedEvents = []; - MatrixClientPeg.matrixClient.sendEvent = ( - roomId: string, - eventType: string, - content: IContent, - txnId?: string, - callback?: Callback, - ): Promise => { - receivedEvents.push({ roomId, eventType, content, txnId, callback }); - return Promise.resolve({ "event_id": "fake_tracked_send_id" }); - }; - const ends = [ endEvent("@me:example.com", 25), ]; @@ -645,7 +586,7 @@ describe("MPollBody", () => { clickEndedOption(body, "wings"); clickEndedOption(body, "italian"); clickEndedOption(body, "poutine"); - expect(receivedEvents).toEqual([]); + expect(mockClient.sendEvent).not.toHaveBeenCalled(); }); it("finds the top answer among several votes", () => { @@ -888,9 +829,8 @@ describe("MPollBody", () => { it("says poll is not ended if endRelations is undefined", () => { const pollEvent = new MatrixEvent(); - const matrixClient = TestUtils.createTestClient(); - setRedactionAllowedForMeOnly(matrixClient); - expect(isPollEnded(pollEvent, matrixClient, undefined)).toBe(false); + setRedactionAllowedForMeOnly(mockClient); + expect(isPollEnded(pollEvent, mockClient, undefined)).toBe(false); }); it("says poll is not ended if asking for relations returns undefined", () => { @@ -899,15 +839,15 @@ describe("MPollBody", () => { "room_id": "#myroom:example.com", "content": newPollStart([]), }); - MatrixClientPeg.matrixClient.getRoom = () => { + mockClient.getRoom.mockImplementation((_roomId) => { return { currentState: { maySendRedactionForEvent: (_evt: MatrixEvent, userId: string) => { return userId === "@me:example.com"; }, }, - }; - }; + } as unknown as Room; + }); const getRelationsForEvent = (eventId: string, relationType: string, eventType: string) => { expect(eventId).toBe("$mypoll"); @@ -1134,7 +1074,12 @@ function newMPollBodyFromEvent( } } } - />); + />, { + wrappingComponent: MatrixClientContext.Provider, + wrappingComponentProps: { + value: mockClient, + }, + }); } function clickRadio(wrapper: ReactWrapper, value: string) { @@ -1271,12 +1216,20 @@ function expectedResponseEvent(answer: string) { "rel_type": "m.reference", }, }, - "eventType": M_POLL_RESPONSE.name, "roomId": "#myroom:example.com", + "eventType": M_POLL_RESPONSE.name, "txnId": undefined, "callback": undefined, }; } +function expectedResponseEventCall(answer: string) { + const { + content, roomId, eventType, + } = expectedResponseEvent(answer); + return [ + roomId, eventType, content, + ]; +} function endEvent( sender = "@me:example.com", @@ -1309,8 +1262,7 @@ function runIsPollEnded(ends: MatrixEvent[]) { "content": newPollStart(), }); - const matrixClient = TestUtils.createTestClient(); - setRedactionAllowedForMeOnly(matrixClient); + setRedactionAllowedForMeOnly(mockClient); const getRelationsForEvent = (eventId: string, relationType: string, eventType: string) => { @@ -1320,7 +1272,7 @@ function runIsPollEnded(ends: MatrixEvent[]) { return newEndRelations(ends); }; - return isPollEnded(pollEvent, matrixClient, getRelationsForEvent); + return isPollEnded(pollEvent, mockClient, getRelationsForEvent); } function runFindTopAnswer(votes: MatrixEvent[], ends: MatrixEvent[]) { @@ -1347,8 +1299,8 @@ function runFindTopAnswer(votes: MatrixEvent[], ends: MatrixEvent[]) { return findTopAnswer(pollEvent, MatrixClientPeg.get(), getRelationsForEvent); } -function setRedactionAllowedForMeOnly(matrixClient: MatrixClient) { - matrixClient.getRoom = (_roomId: string) => { +function setRedactionAllowedForMeOnly(matrixClient: MockedObject) { + matrixClient.getRoom.mockImplementation((_roomId: string) => { return { currentState: { maySendRedactionForEvent: (_evt: MatrixEvent, userId: string) => { @@ -1356,7 +1308,7 @@ function setRedactionAllowedForMeOnly(matrixClient: MatrixClient) { }, }, } as Room; - }; + }); } let EVENT_ID = 0; diff --git a/test/components/views/messages/__snapshots__/DateSeparator-test.tsx.snap b/test/components/views/messages/__snapshots__/DateSeparator-test.tsx.snap index cc65b5cb1f5..c1ce2c860c7 100644 --- a/test/components/views/messages/__snapshots__/DateSeparator-test.tsx.snap +++ b/test/components/views/messages/__snapshots__/DateSeparator-test.tsx.snap @@ -1,116 +1,106 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`DateSeparator renders the date separator correctly 1`] = ` - - -

+

-
-
+ Today + +
+ +
`; exports[`DateSeparator when feature_jump_to_date is enabled renders the date separator correctly 1`] = ` - - -

+ -
- - -

-
-
+
+
+ + + +
+ +
`; diff --git a/test/components/views/messages/__snapshots__/MPollBody-test.tsx.snap b/test/components/views/messages/__snapshots__/MPollBody-test.tsx.snap index 6d080f78871..af37fefb7ba 100644 --- a/test/components/views/messages/__snapshots__/MPollBody-test.tsx.snap +++ b/test/components/views/messages/__snapshots__/MPollBody-test.tsx.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`MPollBody renders a finished poll 1`] = ` - - +

+ What should we order for the party? +

-

- What should we order for the party? -

-
- +
-
- Pizza -
-
- 0 votes -
+ Pizza +
+
+ 0 votes
- -
-
-
+
- +
+
+
+ +
-
- Poutine -
-
- 0 votes -
+ Poutine +
+
+ 0 votes
- -
-
-
+
- +
+
+
+ +
-
- Italian -
-
- 2 votes -
+ Italian +
+
+ 2 votes
- -
-
-
+
- +
+
+
+ +
-
- Wings -
-
- 1 vote -
+ Wings +
+
+ 1 vote
- +
+
+
-
-
+ } + />
-
- Final result based on 3 votes -
- - +
+ Final result based on 3 votes +
+
+ `; exports[`MPollBody renders a finished poll with multiple winners 1`] = ` - - +

+ What should we order for the party? +

-

- What should we order for the party? -

-
- +
-
- Pizza -
-
- 2 votes -
+ Pizza +
+
+ 2 votes
- -
-
-
+
- +
+
+
+ +
-
- Poutine -
-
- 0 votes -
+ Poutine +
+
+ 0 votes
- -
-
-
+
- +
+
+
+ +
-
- Italian -
-
- 0 votes -
+ Italian +
+
+ 0 votes
- -
-
-
+
- +
+
+
+ +
-
- Wings -
-
- 2 votes -
+ Wings +
+
+ 2 votes
- +
+
+
-
-
+ } + />
-
- Final result based on 4 votes -
- - +
+ Final result based on 4 votes +
+
+ `; exports[`MPollBody renders a finished poll with no votes 1`] = ` - - +

+ What should we order for the party? +

-

- What should we order for the party? -

-
- +
-
- Pizza -
-
- 0 votes -
+ Pizza +
+
+ 0 votes
- -
-
-
+
- +
+
+
+ +
-
- Poutine -
-
- 0 votes -
+ Poutine +
+
+ 0 votes
- -
-
-
+
- +
+
+
+ +
-
- Italian -
-
- 0 votes -
+ Italian +
+
+ 0 votes
- -
-
-
+
- +
+
+
+ +
-
- Wings -
-
- 0 votes -
+ Wings +
+
+ 0 votes
- +
+
+
-
-
-
-
-
- Final result based on 0 votes + } + /> +
- - +
+ Final result based on 0 votes +
+
+ `; exports[`MPollBody renders a poll that I have not voted in 1`] = ` - - +

+ What should we order for the party? +

-

- What should we order for the party? -

-
- + - -