From 44eeccb253a1742aabf55bd0077cd096e19858ab Mon Sep 17 00:00:00 2001 From: Benjamin Thiemann Date: Tue, 13 Feb 2024 16:10:16 +0100 Subject: [PATCH] TODO: cypress: e2e: Add test for open read-only mode Signed-off-by: Benjamin Thiemann --- cypress/e2e/openreadonly.spec.js | 108 +++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 cypress/e2e/openreadonly.spec.js diff --git a/cypress/e2e/openreadonly.spec.js b/cypress/e2e/openreadonly.spec.js new file mode 100644 index 00000000000..bc6c03c0d7f --- /dev/null +++ b/cypress/e2e/openreadonly.spec.js @@ -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') + }) + }) +})