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:
parent
2bf1d2b287
commit
abc225d3c6
16 changed files with 2663 additions and 3038 deletions
|
@ -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(<MatrixClientContext.Provider value={cli}>
|
||||
|
@ -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 () => {
|
||||
|
|
|
@ -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(
|
||||
<PollCreateDialog room={createRoom()} onFinished={jest.fn()} />,
|
||||
{
|
||||
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(
|
||||
<PollCreateDialog room={createRoom()} onFinished={jest.fn()} />,
|
||||
);
|
||||
|
@ -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(
|
||||
<PollCreateDialog room={createRoom()} onFinished={jest.fn()} />,
|
||||
);
|
||||
|
@ -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": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue