Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

End to end tests for threads #8267

Merged
merged 12 commits into from
Apr 12, 2022
Prev Previous commit
Next Next commit
Scatter the tests with a bunch of assertions
  • Loading branch information
t3chguy committed Apr 8, 2022
commit 86460ef7a20453c59c1df4c7ec106c51d4a4c089
1 change: 1 addition & 0 deletions test/end-to-end-tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ element/env
performance-entries.json
lib
logs
homeserver.log
29 changes: 27 additions & 2 deletions test/end-to-end-tests/src/scenarios/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ limitations under the License.

import { ElementSession } from "../session";
import {
assertTimelineThreadSummary,
clickTimelineThreadSummary,
editThreadMessage,
enableThreads, reactThreadMessage,
redactThreadMessage,
sendThreadMessage,
Expand All @@ -38,24 +40,47 @@ export async function threadsScenarios(alice: ElementSession, bob: ElementSessio

// Alice sends message
await sendMessage(alice, "Hey bob, what do you think about X?");

// Bob responds via a thread
await startThread(bob, "I think its Y!");

// Alice sees thread summary and opens thread panel
await assertTimelineThreadSummary(alice, "bob", "I think its Y!");
await assertTimelineThreadSummary(bob, "bob", "I think its Y!");
await clickTimelineThreadSummary(alice);

// Bob closes right panel
await closeRoomRightPanel(bob);

// Alice responds in thread
await sendThreadMessage(alice, "Great!");
await assertTimelineThreadSummary(alice, "alice", "Great!");
await assertTimelineThreadSummary(bob, "alice", "Great!");

// Alice reacts to Bob's message instead
await reactThreadMessage(alice, "😁");
await assertTimelineThreadSummary(alice, "alice", "Great!");
await assertTimelineThreadSummary(bob, "alice", "Great!");
await redactThreadMessage(alice);
await assertTimelineThreadSummary(alice, "bob", "I think its Y!");
await assertTimelineThreadSummary(bob, "bob", "I think its Y!");

// Bob sees notification dot on the thread header icon
await assertThreadListHasUnreadIndicator(bob);

// Bob opens thread list and inspects it
await openThreadListPanel(bob);

// Bob opens thread in right panel via thread list
await clickLatestThreadInThreadListPanel(bob);

// A & B both inspect their views
// TODO
// Bob responds to thread
await sendThreadMessage(bob, "Testing threads s'more :)");
await assertTimelineThreadSummary(alice, "bob", "Testing threads s'more :)");
await assertTimelineThreadSummary(bob, "bob", "Testing threads s'more :)");

// Bob edits thread response
await editThreadMessage(bob, "Testing threads some more :)");
await assertTimelineThreadSummary(alice, "bob", "Testing threads some more :)");
await assertTimelineThreadSummary(bob, "bob", "Testing threads some more :)");
}
35 changes: 33 additions & 2 deletions test/end-to-end-tests/src/usecases/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ export async function sendThreadMessage(session: ElementSession, message: string
session.log.done();
}

export async function editThreadMessage(session: ElementSession, message: string): Promise<void> {
session.log.step(`edits thread response "${message}"`);
const events = await session.queryAll(".mx_EventTile_line");
const event = events[events.length - 1];
await event.hover();
const button = await event.$(".mx_MessageActionBar_editButton");
await button.click();

const composer = await session.query(".mx_ThreadView .mx_EditMessageComposer .mx_BasicMessageComposer_input");
await composer.click({ clickCount: 3 });
await composer.type(message);

const text = await session.innerText(composer);
assert.equal(text.trim(), message.trim());
await composer.press("Enter");
// wait for the edit to appear sent
await session.query(".mx_ThreadView .mx_EventTile_last:not(.mx_EventTile_sending)");
session.log.done();
}

export async function redactThreadMessage(session: ElementSession): Promise<void> {
session.log.startGroup(`redacts latest thread response`);

Expand Down Expand Up @@ -100,12 +120,23 @@ export async function reactThreadMessage(session: ElementSession, reaction: stri
}

export async function startThread(session: ElementSession, response: string): Promise<void> {
session.log.step(`creates thread on latest message`);
session.log.startGroup(`creates thread on latest message`);

await clickReplyInThread(session);
await sendThreadMessage(session, response);

session.log.done();
session.log.endGroup();
}

export async function assertTimelineThreadSummary(
session: ElementSession,
sender: string,
content: string,
): Promise<void> {
const summaries = await session.queryAll(".mx_MainSplit_timeline .mx_ThreadInfo");
const summary = summaries[summaries.length - 1];
assert.equal(await session.innerText(await summary.$(".mx_ThreadInfo_sender")), sender);
assert.equal(await session.innerText(await summary.$(".mx_ThreadInfo_content")), content);
}

export async function clickTimelineThreadSummary(session: ElementSession): Promise<void> {
Expand Down