Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 31 additions & 33 deletions cypress/e2e/shared_albums.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
*/
import { randHash } from '../utils'

const randUser = randHash()
const randUser2 = randHash()
const randUser3 = randHash()
const alice = `alice_${randHash()}`
const bob = `bob_${randHash()}`
const charlie = `charlie_${randHash()}`

const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/
Cypress.on('uncaught:exception', (err) => {
Expand All @@ -35,30 +35,30 @@ Cypress.on('uncaught:exception', (err) => {

describe('Manage shared albums', () => {
before(() => {
cy.visit('')
cy.logout()

cy.nextcloudCreateUser(randUser, 'password')
cy.nextcloudCreateUser(randUser2, 'password')
cy.nextcloudCreateUser(randUser3, 'password')
cy.nextcloudCreateUser(alice, 'password')
cy.nextcloudCreateUser(bob, 'password')
cy.nextcloudCreateUser(charlie, 'password')

cy.login(randUser2, 'password')
cy.login(bob, 'password')
cy.uploadTestMedia()
cy.logout()
})

beforeEach(() => {
cy.logout()
cy.login(randUser2, 'password')
cy.visit(`${Cypress.env('baseUrl')}/index.php/apps/photos/sharedalbums`)
cy.login(bob, 'password', '/apps/photos/sharedalbums')
})

context('Adding and removing files in a shared album', () => {
before(() => {
cy.logout()
cy.login(randUser, 'password')
cy.login(alice, 'password')
cy.visit(`${Cypress.env('baseUrl')}/index.php/apps/photos/albums`)
cy.createAnAlbumFromAlbums('shared_album_test1')
cy.addCollaborators([randUser2])
cy.addCollaborators([bob])
cy.logout()
})

Expand Down Expand Up @@ -86,13 +86,13 @@ describe('Manage shared albums', () => {
context('Download files from a shared album', () => {
before(() => {
cy.logout()
cy.login(randUser, 'password')
cy.login(alice, 'password')
cy.visit(`${Cypress.env('baseUrl')}/index.php/apps/photos/albums`)
cy.createAnAlbumFromAlbums('shared_album_test2')
cy.addCollaborators([randUser2])
cy.addCollaborators([bob])
cy.logout()

cy.login(randUser2, 'password')
cy.login(bob, 'password')
cy.visit(`${Cypress.env('baseUrl')}/index.php/apps/photos/sharedalbums`)
cy.goToSharedAlbum('shared_album_test2')
cy.addFilesToAlbumFromAlbum('shared_album_test2', [0, 1, 2])
Expand Down Expand Up @@ -122,10 +122,10 @@ describe('Manage shared albums', () => {
context('Delete a received shared album', () => {
before(() => {
cy.logout()
cy.login(randUser, 'password')
cy.login(alice, 'password')
cy.visit(`${Cypress.env('baseUrl')}/index.php/apps/photos/albums`)
cy.createAnAlbumFromAlbums('shared_album_test3')
cy.addCollaborators([randUser2])
cy.addCollaborators([bob])
cy.logout()
})

Expand All @@ -138,52 +138,50 @@ describe('Manage shared albums', () => {
context('Remove a collaborator from an album', () => {
before(() => {
cy.logout()
cy.login(randUser, 'password')
cy.visit(`${Cypress.env('baseUrl')}/index.php/apps/photos/albums`)
cy.login(alice, 'password', '/apps/photos/albums')
cy.createAnAlbumFromAlbums('shared_album_test4')
cy.addCollaborators([randUser2])
cy.addCollaborators([bob])
cy.logout()
})

it('Remove collaborator from an album', () => {
cy.get('ul.collections__list li').should('have.length', 4)
cy.get('ul.collections__list li')
.should('contain', `shared_album_test4 (${alice})`)

cy.logout()
cy.login(randUser, 'password')
cy.visit(`${Cypress.env('baseUrl')}/index.php/apps/photos`)
cy.login(alice, 'password', '/apps/photos')
cy.goToAlbum('shared_album_test4')
cy.removeCollaborators([randUser2])
cy.removeCollaborators([bob])
cy.logout()

cy.login(randUser2, 'password')
cy.visit(`${Cypress.env('baseUrl')}/index.php/apps/photos/sharedalbums`)

cy.get('ul.collections__list li').should('have.length', 3)
cy.login(bob, 'password', '/apps/photos/sharedalbums')
cy.get('body')
.should('not.contain', `shared_album_test4 (${alice})`)
})
})

context('Two shared albums with the same name', () => {
before(() => {
cy.logout()
cy.login(randUser, 'password')
cy.login(alice, 'password')
cy.visit(`${Cypress.env('baseUrl')}/index.php/apps/photos/albums`)
cy.createAnAlbumFromAlbums('shared_album_test5')
cy.addCollaborators([randUser2])
cy.addCollaborators([bob])
cy.logout()

cy.login(randUser3, 'password')
cy.login(charlie, 'password')
cy.visit(`${Cypress.env('baseUrl')}/index.php/apps/photos/albums`)
cy.createAnAlbumFromAlbums('shared_album_test5')
cy.addCollaborators([randUser2])
cy.addCollaborators([bob])
cy.logout()
})


it('It should display two shared albums', () => {
cy.get('ul.collections__list li')
.contains(`shared_album_test5 (${randUser})`)
.contains(`shared_album_test5 (${alice})`)
cy.get('ul.collections__list li')
.contains(`shared_album_test5 (${randUser3})`)
.contains(`shared_album_test5 (${charlie})`)
})
})
})
18 changes: 8 additions & 10 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const url = Cypress.config('baseUrl').replace(/\/index.php\/?$/g, '')
Cypress.env('baseUrl', url)

Cypress.Commands.add('login', (user, password, route = '/apps/files') => {
cy.clearCookies()
Cypress.Cookies.defaults({
preserve: /^(oc|nc)/,
})
Expand All @@ -39,7 +38,6 @@ Cypress.Commands.add('login', (user, password, route = '/apps/files') => {
})

Cypress.Commands.add('logout', () => {
cy.visit('')
cy.getCookies()
.then(cookies => {
if (cookies.length === 0) {
Expand All @@ -49,20 +47,19 @@ Cypress.Commands.add('logout', () => {

return cy.get("body")
.then($body => {
const logout = $body.find('#expanddiv li[data-id="logout"] a')
if (logout.length > 0) {
cy.log('Loging out...')
cy.visit(logout[0].href)
} else {
cy.log('Nothing')
const $settingsButton = $body.find('#settings #expand')
if ($settingsButton.length === 0) {
cy.log("Not logged in.")
return
}

$settingsButton.click()
cy.contains('Log out').click()
})
})
})

Cypress.Commands.add('nextcloudCreateUser', (user, password) => {
cy.clearCookies()
cy.visit('/')
cy.request({
method: 'POST',
url: `${Cypress.env('baseUrl')}/ocs/v1.php/cloud/users?format=json`,
Expand All @@ -78,6 +75,7 @@ Cypress.Commands.add('nextcloudCreateUser', (user, password) => {
Authorization: `Basic ${Buffer.from('admin:admin').toString('base64')}`,
},
})
cy.clearCookies()
})

Cypress.Commands.add('uploadTestMedia', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/Album/AlbumMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public function getSharedAlbumsForCollaboratorWithFiles(string $collaboratorId,
// Suffix album name with the album owner to prevent duplicates.
// Not done for public link as it would like owner's uid.
if ($collaboratorType !== self::TYPE_LINK) {
$row['album_name'].' ('.$row['album_user'].')';
$albumName = $row['album_name'].' ('.$row['album_user'].')';
}
$albumsById[$albumId] = new AlbumInfo($albumId, $row['album_user'], $albumName, $row['location'], (int)$row['created'], (int)$row['last_added_photo']);
}
Expand Down