Skip to content

Commit

Permalink
Merge branch 'develop' into kerry/sort-muted
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry committed May 5, 2023
2 parents 30be86f + 3ca957b commit 947f994
Show file tree
Hide file tree
Showing 87 changed files with 1,981 additions and 1,604 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/i18n_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: "Get modified files"
id: changed_files
if: github.event_name == 'pull_request' && github.event.pull_request.user.login != 'RiotTranslateBot'
uses: tj-actions/changed-files@7ecfc6730dff8072d1cc5215a24cc9478f55264d # v35
uses: tj-actions/changed-files@b2d17f51244a144849c6b37a3a6791b98a51d86f # v35
with:
files: |
src/i18n/strings/*
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/crypto/crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface CryptoTestContext extends Mocha.Context {
}

const openRoomInfo = () => {
cy.get(".mx_RightPanel_roomSummaryButton").click();
cy.findByRole("button", { name: "Room info" }).click();
return cy.get(".mx_RightPanel");
};

Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/crypto/decryption-failure.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const handleVerificationRequest = (request: VerificationRequest): Chainable<Emoj
const checkTimelineNarrow = (button = true) => {
cy.viewport(800, 600); // SVGA
cy.get(".mx_LeftPanel_minimized").should("exist"); // Wait until the left panel is minimized
cy.get(".mx_RightPanel_roomSummaryButton").click(); // Open the right panel to make the timeline narrow
cy.findByRole("button", { name: "Room info" }).click(); // Open the right panel to make the timeline narrow
cy.get(".mx_BaseCard").should("exist");

// Ensure the failure bar does not cover the timeline
Expand All @@ -74,7 +74,7 @@ const checkTimelineNarrow = (button = true) => {
cy.get("[data-testid='decryption-failure-bar-button']:last-of-type").should("be.visible");
}

cy.get(".mx_RightPanel_roomSummaryButton").click(); // Close the right panel
cy.findByRole("button", { name: "Room info" }).click(); // Close the right panel
cy.get(".mx_BaseCard").should("not.exist");
cy.viewport(1000, 660); // Reset to the default size
};
Expand Down
174 changes: 174 additions & 0 deletions cypress/e2e/invite/invite-dialog.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/*
Copyright 2023 Suguru Hirahara
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import type { MatrixClient } from "matrix-js-sdk/src/client";
import { HomeserverInstance } from "../../plugins/utils/homeserver";

describe("Invite dialog", function () {
let homeserver: HomeserverInstance;
let bot: MatrixClient;
const botName = "BotAlice";

beforeEach(() => {
cy.startHomeserver("default").then((data) => {
homeserver = data;
cy.initTestUser(homeserver, "Hanako");

cy.getBot(homeserver, { displayName: botName, autoAcceptInvites: true }).then((_bot) => {
bot = _bot;
});
});
});

afterEach(() => {
cy.stopHomeserver(homeserver);
});

it("should support inviting a user to a room", () => {
// Create and view a room
cy.createRoom({ name: "Test Room" }).viewRoomByName("Test Room");

// Assert that the room was configured
cy.findByText("Hanako created and configured the room.").should("exist");

// Open the room info panel
cy.findByRole("button", { name: "Room info" }).click();

// Click "People" button on the panel
// Regex pattern due to the string of "mx_BaseCard_Button_sublabel"
cy.findByRole("button", { name: /People/ }).click();

cy.get(".mx_BaseCard_header").within(() => {
// Click "Invite to this room" button
// Regex pattern due to "mx_MemberList_invite span::before"
cy.findByRole("button", { name: /Invite to this room/ }).click();
});

cy.get(".mx_InviteDialog_other").within(() => {
cy.get(".mx_Dialog_header .mx_Dialog_title").within(() => {
// Assert that the header is rendered
cy.findByText("Invite to Test Room").should("exist");
});

// Assert that the bar is rendered
cy.get(".mx_InviteDialog_addressBar").should("exist");
});

// TODO: unhide userId
const percyCSS = ".mx_InviteDialog_helpText_userId { visibility: hidden !important; }";

// Take a snapshot of the invite dialog including its wrapper
cy.get(".mx_Dialog_wrapper").percySnapshotElement("Invite Dialog - Room (without a user)", { percyCSS });

cy.get(".mx_InviteDialog_other").within(() => {
cy.get(".mx_InviteDialog_identityServer").should("not.exist");

cy.findByTestId("invite-dialog-input").type(bot.getUserId());

// Assert that notification about identity servers appears after typing userId
cy.get(".mx_InviteDialog_identityServer").should("exist");

cy.get(".mx_InviteDialog_tile_nameStack").within(() => {
cy.get(".mx_InviteDialog_tile_nameStack_userId").within(() => {
// Assert that the bot id is rendered properly
cy.findByText(bot.getUserId()).should("exist");
});

cy.get(".mx_InviteDialog_tile_nameStack_name").within(() => {
cy.findByText(botName).click();
});
});

cy.get(".mx_InviteDialog_userTile_pill .mx_InviteDialog_userTile_name").within(() => {
cy.findByText(botName).should("exist");
});
});

// Take a snapshot of the invite dialog with a user pill
cy.get(".mx_Dialog_wrapper").percySnapshotElement("Invite Dialog - Room (with a user pill)", { percyCSS });

cy.get(".mx_InviteDialog_other").within(() => {
// Invite the bot
cy.findByRole("button", { name: "Invite" }).click();
});

// Assert that the invite dialog disappears
cy.get(".mx_InviteDialog_other").should("not.exist");

// Assert that they were invited and joined
cy.findByText(`${botName} joined the room`).should("exist");
});

it("should support inviting a user to Direct Messages", () => {
cy.get(".mx_RoomList").within(() => {
cy.findByRole("button", { name: "Start chat" }).click();
});

cy.get(".mx_InviteDialog_other").within(() => {
cy.get(".mx_Dialog_header .mx_Dialog_title").within(() => {
// Assert that the header is rendered
cy.findByText("Direct Messages").should("exist");
});

// Assert that the bar is rendered
cy.get(".mx_InviteDialog_addressBar").should("exist");
});

// TODO: unhide userId and invite link
const percyCSS =
".mx_InviteDialog_footer_link, .mx_InviteDialog_helpText_userId { visibility: hidden !important; }";

// Take a snapshot of the invite dialog including its wrapper
cy.get(".mx_Dialog_wrapper").percySnapshotElement("Invite Dialog - Direct Messages (without a user)", {
percyCSS,
});

cy.get(".mx_InviteDialog_other").within(() => {
cy.findByTestId("invite-dialog-input").type(bot.getUserId());

cy.get(".mx_InviteDialog_tile_nameStack").within(() => {
cy.findByText(bot.getUserId()).should("exist");
cy.findByText(botName).click();
});

cy.get(".mx_InviteDialog_userTile_pill .mx_InviteDialog_userTile_name").within(() => {
cy.findByText(botName).should("exist");
});
});

// Take a snapshot of the invite dialog with a user pill
cy.get(".mx_Dialog_wrapper").percySnapshotElement("Invite Dialog - Direct Messages (with a user pill)", {
percyCSS,
});

cy.get(".mx_InviteDialog_other").within(() => {
// Open a direct message UI
cy.findByRole("button", { name: "Go" }).click();
});

// Assert that the invite dialog disappears
cy.get(".mx_InviteDialog_other").should("not.exist");

// Send a message to invite the bots
cy.getComposer().type("Hello{enter}");

// Assert that they were invited and joined
cy.findByText(`${botName} joined the room`).should("exist");

// Assert that the message is displayed at the bottom
cy.get(".mx_EventTile_last").findByText("Hello").should("exist");
});
});
133 changes: 133 additions & 0 deletions cypress/e2e/read-receipts/read-receipts.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
Copyright 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/// <reference types="cypress" />

import type { MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
import type { ISendEventResponse } from "matrix-js-sdk/src/@types/requests";
import type { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts";
import { HomeserverInstance } from "../../plugins/utils/homeserver";

describe("Read receipts", () => {
const userName = "Mae";
const botName = "Other User";
const selectedRoomName = "Selected Room";
const otherRoomName = "Other Room";

let homeserver: HomeserverInstance;
let otherRoomId: string;
let selectedRoomId: string;
let bot: MatrixClient | undefined;

const botSendMessage = (): Cypress.Chainable<ISendEventResponse> => {
return cy.botSendMessage(bot, otherRoomId, "Message");
};

const fakeEventFromSent = (eventResponse: ISendEventResponse): MatrixEvent => {
return {
getRoomId: () => otherRoomId,
getId: () => eventResponse.event_id,
threadRootId: undefined,
getTs: () => 1,
} as any as MatrixEvent;
};

beforeEach(() => {
/*
* Create 2 rooms:
*
* - Selected room - this one is clicked in the UI
* - Other room - this one contains the bot, which will send events so
* we can check its unread state.
*/
cy.startHomeserver("default").then((data) => {
homeserver = data;
cy.initTestUser(homeserver, userName)
.then(() => {
cy.createRoom({ name: selectedRoomName }).then((createdRoomId) => {
selectedRoomId = createdRoomId;
});
})
.then(() => {
cy.createRoom({ name: otherRoomName }).then((createdRoomId) => {
otherRoomId = createdRoomId;
});
})
.then(() => {
cy.getBot(homeserver, { displayName: botName }).then((botClient) => {
bot = botClient;
});
})
.then(() => {
// Invite the bot to Other room
cy.inviteUser(otherRoomId, bot.getUserId());
cy.visit("/#/room/" + otherRoomId);
cy.findByText(botName + " joined the room").should("exist");

// Then go into Selected room
cy.visit("/#/room/" + selectedRoomId);
});
});
});

afterEach(() => {
cy.stopHomeserver(homeserver);
});

it(
"Considers room read if there's a receipt for main even if an earlier unthreaded receipt exists #24629",
{
// When #24629 exists, the test fails the first time but passes later, so we disable retries
// to be sure we are going to fail if the bug comes back.
// Why does it pass the second time? I wish I knew. (andyb)
retries: 0,
},
() => {
// Details are in https://github.com/vector-im/element-web/issues/24629
// This proves we've fixed one of the "stuck unreads" issues.

// Given we sent 3 events on the main thread
botSendMessage();
botSendMessage().then((main2) => {
botSendMessage().then((main3) => {
// (So the room starts off unread)
cy.findByLabelText(`${otherRoomName} 3 unread messages.`).should("exist");

// When we send a threaded receipt for the last event in main
// And an unthreaded receipt for an earlier event
cy.sendReadReceipt(fakeEventFromSent(main3));
cy.sendReadReceipt(fakeEventFromSent(main2), "m.read" as any as ReceiptType, true);

// (So the room has no unreads)
cy.findByLabelText(`${otherRoomName}`).should("exist");

// And we persuade the app to persist its state to indexeddb by reloading and waiting
cy.reload();
cy.findByLabelText(`${selectedRoomName}`).should("exist");

// And we reload again, fetching the persisted state FROM indexeddb
cy.reload();

// Then the room is read, because the persisted state correctly remembers both
// receipts. (In #24629, the unthreaded receipt overwrote the main thread one,
// meaning that the room still said it had unread messages.)
cy.findByLabelText(`${otherRoomName}`).should("exist");
cy.findByLabelText(`${otherRoomName} Unread messages.`).should("not.exist");
});
});
},
);
});
2 changes: 1 addition & 1 deletion cypress/e2e/right-panel/right-panel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const getMemberTileByName = (name: string): Chainable<JQuery<HTMLElement>> => {

const viewRoomSummaryByName = (name: string): Chainable<JQuery<HTMLElement>> => {
cy.viewRoomByName(name);
cy.get(".mx_RightPanel_roomSummaryButton").click();
cy.findByRole("button", { name: "Room info" }).click();
return checkRoomSummaryCard(name);
};

Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/timeline/timeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe("Timeline", () => {
// Check the profile resizer's place
// See: _IRCLayout
// --RoomView_MessageList-padding = 18px (See: _RoomView.pcss)
// --MessageTimestamp-width = $MessageTimestamp_width = 46px (See: _common.pcss)
// --MessageTimestamp-width = 46px (See: _MessageTimestamp.pcss)
// --icon-width = 14px
// --right-padding = 5px
// --name-width = 80px
Expand Down Expand Up @@ -207,7 +207,7 @@ describe("Timeline", () => {
cy.get(".mx_GenericEventListSummary[data-layout=irc] .mx_GenericEventListSummary_spacer").should(
"have.css",
"line-height",
"18px", // $irc-line-height: $font-18px (See: _IRCLayout.pcss)
"18px", // var(--irc-line-height): $font-18px (See: _IRCLayout.pcss)
);

cy.get(".mx_MainSplit").percySnapshotElement("Expanded GELS on IRC layout", { percyCSS });
Expand Down Expand Up @@ -371,7 +371,7 @@ describe("Timeline", () => {
// Check inline start spacing of collapsed GELS
// See: _EventTile.pcss
// .mx_GenericEventListSummary[data-layout="irc"] > .mx_EventTile_line
// = var(--name-width) + var(--icon-width) + $MessageTimestamp_width + 2 * var(--right-padding)
// = var(--name-width) + var(--icon-width) + var(--MessageTimestamp-width) + 2 * var(--right-padding)
// = 80 + 14 + 46 + 2 * 5
// = 150px
cy.get(".mx_GenericEventListSummary[data-layout=irc] > .mx_EventTile_line").should(
Expand All @@ -388,7 +388,7 @@ describe("Timeline", () => {
.should("have.css", "margin-inline-end", "0px");
// --icon-width should be applied
cy.get(".mx_EventTile .mx_EventTile_avatar > .mx_BaseAvatar").should("have.css", "width", "14px");
// $MessageTimestamp_width should be applied
// var(--MessageTimestamp-width) should be applied
cy.get(".mx_EventTile > a").should("have.css", "min-width", "46px");
// Record alignment of collapsed GELS and messages on messagePanel
cy.get(".mx_MainSplit").percySnapshotElement("Collapsed GELS and messages on IRC layout", { percyCSS });
Expand Down
Loading

0 comments on commit 947f994

Please sign in to comment.