Unit test tsc fixes part 15 (#8104)

* fix ts issues in MPollBody test

Signed-off-by: Kerry Archibald <kerrya@element.io>

* fix ts issues in PollCreateDialog

Signed-off-by: Kerry Archibald <kerrya@element.io>

* fix settings components

Signed-off-by: Kerry Archibald <kerrya@element.io>

* fix DateSeparator

Signed-off-by: Kerry Archibald <kerrya@element.io>

* fix loosies

Signed-off-by: Kerry Archibald <kerrya@element.io>

* update tsconfig

Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
Kerry 2022-03-22 11:32:35 +01:00 committed by GitHub
parent 2bf1d2b287
commit abc225d3c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 2663 additions and 3038 deletions

View File

@ -114,6 +114,10 @@ describe("AppTile", () => {
await RightPanelStore.instance.onReady(); await RightPanelStore.instance.onReady();
}); });
beforeEach(() => {
jest.spyOn(SettingsStore, "getValue").mockRestore();
});
it("tracks live tiles correctly", () => { it("tracks live tiles correctly", () => {
expect(AppTile.isLive("1", "r1")).toEqual(false); expect(AppTile.isLive("1", "r1")).toEqual(false);
@ -196,7 +200,7 @@ describe("AppTile", () => {
it("distinguishes widgets with the same ID in different rooms", async () => { it("distinguishes widgets with the same ID in different rooms", async () => {
// Set up right panel state // Set up right panel state
const realGetValue = SettingsStore.getValue; const realGetValue = SettingsStore.getValue;
SettingsStore.getValue = (name, roomId) => { jest.spyOn(SettingsStore, 'getValue').mockImplementation((name, roomId) => {
if (name === "RightPanel.phases") { if (name === "RightPanel.phases") {
if (roomId === "r1") { if (roomId === "r1") {
return { return {
@ -212,7 +216,7 @@ describe("AppTile", () => {
return null; return null;
} }
return realGetValue(name, roomId); return realGetValue(name, roomId);
}; });
// Run initial render with room 1, and also running lifecycle methods // Run initial render with room 1, and also running lifecycle methods
const renderer = TestRenderer.create(<MatrixClientContext.Provider value={cli}> const renderer = TestRenderer.create(<MatrixClientContext.Provider value={cli}>
@ -232,7 +236,7 @@ describe("AppTile", () => {
expect(AppTile.isLive("1", "r1")).toBe(true); expect(AppTile.isLive("1", "r1")).toBe(true);
expect(AppTile.isLive("1", "r2")).toBe(false); expect(AppTile.isLive("1", "r2")).toBe(false);
SettingsStore.getValue = (name, roomId) => { jest.spyOn(SettingsStore, "getValue").mockImplementation((name, roomId) => {
if (name === "RightPanel.phases") { if (name === "RightPanel.phases") {
if (roomId === "r2") { if (roomId === "r2") {
return { return {
@ -248,7 +252,7 @@ describe("AppTile", () => {
return null; return null;
} }
return realGetValue(name, roomId); return realGetValue(name, roomId);
}; });
// Wait for RPS room 2 updates to fire // Wait for RPS room 2 updates to fire
const rpsUpdated2 = waitForRps("r2"); const rpsUpdated2 = waitForRps("r2");
// Switch to room 2 // Switch to room 2
@ -266,8 +270,6 @@ describe("AppTile", () => {
expect(AppTile.isLive("1", "r1")).toBe(false); expect(AppTile.isLive("1", "r1")).toBe(false);
expect(AppTile.isLive("1", "r2")).toBe(true); expect(AppTile.isLive("1", "r2")).toBe(true);
SettingsStore.getValue = realGetValue;
}); });
it("preserves non-persisted widget on container move", async () => { it("preserves non-persisted widget on container move", async () => {

View File

@ -26,16 +26,15 @@ import {
M_TEXT, M_TEXT,
PollStartEvent, PollStartEvent,
} from 'matrix-events-sdk'; } from 'matrix-events-sdk';
import { IContent, MatrixEvent } from 'matrix-js-sdk/src/models/event'; import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { import {
wrapInMatrixClientContext,
findById, findById,
stubClient, getMockClientWithEventEmitter,
} from '../../../test-utils'; } from '../../../test-utils';
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
import _PollCreateDialog from "../../../../src/components/views/elements/PollCreateDialog"; import PollCreateDialog from "../../../../src/components/views/elements/PollCreateDialog";
const PollCreateDialog = wrapInMatrixClientContext(_PollCreateDialog); import MatrixClientContext from '../../../../src/contexts/MatrixClientContext';
// Fake date to give a predictable snapshot // Fake date to give a predictable snapshot
const realDateNow = Date.now; const realDateNow = Date.now;
@ -51,9 +50,21 @@ afterAll(() => {
}); });
describe("PollCreateDialog", () => { describe("PollCreateDialog", () => {
const mockClient = getMockClientWithEventEmitter({
sendEvent: jest.fn().mockResolvedValue({ event_id: '1' }),
});
beforeEach(() => {
mockClient.sendEvent.mockClear();
});
it("renders a blank poll", () => { it("renders a blank poll", () => {
const dialog = mount( const dialog = mount(
<PollCreateDialog room={createRoom()} onFinished={jest.fn()} />, <PollCreateDialog room={createRoom()} onFinished={jest.fn()} />,
{
wrappingComponent: MatrixClientContext.Provider,
wrappingComponentProps: { value: mockClient },
},
); );
expect(dialog.html()).toMatchSnapshot(); expect(dialog.html()).toMatchSnapshot();
}); });
@ -207,9 +218,6 @@ describe("PollCreateDialog", () => {
}); });
it("displays a spinner after submitting", () => { it("displays a spinner after submitting", () => {
stubClient();
MatrixClientPeg.get().sendEvent = jest.fn(() => Promise.resolve());
const dialog = mount( const dialog = mount(
<PollCreateDialog room={createRoom()} onFinished={jest.fn()} />, <PollCreateDialog room={createRoom()} onFinished={jest.fn()} />,
); );
@ -223,21 +231,6 @@ describe("PollCreateDialog", () => {
}); });
it("sends a poll create event when submitted", () => { 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( const dialog = mount(
<PollCreateDialog room={createRoom()} onFinished={jest.fn()} />, <PollCreateDialog room={createRoom()} onFinished={jest.fn()} />,
); );
@ -246,6 +239,8 @@ describe("PollCreateDialog", () => {
changeValue(dialog, "Option 2", "A2"); changeValue(dialog, "Option 2", "A2");
dialog.find("button").simulate("click"); dialog.find("button").simulate("click");
const [, , eventType, sentEventContent] = mockClient.sendEvent.mock.calls[0];
expect(M_POLL_START.matches(eventType)).toBeTruthy();
expect(sentEventContent).toEqual( expect(sentEventContent).toEqual(
{ {
[M_TEXT.name]: "Q\n1. A1\n2. A2", [M_TEXT.name]: "Q\n1. A1\n2. A2",
@ -275,21 +270,6 @@ describe("PollCreateDialog", () => {
}); });
it("sends a poll edit event when editing", () => { 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( const previousEvent: MatrixEvent = new MatrixEvent(
PollStartEvent.from( PollStartEvent.from(
"Poll Q", "Poll Q",
@ -312,6 +292,8 @@ describe("PollCreateDialog", () => {
changeKind(dialog, M_POLL_KIND_UNDISCLOSED.name); changeKind(dialog, M_POLL_KIND_UNDISCLOSED.name);
dialog.find("button").simulate("click"); dialog.find("button").simulate("click");
const [, , eventType, sentEventContent] = mockClient.sendEvent.mock.calls[0];
expect(M_POLL_START.matches(eventType)).toBeTruthy();
expect(sentEventContent).toEqual( expect(sentEventContent).toEqual(
{ {
"m.new_content": { "m.new_content": {

View File

@ -16,17 +16,18 @@ limitations under the License.
import React from "react"; import React from "react";
import { mount } from "enzyme"; import { mount } from "enzyme";
import { mocked } from "jest-mock";
import sdk from "../../../skinned-sdk"; import sdk from "../../../skinned-sdk";
import * as TestUtils from "../../../test-utils";
import { formatFullDateNoTime } from "../../../../src/DateUtils"; import { formatFullDateNoTime } from "../../../../src/DateUtils";
import SettingsStore from "../../../../src/settings/SettingsStore"; import SettingsStore from "../../../../src/settings/SettingsStore";
import { UIFeature } from "../../../../src/settings/UIFeature"; import { UIFeature } from "../../../../src/settings/UIFeature";
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
import { getMockClientWithEventEmitter } from "../../../test-utils";
jest.mock("../../../../src/settings/SettingsStore"); jest.mock("../../../../src/settings/SettingsStore");
const _DateSeparator = sdk.getComponent("views.messages.DateSeparator"); const DateSeparator = sdk.getComponent("views.messages.DateSeparator");
const DateSeparator = TestUtils.wrapInMatrixClientContext(_DateSeparator);
describe("DateSeparator", () => { describe("DateSeparator", () => {
const HOUR_MS = 3600000; const HOUR_MS = 3600000;
@ -45,8 +46,12 @@ describe("DateSeparator", () => {
} }
} }
const mockClient = getMockClientWithEventEmitter({});
const getComponent = (props = {}) => const getComponent = (props = {}) =>
mount(<DateSeparator {...defaultProps} {...props} />); mount(<DateSeparator {...defaultProps} {...props} />, {
wrappingComponent: MatrixClientContext.Provider,
wrappingComponentProps: { value: mockClient },
});
type TestCase = [string, number, string]; type TestCase = [string, number, string];
const testCases: TestCase[] = [ const testCases: TestCase[] = [
@ -106,7 +111,7 @@ describe("DateSeparator", () => {
describe('when feature_jump_to_date is enabled', () => { describe('when feature_jump_to_date is enabled', () => {
beforeEach(() => { beforeEach(() => {
(SettingsStore.getValue as jest.Mock) = jest.fn((arg) => { mocked(SettingsStore).getValue.mockImplementation((arg) => {
if (arg === "feature_jump_to_date") { if (arg === "feature_jump_to_date") {
return true; return true;
} }

View File

@ -222,7 +222,7 @@ describe("MLocationBody", () => {
describe("isSelfLocation", () => { describe("isSelfLocation", () => {
it("Returns true for a full m.asset event", () => { it("Returns true for a full m.asset event", () => {
const content = makeLocationContent("", 0); const content = makeLocationContent("", '0');
expect(isSelfLocation(content)).toBe(true); expect(isSelfLocation(content)).toBe(true);
}); });

View File

@ -16,8 +16,7 @@ limitations under the License.
import React from "react"; import React from "react";
import { mount, ReactWrapper } from "enzyme"; import { mount, ReactWrapper } from "enzyme";
import { Callback, IContent, MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix"; import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
import { ISendEventResponse } from "matrix-js-sdk/src/@types/requests";
import { Relations } from "matrix-js-sdk/src/models/relations"; import { Relations } from "matrix-js-sdk/src/models/relations";
import { RelatedRelations } from "matrix-js-sdk/src/models/related-relations"; import { RelatedRelations } from "matrix-js-sdk/src/models/related-relations";
import { import {
@ -30,8 +29,8 @@ import {
M_TEXT, M_TEXT,
POLL_ANSWER, POLL_ANSWER,
} from "matrix-events-sdk"; } from "matrix-events-sdk";
import { MockedObject } from "jest-mock";
import * as TestUtils from "../../../test-utils";
import sdk from "../../../skinned-sdk"; import sdk from "../../../skinned-sdk";
import { import {
UserVote, UserVote,
@ -42,19 +41,26 @@ import {
} from "../../../../src/components/views/messages/MPollBody"; } from "../../../../src/components/views/messages/MPollBody";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
import { IBodyProps } from "../../../../src/components/views/messages/IBodyProps"; 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 CHECKED = "mx_MPollBody_option_checked";
const _MPollBody = sdk.getComponent("views.messages.MPollBody"); const MPollBody = sdk.getComponent("views.messages.MPollBody");
const MPollBody = TestUtils.wrapInMatrixClientContext(_MPollBody);
MatrixClientPeg.matrixClient = { const mockClient = getMockClientWithEventEmitter({
getUserId: () => "@me:example.com", getUserId: jest.fn().mockReturnValue("@me:example.com"),
sendEvent: () => Promise.resolve({ "event_id": "fake_send_id" }), sendEvent: jest.fn().mockReturnValue(Promise.resolve({ "event_id": "fake_send_id" })),
}; getRoom: jest.fn(),
setRedactionAllowedForMeOnly(MatrixClientPeg.matrixClient); });
setRedactionAllowedForMeOnly(mockClient);
describe("MPollBody", () => { describe("MPollBody", () => {
beforeEach(() => {
mockClient.sendEvent.mockClear();
});
it("finds no votes if there are none", () => { it("finds no votes if there are none", () => {
expect( expect(
allVotes( allVotes(
@ -110,13 +116,12 @@ describe("MPollBody", () => {
]), ]),
]); ]);
const matrixClient = TestUtils.createTestClient(); setRedactionAllowedForMeOnly(mockClient);
setRedactionAllowedForMeOnly(matrixClient);
expect( expect(
pollEndTs( pollEndTs(
{ getRoomId: () => "$room" } as MatrixEvent, { getRoomId: () => "$room" } as MatrixEvent,
matrixClient, mockClient,
endRelations, endRelations,
), ),
).toBe(12); ).toBe(12);
@ -132,13 +137,12 @@ describe("MPollBody", () => {
]), ]),
]); ]);
const matrixClient = TestUtils.createTestClient(); setRedactionAllowedForMeOnly(mockClient);
setRedactionAllowedForMeOnly(matrixClient);
expect( expect(
pollEndTs( pollEndTs(
{ getRoomId: () => "$room" } as MatrixEvent, { getRoomId: () => "$room" } as MatrixEvent,
matrixClient, mockClient,
endRelations, endRelations,
), ),
).toBe(13); ).toBe(13);
@ -460,7 +464,7 @@ describe("MPollBody", () => {
const votes = []; const votes = [];
const ends = []; const ends = [];
const body = newMPollBody(votes, ends, answers); const body = newMPollBody(votes, ends, answers);
expect(body.html()).toBe(""); expect(body.html()).toBeNull();
}); });
it("renders the first 20 answers if 21 were given", () => { 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", () => { 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<ISendEventResponse> => {
receivedEvents.push({ roomId, eventType, content, txnId, callback });
return Promise.resolve({ "event_id": "fake_tracked_send_id" });
};
const votes = []; const votes = [];
const body = newMPollBody(votes); const body = newMPollBody(votes);
clickRadio(body, "wings"); clickRadio(body, "wings");
expect(receivedEvents).toEqual([ expect(mockClient.sendEvent).toHaveBeenCalledWith(...expectedResponseEventCall("wings"));
expectedResponseEvent("wings"),
]);
}); });
it("sends only one vote event when I click several times", () => { 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<ISendEventResponse> => {
receivedEvents.push({ roomId, eventType, content, txnId, callback });
return Promise.resolve({ "event_id": "fake_tracked_send_id" });
};
const votes = []; const votes = [];
const body = newMPollBody(votes); const body = newMPollBody(votes);
clickRadio(body, "wings"); clickRadio(body, "wings");
clickRadio(body, "wings"); clickRadio(body, "wings");
clickRadio(body, "wings"); clickRadio(body, "wings");
clickRadio(body, "wings"); clickRadio(body, "wings");
expect(receivedEvents).toEqual([ expect(mockClient.sendEvent).toHaveBeenCalledWith(
expectedResponseEvent("wings"), ...expectedResponseEventCall("wings"),
]); );
}); });
it("sends no vote event when I click what I already chose", () => { 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<ISendEventResponse> => {
receivedEvents.push({ roomId, eventType, content, txnId, callback });
return Promise.resolve({ "event_id": "fake_tracked_send_id" });
};
const votes = [responseEvent("@me:example.com", "wings")]; const votes = [responseEvent("@me:example.com", "wings")];
const body = newMPollBody(votes); const body = newMPollBody(votes);
clickRadio(body, "wings"); clickRadio(body, "wings");
clickRadio(body, "wings"); clickRadio(body, "wings");
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", () => { 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<ISendEventResponse> => {
receivedEvents.push({ roomId, eventType, content, txnId, callback });
return Promise.resolve({ "event_id": "fake_tracked_send_id" });
};
const votes = []; const votes = [];
const body = newMPollBody(votes); const body = newMPollBody(votes);
clickRadio(body, "wings"); clickRadio(body, "wings");
clickRadio(body, "italian"); clickRadio(body, "italian");
clickRadio(body, "poutine"); clickRadio(body, "poutine");
expect(receivedEvents).toEqual([ expect(mockClient.sendEvent).toHaveBeenCalledTimes(3);
expectedResponseEvent("wings"), expect(mockClient.sendEvent).toHaveBeenCalledWith(...expectedResponseEventCall("wings"));
expectedResponseEvent("italian"), expect(mockClient.sendEvent).toHaveBeenCalledWith(...expectedResponseEventCall("italian"));
expectedResponseEvent("poutine"), expect(mockClient.sendEvent).toHaveBeenCalledWith(...expectedResponseEventCall("poutine"));
]);
}); });
it("sends no events when I click in an ended poll", () => { 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<ISendEventResponse> => {
receivedEvents.push({ roomId, eventType, content, txnId, callback });
return Promise.resolve({ "event_id": "fake_tracked_send_id" });
};
const ends = [ const ends = [
endEvent("@me:example.com", 25), endEvent("@me:example.com", 25),
]; ];
@ -645,7 +586,7 @@ describe("MPollBody", () => {
clickEndedOption(body, "wings"); clickEndedOption(body, "wings");
clickEndedOption(body, "italian"); clickEndedOption(body, "italian");
clickEndedOption(body, "poutine"); clickEndedOption(body, "poutine");
expect(receivedEvents).toEqual([]); expect(mockClient.sendEvent).not.toHaveBeenCalled();
}); });
it("finds the top answer among several votes", () => { it("finds the top answer among several votes", () => {
@ -888,9 +829,8 @@ describe("MPollBody", () => {
it("says poll is not ended if endRelations is undefined", () => { it("says poll is not ended if endRelations is undefined", () => {
const pollEvent = new MatrixEvent(); const pollEvent = new MatrixEvent();
const matrixClient = TestUtils.createTestClient(); setRedactionAllowedForMeOnly(mockClient);
setRedactionAllowedForMeOnly(matrixClient); expect(isPollEnded(pollEvent, mockClient, undefined)).toBe(false);
expect(isPollEnded(pollEvent, matrixClient, undefined)).toBe(false);
}); });
it("says poll is not ended if asking for relations returns undefined", () => { it("says poll is not ended if asking for relations returns undefined", () => {
@ -899,15 +839,15 @@ describe("MPollBody", () => {
"room_id": "#myroom:example.com", "room_id": "#myroom:example.com",
"content": newPollStart([]), "content": newPollStart([]),
}); });
MatrixClientPeg.matrixClient.getRoom = () => { mockClient.getRoom.mockImplementation((_roomId) => {
return { return {
currentState: { currentState: {
maySendRedactionForEvent: (_evt: MatrixEvent, userId: string) => { maySendRedactionForEvent: (_evt: MatrixEvent, userId: string) => {
return userId === "@me:example.com"; return userId === "@me:example.com";
}, },
}, },
}; } as unknown as Room;
}; });
const getRelationsForEvent = const getRelationsForEvent =
(eventId: string, relationType: string, eventType: string) => { (eventId: string, relationType: string, eventType: string) => {
expect(eventId).toBe("$mypoll"); expect(eventId).toBe("$mypoll");
@ -1134,7 +1074,12 @@ function newMPollBodyFromEvent(
} }
} }
} }
/>); />, {
wrappingComponent: MatrixClientContext.Provider,
wrappingComponentProps: {
value: mockClient,
},
});
} }
function clickRadio(wrapper: ReactWrapper, value: string) { function clickRadio(wrapper: ReactWrapper, value: string) {
@ -1271,12 +1216,20 @@ function expectedResponseEvent(answer: string) {
"rel_type": "m.reference", "rel_type": "m.reference",
}, },
}, },
"eventType": M_POLL_RESPONSE.name,
"roomId": "#myroom:example.com", "roomId": "#myroom:example.com",
"eventType": M_POLL_RESPONSE.name,
"txnId": undefined, "txnId": undefined,
"callback": undefined, "callback": undefined,
}; };
} }
function expectedResponseEventCall(answer: string) {
const {
content, roomId, eventType,
} = expectedResponseEvent(answer);
return [
roomId, eventType, content,
];
}
function endEvent( function endEvent(
sender = "@me:example.com", sender = "@me:example.com",
@ -1309,8 +1262,7 @@ function runIsPollEnded(ends: MatrixEvent[]) {
"content": newPollStart(), "content": newPollStart(),
}); });
const matrixClient = TestUtils.createTestClient(); setRedactionAllowedForMeOnly(mockClient);
setRedactionAllowedForMeOnly(matrixClient);
const getRelationsForEvent = const getRelationsForEvent =
(eventId: string, relationType: string, eventType: string) => { (eventId: string, relationType: string, eventType: string) => {
@ -1320,7 +1272,7 @@ function runIsPollEnded(ends: MatrixEvent[]) {
return newEndRelations(ends); return newEndRelations(ends);
}; };
return isPollEnded(pollEvent, matrixClient, getRelationsForEvent); return isPollEnded(pollEvent, mockClient, getRelationsForEvent);
} }
function runFindTopAnswer(votes: MatrixEvent[], ends: MatrixEvent[]) { function runFindTopAnswer(votes: MatrixEvent[], ends: MatrixEvent[]) {
@ -1347,8 +1299,8 @@ function runFindTopAnswer(votes: MatrixEvent[], ends: MatrixEvent[]) {
return findTopAnswer(pollEvent, MatrixClientPeg.get(), getRelationsForEvent); return findTopAnswer(pollEvent, MatrixClientPeg.get(), getRelationsForEvent);
} }
function setRedactionAllowedForMeOnly(matrixClient: MatrixClient) { function setRedactionAllowedForMeOnly(matrixClient: MockedObject<MatrixClient>) {
matrixClient.getRoom = (_roomId: string) => { matrixClient.getRoom.mockImplementation((_roomId: string) => {
return { return {
currentState: { currentState: {
maySendRedactionForEvent: (_evt: MatrixEvent, userId: string) => { maySendRedactionForEvent: (_evt: MatrixEvent, userId: string) => {
@ -1356,7 +1308,7 @@ function setRedactionAllowedForMeOnly(matrixClient: MatrixClient) {
}, },
}, },
} as Room; } as Room;
}; });
} }
let EVENT_ID = 0; let EVENT_ID = 0;

View File

@ -1,116 +1,106 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`DateSeparator renders the date separator correctly 1`] = ` exports[`DateSeparator renders the date separator correctly 1`] = `
<Wrapper <DateSeparator
now="2021-12-17T08:09:00.000Z" now="2021-12-17T08:09:00.000Z"
ts={1639728540000} ts={1639728540000}
> >
<DateSeparator <h2
now="2021-12-17T08:09:00.000Z" aria-label="Today"
ts={1639728540000} className="mx_DateSeparator"
role="separator"
tabIndex={-1}
> >
<h2 <hr
aria-label="Today" role="none"
className="mx_DateSeparator" />
role="separator" <div
tabIndex={-1} aria-hidden="true"
> >
<hr Today
role="none" </div>
/> <hr
<div role="none"
aria-hidden="true" />
> </h2>
Today </DateSeparator>
</div>
<hr
role="none"
/>
</h2>
</DateSeparator>
</Wrapper>
`; `;
exports[`DateSeparator when feature_jump_to_date is enabled renders the date separator correctly 1`] = ` exports[`DateSeparator when feature_jump_to_date is enabled renders the date separator correctly 1`] = `
<Wrapper <DateSeparator
now="2021-12-17T08:09:00.000Z" now="2021-12-17T08:09:00.000Z"
ts={1639728540000} ts={1639728540000}
> >
<DateSeparator <h2
now="2021-12-17T08:09:00.000Z" aria-label="Fri, Dec 17 2021"
ts={1639728540000} className="mx_DateSeparator"
role="separator"
tabIndex={-1}
> >
<h2 <hr
aria-label="Fri, Dec 17 2021" role="none"
className="mx_DateSeparator" />
role="separator" <ContextMenuTooltipButton
tabIndex={-1} className="mx_DateSeparator_jumpToDateMenu"
isExpanded={false}
onClick={[Function]}
title="Jump to date"
> >
<hr <AccessibleTooltipButton
role="none" aria-expanded={false}
/> aria-haspopup={true}
<ContextMenuTooltipButton
className="mx_DateSeparator_jumpToDateMenu" className="mx_DateSeparator_jumpToDateMenu"
isExpanded={false} forceHide={false}
onClick={[Function]} onClick={[Function]}
onContextMenu={[Function]}
title="Jump to date" title="Jump to date"
> >
<AccessibleTooltipButton <AccessibleButton
aria-expanded={false} aria-expanded={false}
aria-haspopup={true} aria-haspopup={true}
aria-label="Jump to date"
className="mx_DateSeparator_jumpToDateMenu" className="mx_DateSeparator_jumpToDateMenu"
forceHide={false} element="div"
onBlur={[Function]}
onClick={[Function]} onClick={[Function]}
onContextMenu={[Function]} onContextMenu={[Function]}
title="Jump to date" onFocus={[Function]}
onMouseLeave={[Function]}
onMouseOver={[Function]}
role="button"
tabIndex={0}
> >
<AccessibleButton <div
aria-expanded={false} aria-expanded={false}
aria-haspopup={true} aria-haspopup={true}
aria-label="Jump to date" aria-label="Jump to date"
className="mx_DateSeparator_jumpToDateMenu" className="mx_AccessibleButton mx_DateSeparator_jumpToDateMenu"
element="div"
onBlur={[Function]} onBlur={[Function]}
onClick={[Function]} onClick={[Function]}
onContextMenu={[Function]} onContextMenu={[Function]}
onFocus={[Function]} onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseLeave={[Function]} onMouseLeave={[Function]}
onMouseOver={[Function]} onMouseOver={[Function]}
role="button" role="button"
tabIndex={0} tabIndex={0}
> >
<div <div
aria-expanded={false} aria-hidden="true"
aria-haspopup={true}
aria-label="Jump to date"
className="mx_AccessibleButton mx_DateSeparator_jumpToDateMenu"
onBlur={[Function]}
onClick={[Function]}
onContextMenu={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseLeave={[Function]}
onMouseOver={[Function]}
role="button"
tabIndex={0}
> >
<div Fri, Dec 17 2021
aria-hidden="true"
>
Fri, Dec 17 2021
</div>
<div
className="mx_DateSeparator_chevron"
/>
</div> </div>
</AccessibleButton> <div
</AccessibleTooltipButton> className="mx_DateSeparator_chevron"
</ContextMenuTooltipButton> />
<hr </div>
role="none" </AccessibleButton>
/> </AccessibleTooltipButton>
</h2> </ContextMenuTooltipButton>
</DateSeparator> <hr
</Wrapper> role="none"
/>
</h2>
</DateSeparator>
`; `;

View File

@ -19,9 +19,7 @@ import { mount } from "enzyme";
import '../../../skinned-sdk'; import '../../../skinned-sdk';
import * as TestUtils from "../../../test-utils"; import * as TestUtils from "../../../test-utils";
import _FontScalingPanel from '../../../../src/components/views/settings/FontScalingPanel'; import FontScalingPanel from '../../../../src/components/views/settings/FontScalingPanel';
const FontScalingPanel = TestUtils.wrapInMatrixClientContext(_FontScalingPanel);
// Fake random strings to give a predictable snapshot // Fake random strings to give a predictable snapshot
jest.mock( jest.mock(

View File

@ -19,7 +19,7 @@ import React from "react";
import { mount, ReactWrapper } from "enzyme"; import { mount, ReactWrapper } from "enzyme";
import { Key } from "../../../../src/Keyboard"; import { Key } from "../../../../src/Keyboard";
import PlatformPeg from "../../../../src/PlatformPeg"; import { mockPlatformPeg, unmockPlatformPeg } from "../../../test-utils/platform";
const PATH_TO_COMPONENT = "../../../../src/components/views/settings/KeyboardShortcut.tsx"; const PATH_TO_COMPONENT = "../../../../src/components/views/settings/KeyboardShortcut.tsx";
@ -31,6 +31,7 @@ const renderKeyboardShortcut = async (component, props?): Promise<ReactWrapper>
describe("KeyboardShortcut", () => { describe("KeyboardShortcut", () => {
beforeEach(() => { beforeEach(() => {
jest.resetModules(); jest.resetModules();
unmockPlatformPeg();
}); });
it("renders key icon", async () => { it("renders key icon", async () => {
@ -49,7 +50,7 @@ describe("KeyboardShortcut", () => {
}); });
it("doesn't render same modifier twice", async () => { it("doesn't render same modifier twice", async () => {
PlatformPeg.get = () => ({ overrideBrowserShortcuts: () => false }); mockPlatformPeg({ overrideBrowserShortcuts: jest.fn().mockReturnValue(false) });
const body1 = await renderKeyboardShortcut("KeyboardShortcut", { const body1 = await renderKeyboardShortcut("KeyboardShortcut", {
value: { value: {
key: Key.A, key: Key.A,

View File

@ -15,14 +15,14 @@ limitations under the License.
import React from 'react'; import React from 'react';
import { mount } from 'enzyme'; import { mount } from 'enzyme';
import '../../../skinned-sdk'; import '../../../skinned-sdk';
import { IPushRule, IPushRules, RuleId } from 'matrix-js-sdk/src/matrix'; import { IPushRule, IPushRules, RuleId, IPusher } from 'matrix-js-sdk/src/matrix';
import { ThreepidMedium } from 'matrix-js-sdk/src/@types/threepids'; import { IThreepid, ThreepidMedium } from 'matrix-js-sdk/src/@types/threepids';
import { act } from 'react-dom/test-utils'; import { act } from 'react-dom/test-utils';
import Notifications from '../../../../src/components/views/settings/Notifications'; import Notifications from '../../../../src/components/views/settings/Notifications';
import SettingsStore from "../../../../src/settings/SettingsStore"; import SettingsStore from "../../../../src/settings/SettingsStore";
import { MatrixClientPeg } from '../../../../src/MatrixClientPeg';
import { StandardActions } from '../../../../src/notifications/StandardActions'; import { StandardActions } from '../../../../src/notifications/StandardActions';
import { getMockClientWithEventEmitter } from '../../../test-utils';
jest.mock('../../../../src/settings/SettingsStore', () => ({ jest.mock('../../../../src/settings/SettingsStore', () => ({
monitorSetting: jest.fn(), monitorSetting: jest.fn(),
@ -64,7 +64,7 @@ describe('<Notifications />', () => {
return component; return component;
}; };
const mockClient = { const mockClient = getMockClientWithEventEmitter({
getPushRules: jest.fn(), getPushRules: jest.fn(),
getPushers: jest.fn(), getPushers: jest.fn(),
getThreePids: jest.fn(), getThreePids: jest.fn(),
@ -72,15 +72,11 @@ describe('<Notifications />', () => {
setPushRuleEnabled: jest.fn(), setPushRuleEnabled: jest.fn(),
setPushRuleActions: jest.fn(), setPushRuleActions: jest.fn(),
getRooms: jest.fn().mockReturnValue([]), getRooms: jest.fn().mockReturnValue([]),
}; });
mockClient.getPushRules.mockResolvedValue(pushRules); mockClient.getPushRules.mockResolvedValue(pushRules);
const findByTestId = (component, id) => component.find(`[data-test-id="${id}"]`); const findByTestId = (component, id) => component.find(`[data-test-id="${id}"]`);
beforeAll(() => {
MatrixClientPeg.get = () => mockClient;
});
beforeEach(() => { beforeEach(() => {
mockClient.getPushRules.mockClear().mockResolvedValue(pushRules); mockClient.getPushRules.mockClear().mockResolvedValue(pushRules);
mockClient.getPushers.mockClear().mockResolvedValue({ pushers: [] }); mockClient.getPushers.mockClear().mockResolvedValue({ pushers: [] });
@ -124,7 +120,7 @@ describe('<Notifications />', () => {
...pushRules.global, ...pushRules.global,
override: [{ ...masterRule, enabled: true }], override: [{ ...masterRule, enabled: true }],
}, },
}; } as unknown as IPushRules;
mockClient.getPushRules.mockClear().mockResolvedValue(disableNotificationsPushRules); mockClient.getPushRules.mockClear().mockResolvedValue(disableNotificationsPushRules);
const component = await getComponentAndWait(); const component = await getComponentAndWait();
@ -148,7 +144,7 @@ describe('<Notifications />', () => {
{ {
medium: ThreepidMedium.Email, medium: ThreepidMedium.Email,
address: testEmail, address: testEmail,
}, } as unknown as IThreepid,
], ],
}); });
}); });
@ -160,7 +156,11 @@ describe('<Notifications />', () => {
}); });
it('renders email switches correctly when notifications are on for email', async () => { it('renders email switches correctly when notifications are on for email', async () => {
mockClient.getPushers.mockResolvedValue({ pushers: [{ kind: 'email', pushkey: testEmail }] }); mockClient.getPushers.mockResolvedValue({
pushers: [
{ kind: 'email', pushkey: testEmail } as unknown as IPusher,
],
});
const component = await getComponentAndWait(); const component = await getComponentAndWait();
expect(findByTestId(component, 'notif-email-switch').props().value).toEqual(true); expect(findByTestId(component, 'notif-email-switch').props().value).toEqual(true);
@ -205,7 +205,7 @@ describe('<Notifications />', () => {
}); });
it('enables email notification when toggling off', async () => { it('enables email notification when toggling off', async () => {
const testPusher = { kind: 'email', pushkey: 'tester@test.com' }; const testPusher = { kind: 'email', pushkey: 'tester@test.com' } as unknown as IPusher;
mockClient.getPushers.mockResolvedValue({ pushers: [testPusher] }); mockClient.getPushers.mockResolvedValue({ pushers: [testPusher] });
const component = await getComponentAndWait(); const component = await getComponentAndWait();

View File

@ -19,9 +19,7 @@ import { mount } from "enzyme";
import '../../../skinned-sdk'; import '../../../skinned-sdk';
import * as TestUtils from "../../../test-utils"; import * as TestUtils from "../../../test-utils";
import _ThemeChoicePanel from '../../../../src/components/views/settings/ThemeChoicePanel'; import ThemeChoicePanel from '../../../../src/components/views/settings/ThemeChoicePanel';
const ThemeChoicePanel = TestUtils.wrapInMatrixClientContext(_ThemeChoicePanel);
// Fake random strings to give a predictable snapshot // Fake random strings to give a predictable snapshot
jest.mock( jest.mock(

View File

@ -1,313 +1,311 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`FontScalingPanel renders the font scaling UI 1`] = ` exports[`FontScalingPanel renders the font scaling UI 1`] = `
<Wrapper> <FontScalingPanel>
<FontScalingPanel> <div
<div className="mx_SettingsTab_section mx_FontScalingPanel"
className="mx_SettingsTab_section mx_FontScalingPanel" >
<span
className="mx_SettingsTab_subheading"
>
Font size
</span>
<EventTilePreview
avatarUrl={null}
className="mx_FontScalingPanel_fontSlider_preview"
displayName={null}
layout="group"
message="Hey you. You're the best!"
userId={null}
> >
<span
className="mx_SettingsTab_subheading"
>
Font size
</span>
<EventTilePreview
avatarUrl={null}
className="mx_FontScalingPanel_fontSlider_preview"
displayName={null}
layout="group"
message="Hey you. You're the best!"
userId={null}
>
<div
className="mx_FontScalingPanel_fontSlider_preview mx_GroupLayout mx_EventTilePreview_loader"
>
<Spinner
h={32}
w={32}
>
<div
className="mx_Spinner"
>
<div
aria-label="Loading..."
className="mx_Spinner_icon"
style={
Object {
"height": 32,
"width": 32,
}
}
/>
</div>
</Spinner>
</div>
</EventTilePreview>
<div <div
className="mx_FontScalingPanel_fontSlider" className="mx_FontScalingPanel_fontSlider_preview mx_GroupLayout mx_EventTilePreview_loader"
> >
<div <Spinner
className="mx_FontScalingPanel_fontSlider_smallText" h={32}
> w={32}
Aa
</div>
<Slider
disabled={false}
displayFunc={[Function]}
onSelectionChange={[Function]}
value={15}
values={
Array [
13,
14,
15,
16,
18,
]
}
> >
<div <div
className="mx_Slider" className="mx_Spinner"
> >
<div> <div
aria-label="Loading..."
className="mx_Spinner_icon"
style={
Object {
"height": 32,
"width": 32,
}
}
/>
</div>
</Spinner>
</div>
</EventTilePreview>
<div
className="mx_FontScalingPanel_fontSlider"
>
<div
className="mx_FontScalingPanel_fontSlider_smallText"
>
Aa
</div>
<Slider
disabled={false}
displayFunc={[Function]}
onSelectionChange={[Function]}
value={15}
values={
Array [
13,
14,
15,
16,
18,
]
}
>
<div
className="mx_Slider"
>
<div>
<div
className="mx_Slider_bar"
>
<hr
onClick={[Function]}
/>
<div <div
className="mx_Slider_bar" className="mx_Slider_selection"
> >
<hr
onClick={[Function]}
/>
<div <div
className="mx_Slider_selection" className="mx_Slider_selectionDot"
style={
Object {
"left": "calc(-1.195em + 50%)",
}
}
> >
<div <div
className="mx_Slider_selectionDot" className="mx_Slider_selectionText"
style={
Object {
"left": "calc(-1.195em + 50%)",
}
}
> >
<div 15
className="mx_Slider_selectionText"
>
15
</div>
</div> </div>
<hr
style={
Object {
"width": "50%",
}
}
/>
</div> </div>
</div> <hr
<div style={
className="mx_Slider_dotContainer" Object {
> "width": "50%",
<Dot }
active={true} }
disabled={false}
key="13"
label=""
onClick={[Function]}
>
<span
className="mx_Slider_dotValue"
onClick={[Function]}
>
<div
className="mx_Slider_dot mx_Slider_dotActive"
/>
<div
className="mx_Slider_labelContainer"
>
<div
className="mx_Slider_label"
/>
</div>
</span>
</Dot>
<Dot
active={true}
disabled={false}
key="14"
label=""
onClick={[Function]}
>
<span
className="mx_Slider_dotValue"
onClick={[Function]}
>
<div
className="mx_Slider_dot mx_Slider_dotActive"
/>
<div
className="mx_Slider_labelContainer"
>
<div
className="mx_Slider_label"
/>
</div>
</span>
</Dot>
<Dot
active={true}
disabled={false}
key="15"
label=""
onClick={[Function]}
>
<span
className="mx_Slider_dotValue"
onClick={[Function]}
>
<div
className="mx_Slider_dot mx_Slider_dotActive"
/>
<div
className="mx_Slider_labelContainer"
>
<div
className="mx_Slider_label"
/>
</div>
</span>
</Dot>
<Dot
active={false}
disabled={false}
key="16"
label=""
onClick={[Function]}
>
<span
className="mx_Slider_dotValue"
onClick={[Function]}
>
<div
className="mx_Slider_dot"
/>
<div
className="mx_Slider_labelContainer"
>
<div
className="mx_Slider_label"
/>
</div>
</span>
</Dot>
<Dot
active={false}
disabled={false}
key="18"
label=""
onClick={[Function]}
>
<span
className="mx_Slider_dotValue"
onClick={[Function]}
>
<div
className="mx_Slider_dot"
/>
<div
className="mx_Slider_labelContainer"
>
<div
className="mx_Slider_label"
/>
</div>
</span>
</Dot>
</div>
</div>
</div>
</Slider>
<div
className="mx_FontScalingPanel_fontSlider_largeText"
>
Aa
</div>
</div>
<SettingsFlag
level="account"
name="useCustomFontSize"
onChange={[Function]}
useCheckbox={true}
>
<StyledCheckbox
checked={false}
className=""
disabled={false}
onChange={[Function]}
>
<span
className="mx_Checkbox mx_Checkbox_hasKind mx_Checkbox_kind_solid"
>
<input
checked={false}
disabled={false}
id="checkbox_abdefghi"
onChange={[Function]}
type="checkbox"
/>
<label
htmlFor="checkbox_abdefghi"
>
<div
className="mx_Checkbox_background"
>
<div
className="mx_Checkbox_checkmark"
/> />
</div> </div>
<div> </div>
Use custom size <div
</div> className="mx_Slider_dotContainer"
</label> >
</span> <Dot
</StyledCheckbox> active={true}
</SettingsFlag> disabled={false}
<Field key="13"
autoComplete="off" label=""
className="mx_FontScalingPanel_customFontSizeField" onClick={[Function]}
disabled={true} >
element="input" <span
id="font_size_field" className="mx_Slider_dotValue"
label="Font size" onClick={[Function]}
onChange={[Function]} >
onValidate={[Function]} <div
placeholder="15" className="mx_Slider_dot mx_Slider_dotActive"
type="number" />
validateOnBlur={true} <div
validateOnChange={true} className="mx_Slider_labelContainer"
validateOnFocus={true} >
value="15" <div
className="mx_Slider_label"
/>
</div>
</span>
</Dot>
<Dot
active={true}
disabled={false}
key="14"
label=""
onClick={[Function]}
>
<span
className="mx_Slider_dotValue"
onClick={[Function]}
>
<div
className="mx_Slider_dot mx_Slider_dotActive"
/>
<div
className="mx_Slider_labelContainer"
>
<div
className="mx_Slider_label"
/>
</div>
</span>
</Dot>
<Dot
active={true}
disabled={false}
key="15"
label=""
onClick={[Function]}
>
<span
className="mx_Slider_dotValue"
onClick={[Function]}
>
<div
className="mx_Slider_dot mx_Slider_dotActive"
/>
<div
className="mx_Slider_labelContainer"
>
<div
className="mx_Slider_label"
/>
</div>
</span>
</Dot>
<Dot
active={false}
disabled={false}
key="16"
label=""
onClick={[Function]}
>
<span
className="mx_Slider_dotValue"
onClick={[Function]}
>
<div
className="mx_Slider_dot"
/>
<div
className="mx_Slider_labelContainer"
>
<div
className="mx_Slider_label"
/>
</div>
</span>
</Dot>
<Dot
active={false}
disabled={false}
key="18"
label=""
onClick={[Function]}
>
<span
className="mx_Slider_dotValue"
onClick={[Function]}
>
<div
className="mx_Slider_dot"
/>
<div
className="mx_Slider_labelContainer"
>
<div
className="mx_Slider_label"
/>
</div>
</span>
</Dot>
</div>
</div>
</div>
</Slider>
<div
className="mx_FontScalingPanel_fontSlider_largeText"
> >
<div Aa
className="mx_Field mx_Field_input mx_FontScalingPanel_customFontSizeField" </div>
</div>
<SettingsFlag
level="account"
name="useCustomFontSize"
onChange={[Function]}
useCheckbox={true}
>
<StyledCheckbox
checked={false}
className=""
disabled={false}
onChange={[Function]}
>
<span
className="mx_Checkbox mx_Checkbox_hasKind mx_Checkbox_kind_solid"
> >
<input <input
autoComplete="off" checked={false}
disabled={true} disabled={false}
id="font_size_field" id="checkbox_abdefghi"
label="Font size"
onBlur={[Function]}
onChange={[Function]} onChange={[Function]}
onFocus={[Function]} type="checkbox"
placeholder="15"
type="number"
value="15"
/> />
<label <label
htmlFor="font_size_field" htmlFor="checkbox_abdefghi"
> >
Font size <div
className="mx_Checkbox_background"
>
<div
className="mx_Checkbox_checkmark"
/>
</div>
<div>
Use custom size
</div>
</label> </label>
</div> </span>
</Field> </StyledCheckbox>
</div> </SettingsFlag>
</FontScalingPanel> <Field
</Wrapper> autoComplete="off"
className="mx_FontScalingPanel_customFontSizeField"
disabled={true}
element="input"
id="font_size_field"
label="Font size"
onChange={[Function]}
onValidate={[Function]}
placeholder="15"
type="number"
validateOnBlur={true}
validateOnChange={true}
validateOnFocus={true}
value="15"
>
<div
className="mx_Field mx_Field_input mx_FontScalingPanel_customFontSizeField"
>
<input
autoComplete="off"
disabled={true}
id="font_size_field"
label="Font size"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
placeholder="15"
type="number"
value="15"
/>
<label
htmlFor="font_size_field"
>
Font size
</label>
</div>
</Field>
</div>
</FontScalingPanel>
`; `;

View File

@ -1,115 +1,113 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ThemeChoicePanel renders the theme choice UI 1`] = ` exports[`ThemeChoicePanel renders the theme choice UI 1`] = `
<Wrapper> <ThemeChoicePanel>
<ThemeChoicePanel> <div
<div className="mx_SettingsTab_section mx_ThemeChoicePanel"
className="mx_SettingsTab_section mx_ThemeChoicePanel" >
<span
className="mx_SettingsTab_subheading"
> >
<span Theme
className="mx_SettingsTab_subheading" </span>
<div
className="mx_ThemeSelectors"
>
<StyledRadioGroup
definitions={
Array [
Object {
"className": "mx_ThemeSelector_light",
"disabled": true,
"label": "Light",
"value": "light",
},
Object {
"className": "mx_ThemeSelector_dark",
"disabled": true,
"label": "Dark",
"value": "dark",
},
]
}
name="theme"
onChange={[Function]}
outlined={true}
> >
Theme <StyledRadioButton
</span> checked={false}
<div childrenInLabel={true}
className="mx_ThemeSelectors" className="mx_ThemeSelector_light"
> disabled={true}
<StyledRadioGroup id="theme-light"
definitions={
Array [
Object {
"className": "mx_ThemeSelector_light",
"disabled": true,
"label": "Light",
"value": "light",
},
Object {
"className": "mx_ThemeSelector_dark",
"disabled": true,
"label": "Dark",
"value": "dark",
},
]
}
name="theme" name="theme"
onChange={[Function]} onChange={[Function]}
outlined={true} outlined={true}
value="light"
> >
<StyledRadioButton <label
checked={false} className="mx_StyledRadioButton mx_ThemeSelector_light mx_StyledRadioButton_disabled mx_StyledRadioButton_outlined"
childrenInLabel={true}
className="mx_ThemeSelector_light"
disabled={true}
id="theme-light"
name="theme"
onChange={[Function]}
outlined={true}
value="light"
> >
<label <input
className="mx_StyledRadioButton mx_ThemeSelector_light mx_StyledRadioButton_disabled mx_StyledRadioButton_outlined" checked={false}
disabled={true}
id="theme-light"
name="theme"
onChange={[Function]}
type="radio"
value="light"
/>
<div>
<div />
</div>
<div
className="mx_StyledRadioButton_content"
> >
<input Light
checked={false} </div>
disabled={true} <div
id="theme-light" className="mx_StyledRadioButton_spacer"
name="theme" />
onChange={[Function]} </label>
type="radio" </StyledRadioButton>
value="light" <StyledRadioButton
/> checked={false}
<div> childrenInLabel={true}
<div /> className="mx_ThemeSelector_dark"
</div> disabled={true}
<div id="theme-dark"
className="mx_StyledRadioButton_content" name="theme"
> onChange={[Function]}
Light outlined={true}
</div> value="dark"
<div >
className="mx_StyledRadioButton_spacer" <label
/> className="mx_StyledRadioButton mx_ThemeSelector_dark mx_StyledRadioButton_disabled mx_StyledRadioButton_outlined"
</label>
</StyledRadioButton>
<StyledRadioButton
checked={false}
childrenInLabel={true}
className="mx_ThemeSelector_dark"
disabled={true}
id="theme-dark"
name="theme"
onChange={[Function]}
outlined={true}
value="dark"
> >
<label <input
className="mx_StyledRadioButton mx_ThemeSelector_dark mx_StyledRadioButton_disabled mx_StyledRadioButton_outlined" checked={false}
disabled={true}
id="theme-dark"
name="theme"
onChange={[Function]}
type="radio"
value="dark"
/>
<div>
<div />
</div>
<div
className="mx_StyledRadioButton_content"
> >
<input Dark
checked={false} </div>
disabled={true} <div
id="theme-dark" className="mx_StyledRadioButton_spacer"
name="theme" />
onChange={[Function]} </label>
type="radio" </StyledRadioButton>
value="dark" </StyledRadioGroup>
/>
<div>
<div />
</div>
<div
className="mx_StyledRadioButton_content"
>
Dark
</div>
<div
className="mx_StyledRadioButton_spacer"
/>
</label>
</StyledRadioButton>
</StyledRadioGroup>
</div>
</div> </div>
</ThemeChoicePanel> </div>
</Wrapper> </ThemeChoicePanel>
`; `;

View File

@ -28,7 +28,7 @@ import { findById } from '../../../test-utils';
import { SettingLevel } from '../../../../src/settings/SettingLevel'; import { SettingLevel } from '../../../../src/settings/SettingLevel';
import dis from '../../../../src/dispatcher/dispatcher'; import dis from '../../../../src/dispatcher/dispatcher';
import { Action } from '../../../../src/dispatcher/actions'; import { Action } from '../../../../src/dispatcher/actions';
import PlatformPeg from "../../../../src/PlatformPeg"; import { mockPlatformPeg } from '../../../test-utils/platform';
jest.mock('../../../../src/theme'); jest.mock('../../../../src/theme');
jest.mock('../../../../src/components/views/settings/ThemeChoicePanel', () => ({ jest.mock('../../../../src/components/views/settings/ThemeChoicePanel', () => ({
@ -45,7 +45,7 @@ jest.mock('../../../../src/dispatcher/dispatcher', () => ({
register: jest.fn(), register: jest.fn(),
})); }));
PlatformPeg.get = () => ({ overrideBrowserShortcuts: () => false }); mockPlatformPeg({ overrideBrowserShortcuts: jest.fn().mockReturnValue(false) });
describe('<QuickThemeSwitcher />', () => { describe('<QuickThemeSwitcher />', () => {
const defaultProps = { const defaultProps = {

View File

@ -1,6 +1,7 @@
// skinned-sdk should be the first import in most tests // skinned-sdk should be the first import in most tests
import '../../../skinned-sdk'; import '../../../skinned-sdk';
import React from "react"; import React from "react";
import { mocked } from 'jest-mock';
import { import {
renderIntoDocument, renderIntoDocument,
Simulate, Simulate,
@ -53,11 +54,10 @@ describe('<SpaceSettingsVisibilityTab />', () => {
]; ];
const space = mkSpace(client, mockSpaceId); const space = mkSpace(client, mockSpaceId);
const getStateEvents = mockStateEventImplementation(events); const getStateEvents = mockStateEventImplementation(events);
space.currentState.getStateEvents.mockImplementation(getStateEvents); mocked(space.currentState).getStateEvents.mockImplementation(getStateEvents);
space.currentState.mayClientSendStateEvent.mockReturnValue(false); mocked(space.currentState).mayClientSendStateEvent.mockReturnValue(false);
const mockGetJoinRule = jest.fn().mockReturnValue(joinRule); space.getJoinRule.mockReturnValue(joinRule);
space.getJoinRule = mockGetJoinRule; mocked(space.currentState).getJoinRule.mockReturnValue(joinRule);
space.currentState.getJoinRule = mockGetJoinRule;
return space as unknown as Room; return space as unknown as Room;
}; };
const defaultProps = { const defaultProps = {
@ -70,6 +70,7 @@ describe('<SpaceSettingsVisibilityTab />', () => {
const wrapper = renderIntoDocument<HTMLSpanElement>( const wrapper = renderIntoDocument<HTMLSpanElement>(
// wrap in element so renderIntoDocument can render functional component // wrap in element so renderIntoDocument can render functional component
<span> <span>
{ /* @ts-ignore */ }
<SpaceSettingsVisibilityTab {...defaultProps} {...props} /> <SpaceSettingsVisibilityTab {...defaultProps} {...props} />
</span>, </span>,
) as HTMLSpanElement; ) as HTMLSpanElement;

View File

@ -28,14 +28,8 @@
"./test/utils/**/*.tsx", "./test/utils/**/*.tsx",
"./test/stores/**/*.ts", "./test/stores/**/*.ts",
"./test/stores/**/*.tsx", "./test/stores/**/*.tsx",
"./test/components/structures/**/*.ts", "./test/components/**/*.tsx",
"./test/components/structures/**/*.tsx", "./test/components/**/*.ts",
"./test/components/views/context_menus/**/*.ts",
"./test/components/views/context_menus/**/*.tsx",
"./test/components/views/rooms/**/*.tsx",
"./test/components/views/rooms/**/*.ts",
"./test/components/views/right_panel/**/*.tsx",
"./test/components/views/right_panel/**/*.ts",
], ],
"exclude": [ "exclude": [
"./test/end-to-end-tests/" "./test/end-to-end-tests/"