Skip to content

Commit

Permalink
cypress: e2e: Add test for open read-only mode
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Thiemann <benjamin.thiemann@optonic.com>
  • Loading branch information
benthie committed Feb 26, 2024
1 parent d1bb0ae commit 77259a8
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions cypress/e2e/openreadonly.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { User } from '@nextcloud/cypress'
import { randUser } from '../utils/index.js'

const admin = new User('admin', 'admin')
const user = randUser()

describe('Open read-only mode', function () {

Check failure on line 7 in cypress/e2e/openreadonly.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected space before function parentheses

const setReadOnlyMode = function (mode) {

Check failure on line 9 in cypress/e2e/openreadonly.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected space before function parentheses
cy.login(admin)
cy.ocsRequest({
method: 'POST',
url: 'http://localhost/ocs/v2.php/apps/testing/api/v1/app/text/open_read_only_enabled',
body: { value: mode }

Check warning on line 14 in cypress/e2e/openreadonly.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

Missing trailing comma
}).then(response => {
cy.log(response.status)
})
cy.logout()
}

describe('Disabled', function () {

Check failure on line 21 in cypress/e2e/openreadonly.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected space before function parentheses
const checkMenubar = function () {

Check failure on line 22 in cypress/e2e/openreadonly.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected space before function parentheses
cy.get('.text-editor--readonly-bar').should('not.exist')
cy.get('.text-menubar').getActionEntry('done').should('not.exist')
}

beforeEach(function () {

Check failure on line 27 in cypress/e2e/openreadonly.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected space before function parentheses
setReadOnlyMode(0)

cy.createUser(user)
cy.login(user)

cy.uploadFile('test.md', 'text/markdown')
cy.uploadFile('test.md', 'text/markdown', 'test.txt')

cy.visit('/apps/files')
})

it('Test writable markdown file', function () {

Check failure on line 39 in cypress/e2e/openreadonly.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected space before function parentheses
cy.openFile('test.md')
checkMenubar()
})

it('Test writable text file', function () {

Check failure on line 44 in cypress/e2e/openreadonly.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected space before function parentheses
cy.openFile('test.txt')
checkMenubar()
})
})

describe('Enabled', function () {

Check failure on line 50 in cypress/e2e/openreadonly.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected space before function parentheses
const requireReadOnlyBar = function () {

Check failure on line 51 in cypress/e2e/openreadonly.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected space before function parentheses
cy.get('.text-editor--readonly-bar').should('exist')
cy.get('.text-editor--readonly-bar').getActionEntry('edit').should('exist')
}

const requireMenubar = function () {

Check failure on line 56 in cypress/e2e/openreadonly.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected space before function parentheses
cy.get('.text-editor--readonly-bar').should('not.exist')
cy.get('.text-menubar').getActionEntry('done').should('exist')
}

beforeEach(function () {
setReadOnlyMode(1)

cy.createUser(user)
cy.login(user)

cy.removeFile('test.md')
cy.removeFile('test.txt')

cy.uploadFile('test.md', 'text/markdown')
cy.uploadFile('test.md', 'text/plain', 'test.txt')

cy.visit('/apps/files')
})

it('Test read-only markdown file', function () {
cy.openFile('test.md')

requireReadOnlyBar()

// Switch to edit-mode
cy.get('.text-editor--readonly-bar').getActionEntry('edit').click()

requireMenubar()

// Switch to read-only mode
cy.get('.text-menubar').getActionEntry('done').click()

requireReadOnlyBar()
})

it('Test read-only text file', function () {
cy.openFile('test.txt')

requireReadOnlyBar()

// Switch to edit-mode
cy.get('.text-editor--readonly-bar').getActionEntry('edit').click()

// Check that read-only bar does not exist
cy.get('.text-editor--readonly-bar').should('not.exist')
})
})
})

0 comments on commit 77259a8

Please sign in to comment.