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

Set relations helper when creating event tile context menu #9253

Merged
merged 9 commits into from
Oct 18, 2022
85 changes: 85 additions & 0 deletions cypress/e2e/polls/polls.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,91 @@ describe("Polls", () => {
});
});

it("Polls without votes can be edited from context menu", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw, test naming is typically in the following form:

describe("TheTheThingBeingTested", () => {
  it("should have a particular behaviour", () => { ... });
});

for example, this test would be something like:

describe("Polls", () => {
  it("should be editable if they have no votes", () => { ... });
});

in the grand scheme of things it doesn't really matter - just spreading the word for eventual consistency :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually that was my understanding, too. I just followed the style used in the other test methods in this file. I've switched all of them over to the idiomatic format now.

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("Polls with votes cannot be edited from context menu", () => {
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("displays polls correctly in thread panel", () => {
let botBob: MatrixClient;
let botCharlie: MatrixClient;
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 @@ -929,6 +929,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