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

Commit 7f07443

Browse files
Re-add timeline.spec.ts (#9040)
1 parent 3855c44 commit 7f07443

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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 { MessageEvent } from "matrix-events-sdk";
20+
21+
import type { ISendEventResponse } from "matrix-js-sdk/src/@types/requests";
22+
import type { EventType } from "matrix-js-sdk/src/@types/event";
23+
import type { MatrixClient } from "matrix-js-sdk/src/client";
24+
import { SynapseInstance } from "../../plugins/synapsedocker";
25+
import { SettingLevel } from "../../../src/settings/SettingLevel";
26+
import Chainable = Cypress.Chainable;
27+
28+
// The avatar size used in the timeline
29+
const AVATAR_SIZE = 30;
30+
// The resize method used in the timeline
31+
const AVATAR_RESIZE_METHOD = "crop";
32+
33+
const ROOM_NAME = "Test room";
34+
const OLD_AVATAR = "avatar_image1";
35+
const NEW_AVATAR = "avatar_image2";
36+
const OLD_NAME = "Alan";
37+
const NEW_NAME = "Alan (away)";
38+
39+
const getEventTilesWithBodies = (): Chainable<JQuery> => {
40+
return cy.get(".mx_EventTile").filter((_i, e) => e.getElementsByClassName("mx_EventTile_body").length > 0);
41+
};
42+
43+
const expectDisplayName = (e: JQuery<HTMLElement>, displayName: string): void => {
44+
expect(e.find(".mx_DisambiguatedProfile_displayName").text()).to.equal(displayName);
45+
};
46+
47+
const expectAvatar = (e: JQuery<HTMLElement>, avatarUrl: string): void => {
48+
cy.getClient().then((cli: MatrixClient) => {
49+
expect(e.find(".mx_BaseAvatar_image").attr("src")).to.equal(
50+
// eslint-disable-next-line no-restricted-properties
51+
cli.mxcUrlToHttp(avatarUrl, AVATAR_SIZE, AVATAR_SIZE, AVATAR_RESIZE_METHOD),
52+
);
53+
});
54+
};
55+
56+
const sendEvent = (roomId: string): Chainable<ISendEventResponse> => {
57+
return cy.sendEvent(
58+
roomId,
59+
null,
60+
"m.room.message" as EventType,
61+
MessageEvent.from("Message").serialize().content,
62+
);
63+
};
64+
65+
describe("Timeline", () => {
66+
let synapse: SynapseInstance;
67+
68+
let roomId: string;
69+
70+
let oldAvatarUrl: string;
71+
let newAvatarUrl: string;
72+
73+
describe("useOnlyCurrentProfiles", () => {
74+
beforeEach(() => {
75+
cy.startSynapse("default").then(data => {
76+
synapse = data;
77+
cy.initTestUser(synapse, OLD_NAME).then(() =>
78+
cy.window({ log: false }).then(() => {
79+
cy.createRoom({ name: ROOM_NAME }).then(_room1Id => {
80+
roomId = _room1Id;
81+
});
82+
}),
83+
).then(() => {
84+
cy.uploadContent(OLD_AVATAR).then((url) => {
85+
oldAvatarUrl = url;
86+
cy.setAvatarUrl(url);
87+
});
88+
}).then(() => {
89+
cy.uploadContent(NEW_AVATAR).then((url) => {
90+
newAvatarUrl = url;
91+
});
92+
});
93+
});
94+
});
95+
96+
afterEach(() => {
97+
cy.stopSynapse(synapse);
98+
});
99+
100+
it("should show historical profiles if disabled", () => {
101+
cy.setSettingValue("useOnlyCurrentProfiles", null, SettingLevel.ACCOUNT, false);
102+
sendEvent(roomId);
103+
cy.setDisplayName("Alan (away)");
104+
cy.setAvatarUrl(newAvatarUrl);
105+
// XXX: If we send the second event too quickly, there won't be
106+
// enough time for the client to register the profile change
107+
cy.wait(500);
108+
sendEvent(roomId);
109+
cy.viewRoomByName(ROOM_NAME);
110+
111+
const events = getEventTilesWithBodies();
112+
113+
events.should("have.length", 2);
114+
events.each((e, i) => {
115+
if (i === 0) {
116+
expectDisplayName(e, OLD_NAME);
117+
expectAvatar(e, oldAvatarUrl);
118+
} else if (i === 1) {
119+
expectDisplayName(e, NEW_NAME);
120+
expectAvatar(e, newAvatarUrl);
121+
}
122+
});
123+
});
124+
125+
it("should not show historical profiles if enabled", () => {
126+
cy.setSettingValue("useOnlyCurrentProfiles", null, SettingLevel.ACCOUNT, true);
127+
sendEvent(roomId);
128+
cy.setDisplayName(NEW_NAME);
129+
cy.setAvatarUrl(newAvatarUrl);
130+
// XXX: If we send the second event too quickly, there won't be
131+
// enough time for the client to register the profile change
132+
cy.wait(500);
133+
sendEvent(roomId);
134+
cy.viewRoomByName(ROOM_NAME);
135+
136+
const events = getEventTilesWithBodies();
137+
138+
events.should("have.length", 2);
139+
events.each((e) => {
140+
expectDisplayName(e, NEW_NAME);
141+
expectAvatar(e, newAvatarUrl);
142+
});
143+
});
144+
});
145+
});

0 commit comments

Comments
 (0)