-
-
Notifications
You must be signed in to change notification settings - Fork 823
Add E2E test of audio player #10441
Add E2E test of audio player #10441
Changes from 1 commit
4dcc8e7
1694921
ddc7898
b8facfe
f88ff9c
133cf69
2e55e28
f2a6d0a
c6cf476
f23cfc2
617f979
b282fff
c6b908d
f0b120e
495b612
649d20b
445be1d
3742b4f
f6ffc1a
b18794d
36b650e
399a434
fa97ee6
725d020
82e4804
bcf8634
376ef1b
6d559f0
1e0560c
39cdbe3
8ff182a
b148eb8
f4a0ee5
e8094bd
6b496e8
98dd473
1a0fde5
1b279fd
698f443
437ee52
a59586f
555f5de
cdc77d6
946b330
c581aae
6969e5a
af07043
04ad2f8
a20648f
dd1d306
6495655
7774d44
5dc2463
3c5bb25
7488d88
a9fc678
21d0798
b11f30d
7019c86
b176a22
50a0c1a
0175351
e2e08b3
f3fc364
b38ee4d
df5f2b9
bf296a4
d95b153
c1baa6d
c0d9733
7d0df71
e1ae92b
febe45b
4c9c613
450a48f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,235 @@ | ||
/* | ||
Copyright 2023 Suguru Hirahara | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
/// <reference types="cypress" /> | ||
|
||
import { HomeserverInstance } from "../../plugins/utils/homeserver"; | ||
import { SettingLevel } from "../../../src/settings/SettingLevel"; | ||
import { Layout } from "../../../src/settings/enums/Layout"; | ||
|
||
describe("Audio player", () => { | ||
let homeserver: HomeserverInstance; | ||
let roomId: string; | ||
|
||
// FIXME: hide mx_SeekBar because flaky - see https://github.com/vector-im/element-web/issues/24898 | ||
const percyCSS = ".mx_SeekBar { visibility: hidden !important; }"; | ||
|
||
const visitRoom = () => { | ||
cy.visit("/#/room/" + roomId); | ||
cy.setSettingValue("layout", null, SettingLevel.DEVICE, Layout.Group); | ||
|
||
// Wait until configuration is finished | ||
cy.contains( | ||
".mx_RoomView_body .mx_GenericEventListSummary[data-layout='group'] .mx_GenericEventListSummary_summary", | ||
"created and configured the room.", | ||
).should("exist"); | ||
}; | ||
|
||
const uploadFile = (file: string) => { | ||
// Upload a file from the message composer | ||
cy.get(".mx_MessageComposer_actions input[type='file']").selectFile(file, { force: true }); | ||
|
||
cy.get(".mx_Dialog").within(() => { | ||
// Click "Upload" button | ||
cy.get("[data-testid='dialog-primary-button']").should("have.text", "Upload").click(); | ||
}); | ||
|
||
// Wait until the file is sent | ||
cy.get(".mx_RoomView_statusArea_expanded").should("not.exist"); | ||
cy.get(".mx_EventTile.mx_EventTile_last .mx_EventTile_receiptSent").should("exist"); | ||
}; | ||
|
||
const checkPlayerFilenameLong = () => { | ||
// Detect the audio file | ||
cy.get(".mx_EventTile_mediaLine .mx_MAudioBody").within(() => { | ||
// Assert that the audio player is rendered | ||
cy.get(".mx_AudioPlayer_container").within(() => { | ||
// Assert that media information is rendered | ||
cy.get(".mx_AudioPlayer_mediaInfo").within(() => { | ||
cy.get(".mx_AudioPlayer_mediaName").should("have.text", "1sec-long-name-audio-file.ogg"); | ||
cy.contains(".mx_AudioPlayer_byline", "00:01").should("exist"); | ||
cy.contains(".mx_AudioPlayer_byline", "(3.56 KB)").should("exist"); // actual size | ||
}); | ||
|
||
// Assert that the play button is rendered | ||
cy.get("[data-testid='play-pause-button'][aria-label='Play']").should("exist"); | ||
}); | ||
}); | ||
}; | ||
|
||
// Take snapshots in modern and bubble layout, outputting log for reference/debugging | ||
// Player on IRC layout should have the same layout as group layout | ||
luixxiul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const takeSnapshots = (detail: string) => { | ||
// Check the status of the seek bar | ||
// TODO: check if visible - currently visibility check on a narrow timeline causes an error | ||
cy.get(".mx_AudioPlayer_seek input[type='range']").should("exist"); | ||
|
||
// Assert that the pause button is not rendered | ||
cy.get("[data-testid='play-pause-button'][aria-label='Pause']").should("not.exist"); | ||
|
||
// Assert that the play button is rendered | ||
cy.get("[data-testid='play-pause-button'][aria-label='Play']").should("exist"); | ||
|
||
// Enable group layout | ||
cy.setSettingValue("layout", null, SettingLevel.DEVICE, Layout.Group); | ||
|
||
// 243 + 12px + 12px = 267px | ||
// See _MediaBody.pcss and _AudioPlayer.pcss for spacing | ||
cy.get(".mx_MAudioBody").percySnapshotElement(detail + " on group layout", { | ||
percyCSS, | ||
widths: [267], | ||
}); | ||
|
||
cy.log("Took a snapshot of " + detail + " on group layout"); | ||
|
||
// Enable bubble layout | ||
cy.setSettingValue("layout", null, SettingLevel.DEVICE, Layout.Bubble); | ||
|
||
// 243px + 12px + 48px = 303px | ||
// See _EventBubbleTile.pcss and _AudioPlayer.pcss for spacing | ||
cy.get(".mx_MAudioBody").percySnapshotElement(detail + " on bubble layout", { | ||
percyCSS, | ||
widths: [303], | ||
}); | ||
|
||
cy.log("Took a snapshot of " + detail + " on bubble layout"); | ||
|
||
// Reset the layout | ||
cy.setSettingValue("layout", null, SettingLevel.DEVICE, Layout.Group); | ||
}; | ||
|
||
beforeEach(() => { | ||
cy.startHomeserver("default").then((data) => { | ||
homeserver = data; | ||
cy.initTestUser(homeserver, "Hanako").then(() => | ||
cy.createRoom({}).then((_roomId) => { | ||
roomId = _roomId; | ||
}), | ||
); | ||
}); | ||
|
||
cy.injectAxe(); | ||
}); | ||
|
||
afterEach(() => { | ||
cy.stopHomeserver(homeserver); | ||
}); | ||
|
||
it("should render player on every layout", () => { | ||
luixxiul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
visitRoom(); | ||
|
||
// Upload one second audio file with a long file name | ||
uploadFile("cypress/fixtures/1sec-long-name-audio-file.ogg"); | ||
|
||
cy.get(".mx_RoomView_MessageList").within(() => { | ||
checkPlayerFilenameLong(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this necessary? it seems it doesn't matter if the audio player is rendered before we change layout? Likewise below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The intention of it was to ensure that the audio player renders every information properly, but it indeed seems There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that if you're going to check it, you should check it after we change layout - otherwise there is no difference between the tests. It may not be entirely necessary because of the Percy check, but I think it is harmless. |
||
|
||
// Check audio player on IRC layout here, which currently should be same as on modern layout | ||
cy.setSettingValue("layout", null, SettingLevel.DEVICE, Layout.IRC); | ||
// 243 + 12px + 12px = 267px | ||
// See _MediaBody.pcss and _AudioPlayer.pcss for spacing | ||
cy.get(".mx_MAudioBody").percySnapshotElement("Audio player (light theme) on IRC layout", { | ||
percyCSS, | ||
widths: [267], | ||
}); | ||
cy.log("Took a snapshot of Audio player (light theme) on IRC layout"); | ||
richvdh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Reset to the default layout | ||
cy.setSettingValue("layout", null, SettingLevel.DEVICE, Layout.Group); | ||
richvdh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Take snapshots (light theme) | ||
takeSnapshots("Audio player (light theme)"); | ||
|
||
// Take snapshots (light theme, monospace font) | ||
cy.setSettingValue("useSystemFont", null, SettingLevel.DEVICE, true); | ||
cy.setSettingValue("systemFont", null, SettingLevel.DEVICE, "monospace"); | ||
// Assert that the monospace timer is visible | ||
cy.get("[role='timer']").should("have.css", "font-family", '"monospace"').should("be.visible"); | ||
takeSnapshots("Audio player (light theme, monospace)"); | ||
|
||
// Reset font setting | ||
cy.setSettingValue("useSystemFont", null, SettingLevel.DEVICE, false); | ||
|
||
// Take snapshots (dark theme) | ||
cy.setSettingValue("theme", null, SettingLevel.ACCOUNT, "dark"); | ||
takeSnapshots("Audio player (dark theme)"); | ||
}); | ||
}); | ||
|
||
it("should render player on high contrast theme", () => { | ||
visitRoom(); | ||
|
||
// Upload one second audio file with a long file name | ||
uploadFile("cypress/fixtures/1sec-long-name-audio-file.ogg"); | ||
|
||
cy.get(".mx_RoomView_MessageList").within(() => { | ||
checkPlayerFilenameLong(); | ||
}); | ||
|
||
// Enable high contrast manually | ||
cy.openUserSettings("Appearance"); | ||
cy.get(".mx_UserSettingsDialog").within(() => { | ||
cy.get(".mx_ThemeChoicePanel").within(() => { | ||
cy.get("[data-testid='theme-choice-panel-selectors']").within(() => { | ||
// Enable light theme | ||
cy.get(".mx_ThemeSelector_light").click(); | ||
}); | ||
|
||
cy.get("[data-testid='theme-choice-panel-highcontrast']").within(() => { | ||
// Click the checkbox | ||
cy.get("label .mx_Checkbox_background").click(); | ||
}); | ||
}); | ||
|
||
// Close the user settings dialog | ||
cy.get("[aria-label='Close dialog']").click(); | ||
}); | ||
|
||
// Take snapshots (high contrast, light theme only) | ||
cy.get(".mx_RoomView_MessageList").within(() => { | ||
takeSnapshots("Audio player (high contrast)"); | ||
}); | ||
}); | ||
|
||
it("should play an audio file", () => { | ||
visitRoom(); | ||
|
||
// Upload an audio file | ||
uploadFile("cypress/fixtures/1sec.ogg"); | ||
|
||
cy.get(".mx_RoomView_MessageList").within(() => { | ||
cy.get(".mx_EventTile_mediaLine .mx_MAudioBody").within(() => { | ||
// Assert that the audio player is rendered | ||
cy.get(".mx_AudioPlayer_container").within(() => { | ||
// Assert that the counter is zero before clicking the play button | ||
cy.contains(".mx_AudioPlayer_seek [role='timer']", "00:00").should("exist"); | ||
|
||
// Click the play button | ||
cy.get("[data-testid='play-pause-button'][aria-label='Play']").click(); | ||
|
||
// Assert that the pause button is rendered | ||
cy.get("[data-testid='play-pause-button'][aria-label='Pause']").should("exist"); | ||
|
||
// Assert that the timer is reset when the audio file finished playing | ||
cy.contains(".mx_AudioPlayer_seek [role='timer']", "00:00").should("exist"); | ||
|
||
// Assert that the play button is rendered | ||
cy.get("[data-testid='play-pause-button'][aria-label='Play']").should("exist"); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
Uh oh!
There was an error while loading. Please reload this page.