Fix wrong buttons being used when exploring public rooms (#9062)

This commit is contained in:
Šimon Brandner 2022-07-20 12:48:31 +02:00 committed by GitHub
parent be0f4a1fe5
commit dca4b8b291
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 2 deletions

View file

@ -139,6 +139,9 @@ describe("Spotlight", () => {
const room2Name = "Lounge"; const room2Name = "Lounge";
let room2Id: string; let room2Id: string;
const room3Name = "Public";
let room3Id: string;
beforeEach(() => { beforeEach(() => {
cy.startSynapse("default").then(data => { cy.startSynapse("default").then(data => {
synapse = data; synapse = data;
@ -163,6 +166,19 @@ describe("Spotlight", () => {
room2Id = _room2Id; room2Id = _room2Id;
bot2.invite(room2Id, bot1.getUserId()); bot2.invite(room2Id, bot1.getUserId());
}); });
bot2.createRoom({
name: room3Name,
visibility: Visibility.Public, initial_state: [{
type: "m.room.history_visibility",
state_key: "",
content: {
history_visibility: "world_readable",
},
}],
}).then(({ room_id: _room3Id }) => {
room3Id = _room3Id;
bot2.invite(room3Id, bot1.getUserId());
});
}), }),
).then(() => ).then(() =>
cy.get('.mx_RoomSublist_skeletonUI').should('not.exist'), cy.get('.mx_RoomSublist_skeletonUI').should('not.exist'),
@ -212,6 +228,7 @@ describe("Spotlight", () => {
cy.spotlightSearch().clear().type(room1Name); cy.spotlightSearch().clear().type(room1Name);
cy.spotlightResults().should("have.length", 1); cy.spotlightResults().should("have.length", 1);
cy.spotlightResults().eq(0).should("contain", room1Name); cy.spotlightResults().eq(0).should("contain", room1Name);
cy.spotlightResults().eq(0).should("contain", "View");
cy.spotlightResults().eq(0).click(); cy.spotlightResults().eq(0).click();
cy.url().should("contain", room1Id); cy.url().should("contain", room1Id);
}).then(() => { }).then(() => {
@ -225,6 +242,7 @@ describe("Spotlight", () => {
cy.spotlightSearch().clear().type(room2Name); cy.spotlightSearch().clear().type(room2Name);
cy.spotlightResults().should("have.length", 1); cy.spotlightResults().should("have.length", 1);
cy.spotlightResults().eq(0).should("contain", room2Name); cy.spotlightResults().eq(0).should("contain", room2Name);
cy.spotlightResults().eq(0).should("contain", "Join");
cy.spotlightResults().eq(0).click(); cy.spotlightResults().eq(0).click();
cy.url().should("contain", room2Id); cy.url().should("contain", room2Id);
}).then(() => { }).then(() => {
@ -233,6 +251,21 @@ describe("Spotlight", () => {
}); });
}); });
it("should find unknown public world readable rooms", () => {
cy.openSpotlightDialog().within(() => {
cy.spotlightFilter(Filter.PublicRooms);
cy.spotlightSearch().clear().type(room3Name);
cy.spotlightResults().should("have.length", 1);
cy.spotlightResults().eq(0).should("contain", room3Name);
cy.spotlightResults().eq(0).should("contain", "View");
cy.spotlightResults().eq(0).click();
cy.url().should("contain", room3Id);
}).then(() => {
cy.get(".mx_RoomPreviewBar_actions .mx_AccessibleButton").click();
cy.roomHeaderName().should("contain", room3Name);
});
});
// TODO: We currently cant test finding rooms on other homeservers/other protocols // TODO: We currently cant test finding rooms on other homeservers/other protocols
// We obviously dont have federation or bridges in cypress tests // We obviously dont have federation or bridges in cypress tests
/* /*

View file

@ -607,6 +607,16 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
} }
if (isPublicRoomResult(result)) { if (isPublicRoomResult(result)) {
const clientRoom = cli.getRoom(result.publicRoom.room_id); const clientRoom = cli.getRoom(result.publicRoom.room_id);
// Element Web currently does not allow guests to join rooms, so we
// instead show them view buttons for all rooms. If the room is not
// world readable, a modal will appear asking you to register first. If
// it is readable, the preview appears as normal.
const showViewButton = (
clientRoom?.getMyMembership() === "join" ||
result.publicRoom.world_readable ||
cli.isGuest()
);
const listener = (ev) => { const listener = (ev) => {
const { publicRoom } = result; const { publicRoom } = result;
viewRoom({ viewRoom({
@ -622,11 +632,11 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
onClick={listener} onClick={listener}
endAdornment={ endAdornment={
<AccessibleButton <AccessibleButton
kind={clientRoom ? "primary" : "primary_outline"} kind={showViewButton ? "primary_outline" : "primary"}
onClick={listener} onClick={listener}
tabIndex={-1} tabIndex={-1}
> >
{ _t(clientRoom ? "View" : "Join") } { showViewButton ? _t("View") : _t("Join") }
</AccessibleButton>} </AccessibleButton>}
aria-labelledby={`mx_SpotlightDialog_button_result_${result.publicRoom.room_id}_name`} aria-labelledby={`mx_SpotlightDialog_button_result_${result.publicRoom.room_id}_name`}
aria-describedby={`mx_SpotlightDialog_button_result_${result.publicRoom.room_id}_alias`} aria-describedby={`mx_SpotlightDialog_button_result_${result.publicRoom.room_id}_alias`}