diff --git a/test/TextForEvent-test.ts b/test/TextForEvent-test.ts index 0b3b73613a..b50996c186 100644 --- a/test/TextForEvent-test.ts +++ b/test/TextForEvent-test.ts @@ -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(); + }); }); }); diff --git a/test/__snapshots__/TextForEvent-test.ts.snap b/test/__snapshots__/TextForEvent-test.ts.snap index 124f7e0663..2b73dbeb3d 100644 --- a/test/__snapshots__/TextForEvent-test.ts.snap +++ b/test/__snapshots__/TextForEvent-test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`TextForPinnedEvent - newly pinned message(s) (JSX) mentions message when a single message was pinned, with multiple previously pinned messages 1`] = ` +exports[`TextForEvent TextForPinnedEvent mentions message when a single message was pinned, with multiple previously pinned messages 1`] = ` @foo:example.com pinned @@ -20,7 +20,7 @@ exports[`TextForPinnedEvent - newly pinned message(s) (JSX) mentions message whe `; -exports[`TextForPinnedEvent - newly pinned message(s) (JSX) mentions message when a single message was pinned, with no previously pinned messages 1`] = ` +exports[`TextForEvent TextForPinnedEvent mentions message when a single message was pinned, with no previously pinned messages 1`] = ` @foo:example.com pinned @@ -40,23 +40,7 @@ exports[`TextForPinnedEvent - newly pinned message(s) (JSX) mentions message whe `; -exports[`TextForPinnedEvent - newly pinned message(s) (JSX) shows generic text when multiple messages were pinned 1`] = ` - - - @foo:example.com changed the - - - pinned messages - - - for the room. - - -`; - -exports[`TextForPinnedEvent - newly unpinned message(s) (JSX) mentions message when a single message was unpinned, with a single message previously pinned 1`] = ` +exports[`TextForEvent TextForPinnedEvent mentions message when a single message was unpinned, with a single message previously pinned 1`] = ` @foo:example.com unpinned @@ -76,7 +60,7 @@ exports[`TextForPinnedEvent - newly unpinned message(s) (JSX) mentions message w `; -exports[`TextForPinnedEvent - newly unpinned message(s) (JSX) mentions message when a single message was unpinned, with multiple previously pinned messages 1`] = ` +exports[`TextForEvent TextForPinnedEvent mentions message when a single message was unpinned, with multiple previously pinned messages 1`] = ` @foo:example.com unpinned @@ -96,7 +80,23 @@ exports[`TextForPinnedEvent - newly unpinned message(s) (JSX) mentions message w `; -exports[`TextForPinnedEvent - newly unpinned message(s) (JSX) shows generic text when multiple messages were unpinned 1`] = ` +exports[`TextForEvent TextForPinnedEvent shows generic text when multiple messages were pinned 1`] = ` + + + @foo:example.com changed the + + + pinned messages + + + for the room. + + +`; + +exports[`TextForEvent TextForPinnedEvent shows generic text when multiple messages were unpinned 1`] = ` @foo:example.com changed the