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

Commit 7ef7ccb

Browse files
authored
Update audio-player.spec.ts to reflect the latest status (#10537)
* audio-player.spec.ts - deprecate custom commands of find.ts Signed-off-by: Suguru Hirahara <[email protected]> * audio-player.spec.ts Signed-off-by: Suguru Hirahara <[email protected]> * audio-player.spec.ts - fix findByRole for 'Upload' button and use findByTestId Signed-off-by: Suguru Hirahara <[email protected]> * Enable high contrast with 'findByLabelText' Signed-off-by: Suguru Hirahara <[email protected]> --------- Signed-off-by: Suguru Hirahara <[email protected]>
1 parent d820389 commit 7ef7ccb

File tree

1 file changed

+24
-35
lines changed

1 file changed

+24
-35
lines changed

cypress/e2e/audio-player/audio-player.spec.ts

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe("Audio player", () => {
3737

3838
cy.get(".mx_Dialog").within(() => {
3939
// Find and click primary "Upload" button
40-
cy.get("[data-testid='dialog-primary-button']").findButton("Upload").click();
40+
cy.findByRole("button", { name: "Upload" }).click();
4141
});
4242

4343
// Wait until the file is sent
@@ -65,7 +65,7 @@ describe("Audio player", () => {
6565
);
6666

6767
// Assert that the play button can be found and is visible
68-
cy.findButton("Play").should("be.visible");
68+
cy.findByRole("button", { name: "Play" }).should("be.visible");
6969

7070
if (monospace) {
7171
// Assert that the monospace timer is visible
@@ -148,10 +148,9 @@ describe("Audio player", () => {
148148
cy.createRoom({ name: "Test Room" }).viewRoomByName("Test Room");
149149

150150
// Wait until configuration is finished
151-
cy.contains(
152-
".mx_RoomView_body .mx_GenericEventListSummary[data-layout='group'] .mx_GenericEventListSummary_summary",
153-
"created and configured the room.",
154-
).should("exist");
151+
cy.get(".mx_GenericEventListSummary[data-layout='group'] .mx_GenericEventListSummary_summary").within(() => {
152+
cy.findByText(TEST_USER + " created and configured the room.").should("exist");
153+
});
155154
});
156155

157156
afterEach(() => {
@@ -178,20 +177,8 @@ describe("Audio player", () => {
178177
// Enable high contrast manually
179178
cy.openUserSettings("Appearance")
180179
.get(".mx_ThemeChoicePanel")
181-
.within(() => {
182-
cy.get("[data-testid='theme-choice-panel-selectors']").within(() => {
183-
// Enable light theme
184-
cy.get(".mx_ThemeSelector_light").click();
185-
186-
// Assert that the radio button for light theme was checked
187-
cy.get(".mx_StyledRadioButton_checked input[value='light']").should("exist");
188-
});
189-
190-
cy.get("[data-testid='theme-choice-panel-highcontrast']").within(() => {
191-
// Click the checkbox
192-
cy.get("label .mx_Checkbox_background").click();
193-
});
194-
});
180+
.findByLabelText("Use high contrast")
181+
.click({ force: true }); // force click because the size of the checkbox is zero
195182

196183
cy.closeDialog();
197184

@@ -218,24 +205,24 @@ describe("Audio player", () => {
218205
cy.contains(".mx_AudioPlayer_seek [role='timer']", "00:00").should("exist");
219206

220207
// Find and click "Play" button
221-
cy.findButton("Play").click();
208+
cy.findByRole("button", { name: "Play" }).click();
222209

223210
// Assert that "Pause" button can be found
224-
cy.findButton("Pause").should("exist");
211+
cy.findByRole("button", { name: "Pause" }).should("exist");
225212

226213
// Assert that the timer is reset when the audio file finished playing
227214
cy.contains(".mx_AudioPlayer_seek [role='timer']", "00:00").should("exist");
228215

229216
// Assert that "Play" button can be found
230-
cy.findButton("Play").should("exist");
217+
cy.findByRole("button", { name: "Play" }).should("exist");
231218
});
232219
});
233220

234221
it("should support downloading an audio file", () => {
235222
uploadFile("cypress/fixtures/1sec.ogg");
236223

237224
// Find and click "Download" button on MessageActionBar
238-
cy.get(".mx_EventTile_last").realHover().findButton("Download").click();
225+
cy.get(".mx_EventTile_last").realHover().findByRole("button", { name: "Download" }).click();
239226

240227
// Assert that the file was downloaded
241228
cy.readFile("cypress/downloads/1sec.ogg").should("exist");
@@ -248,7 +235,7 @@ describe("Audio player", () => {
248235
cy.get(".mx_EventTile_last .mx_AudioPlayer_container").should("exist");
249236

250237
// Find and click "Reply" button on MessageActionBar
251-
cy.get(".mx_EventTile_last").realHover().findButton("Reply").click();
238+
cy.get(".mx_EventTile_last").realHover().findByRole("button", { name: "Reply" }).click();
252239

253240
// Reply to the player with another audio file
254241
uploadFile("cypress/fixtures/1sec.ogg");
@@ -276,7 +263,7 @@ describe("Audio player", () => {
276263

277264
// Find and click "Reply" button
278265
const clickButtonReply = () => {
279-
cy.get(".mx_EventTile_last").realHover().findButton("Reply").click();
266+
cy.get(".mx_EventTile_last").realHover().findByRole("button", { name: "Reply" }).click();
280267
};
281268

282269
uploadFile("cypress/fixtures/upload-first.ogg");
@@ -305,7 +292,9 @@ describe("Audio player", () => {
305292
cy.get(".mx_ReplyChain").should("have.length", 2);
306293

307294
// Assert that one line contains the user name
308-
cy.contains(".mx_ReplyChain .mx_ReplyTile_sender", TEST_USER);
295+
cy.get(".mx_ReplyChain .mx_ReplyTile_sender").within(() => {
296+
cy.findByText(TEST_USER);
297+
});
309298

310299
// Assert that the other line contains the file button
311300
cy.get(".mx_ReplyChain .mx_MFileBody").should("exist");
@@ -315,7 +304,7 @@ describe("Audio player", () => {
315304

316305
cy.get("blockquote.mx_ReplyChain:first-of-type").within(() => {
317306
// Assert that "In reply to" has disappeared
318-
cy.contains("In reply to").should("not.exist");
307+
cy.findByText("In reply to").should("not.exist");
319308

320309
// Assert that audio file on the first row is rendered as file button
321310
cy.get(".mx_MFileBody_info[role='button']").within(() => {
@@ -338,7 +327,7 @@ describe("Audio player", () => {
338327
cy.get(".mx_EventTile_last .mx_AudioPlayer_container").should("exist");
339328

340329
// Find and click "Reply in thread" button
341-
cy.get(".mx_EventTile_last").realHover().findButton("Reply in thread").click();
330+
cy.get(".mx_EventTile_last").realHover().findByRole("button", { name: "Reply in thread" }).click();
342331
});
343332

344333
// On a thread
@@ -351,20 +340,20 @@ describe("Audio player", () => {
351340
cy.contains(".mx_AudioPlayer_seek [role='timer']", "00:00").should("exist");
352341

353342
// Find and click "Play" button
354-
cy.findButton("Play").click();
343+
cy.findByRole("button", { name: "Play" }).click();
355344

356345
// Assert that "Pause" button can be found
357-
cy.findButton("Pause").should("exist");
346+
cy.findByRole("button", { name: "Pause" }).should("exist");
358347

359348
// Assert that the timer is reset when the audio file finished playing
360349
cy.contains(".mx_AudioPlayer_seek [role='timer']", "00:00").should("exist");
361350

362351
// Assert that "Play" button can be found
363-
cy.findButton("Play").should("exist");
352+
cy.findByRole("button", { name: "Play" }).should("exist");
364353
});
365354
})
366355
.realHover()
367-
.findButton("Reply")
356+
.findByRole("button", { name: "Reply" })
368357
.click(); // Find and click "Reply" button
369358

370359
cy.get(".mx_MessageComposer--compact").within(() => {
@@ -375,9 +364,9 @@ describe("Audio player", () => {
375364
});
376365

377366
// Select :smile: emoji and send it
378-
cy.get("[data-testid='basicmessagecomposer']").type(":smile:");
367+
cy.findByTestId("basicmessagecomposer").type(":smile:");
379368
cy.get(".mx_Autocomplete_Completion[aria-selected='true']").click();
380-
cy.get("[data-testid='basicmessagecomposer']").type("{enter}");
369+
cy.findByTestId("basicmessagecomposer").type("{enter}");
381370
});
382371

383372
cy.get(".mx_EventTile_last").within(() => {

0 commit comments

Comments
 (0)