Skip to content

Commit

Permalink
Extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
weeman1337 committed Apr 18, 2023
1 parent d5751eb commit f0e4a07
Showing 1 changed file with 48 additions and 18 deletions.
66 changes: 48 additions & 18 deletions test/components/views/rooms/RoomTile-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,37 @@ describe("RoomTile", () => {
"Room !1:example.org does not have an m.room.create event",
);

const addMessageToRoom = (ts: number) => {
const message = mkMessage({
event: true,
room: room.roomId,
msg: "test message",
user: client.getSafeUserId(),
ts,
});

room.timeline.push(message);
};

const addThreadMessageToRoom = (ts: number) => {
const message = mkMessage({
event: true,
room: room.roomId,
msg: "test thread reply",
user: client.getSafeUserId(),
ts,
});

// Mock thread reply for tests.
jest.spyOn(room, "getThreads").mockReturnValue([
// @ts-ignore
{
lastReply: () => message,
timeline: [],
} as Thread,
]);
};

beforeEach(() => {
sdkContext = new TestSdkContext();

Expand Down Expand Up @@ -262,14 +293,7 @@ describe("RoomTile", () => {

describe("and there is a message in the room", () => {
beforeEach(() => {
const message = mkMessage({
event: true,
room: room.roomId,
msg: "test message",
user: client.getSafeUserId(),
});

room.timeline.push(message);
addMessageToRoom(23);
});

it("should render as expected", async () => {
Expand All @@ -281,27 +305,33 @@ describe("RoomTile", () => {

describe("and there is a message in a thread", () => {
beforeEach(() => {
const message = mkMessage({
event: true,
room: room.roomId,
msg: "test thread reply",
user: client.getSafeUserId(),
});
addThreadMessageToRoom(23);
});

it("should render as expected", async () => {
renderRoomTile();
expect(await screen.findByText("test thread reply")).toBeInTheDocument();
expect(renderResult.asFragment()).toMatchSnapshot();
});
});

describe("and there is a mesage and a thread without a reply", () => {
beforeEach(() => {
addMessageToRoom(23);

// Mock thread reply for tests.
jest.spyOn(room, "getThreads").mockReturnValue([
// @ts-ignore
{
lastReply: () => message,
lastReply: () => null,
timeline: [],
} as Thread,
]);
});

it("should render as expected", async () => {
it("should render the message preview", async () => {
renderRoomTile();
expect(await screen.findByText("test thread reply")).toBeInTheDocument();
expect(renderResult.asFragment()).toMatchSnapshot();
expect(await screen.findByText("test message")).toBeInTheDocument();
});
});
});
Expand Down

0 comments on commit f0e4a07

Please sign in to comment.