mirror of
https://github.com/element-hq/element-web
synced 2024-11-22 09:15:41 +03:00
Add test for textForPinnedEvent
Signed-off-by: Paulo Pinto <paulo.pinto@automattic.com>
This commit is contained in:
parent
e7151ebf2d
commit
40ead34c08
2 changed files with 60 additions and 0 deletions
43
test/TextForEvent-test.ts
Normal file
43
test/TextForEvent-test.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
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", () => {
|
||||
SettingsStore.setValue("feature_pinning", null, SettingLevel.DEVICE, true);
|
||||
|
||||
it("should mention sender", () => {
|
||||
const event = mockPinnedEvent();
|
||||
expect(textForEvent(event)).toBe("@foo:example.com changed the pinned messages for the room.");
|
||||
});
|
||||
});
|
||||
|
||||
describe("TextForPinnedEvent (JSX)", () => {
|
||||
SettingsStore.setValue("feature_pinning", null, SettingLevel.DEVICE, true);
|
||||
|
||||
it("should mention sender", () => {
|
||||
const event = mockPinnedEvent();
|
||||
const component = renderer.create(textForEvent(event, true));
|
||||
expect(component.toJSON()).toMatchSnapshot();
|
||||
});
|
||||
});
|
17
test/__snapshots__/TextForEvent-test.ts.snap
Normal file
17
test/__snapshots__/TextForEvent-test.ts.snap
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`TextForPinnedEvent (JSX) should mention sender 1`] = `
|
||||
<span>
|
||||
<span>
|
||||
@foo:example.com changed the
|
||||
<a
|
||||
onClick={[Function]}
|
||||
>
|
||||
|
||||
pinned messages
|
||||
|
||||
</a>
|
||||
for the room.
|
||||
</span>
|
||||
</span>
|
||||
`;
|
Loading…
Reference in a new issue