|
| 1 | +/** |
| 2 | + * @copyright Copyright (c) 2024 Louis Chmn <[email protected]> |
| 3 | + * |
| 4 | + * @author Louis Chmn <[email protected]> |
| 5 | + * |
| 6 | + * @license AGPL-3.0-or-later |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Affero General Public License as |
| 10 | + * published by the Free Software Foundation, either version 3 of the |
| 11 | + * License, or (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU Affero General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Affero General Public License |
| 19 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | +import type { User } from '@nextcloud/cypress' |
| 24 | +import { closeSidebar, copyFile, getRowForFile, getRowForFileId, renameFile, triggerActionForFile, triggerInlineActionForFileId } from './FilesUtils' |
| 25 | + |
| 26 | +/** |
| 27 | + * |
| 28 | + * @param label |
| 29 | + */ |
| 30 | +function refreshView(label: string) { |
| 31 | + cy.intercept('PROPFIND', /\/remote.php\/dav\//).as('propfind') |
| 32 | + cy.get('[data-cy-files-content-breadcrumbs]').contains(label).click() |
| 33 | + cy.wait('@propfind') |
| 34 | +} |
| 35 | + |
| 36 | +/** |
| 37 | + * |
| 38 | + * @param user |
| 39 | + * @param fileName |
| 40 | + * @param domain |
| 41 | + * @param requesttoken |
| 42 | + * @param metadata |
| 43 | + */ |
| 44 | +function setMetadata(user: User, fileName: string, domain: string, requesttoken: string, metadata: object) { |
| 45 | + cy.request({ |
| 46 | + method: 'PROPPATCH', |
| 47 | + url: `http://${domain}/remote.php/dav/files/${user.userId}/${fileName}`, |
| 48 | + auth: { user: user.userId, pass: user.password }, |
| 49 | + headers: { |
| 50 | + requesttoken, |
| 51 | + }, |
| 52 | + body: `<?xml version="1.0"?> |
| 53 | + <d:propertyupdate xmlns:d="DAV:" xmlns:nc="http://nextcloud.org/ns"> |
| 54 | + <d:set> |
| 55 | + <d:prop> |
| 56 | + ${Object.entries(metadata).map(([key, value]) => `<${key}>${value}</${key}>`).join('\n')} |
| 57 | + </d:prop> |
| 58 | + </d:set> |
| 59 | + </d:propertyupdate>`, |
| 60 | + }) |
| 61 | +} |
| 62 | + |
| 63 | +describe('Files: Live photos', { testIsolation: true }, () => { |
| 64 | + let currentUser: User |
| 65 | + let randomFileName: string |
| 66 | + let jpgFileId: number |
| 67 | + let movFileId: number |
| 68 | + let hostname: string |
| 69 | + let requesttoken: string |
| 70 | + |
| 71 | + before(() => { |
| 72 | + cy.createRandomUser().then((user) => { |
| 73 | + currentUser = user |
| 74 | + cy.login(currentUser) |
| 75 | + cy.visit('/apps/files') |
| 76 | + }) |
| 77 | + |
| 78 | + cy.url().then(url => { hostname = new URL(url).hostname }) |
| 79 | + }) |
| 80 | + |
| 81 | + beforeEach(() => { |
| 82 | + randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) |
| 83 | + |
| 84 | + cy.uploadContent(currentUser, new Blob(['jpg file'], { type: 'image/jpg' }), 'image/jpg', `/${randomFileName}.jpg`) |
| 85 | + .then(response => { jpgFileId = parseInt(response.headers['oc-fileid']) }) |
| 86 | + cy.uploadContent(currentUser, new Blob(['mov file'], { type: 'video/mov' }), 'video/mov', `/${randomFileName}.mov`) |
| 87 | + .then(response => { movFileId = parseInt(response.headers['oc-fileid']) }) |
| 88 | + |
| 89 | + cy.login(currentUser) |
| 90 | + cy.visit('/apps/files') |
| 91 | + |
| 92 | + cy.get('head').invoke('attr', 'data-requesttoken').then(_requesttoken => { requesttoken = _requesttoken as string }) |
| 93 | + |
| 94 | + cy.then(() => { |
| 95 | + setMetadata(currentUser, `${randomFileName}.jpg`, hostname, requesttoken, { 'nc:metadata-files-live-photo': movFileId }) |
| 96 | + setMetadata(currentUser, `${randomFileName}.mov`, hostname, requesttoken, { 'nc:metadata-files-live-photo': jpgFileId }) |
| 97 | + }) |
| 98 | + |
| 99 | + cy.then(() => { |
| 100 | + cy.visit(`/apps/files/files/${jpgFileId}`) // Refresh and scroll to the .jpg file. |
| 101 | + closeSidebar() |
| 102 | + }) |
| 103 | + }) |
| 104 | + |
| 105 | + it('Only renders the .jpg file', () => { |
| 106 | + getRowForFileId(jpgFileId).should('have.length', 1) |
| 107 | + getRowForFileId(movFileId).should('have.length', 0) |
| 108 | + }) |
| 109 | + |
| 110 | + context("'Show hidden files' is enabled", () => { |
| 111 | + before(() => { |
| 112 | + cy.login(currentUser) |
| 113 | + cy.visit('/apps/files') |
| 114 | + cy.get('[data-cy-files-navigation-settings-button]').click() |
| 115 | + // Force:true because the checkbox is hidden by the pretty UI. |
| 116 | + cy.get('[data-cy-files-settings-setting="show_hidden"] input').check({ force: true }) |
| 117 | + }) |
| 118 | + |
| 119 | + it("Shows both files when 'Show hidden files' is enabled", () => { |
| 120 | + getRowForFileId(jpgFileId).should('have.length', 1).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}.jpg`) |
| 121 | + getRowForFileId(movFileId).should('have.length', 1).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}.mov`) |
| 122 | + }) |
| 123 | + |
| 124 | + it('Copies both files when copying the .jpg', () => { |
| 125 | + copyFile(`${randomFileName}.jpg`, '.') |
| 126 | + refreshView('All files') |
| 127 | + |
| 128 | + getRowForFile(`${randomFileName}.jpg`).should('have.length', 1) |
| 129 | + getRowForFile(`${randomFileName}.mov`).should('have.length', 1) |
| 130 | + getRowForFile(`${randomFileName} (copy).jpg`).should('have.length', 1) |
| 131 | + getRowForFile(`${randomFileName} (copy).mov`).should('have.length', 1) |
| 132 | + }) |
| 133 | + |
| 134 | + it('Copies both files when copying the .mov', () => { |
| 135 | + copyFile(`${randomFileName}.mov`, '.') |
| 136 | + refreshView('All files') |
| 137 | + |
| 138 | + getRowForFile(`${randomFileName}.mov`).should('have.length', 1) |
| 139 | + getRowForFile(`${randomFileName} (copy).jpg`).should('have.length', 1) |
| 140 | + getRowForFile(`${randomFileName} (copy).mov`).should('have.length', 1) |
| 141 | + }) |
| 142 | + |
| 143 | + it('Moves files when moving the .jpg', () => { |
| 144 | + renameFile(`${randomFileName}.jpg`, `${randomFileName}_moved.jpg`) |
| 145 | + refreshView('All files') |
| 146 | + |
| 147 | + getRowForFileId(jpgFileId).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}_moved.jpg`) |
| 148 | + getRowForFileId(movFileId).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}_moved.mov`) |
| 149 | + }) |
| 150 | + |
| 151 | + it('Moves files when moving the .mov', () => { |
| 152 | + renameFile(`${randomFileName}.mov`, `${randomFileName}_moved.mov`) |
| 153 | + refreshView('All files') |
| 154 | + |
| 155 | + getRowForFileId(jpgFileId).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}_moved.jpg`) |
| 156 | + getRowForFileId(movFileId).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}_moved.mov`) |
| 157 | + }) |
| 158 | + |
| 159 | + it('Deletes files when deleting the .jpg', () => { |
| 160 | + triggerActionForFile(`${randomFileName}.jpg`, 'delete') |
| 161 | + refreshView('All files') |
| 162 | + |
| 163 | + getRowForFile(`${randomFileName}.jpg`).should('have.length', 0) |
| 164 | + getRowForFile(`${randomFileName}.mov`).should('have.length', 0) |
| 165 | + |
| 166 | + cy.visit('/apps/files/trashbin') |
| 167 | + |
| 168 | + getRowForFileId(jpgFileId).invoke('attr', 'data-cy-files-list-row-name').should('to.match', new RegExp(`^${randomFileName}.jpg\\.d[0-9]+$`)) |
| 169 | + getRowForFileId(movFileId).invoke('attr', 'data-cy-files-list-row-name').should('to.match', new RegExp(`^${randomFileName}.mov\\.d[0-9]+$`)) |
| 170 | + }) |
| 171 | + |
| 172 | + it('Block deletion when deleting the .mov', () => { |
| 173 | + triggerActionForFile(`${randomFileName}.mov`, 'delete') |
| 174 | + refreshView('All files') |
| 175 | + |
| 176 | + getRowForFile(`${randomFileName}.jpg`).should('have.length', 1) |
| 177 | + getRowForFile(`${randomFileName}.mov`).should('have.length', 1) |
| 178 | + |
| 179 | + cy.visit('/apps/files/trashbin') |
| 180 | + |
| 181 | + getRowForFileId(jpgFileId).should('have.length', 0) |
| 182 | + getRowForFileId(movFileId).should('have.length', 0) |
| 183 | + }) |
| 184 | + |
| 185 | + it('Restores files when restoring the .jpg', () => { |
| 186 | + triggerActionForFile(`${randomFileName}.jpg`, 'delete') |
| 187 | + cy.visit('/apps/files/trashbin') |
| 188 | + triggerInlineActionForFileId(jpgFileId, 'restore') |
| 189 | + refreshView('Deleted files') |
| 190 | + |
| 191 | + getRowForFile(`${randomFileName}.jpg`).should('have.length', 0) |
| 192 | + getRowForFile(`${randomFileName}.mov`).should('have.length', 0) |
| 193 | + |
| 194 | + cy.visit('/apps/files') |
| 195 | + |
| 196 | + getRowForFile(`${randomFileName}.jpg`).should('have.length', 1) |
| 197 | + getRowForFile(`${randomFileName}.mov`).should('have.length', 1) |
| 198 | + }) |
| 199 | + |
| 200 | + it('Blocks restoration when restoring the .mov', () => { |
| 201 | + triggerActionForFile(`${randomFileName}.jpg`, 'delete') |
| 202 | + cy.visit('/apps/files/trashbin') |
| 203 | + triggerInlineActionForFileId(movFileId, 'restore') |
| 204 | + refreshView('Deleted files') |
| 205 | + |
| 206 | + getRowForFileId(jpgFileId).should('have.length', 1) |
| 207 | + getRowForFileId(movFileId).should('have.length', 1) |
| 208 | + |
| 209 | + cy.visit('/apps/files') |
| 210 | + |
| 211 | + getRowForFile(`${randomFileName}.jpg`).should('have.length', 0) |
| 212 | + getRowForFile(`${randomFileName}.mov`).should('have.length', 0) |
| 213 | + }) |
| 214 | + }) |
| 215 | +}) |
0 commit comments