|
| 1 | +/** |
| 2 | + * @copyright Copyright (c) 2021 Azul <azul@riseup.net> |
| 3 | + * |
| 4 | + * @author Azul <azul@riseup.net> |
| 5 | + * |
| 6 | + * @license GNU AGPL version 3 or any later version |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Affero General Public License as |
| 10 | + * published by the Free Software Foundation, either version 3 of the |
| 11 | + * License, or (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU Affero General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Affero General Public License |
| 19 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | + |
| 24 | +import { randHash } from '../utils/' |
| 25 | +const randUser = randHash() |
| 26 | + |
| 27 | +describe('Workspace', function() { |
| 28 | + |
| 29 | + before(function() { |
| 30 | + cy.nextcloudCreateUser(randUser, 'password') |
| 31 | + }) |
| 32 | + |
| 33 | + beforeEach(function() { |
| 34 | + cy.login(randUser, 'password') |
| 35 | + cy.visit('/apps/files') |
| 36 | + // isolate tests - each happens in it's own folder |
| 37 | + cy.createFolder(Cypress.currentTest.title) |
| 38 | + cy.openFile(Cypress.currentTest.title) |
| 39 | + }) |
| 40 | + |
| 41 | + it('adds a Readme.md', function() { |
| 42 | + cy.get('#fileList').should('not.contain', 'Readme.md') |
| 43 | + openWorkspace() |
| 44 | + .type('Hello') |
| 45 | + .should('contain', 'Hello') |
| 46 | + cy.get('#fileList').should('contain', 'Readme.md') |
| 47 | + }) |
| 48 | + |
| 49 | + it('formats text', function() { |
| 50 | + openWorkspace() |
| 51 | + .type('Format me') |
| 52 | + .type('{selectall}') |
| 53 | + ;[['bold', 'strong'], ['italic', 'em'], ['strike', 's']] |
| 54 | + .forEach(([button, tag]) => { |
| 55 | + menuButton(button) |
| 56 | + .click() |
| 57 | + .should('have.class', 'is-active') |
| 58 | + cy.get(`.ProseMirror ${tag}`).should('contain', 'Format me') |
| 59 | + menuButton(button) |
| 60 | + .click() |
| 61 | + .should('not.have.class', 'is-active') |
| 62 | + }) |
| 63 | + }) |
| 64 | + |
| 65 | + it('links via menububble', function() { |
| 66 | + openWorkspace() |
| 67 | + .type('Nextcloud') |
| 68 | + .type('{selectall}') |
| 69 | + menuBubbleButton('link').click() |
| 70 | + cy.get('.menububble input').type('https://nextcloud.com{enter}') |
| 71 | + cy.get('.ProseMirror a') |
| 72 | + .should('contain', 'Nextcloud') |
| 73 | + .should('be.visible') |
| 74 | + cy.get('.ProseMirror a').invoke('attr', 'href') |
| 75 | + .should('include', 'https://nextcloud.com') |
| 76 | + cy.window().then((win) => { |
| 77 | + cy.stub(win, 'open').as('windowOpen') |
| 78 | + }) |
| 79 | + cy.get('.ProseMirror a').click() |
| 80 | + cy.get('@windowOpen').should('be.calledWith', 'https://nextcloud.com/') |
| 81 | + cy.get('.ProseMirror').type('{selectall}') |
| 82 | + menuBubbleButton('link').click() |
| 83 | + cy.get('.menububble input').type('/team{enter}') |
| 84 | + cy.get('.ProseMirror a').click() |
| 85 | + cy.get('@windowOpen').should('be.calledWith', 'https://nextcloud.com/team') |
| 86 | + }) |
| 87 | + |
| 88 | + it('creates headings via submenu', function() { |
| 89 | + openWorkspace() |
| 90 | + .type('Heading') |
| 91 | + .type('{selectall}') |
| 92 | + ;['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].forEach((heading) => { |
| 93 | + menuButton('h1').click() |
| 94 | + submenuButton(heading).click() |
| 95 | + menuButton(heading).should('have.class', 'is-active') |
| 96 | + cy.get(`.ProseMirror ${heading}`) |
| 97 | + .should('contain', 'Heading') |
| 98 | + menuButton(heading).click() |
| 99 | + submenuButton(heading).click() |
| 100 | + menuButton('h1').should('not.have.class', 'is-active') |
| 101 | + }) |
| 102 | + }) |
| 103 | + |
| 104 | +}) |
| 105 | + |
| 106 | +const menuButton = (name) => { |
| 107 | + return cy.get(`#editor button.icon-${name}`) |
| 108 | +} |
| 109 | + |
| 110 | +const submenuButton = (name) => { |
| 111 | + return cy.get(`#editor button .icon-${name}`) |
| 112 | +} |
| 113 | + |
| 114 | +const menuBubbleButton = submenuButton |
| 115 | + |
| 116 | +const openWorkspace = () => { |
| 117 | + cy.get('#rich-workspace').click() |
| 118 | + cy.get('#editor .content-wrapper').click() |
| 119 | + return cy.get('#rich-workspace .ProseMirror') |
| 120 | +} |
0 commit comments