|
| 1 | +/* |
| 2 | +Copyright 2023 Suguru Hirahara |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +/// <reference types="cypress" /> |
| 18 | + |
| 19 | +import { HomeserverInstance } from "../../plugins/utils/homeserver"; |
| 20 | +import Chainable = Cypress.Chainable; |
| 21 | + |
| 22 | +const ROOM_NAME = "Test room"; |
| 23 | +const NAME = "Alice"; |
| 24 | + |
| 25 | +const viewRoomSummaryByName = (name: string): Chainable<JQuery<HTMLElement>> => { |
| 26 | + cy.viewRoomByName(name); |
| 27 | + cy.get(".mx_RightPanel_roomSummaryButton").click(); |
| 28 | + return checkRoomSummaryCard(name); |
| 29 | +}; |
| 30 | + |
| 31 | +const checkRoomSummaryCard = (name: string): Chainable<JQuery<HTMLElement>> => { |
| 32 | + cy.get(".mx_RoomSummaryCard").should("have.length", 1); |
| 33 | + return cy.get(".mx_BaseCard_header").should("contain", name); |
| 34 | +}; |
| 35 | + |
| 36 | +const uploadFile = (file: string) => { |
| 37 | + // Upload a file from the message composer |
| 38 | + cy.get(".mx_MessageComposer_actions input[type='file']").selectFile(file, { force: true }); |
| 39 | + |
| 40 | + cy.get(".mx_Dialog").within(() => { |
| 41 | + // Click "Upload" button |
| 42 | + cy.get("[data-testid='dialog-primary-button']").should("have.text", "Upload").click(); |
| 43 | + }); |
| 44 | + |
| 45 | + // Wait until the file is sent |
| 46 | + cy.get(".mx_RoomView_statusArea_expanded").should("not.exist"); |
| 47 | + cy.get(".mx_EventTile.mx_EventTile_last .mx_EventTile_receiptSent").should("exist"); |
| 48 | +}; |
| 49 | + |
| 50 | +describe("FilePanel", () => { |
| 51 | + let homeserver: HomeserverInstance; |
| 52 | + |
| 53 | + beforeEach(() => { |
| 54 | + cy.startHomeserver("default").then((data) => { |
| 55 | + homeserver = data; |
| 56 | + cy.initTestUser(homeserver, NAME).then(() => |
| 57 | + cy.window({ log: false }).then(() => { |
| 58 | + cy.createRoom({ name: ROOM_NAME }); |
| 59 | + }), |
| 60 | + ); |
| 61 | + }); |
| 62 | + |
| 63 | + // Open the file panel |
| 64 | + viewRoomSummaryByName(ROOM_NAME); |
| 65 | + cy.get(".mx_RoomSummaryCard_icon_files").click(); |
| 66 | + cy.get(".mx_FilePanel").should("have.length", 1); |
| 67 | + }); |
| 68 | + |
| 69 | + afterEach(() => { |
| 70 | + cy.stopHomeserver(homeserver); |
| 71 | + }); |
| 72 | + |
| 73 | + describe("render", () => { |
| 74 | + it("should list tiles on the panel", () => { |
| 75 | + // Upload multiple files |
| 76 | + uploadFile("cypress/fixtures/riot.png"); // Image |
| 77 | + uploadFile("cypress/fixtures/1sec.ogg"); // Audio |
| 78 | + uploadFile("cypress/fixtures/matrix-org-client-versions.json"); // JSON |
| 79 | + |
| 80 | + cy.get(".mx_RoomView_body").within(() => { |
| 81 | + // Assert that all of the file were uploaded and rendered |
| 82 | + cy.get(".mx_EventTile[data-layout='group']").should("have.length", 3); |
| 83 | + |
| 84 | + // Assert that the image exists and has the alt string |
| 85 | + cy.get(".mx_EventTile[data-layout='group'] img[alt='riot.png']").should("exist"); |
| 86 | + |
| 87 | + // Assert that the audio player is rendered |
| 88 | + cy.get(".mx_EventTile[data-layout='group'] .mx_AudioPlayer_container").should("exist"); |
| 89 | + |
| 90 | + // Assert that the file button exists |
| 91 | + cy.contains(".mx_EventTile_last[data-layout='group'] .mx_MFileBody", ".json").should("exist"); |
| 92 | + }); |
| 93 | + |
| 94 | + cy.get(".mx_FilePanel").within(() => { |
| 95 | + cy.get(".mx_RoomView_MessageList").within(() => { |
| 96 | + // Assert that data-layout attribute is not applied to file tiles on the panel |
| 97 | + cy.get(".mx_EventTile[data-layout='group']").should("not.exist"); |
| 98 | + |
| 99 | + // Assert that all of the file tiles are rendered |
| 100 | + cy.get(".mx_EventTile").should("have.length", 3); |
| 101 | + |
| 102 | + // Assert that the download links are rendered |
| 103 | + cy.get(".mx_MFileBody_download").should("have.length", 3); |
| 104 | + |
| 105 | + // Assert that the sender of the files is rendered on all of the tiles |
| 106 | + cy.get(".mx_EventTile_senderDetails .mx_DisambiguatedProfile_displayName").should("have.length", 3); |
| 107 | + cy.contains(".mx_EventTile_senderDetails .mx_DisambiguatedProfile_displayName", NAME); |
| 108 | + |
| 109 | + // Detect the image file |
| 110 | + cy.get(".mx_EventTile_mediaLine.mx_EventTile_image").within(() => { |
| 111 | + // Assert that the image is specified as thumbnail and has the alt string |
| 112 | + cy.get(".mx_MImageBody").within(() => { |
| 113 | + cy.get("img[class='mx_MImageBody_thumbnail']").should("exist"); |
| 114 | + cy.get("img[alt='riot.png']").should("exist"); |
| 115 | + }); |
| 116 | + }); |
| 117 | + |
| 118 | + // Detect the audio file |
| 119 | + cy.get(".mx_EventTile_mediaLine .mx_MAudioBody").within(() => { |
| 120 | + // Assert that the audio player is rendered |
| 121 | + cy.get(".mx_AudioPlayer_container").within(() => { |
| 122 | + // Assert that the play button is rendered |
| 123 | + cy.get("[data-testid='play-pause-button']").should("exist"); |
| 124 | + }); |
| 125 | + }); |
| 126 | + |
| 127 | + // Detect the JSON file |
| 128 | + // Assert that the tile is rendered as a button |
| 129 | + cy.get(".mx_EventTile_mediaLine .mx_MFileBody .mx_MFileBody_info[role='button']").within(() => { |
| 130 | + // Assert that the file name is rendered inside the button |
| 131 | + // File name: matrix-org-client-versions.json |
| 132 | + cy.contains(".mx_MFileBody_info_filename", "matrix-org"); |
| 133 | + }); |
| 134 | + }); |
| 135 | + |
| 136 | + // Exclude timestamps and read markers from snapshot |
| 137 | + // FIXME: hide mx_SeekBar because flaky - see https://github.com/vector-im/element-web/issues/24897 |
| 138 | + // Remove this once https://github.com/vector-im/element-web/issues/24898 is fixed. |
| 139 | + const percyCSS = |
| 140 | + ".mx_MessageTimestamp, .mx_RoomView_myReadMarker, .mx_SeekBar { visibility: hidden !important; }"; |
| 141 | + cy.get(".mx_RoomView_MessageList").percySnapshotElement("File tiles on FilePanel", { percyCSS }); |
| 142 | + }); |
| 143 | + }); |
| 144 | + |
| 145 | + it("should render the audio pleyer and play the audio file on the panel", () => { |
| 146 | + // Upload an image file |
| 147 | + uploadFile("cypress/fixtures/1sec.ogg"); |
| 148 | + |
| 149 | + cy.get(".mx_FilePanel").within(() => { |
| 150 | + cy.get(".mx_RoomView_MessageList").within(() => { |
| 151 | + // Detect the audio file |
| 152 | + cy.get(".mx_EventTile_mediaLine .mx_MAudioBody").within(() => { |
| 153 | + // Assert that the audio player is rendered |
| 154 | + cy.get(".mx_AudioPlayer_container").within(() => { |
| 155 | + // Assert that the audio file information is rendered |
| 156 | + cy.get(".mx_AudioPlayer_mediaInfo").within(() => { |
| 157 | + cy.get(".mx_AudioPlayer_mediaName").should("have.text", "1sec.ogg"); |
| 158 | + cy.contains(".mx_AudioPlayer_byline", "00:01").should("exist"); |
| 159 | + cy.contains(".mx_AudioPlayer_byline", "(3.56 KB)").should("exist"); // actual size |
| 160 | + }); |
| 161 | + |
| 162 | + // Assert that the counter is zero before clicking the play button |
| 163 | + cy.contains(".mx_AudioPlayer_seek [role='timer']", "00:00").should("exist"); |
| 164 | + |
| 165 | + // Click the play button |
| 166 | + cy.get("[data-testid='play-pause-button'][aria-label='Play']").click(); |
| 167 | + |
| 168 | + // Assert that the pause button is rendered |
| 169 | + cy.get("[data-testid='play-pause-button'][aria-label='Pause']").should("exist"); |
| 170 | + |
| 171 | + // Assert that the timer is reset when the audio file finished playing |
| 172 | + cy.contains(".mx_AudioPlayer_seek [role='timer']", "00:00").should("exist"); |
| 173 | + |
| 174 | + // Assert that the play button is rendered |
| 175 | + cy.get("[data-testid='play-pause-button'][aria-label='Play']").should("exist"); |
| 176 | + }); |
| 177 | + }); |
| 178 | + }); |
| 179 | + }); |
| 180 | + }); |
| 181 | + }); |
| 182 | + |
| 183 | + describe("download", () => { |
| 184 | + it("should download an image via the link on the panel", () => { |
| 185 | + // Upload an image file |
| 186 | + uploadFile("cypress/fixtures/riot.png"); |
| 187 | + |
| 188 | + cy.get(".mx_FilePanel").within(() => { |
| 189 | + cy.get(".mx_RoomView_MessageList").within(() => { |
| 190 | + // Detect the image file on the panel |
| 191 | + cy.get(".mx_EventTile_mediaLine.mx_EventTile_image .mx_MImageBody").within(() => { |
| 192 | + // Click the anchor link (not the image itself) |
| 193 | + cy.get(".mx_MFileBody_download a").click(); |
| 194 | + cy.readFile("cypress/downloads/riot.png").should("exist"); |
| 195 | + }); |
| 196 | + }); |
| 197 | + }); |
| 198 | + }); |
| 199 | + }); |
| 200 | +}); |
0 commit comments