|
| 1 | +/** |
| 2 | + * @copyright Copyright (c) 2022 Vinicius Reis <[email protected]> |
| 3 | + * |
| 4 | + * @author Vinicius Reis <[email protected]> |
| 5 | + * |
| 6 | + * @license AGPL-3.0-or-later |
| 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 | +import { randHash } from '../utils/index.js' |
| 24 | + |
| 25 | +const randUser = randHash() |
| 26 | + |
| 27 | +const prepareTest = () => { |
| 28 | + return cy.openFile(`${Cypress.currentTest.title}.md`) |
| 29 | + .then(() => { |
| 30 | + return cy.getContent() |
| 31 | + .type(Cypress.currentTest.title) |
| 32 | + .type('{selectall}') |
| 33 | + }) |
| 34 | +} |
| 35 | + |
| 36 | +const applyTest = (shortcut, tag) => { |
| 37 | + cy.getContent() |
| 38 | + .type(shortcut) |
| 39 | + |
| 40 | + return cy.getContent() |
| 41 | + .find(tag) |
| 42 | + .should('contain', Cypress.currentTest.title) |
| 43 | +} |
| 44 | + |
| 45 | +const shortcuts = { |
| 46 | + bold: ['{ctrl}b', 'strong'], |
| 47 | + italic: ['{ctrl}i', 'em'], |
| 48 | + underline: ['{ctrl}u', 'u'], |
| 49 | + strikethrough: ['{ctrl}{shift}x', 's'], |
| 50 | + blockquote: ['{ctrl}{shift}b', 'blockquote'], |
| 51 | + codeblock: ['{ctrl}{alt}c', 'pre'], |
| 52 | + 'ordered-list': ['{ctrl}{shift}7', 'ol'], |
| 53 | + 'unordered-list': ['{ctrl}{shift}8', 'ul'], |
| 54 | + 'task-list': ['{ctrl}{shift}9', 'ul[data-type="taskList"]'], |
| 55 | + ...Array.from({ length: 6 }).reduce((acc, _, index) => { |
| 56 | + const num = index + 1 |
| 57 | + const tag = `h${num}` |
| 58 | + acc[`heading-${tag}`] = [`{ctrl}{shift}${num}`, tag] |
| 59 | + |
| 60 | + return acc |
| 61 | + }, {}), |
| 62 | +} |
| 63 | + |
| 64 | +describe('keyboard shortcuts', () => { |
| 65 | + before(() => { |
| 66 | + cy.nextcloudCreateUser(randUser, 'password') |
| 67 | + }) |
| 68 | + |
| 69 | + beforeEach(() => { |
| 70 | + cy.login(randUser, 'password') |
| 71 | + .then(() => { |
| 72 | + return cy.uploadFile( |
| 73 | + 'empty.md', |
| 74 | + 'text/markdown', |
| 75 | + `${Cypress.currentTest.title}.md` |
| 76 | + ) |
| 77 | + }) |
| 78 | + .then(() => cy.reloadFileList()) |
| 79 | + }) |
| 80 | + |
| 81 | + Object.entries(shortcuts) |
| 82 | + .forEach(([name, [shortcut, tag]]) => { |
| 83 | + it(name, () => { |
| 84 | + prepareTest() |
| 85 | + .then(() => applyTest(shortcut, tag)) |
| 86 | + }) |
| 87 | + }) |
| 88 | + |
| 89 | +}) |
0 commit comments