diff options
-rw-r--r-- | cypress/e2e/share.spec.js | 13 | ||||
-rw-r--r-- | cypress/support/commands.js | 17 | ||||
-rw-r--r-- | src/components/ViewerComponent.vue | 4 | ||||
-rw-r--r-- | src/helpers/files.js | 5 | ||||
-rw-r--r-- | src/helpers/token.js | 5 |
5 files changed, 29 insertions, 15 deletions
diff --git a/cypress/e2e/share.spec.js b/cypress/e2e/share.spec.js index e8a8aefcf..9493f9f56 100644 --- a/cypress/e2e/share.spec.js +++ b/cypress/e2e/share.spec.js @@ -99,15 +99,16 @@ describe('Open test.md in viewer', function() { cy.shareFile('/folder') .then((token) => { cy.logout() - cy.visit(`/s/${token}`) + + return cy.visit(`/s/${token}`) }) .then(() => { - cy.get('#rich-workspace').should('contain', 'Hello world') + cy.get('#rich-workspace').getContent().should('contain', 'Hello world') cy.openFile('test.md') - cy.get('#editor-container').should('be.visible') - cy.get('#editor .ProseMirror').should('contain', 'Hello world') - cy.get('#editor .ProseMirror h2').should('contain', 'Hello world') - cy.get('.modal-header button.header-close').click() + cy.getModal().getContent().should('be.visible') + cy.getModal().getContent().should('contain', 'Hello world') + cy.getModal().getContent().find('h2').should('contain', 'Hello world') + cy.getModal().find('.modal-header button.header-close').click() cy.get('.modal-mask').should('not.exist') }) }) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 889745737..576d44289 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -264,8 +264,14 @@ Cypress.Commands.add('deleteFile', fileName => { cy.get(`.files-fileList tr[data-file="${fileName}"]`).should('not.exist') }) -Cypress.Commands.add('getEditor', () => { - return cy.get('[data-text-el="editor-container"]') +Cypress.Commands.add('getModal', () => { + return cy.get('#viewer[data-handler="text"]') +}) + +Cypress.Commands.add('getEditor', { prevSubject: 'optional' }, (subject) => { + return subject + ? cy.wrap(subject).find('[data-text-el="editor-container"]') + : cy.get('[data-text-el="editor-container"]') }) Cypress.Commands.add('getMenu', { prevSubject: 'optional' }, (subject) => { @@ -278,8 +284,9 @@ Cypress.Commands.add('getActionEntry', { prevSubject: 'optional' }, (subject, na .find(`[data-text-action-entry="${name}"]`) }) -Cypress.Commands.add('getContent', () => { - return cy.getEditor().find('.ProseMirror') +Cypress.Commands.add('getContent', { prevSubject: 'optional' }, (subject) => { + return (subject ? cy.wrap(subject) : cy.getEditor()) + .find('.ProseMirror') }) Cypress.Commands.add('getOutline', () => { @@ -296,7 +303,7 @@ Cypress.Commands.add('clearContent', () => { .type('{selectAll}{backspace}', { force: true }) }) -Cypress.Commands.add('openWorkspace', (subject, name) => { +Cypress.Commands.add('openWorkspace', () => { cy.get('#rich-workspace .empty-workspace').click() cy.getEditor().find('[data-text-el="editor-content-wrapper"]').click() diff --git a/src/components/ViewerComponent.vue b/src/components/ViewerComponent.vue index bb9a21db4..fcc56ffca 100644 --- a/src/components/ViewerComponent.vue +++ b/src/components/ViewerComponent.vue @@ -30,6 +30,8 @@ </template> <script> +import { getSharingToken } from '../helpers/token.js' + export default { name: 'ViewerComponent', components: { @@ -54,7 +56,7 @@ export default { }, shareToken: { type: String, - default: null, + default: () => getSharingToken(), }, mime: { type: String, diff --git a/src/helpers/files.js b/src/helpers/files.js index 5a841c458..138053528 100644 --- a/src/helpers/files.js +++ b/src/helpers/files.js @@ -22,6 +22,7 @@ import { loadState } from '@nextcloud/initial-state' import { openMimetypes } from './mime.js' +import { getSharingToken } from './token.js' import RichWorkspace from '../views/RichWorkspace.vue' import { imagePath } from '@nextcloud/router' import store from '../store/index.js' @@ -77,9 +78,8 @@ const registerFileCreate = () => { } const registerFileActionFallback = () => { - const sharingToken = document.getElementById('sharingToken') ? document.getElementById('sharingToken').value : null + const sharingToken = getSharingToken() const filesTable = document.querySelector('#preview table.files-filestable') - if (!sharingToken || !filesTable) { const ViewerRoot = document.createElement('div') ViewerRoot.id = 'text-viewer-fallback' @@ -135,7 +135,6 @@ const registerFileActionFallback = () => { } const FilesWorkspacePlugin = { - el: null, attach(fileList) { diff --git a/src/helpers/token.js b/src/helpers/token.js new file mode 100644 index 000000000..655e965b8 --- /dev/null +++ b/src/helpers/token.js @@ -0,0 +1,5 @@ +const getSharingToken = () => document.getElementById('sharingToken') + ? document.getElementById('sharingToken').value + : null + +export { getSharingToken } |