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

Commit d1461d3

Browse files
authored
Update polls.spec.ts - use Cypress Testing Library (#10609)
Signed-off-by: Suguru Hirahara <[email protected]>
1 parent 1a0e5c1 commit d1461d3

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

cypress/e2e/polls/polls.spec.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,21 @@ describe("Polls", () => {
3636
throw new Error("Poll must have at least two options");
3737
}
3838
cy.get(".mx_PollCreateDialog").within((pollCreateDialog) => {
39-
cy.get("#poll-topic-input").type(title);
39+
cy.findByRole("textbox", { name: "Question or topic" }).type(title);
4040

4141
options.forEach((option, index) => {
4242
const optionId = `#pollcreate_option_${index}`;
4343

4444
// click 'add option' button if needed
4545
if (pollCreateDialog.find(optionId).length === 0) {
46-
cy.get(".mx_PollCreateDialog_addOption").scrollIntoView().click();
46+
cy.findByRole("button", { name: "Add option" }).scrollIntoView().click();
4747
}
4848
cy.get(optionId).scrollIntoView().type(option);
4949
});
5050
});
51-
cy.get('.mx_Dialog button[type="submit"]').click();
51+
cy.get(".mx_Dialog").within(() => {
52+
cy.findByRole("button", { name: "Create Poll" }).click();
53+
});
5254
};
5355

5456
const getPollTile = (pollId: string): Chainable<JQuery> => {
@@ -67,7 +69,7 @@ describe("Polls", () => {
6769

6870
const botVoteForOption = (bot: MatrixClient, roomId: string, pollId: string, optionText: string): void => {
6971
getPollOption(pollId, optionText).within((ref) => {
70-
cy.get('input[type="radio"]')
72+
cy.findByRole("radio")
7173
.invoke("attr", "value")
7274
.then((optionId) => {
7375
// We can't use the js-sdk types for this stuff directly, so manually construct the event.
@@ -111,11 +113,11 @@ describe("Polls", () => {
111113
cy.inviteUser(roomId, bot.getUserId());
112114
cy.visit("/#/room/" + roomId);
113115
// wait until Bob joined
114-
cy.contains(".mx_TextualEvent", "BotBob joined the room").should("exist");
116+
cy.findByText("BotBob joined the room").should("exist");
115117
});
116118

117119
cy.openMessageComposerOptions().within(() => {
118-
cy.get('[aria-label="Poll"]').click();
120+
cy.findByRole("menuitem", { name: "Poll" }).click();
119121
});
120122

121123
// Disabled because flaky - see https://github.com/vector-im/element-web/issues/24688
@@ -142,7 +144,9 @@ describe("Polls", () => {
142144
botVoteForOption(bot, roomId, pollId, pollParams.options[2]);
143145

144146
// no votes shown until I vote, check bots vote has arrived
145-
cy.get(".mx_MPollBody_totalVotes").should("contain", "1 vote cast");
147+
cy.get(".mx_MPollBody_totalVotes").within(() => {
148+
cy.findByText("1 vote cast. Vote to see the results");
149+
});
146150

147151
// vote 'Maybe'
148152
getPollOption(pollId, pollParams.options[2]).click("topLeft");
@@ -183,7 +187,7 @@ describe("Polls", () => {
183187
});
184188

185189
cy.openMessageComposerOptions().within(() => {
186-
cy.get('[aria-label="Poll"]').click();
190+
cy.findByRole("menuitem", { name: "Poll" }).click();
187191
});
188192

189193
const pollParams = {
@@ -203,9 +207,7 @@ describe("Polls", () => {
203207
getPollTile(pollId).rightclick();
204208

205209
// Select edit item
206-
cy.get(".mx_ContextualMenu").within(() => {
207-
cy.get('[aria-label="Edit"]').click();
208-
});
210+
cy.findByRole("menuitem", { name: "Edit" }).click();
209211

210212
// Expect poll editing dialog
211213
cy.get(".mx_PollCreateDialog");
@@ -226,7 +228,7 @@ describe("Polls", () => {
226228
});
227229

228230
cy.openMessageComposerOptions().within(() => {
229-
cy.get('[aria-label="Poll"]').click();
231+
cy.findByRole("menuitem", { name: "Poll" }).click();
230232
});
231233

232234
const pollParams = {
@@ -252,9 +254,7 @@ describe("Polls", () => {
252254
getPollTile(pollId).rightclick();
253255

254256
// Select edit item
255-
cy.get(".mx_ContextualMenu").within(() => {
256-
cy.get('[aria-label="Edit"]').click();
257-
});
257+
cy.findByRole("menuitem", { name: "Edit" }).click();
258258

259259
// Expect error dialog
260260
cy.get(".mx_ErrorDialog");
@@ -278,11 +278,11 @@ describe("Polls", () => {
278278
cy.inviteUser(roomId, botCharlie.getUserId());
279279
cy.visit("/#/room/" + roomId);
280280
// wait until the bots joined
281-
cy.contains(".mx_TextualEvent", "and one other were invited and joined").should("exist");
281+
cy.findByText("BotBob and one other were invited and joined", { timeout: 10000 }).should("exist");
282282
});
283283

284284
cy.openMessageComposerOptions().within(() => {
285-
cy.get('[aria-label="Poll"]').click();
285+
cy.findByRole("menuitem", { name: "Poll" }).click();
286286
});
287287

288288
const pollParams = {
@@ -304,17 +304,21 @@ describe("Polls", () => {
304304
});
305305

306306
// open the thread summary
307-
cy.get(".mx_RoomView_body .mx_ThreadSummary").click();
307+
cy.findByRole("button", { name: "Open thread" }).click();
308308

309309
// Bob votes 'Maybe' in the poll
310310
botVoteForOption(botBob, roomId, pollId, pollParams.options[2]);
311311
// Charlie votes 'No'
312312
botVoteForOption(botCharlie, roomId, pollId, pollParams.options[1]);
313313

314314
// no votes shown until I vote, check votes have arrived in main tl
315-
cy.get(".mx_RoomView_body .mx_MPollBody_totalVotes").should("contain", "2 votes cast");
315+
cy.get(".mx_RoomView_body .mx_MPollBody_totalVotes").within(() => {
316+
cy.findByText("2 votes cast. Vote to see the results").should("exist");
317+
});
316318
// and thread view
317-
cy.get(".mx_ThreadView .mx_MPollBody_totalVotes").should("contain", "2 votes cast");
319+
cy.get(".mx_ThreadView .mx_MPollBody_totalVotes").within(() => {
320+
cy.findByText("2 votes cast. Vote to see the results").should("exist");
321+
});
318322

319323
// Take snapshots of poll on ThreadView
320324
cy.setSettingValue("layout", null, SettingLevel.DEVICE, Layout.Bubble);

0 commit comments

Comments
 (0)