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

Commit

Permalink
Set relations helper when creating event tile context menu (#9253)
Browse files Browse the repository at this point in the history
* Set relations helper when creating event tile context menu

Fixes element-hq/element-web#22018

Signed-off-by: Johannes Marbach <[email protected]>

* Add e2e tests

* Use idiomatic test names

Signed-off-by: Johannes Marbach <[email protected]>
Co-authored-by: Travis Ralston <[email protected]>
  • Loading branch information
Johennes and turt2live authored Oct 18, 2022
1 parent 2cf8a9a commit 26f3d10
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 2 deletions.
89 changes: 87 additions & 2 deletions cypress/e2e/polls/polls.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe("Polls", () => {
cy.stopSynapse(synapse);
});

it("Open polls can be created and voted in", () => {
it("should be creatable and votable", () => {
let bot: MatrixClient;
cy.getBot(synapse, { displayName: "BotBob" }).then(_bot => {
bot = _bot;
Expand Down Expand Up @@ -159,7 +159,92 @@ describe("Polls", () => {
});
});

it("displays polls correctly in thread panel", () => {
it("should be editable from context menu if no votes have been cast", () => {
let bot: MatrixClient;
cy.getBot(synapse, { displayName: "BotBob" }).then(_bot => {
bot = _bot;
});

let roomId: string;
cy.createRoom({}).then(_roomId => {
roomId = _roomId;
cy.inviteUser(roomId, bot.getUserId());
cy.visit('/#/room/' + roomId);
});

cy.openMessageComposerOptions().within(() => {
cy.get('[aria-label="Poll"]').click();
});

const pollParams = {
title: 'Does the polls feature work?',
options: ['Yes', 'No', 'Maybe'],
};
createPoll(pollParams);

// Wait for message to send, get its ID and save as @pollId
cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", pollParams.title)
.invoke("attr", "data-scroll-tokens").as("pollId");

cy.get<string>("@pollId").then(pollId => {
// Open context menu
getPollTile(pollId).rightclick();

// Select edit item
cy.get('.mx_ContextualMenu').within(() => {
cy.get('[aria-label="Edit"]').click();
});

// Expect poll editing dialog
cy.get('.mx_PollCreateDialog');
});
});

it("should not be editable from context menu if votes have been cast", () => {
let bot: MatrixClient;
cy.getBot(synapse, { displayName: "BotBob" }).then(_bot => {
bot = _bot;
});

let roomId: string;
cy.createRoom({}).then(_roomId => {
roomId = _roomId;
cy.inviteUser(roomId, bot.getUserId());
cy.visit('/#/room/' + roomId);
});

cy.openMessageComposerOptions().within(() => {
cy.get('[aria-label="Poll"]').click();
});

const pollParams = {
title: 'Does the polls feature work?',
options: ['Yes', 'No', 'Maybe'],
};
createPoll(pollParams);

// Wait for message to send, get its ID and save as @pollId
cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", pollParams.title)
.invoke("attr", "data-scroll-tokens").as("pollId");

cy.get<string>("@pollId").then(pollId => {
// Bot votes 'Maybe' in the poll
botVoteForOption(bot, roomId, pollId, pollParams.options[2]);

// Open context menu
getPollTile(pollId).rightclick();

// Select edit item
cy.get('.mx_ContextualMenu').within(() => {
cy.get('[aria-label="Edit"]').click();
});

// Expect error dialog
cy.get('.mx_ErrorDialog');
});
});

it("should be displayed correctly in thread panel", () => {
let botBob: MatrixClient;
let botCharlie: MatrixClient;
cy.getBot(synapse, { displayName: "BotBob" }).then(_bot => {
Expand Down
1 change: 1 addition & 0 deletions src/components/views/rooms/EventTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ export class UnwrappedEventTile extends React.Component<IProps, IState> {
rightClick={true}
reactions={this.state.reactions}
link={this.state.contextMenu.link}
getRelationsForEvent={this.props.getRelationsForEvent}
/>
);
}
Expand Down

0 comments on commit 26f3d10

Please sign in to comment.