1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-28 15:22:05 +03:00

Refactor tests

So that there's one top level `describe('TextForEvent')`, followed by a nested
`describe('textForPinnedEvent')`, containting all the `it()`s.

Signed-off-by: Paulo Pinto <paulo.pinto@automattic.com>
This commit is contained in:
Paulo Pinto
2021-08-10 16:06:33 +01:00
parent 94d3dd6bbc
commit 45fd3d83b0
2 changed files with 77 additions and 101 deletions

View File

@ -23,88 +23,64 @@ function mockPinnedEvent(
});
}
describe("TextForPinnedEvent - newly pinned message(s)", () => {
SettingsStore.setValue("feature_pinning", null, SettingLevel.DEVICE, true);
describe('TextForEvent', () => {
describe("TextForPinnedEvent", () => {
SettingsStore.setValue("feature_pinning", null, SettingLevel.DEVICE, true);
it("mentions message when a single message was pinned, with no previously pinned messages", () => {
const event = mockPinnedEvent(['message-1']);
expect(textForEvent(event)).toBe("@foo:example.com pinned a message to this room. See all pinned messages.");
});
it("mentions message when a single message was pinned, with no previously pinned messages", () => {
const event = mockPinnedEvent(['message-1']);
expect(textForEvent(event)).toBe(
"@foo:example.com pinned a message to this room. See all pinned messages.",
);
it("mentions message when a single message was pinned, with multiple previously pinned messages", () => {
const event = mockPinnedEvent(['message-3'], ['message-1', 'message-2']);
expect(textForEvent(event)).toBe("@foo:example.com pinned a message to this room. See all pinned messages.");
});
const component = renderer.create(textForEvent(event, true));
expect(component.toJSON()).toMatchSnapshot();
});
it("shows generic text when multiple messages were pinned", () => {
const event = mockPinnedEvent(['message-1', 'message-2', 'message-3'], ['message-1']);
expect(textForEvent(event)).toBe("@foo:example.com changed the pinned messages for the room.");
});
});
describe("TextForPinnedEvent - newly pinned message(s) (JSX)", () => {
SettingsStore.setValue("feature_pinning", null, SettingLevel.DEVICE, true);
it("mentions message when a single message was pinned, with no previously pinned messages", () => {
const event = mockPinnedEvent(['message-1']);
const component = renderer.create(textForEvent(event, true));
expect(component.toJSON()).toMatchSnapshot();
});
it("mentions message when a single message was pinned, with multiple previously pinned messages", () => {
const event = mockPinnedEvent(['message-3'], ['message-1', 'message-2']);
const component = renderer.create(textForEvent(event, true));
expect(component.toJSON()).toMatchSnapshot();
});
it("shows generic text when multiple messages were pinned", () => {
const event = mockPinnedEvent(['message-1', 'message-2', 'message-3'], ['message-1']);
const component = renderer.create(textForEvent(event, true));
expect(component.toJSON()).toMatchSnapshot();
});
});
describe("TextForPinnedEvent - newly unpinned message(s)", () => {
SettingsStore.setValue("feature_pinning", null, SettingLevel.DEVICE, true);
it("mentions message when a single message was unpinned, with a single message previously pinned", () => {
const event = mockPinnedEvent([], ['message-1']);
expect(textForEvent(event)).toBe(
"@foo:example.com unpinned a message from this room. See all pinned messages.",
);
});
it("mentions message when a single message was unpinned, with multiple previously pinned messages", () => {
const event = mockPinnedEvent(['message-2'], ['message-1', 'message-2']);
expect(textForEvent(event)).toBe(
"@foo:example.com unpinned a message from this room. See all pinned messages.",
);
});
it("shows generic text when multiple messages were unpinned", () => {
const event = mockPinnedEvent(['message-3'], ['message-1', 'message-2', 'message-3']);
expect(textForEvent(event)).toBe("@foo:example.com changed the pinned messages for the room.");
});
});
describe("TextForPinnedEvent - newly unpinned message(s) (JSX)", () => {
SettingsStore.setValue("feature_pinning", null, SettingLevel.DEVICE, true);
it("mentions message when a single message was unpinned, with a single message previously pinned", () => {
const event = mockPinnedEvent([], ['message-1']);
const component = renderer.create(textForEvent(event, true));
expect(component.toJSON()).toMatchSnapshot();
});
it("mentions message when a single message was unpinned, with multiple previously pinned messages", () => {
const event = mockPinnedEvent(['message-2'], ['message-1', 'message-2']);
const component = renderer.create(textForEvent(event, true));
expect(component.toJSON()).toMatchSnapshot();
});
it("shows generic text when multiple messages were unpinned", () => {
const event = mockPinnedEvent(['message-3'], ['message-1', 'message-2', 'message-3']);
const component = renderer.create(textForEvent(event, true));
expect(component.toJSON()).toMatchSnapshot();
it("mentions message when a single message was pinned, with multiple previously pinned messages", () => {
const event = mockPinnedEvent(['message-3'], ['message-1', 'message-2']);
expect(textForEvent(event)).toBe(
"@foo:example.com pinned a message to this room. See all pinned messages.",
);
const component = renderer.create(textForEvent(event, true));
expect(component.toJSON()).toMatchSnapshot();
});
it("shows generic text when multiple messages were pinned", () => {
const event = mockPinnedEvent(['message-1', 'message-2', 'message-3'], ['message-1']);
expect(textForEvent(event)).toBe("@foo:example.com changed the pinned messages for the room.");
const component = renderer.create(textForEvent(event, true));
expect(component.toJSON()).toMatchSnapshot();
});
it("mentions message when a single message was unpinned, with a single message previously pinned", () => {
const event = mockPinnedEvent([], ['message-1']);
expect(textForEvent(event)).toBe(
"@foo:example.com unpinned a message from this room. See all pinned messages.",
);
const component = renderer.create(textForEvent(event, true));
expect(component.toJSON()).toMatchSnapshot();
});
it("mentions message when a single message was unpinned, with multiple previously pinned messages", () => {
const event = mockPinnedEvent(['message-2'], ['message-1', 'message-2']);
expect(textForEvent(event)).toBe(
"@foo:example.com unpinned a message from this room. See all pinned messages.",
);
const component = renderer.create(textForEvent(event, true));
expect(component.toJSON()).toMatchSnapshot();
});
it("shows generic text when multiple messages were unpinned", () => {
const event = mockPinnedEvent(['message-3'], ['message-1', 'message-2', 'message-3']);
expect(textForEvent(event)).toBe("@foo:example.com changed the pinned messages for the room.");
const component = renderer.create(textForEvent(event, true));
expect(component.toJSON()).toMatchSnapshot();
});
});
});