Skip to content

Commit

Permalink
TODO: 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 <[email protected]>
  • Loading branch information
benthie committed Feb 26, 2024
1 parent d1bb0ae commit 44eeccb
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions cypress/e2e/openreadonly.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
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 () {

describe('Disabled', function() {
const checkMenubar = function() {
cy.get('.text-editor--readonly-bar').should('not.exist')
cy.get('.text-menubar').getActionEntry('done').should('not.exist')
}

beforeEach(function() {
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() {
cy.openFile('test.md')
checkMenubar()
})

it('Test writable text file', function() {
cy.openFile('test.txt')
checkMenubar()
})
})

describe('Enabled', function () {
const requireReadOnlyBar = function () {
cy.get('.text-editor--readonly-bar').should('exist')
cy.get('.text-editor--readonly-bar').getActionEntry('edit').should('exist')
}

const requireMenubar = function () {
cy.get('.text-editor--readonly-bar').should('not.exist')
cy.get('.text-menubar').getActionEntry('done').should('exist')
}

beforeEach(function () {
cy.login(admin)
cy.ocsRequest({
method: 'POST',
url: `http://localhost/ocs/v2.php/apps/testing/api/v1/app/text/open_read_only`,
body: { value: '1' }
}).then(response => {
cy.log(response.status)
})
cy.logout()

cy.createUser(user)
cy.login(user)
// cy.runOccCommand('config:app:set text open_read_only_enabled --value=1')

// const requestData = {
// method: 'POST',
// url: 'http://localhost/ocs/v1.php/apps/testing/api/v1/app/text/open_read_only_enabled',
// body: '1'
// }

// cy.request(requestData).then(({ status }) => {
// expect(status).to.eq(200)
// })

// 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 44eeccb

Please sign in to comment.