Upload test images in the /Photos directory

Signed-off-by: Louis Chemineau <louis@chmn.me>
This commit is contained in:
Louis Chemineau 2024-02-13 15:32:51 +01:00
parent 3e0a2d3fb6
commit 1cbfa656d3
No known key found for this signature in database
5 changed files with 40 additions and 5 deletions

View File

@ -30,6 +30,7 @@ import {
import {
deleteSelection,
favoriteSelection,
mkdir,
selectMedia,
unfavoriteSelection,
unselectMedia,
@ -47,10 +48,11 @@ Cypress.on('uncaught:exception', (err) => {
describe('Manage albums', { testIsolation: true }, () => {
let user = null
beforeEach(function() {
beforeEach(function () {
cy.createRandomUser()
.then(_user => {
user = _user
mkdir(user, '/Photos')
uploadTestMedia(user)
cy.login(user)
})

View File

@ -19,12 +19,13 @@
*/
import type { User } from '@nextcloud/cypress'
import axios from 'axios'
export function uploadTestMedia(user: User) {
export function uploadTestMedia(user: User, destination = '/Photos') {
cy.exec('ls cypress/fixtures/media')
.then((result) => {
for (const fileName of result.stdout.split('\n')) {
cy.uploadFile(user, `media/${fileName}`, 'image/png', `/${fileName}`)
cy.uploadFile(user, `media/${fileName}`, 'image/png', `/${destination}/${fileName}`)
}
})
}
@ -72,3 +73,26 @@ export function deleteSelection() {
.click()
.wait('@deleteRequests')
}
export function mkdir(user: User, target: string) {
// eslint-disable-next-line cypress/unsafe-to-chain-command
cy.clearCookies()
.then({ timeout: 8000 }, async () => {
try {
const rootPath = `${Cypress.env('baseUrl')}/remote.php/dav/files/${encodeURIComponent(user.userId)}`
const filePath = target.split('/').map(encodeURIComponent).join('/')
const response = await axios({
url: `${rootPath}${filePath}`,
method: 'MKCOL',
auth: {
username: user.userId,
password: user.password,
},
})
cy.log(`Created directory ${target}`, response)
} catch (error) {
cy.log('error', error)
throw new Error('Unable to process fixture')
}
})
}

View File

@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { uploadTestMedia } from './photosUtils'
import { mkdir, uploadTestMedia } from './photosUtils'
import { navigateToPlace, runOccCommand } from './placesUtils'
const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/
@ -31,9 +31,10 @@ Cypress.on('uncaught:exception', (err) => {
})
describe('Manage places', () => {
before(function() {
before(function () {
cy.createRandomUser()
.then((user) => {
mkdir(user, '/Photos')
uploadTestMedia(user)
runOccCommand('files:scan --all --generate-metadata')
cy.login(user)

View File

@ -34,6 +34,7 @@ import {
deleteSelection,
downloadAllFiles,
downloadSelection,
mkdir,
selectMedia,
uploadTestMedia,
} from './photosUtils'
@ -64,6 +65,9 @@ describe('Manage shared albums', () => {
cy.createUser(alice)
cy.createUser(bob)
cy.createUser(charlie)
mkdir(alice, '/Photos')
mkdir(bob, '/Photos')
mkdir(charlie, '/Photos')
uploadTestMedia(alice)
uploadTestMedia(bob)
uploadTestMedia(charlie)
@ -302,6 +306,7 @@ describe('Manage shared albums', () => {
cy.visit('apps/photos/sharedalbums')
cy.get('body').should('not.contain', `shared_album_test7 (${alice.userId})`)
cy.createUser(alice)
mkdir(alice, '/Photos')
uploadTestMedia(alice)
})
})

View File

@ -33,6 +33,7 @@ import {
deleteSelection,
downloadSelection,
favoriteSelection,
mkdir,
selectMedia,
unfavoriteSelection,
unselectMedia,
@ -59,9 +60,11 @@ const bob = new User(`bob_${randHash()}`)
describe('View list of photos in the main timeline', () => {
before(() => {
cy.createUser(alice).then(() => {
mkdir(alice, '/Photos')
uploadTestMedia(alice)
})
cy.createUser(bob).then(() => {
mkdir(bob, '/Photos')
uploadTestMedia(bob)
})
cy.login(alice)