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

Commit bcb8a90

Browse files
committed
Add timeline.spec.ts
Signed-off-by: Šimon Brandner <[email protected]>
1 parent 0c083dc commit bcb8a90

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
/// <reference types="cypress" />
18+
19+
import { EventType } from "matrix-js-sdk/src/@types/event";
20+
import { MessageEvent } from "matrix-events-sdk";
21+
22+
import { SynapseInstance } from "../../plugins/synapsedocker";
23+
import { SettingLevel } from "../../../src/settings/SettingLevel";
24+
import Chainable = Cypress.Chainable;
25+
26+
const getEventTilesWithBodies = (): Chainable<JQuery> => {
27+
return cy.get(".mx_EventTile").filter((_i, e) => e.getElementsByClassName("mx_EventTile_body").length > 0);
28+
};
29+
30+
const expectDisplayName = (e: JQuery<HTMLElement>, displayName: string): void => {
31+
expect(e.find(".mx_DisambiguatedProfile_displayName").text()).to.equal(displayName);
32+
};
33+
34+
describe("Timeline", () => {
35+
let synapse: SynapseInstance;
36+
37+
const roomName = "Test room";
38+
let roomId: string;
39+
40+
describe("useOnlyCurrentProfiles", () => {
41+
beforeEach(() => {
42+
cy.startSynapse("default").then(data => {
43+
synapse = data;
44+
cy.initTestUser(synapse, "Alan").then(() =>
45+
cy.window({ log: false }).then(() => {
46+
cy.createRoom({ name: roomName }).then(_room1Id => {
47+
roomId = _room1Id;
48+
});
49+
}),
50+
);
51+
});
52+
});
53+
54+
afterEach(() => {
55+
cy.stopSynapse(synapse);
56+
});
57+
58+
it("should show historical profiles if disabled", () => {
59+
cy.setSettingValue("useOnlyCurrentProfiles", null, SettingLevel.ACCOUNT, false);
60+
cy.sendEvent(roomId, null, EventType.RoomMessage, MessageEvent.from("Message 1").serialize().content);
61+
cy.setDisplayName("Alan (away)");
62+
cy.wait(500);
63+
cy.sendEvent(roomId, null, EventType.RoomMessage, MessageEvent.from("Message 2").serialize().content);
64+
cy.viewRoomByName(roomName);
65+
66+
const events = getEventTilesWithBodies();
67+
68+
events.should("have.length", 2);
69+
events.each((e, i) => {
70+
if (i === 0) expectDisplayName(e, "Alan");
71+
else if (i === 1) expectDisplayName(e, "Alan (away)");
72+
});
73+
});
74+
75+
it("should not show historical profiles if enabled", () => {
76+
cy.setSettingValue("useOnlyCurrentProfiles", null, SettingLevel.ACCOUNT, true);
77+
cy.sendEvent(roomId, null, EventType.RoomMessage, MessageEvent.from("Message 1").serialize().content);
78+
cy.setDisplayName("Alan (away)");
79+
cy.wait(500);
80+
cy.sendEvent(roomId, null, EventType.RoomMessage, MessageEvent.from("Message 2").serialize().content);
81+
cy.viewRoomByName(roomName);
82+
83+
const events = getEventTilesWithBodies();
84+
85+
events.should("have.length", 2);
86+
events.each((e) => {
87+
expectDisplayName(e, "Alan (away)");
88+
});
89+
});
90+
});
91+
});

0 commit comments

Comments
 (0)