Skip to content

Commit bd9b7a2

Browse files
committed
Upload test images in the /Photos directory
Signed-off-by: Louis Chemineau <[email protected]>
1 parent fec30fd commit bd9b7a2

5 files changed

Lines changed: 40 additions & 5 deletions

File tree

cypress/e2e/albums.cy.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
import {
3131
deleteSelection,
3232
favoriteSelection,
33+
mkdir,
3334
selectMedia,
3435
unfavoriteSelection,
3536
unselectMedia,
@@ -47,10 +48,11 @@ Cypress.on('uncaught:exception', (err) => {
4748
describe('Manage albums', { testIsolation: true }, () => {
4849
let user = null
4950

50-
beforeEach(function() {
51+
beforeEach(function () {
5152
cy.createRandomUser()
5253
.then(_user => {
5354
user = _user
55+
mkdir(user, '/Photos')
5456
uploadTestMedia(user)
5557
cy.login(user)
5658
})

cypress/e2e/photosUtils.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
*/
2020

2121
import type { User } from '@nextcloud/cypress'
22+
import axios from 'axios'
2223

23-
export function uploadTestMedia(user: User) {
24+
export function uploadTestMedia(user: User, destination = '/Photos') {
2425
cy.exec('ls cypress/fixtures/media')
2526
.then((result) => {
2627
for (const fileName of result.stdout.split('\n')) {
27-
cy.uploadFile(user, `media/${fileName}`, 'image/png', `/${fileName}`)
28+
cy.uploadFile(user, `media/${fileName}`, 'image/png', `/${destination}/${fileName}`)
2829
}
2930
})
3031
}
@@ -72,3 +73,26 @@ export function deleteSelection() {
7273
.click()
7374
.wait('@deleteRequests')
7475
}
76+
77+
export function mkdir(user: User, target: string) {
78+
// eslint-disable-next-line cypress/unsafe-to-chain-command
79+
cy.clearCookies()
80+
.then({ timeout: 8000 }, async () => {
81+
try {
82+
const rootPath = `${Cypress.env('baseUrl')}/remote.php/dav/files/${encodeURIComponent(user.userId)}`
83+
const filePath = target.split('/').map(encodeURIComponent).join('/')
84+
const response = await axios({
85+
url: `${rootPath}${filePath}`,
86+
method: 'MKCOL',
87+
auth: {
88+
username: user.userId,
89+
password: user.password,
90+
},
91+
})
92+
cy.log(`Created directory ${target}`, response)
93+
} catch (error) {
94+
cy.log('error', error)
95+
throw new Error('Unable to process fixture')
96+
}
97+
})
98+
}

cypress/e2e/places.cy.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*
2121
*/
22-
import { uploadTestMedia } from './photosUtils'
22+
import { mkdir, uploadTestMedia } from './photosUtils'
2323
import { navigateToPlace, runOccCommand } from './placesUtils'
2424

2525
const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/
@@ -31,9 +31,10 @@ Cypress.on('uncaught:exception', (err) => {
3131
})
3232

3333
describe('Manage places', () => {
34-
before(function() {
34+
before(function () {
3535
cy.createRandomUser()
3636
.then((user) => {
37+
mkdir(user, '/Photos')
3738
uploadTestMedia(user)
3839
runOccCommand('files:scan --all --generate-metadata')
3940
cy.login(user)

cypress/e2e/shared_albums.cy.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
deleteSelection,
3535
downloadAllFiles,
3636
downloadSelection,
37+
mkdir,
3738
selectMedia,
3839
uploadTestMedia,
3940
} from './photosUtils'
@@ -64,6 +65,9 @@ describe('Manage shared albums', () => {
6465
cy.createUser(alice)
6566
cy.createUser(bob)
6667
cy.createUser(charlie)
68+
mkdir(alice, '/Photos')
69+
mkdir(bob, '/Photos')
70+
mkdir(charlie, '/Photos')
6771
uploadTestMedia(alice)
6872
uploadTestMedia(bob)
6973
uploadTestMedia(charlie)
@@ -302,6 +306,7 @@ describe('Manage shared albums', () => {
302306
cy.visit('apps/photos/sharedalbums')
303307
cy.get('body').should('not.contain', `shared_album_test7 (${alice.userId})`)
304308
cy.createUser(alice)
309+
mkdir(alice, '/Photos')
305310
uploadTestMedia(alice)
306311
})
307312
})

cypress/e2e/timelines.cy.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
deleteSelection,
3434
downloadSelection,
3535
favoriteSelection,
36+
mkdir,
3637
selectMedia,
3738
unfavoriteSelection,
3839
unselectMedia,
@@ -59,9 +60,11 @@ const bob = new User(`bob_${randHash()}`)
5960
describe('View list of photos in the main timeline', () => {
6061
before(() => {
6162
cy.createUser(alice).then(() => {
63+
mkdir(alice, '/Photos')
6264
uploadTestMedia(alice)
6365
})
6466
cy.createUser(bob).then(() => {
67+
mkdir(bob, '/Photos')
6568
uploadTestMedia(bob)
6669
})
6770
cy.login(alice)

0 commit comments

Comments
 (0)