*/
import path from "path"
+import type { User } from "@nextcloud/cypress"
-export function uploadThreeVersions(user) {
+export function uploadThreeVersions(user: User, fileName: string) {
// A new version will not be created if the changes occur
// within less than one second of each other.
// eslint-disable-next-line cypress/no-unnecessary-waiting
- cy.uploadContent(user, new Blob(['v1'], { type: 'text/plain' }), 'text/plain', '/test.txt')
- .wait(10000)
- .uploadContent(user, new Blob(['v2'], { type: 'text/plain' }), 'text/plain', '/test.txt')
- .wait(10000)
- .uploadContent(user, new Blob(['v3'], { type: 'text/plain' }), 'text/plain', '/test.txt')
+ cy.uploadContent(user, new Blob(['v1'], { type: 'text/plain' }), 'text/plain', `/${fileName}`)
+ .wait(1100)
+ .uploadContent(user, new Blob(['v2'], { type: 'text/plain' }), 'text/plain', `/${fileName}`)
+ .wait(1100)
+ .uploadContent(user, new Blob(['v3'], { type: 'text/plain' }), 'text/plain', `/${fileName}`)
cy.login(user)
}
cy.get(':focused').type(`${name}{enter}`)
}
-export function assertVersionContent(index: number, expectedContent: string) {
+export function assertVersionContent(filename: string, index: number, expectedContent: string) {
const downloadsFolder = Cypress.config('downloadsFolder')
openVersionMenu(index)
clickPopperAction('Download version')
- return cy.readFile(path.join(downloadsFolder, 'test.txt'))
+ return cy.readFile(path.join(downloadsFolder, filename))
.then((versionContent) => expect(versionContent).to.equal(expectedContent))
- .then(() => cy.exec(`rm ${downloadsFolder}/test.txt`))
+ .then(() => cy.exec(`rm ${downloadsFolder}/${filename}`))
}
\ No newline at end of file
import { openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
describe('Versions creation', () => {
+ let randomFileName = ''
+
before(() => {
+ randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
+
cy.createRandomUser()
.then((user) => {
- uploadThreeVersions(user)
+ uploadThreeVersions(user, randomFileName)
cy.login(user)
cy.visit('/apps/files')
- openVersionsPanel('test.txt')
+ openVersionsPanel(randomFileName)
})
})
it('Opens the versions panel and sees the versions', () => {
- openVersionsPanel('test.txt')
+ openVersionsPanel(randomFileName)
cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').should('have.length', 3)
import { assertVersionContent, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
describe('Versions download', () => {
+ let randomFileName = ''
+
before(() => {
+ randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
+
cy.createRandomUser()
.then((user) => {
- uploadThreeVersions(user)
+ uploadThreeVersions(user, randomFileName)
cy.login(user)
cy.visit('/apps/files')
- openVersionsPanel('test.txt')
+ openVersionsPanel(randomFileName)
})
})
it('Download versions and assert there content', () => {
- assertVersionContent(0, 'v3')
- assertVersionContent(1, 'v2')
- assertVersionContent(2, 'v1')
+ assertVersionContent(randomFileName, 0, 'v3')
+ assertVersionContent(randomFileName, 1, 'v2')
+ assertVersionContent(randomFileName, 2, 'v1')
})
})
import { assertVersionContent, nameVersion, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
describe('Versions expiration', () => {
+ let randomFileName = ''
+
beforeEach(() => {
+ randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
+
cy.createRandomUser()
.then((user) => {
- uploadThreeVersions(user)
+ uploadThreeVersions(user, randomFileName)
cy.login(user)
cy.visit('/apps/files')
- openVersionsPanel('test.txt')
+ openVersionsPanel(randomFileName)
})
})
it('Expire all versions', () => {
cy.runOccCommand('versions:expire')
cy.visit('/apps/files')
- openVersionsPanel('test.txt')
+ openVersionsPanel(randomFileName)
cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').should('have.length', 1)
cy.get('[data-files-versions-version]').eq(0).contains('Current version')
})
- assertVersionContent(0, 'v3')
+ assertVersionContent(randomFileName, 0, 'v3')
})
it('Expire versions v2', () => {
cy.runOccCommand('versions:expire')
cy.visit('/apps/files')
- openVersionsPanel('test.txt')
+ openVersionsPanel(randomFileName)
cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').should('have.length', 2)
cy.get('[data-files-versions-version]').eq(1).contains('v1')
})
- assertVersionContent(0, 'v3')
- assertVersionContent(1, 'v1')
+ assertVersionContent(randomFileName, 0, 'v3')
+ assertVersionContent(randomFileName, 1, 'v1')
})
})
import { nameVersion, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
describe('Versions naming', () => {
+ let randomFileName = ''
+
before(() => {
+ randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
+
cy.createRandomUser()
.then((user) => {
- uploadThreeVersions(user)
+ uploadThreeVersions(user, randomFileName)
cy.login(user)
cy.visit('/apps/files')
- openVersionsPanel('test.txt')
+ openVersionsPanel(randomFileName)
})
})
}
describe('Versions restoration', () => {
+ let randomFileName = ''
+
before(() => {
+ randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
+
cy.createRandomUser()
.then((user) => {
- uploadThreeVersions(user)
+ uploadThreeVersions(user, randomFileName)
cy.login(user)
cy.visit('/apps/files')
- openVersionsPanel('test.txt')
+ openVersionsPanel(randomFileName)
})
})
})
it('Downloads versions and assert there content', () => {
- assertVersionContent(0, 'v1')
- assertVersionContent(1, 'v3')
- assertVersionContent(2, 'v2')
+ assertVersionContent(randomFileName, 0, 'v1')
+ assertVersionContent(randomFileName, 1, 'v3')
+ assertVersionContent(randomFileName, 2, 'v2')
})
})