diff options
author | Vinicius Reis <vinicius.reis@nextcloud.com> | 2022-05-24 22:08:35 +0300 |
---|---|---|
committer | Vinicius Reis <vinicius.reis@nextcloud.com> | 2022-05-24 22:08:35 +0300 |
commit | c9ffd507dae4cc8ad9bf7bd4afe5fff43bdb9c44 (patch) | |
tree | 8f76fe6365a00b8b8447d3f1e341a64bbf57ae03 /cypress | |
parent | 7785ee96ecf690fd5af57643c85bc8e991c77a9d (diff) |
✅ (#2345): fix workspace tests
Signed-off-by: Vinicius Reis <vinicius.reis@nextcloud.com>
Diffstat (limited to 'cypress')
-rw-r--r-- | cypress/integration/workspace.spec.js | 188 | ||||
-rw-r--r-- | cypress/support/commands.js | 7 |
2 files changed, 100 insertions, 95 deletions
diff --git a/cypress/integration/workspace.spec.js b/cypress/integration/workspace.spec.js index f103a0b52..072c2912d 100644 --- a/cypress/integration/workspace.spec.js +++ b/cypress/integration/workspace.spec.js @@ -20,7 +20,7 @@ * */ -import { randHash } from '../utils/' +import { randHash } from '../utils/index.js' const randUser = randHash() describe('Workspace', function() { @@ -38,7 +38,7 @@ describe('Workspace', function() { it('adds a Readme.md', function() { cy.get('#fileList').should('not.contain', 'Readme.md') - openWorkspace() + cy.openWorkspace() .type('Hello') .should('contain', 'Hello') openSidebar('Readme.md') @@ -49,7 +49,7 @@ describe('Workspace', function() { }) it('formats text', function() { - openWorkspace() + cy.openWorkspace() .type('Format me') .type('{selectall}') ;[ @@ -69,7 +69,7 @@ describe('Workspace', function() { }) it('links via menububble', function() { - openWorkspace() + cy.openWorkspace() .type('Nextcloud') .type('{selectall}') menuBubbleButton('add-link').click() @@ -92,12 +92,7 @@ describe('Workspace', function() { }) it('creates headings via submenu', function() { - const getSubmenuItem = (parent, item) => { - menuButton(parent).click() - return submenuButton(item) - } - - openWorkspace() + cy.openWorkspace() .type('Heading') .type('{selectall}') ;['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].forEach((heading) => { @@ -117,13 +112,13 @@ describe('Workspace', function() { }) it('creates lists', function() { - openWorkspace() + cy.openWorkspace() .type('List me') .type('{selectall}') ;[ - ['ul', 'ul'], - ['ol', 'ol'], - ['tasklist', 'ul[data-type="taskList"]'], + ['unordered-list', 'ul'], + ['ordered-list', 'ol'], + ['task-list', 'ul[data-type="taskList"]'], ].forEach(([button, tag]) => { menuButton(button) .click({ force: true }) @@ -145,99 +140,108 @@ describe('Workspace', function() { .should('contain', 'Hello world') }) - it('takes localized file name into account', function() { - cy.nextcloudUpdateUser(randUser, 'password', 'language', 'de_DE') - cy.uploadFile('test.md', 'text/markdown', `${Cypress.currentTest.title}/Anleitung.md`) - cy.reload() - cy.get('#fileList').should('contain', 'Anleitung.md') - cy.get('#rich-workspace .ProseMirror') - .should('contain', 'Hello world') - }) + it('inserts and removes a table', function() { + cy.openWorkspace() + .type('Let\'s insert a Table') - it('ignores localized file name in other language', function() { - cy.nextcloudUpdateUser(randUser, 'password', 'language', 'fr') - cy.uploadFile('test.md', 'text/markdown', `${Cypress.currentTest.title}/Anleitung.md`) - cy.reload() - cy.get('#fileList').should('contain', 'Anleitung.md') - cy.get('.empty-workspace').should('contain', 'Ajoutez des notes, listes ou liens') + toggleMoreActions() + submenuButton('table') + .click() + + cy.get('.ProseMirror').type('content') + cy.get('.ProseMirror table tr:first-child th:first-child') + .should('contain', 'content') + cy.get('.ProseMirror [data-text-table-actions="settings"]').click() + + cy.get('[data-text-table-action="delete"]').click() + cy.get('.ProseMirror') + .should('not.contain', 'content') }) describe('callouts', () => { const types = ['info', 'warn', 'error', 'success'] - it('create callouts', () => { - const workspace = openWorkspace() - workspace.type('Callout') - types.forEach(type => { - // enable callout - menuButton('info').click({ force: true }) - submenuButton(type).click({ force: true }) - - // check if is active - menuButton(type).should('have.class', 'is-active') + before(function() { + cy.nextcloudCreateUser(randUser, 'password') + }) - // check content - cy.get(`.ProseMirror .callout.callout-${type}`) - .should('contain', 'Callout') + beforeEach(function() { + cy.login(randUser, 'password') + // isolate tests - each happens in it's own folder + cy.createFolder(Cypress.currentTest.title) + cy.visit(`apps/files?dir=/${encodeURIComponent(Cypress.currentTest.title)}`) + cy.openWorkspace().type('Callout') + }) + // eslint-disable-next-line cypress/no-async-tests + it('create callout', () => { + cy.wrap(types).each((type) => { + cy.log(`creating ${type} callout`) - // disable - menuButton(type).click({ force: true }) - submenuButton(type).click({ force: true }) + const actionName = `callout-${type}` - // check if is inactive - menuButton('info').should('not.have.class', 'is-active') + // enable callout + getSubmenuItem('callouts', actionName) + .click() + .then(() => { + // check content + cy.get(`.ProseMirror .callout.callout-${type}`) + .should('contain', 'Callout') + + // disable + return getSubmenuItem('callouts', actionName) + .should('have.class', 'is-active') + .click() + }) }) }) it('toggle callouts', () => { - const workspace = openWorkspace() - workspace.type('Callout') - const [first, ...rest] = types let last = first // enable callout - menuButton('info').click() - submenuButton(first).click() - - rest.forEach(type => { - // enable callout - menuButton(last).click() - submenuButton(type).click() - - last = type - - // check if is active - menuButton(type).should('have.class', 'is-active') - - // check content - cy.get(`.ProseMirror .callout.callout-${type}`) - .should('contain', 'Callout') - }) - - // disable - menuButton(last).click() - submenuButton(last).click() + getSubmenuItem('callouts', `callout-${first}`) + .click() - // check if is inactive - menuButton('info').should('not.have.class', 'is-active') + cy.wrap(rest) + .each(type => { + const actionName = `callout-${type}` + return getSubmenuItem('callouts', actionName) + .click() + .then(() => cy.get(`.ProseMirror .callout.callout-${type}`)) + .should('contain', 'Callout') + .then(() => { + last = type + }) + }) + .then(() => { + getSubmenuItem('callouts', `callout-${last}`) + .click() + + menuButton('callouts') + .should('not.have.class', 'is-active') + }) }) }) - it('inserts and removes a table', function() { - openWorkspace() - .type('Let\'s insert a Table') - toggleMoreActions() - popoverButton('table') - .click() - cy.get('.ProseMirror').type('content') - cy.get('.ProseMirror table tr:first-child th:first-child') - .should('contain', 'content') - cy.get('.ProseMirror .table-settings').click() - popoverButton('delete').click() - cy.get('.ProseMirror') - .should('not.contain', 'content') + describe('localize', () => { + it('takes localized file name into account', function() { + cy.nextcloudUpdateUser(randUser, 'password', 'language', 'de_DE') + cy.uploadFile('test.md', 'text/markdown', `${Cypress.currentTest.title}/Anleitung.md`) + cy.reload() + cy.get('#fileList').should('contain', 'Anleitung.md') + cy.get('#rich-workspace .ProseMirror') + .should('contain', 'Hello world') + }) + + it('ignores localized file name in other language', function() { + cy.nextcloudUpdateUser(randUser, 'password', 'language', 'fr') + cy.uploadFile('test.md', 'text/markdown', `${Cypress.currentTest.title}/Anleitung.md`) + cy.reload() + cy.get('#fileList').should('contain', 'Anleitung.md') + cy.get('.empty-workspace').should('contain', 'Ajoutez des notes, listes ou liens') + }) }) }) @@ -250,23 +254,17 @@ const submenuButton = (name) => { return cy.get('.popover.open').getActionEntry(name) } -const popoverButton = (name) => { - return cy.get(`.popover button .icon-${name}`) -} - const toggleMoreActions = () => { - cy.get('.menubar .action-item__menutoggle--default-icon').click() + return menuButton('remain').click() } const menuBubbleButton = (name) => { return cy.get('[data-text-el="menu-bubble"]').find(`[data-text-bubble-action="${name}"]`) } -const openWorkspace = () => { - cy.get('#rich-workspace .empty-workspace').click() - cy.getEditor().find('[data-text-el="editor-content-wrapper"]').click() - - return cy.getEditor().find('.ProseMirror') +const getSubmenuItem = (parent, item) => { + menuButton(parent).click() + return submenuButton(item) } const openSidebar = filename => { diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 0b466e4ad..4bfa8149a 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -190,3 +190,10 @@ Cypress.Commands.add('getActionEntry', { prevSubject: 'optional' }, (subject, na return (subject ? cy.wrap(subject) : cy.getMenu()) .find(`[data-text-action-entry="${name}"]`) }) + +Cypress.Commands.add('openWorkspace', (subject, name) => { + cy.get('#rich-workspace .empty-workspace').click() + cy.getEditor().find('[data-text-el="editor-content-wrapper"]').click() + + return cy.getEditor().find('.ProseMirror') +}) |