3f2dadf0fe
Signed-off-by: Paulo Pinto <paulo.pinto@automattic.com>
106 lines
4.8 KiB
TypeScript
106 lines
4.8 KiB
TypeScript
import './skinned-sdk';
|
|
|
|
import { textForEvent } from "../src/TextForEvent";
|
|
import { MatrixEvent } from "matrix-js-sdk";
|
|
import SettingsStore from "../src/settings/SettingsStore";
|
|
import { SettingLevel } from "../src/settings/SettingLevel";
|
|
import renderer from 'react-test-renderer';
|
|
|
|
function mockPinnedEvent(
|
|
pinnedMessageIds?: string[],
|
|
prevPinnedMessageIds?: string[],
|
|
): MatrixEvent {
|
|
return new MatrixEvent({
|
|
type: "m.room.pinned_events",
|
|
state_key: "",
|
|
sender: "@foo:example.com",
|
|
content: {
|
|
pinned: pinnedMessageIds,
|
|
},
|
|
prev_content: {
|
|
pinned: prevPinnedMessageIds,
|
|
},
|
|
});
|
|
}
|
|
|
|
describe("TextForPinnedEvent - newly pinned message(s)", () => {
|
|
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 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.");
|
|
});
|
|
|
|
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();
|
|
});
|
|
});
|