Skip to content

Commit a84d082

Browse files
author
Vinicius Reis
authored
Merge pull request #2762 from nextcloud/2735-bitva11y-currently-keyboard-accessible-using-keyboard-shortcuts-common-in-text-editors-however-there-is-a-wai-aria-best-practice
[a11y] add aria-keyshortcuts
2 parents 6b6af3c + c600ec4 commit a84d082

20 files changed

+178
-44
lines changed

cypress/e2e/shortcuts.spec.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* @copyright Copyright (c) 2022 Vinicius Reis <vinicius@nextcloud.com>
3+
*
4+
* @author Vinicius Reis <vinicius@nextcloud.com>
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+
})

js/editor-rich.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/editor-rich.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/editor.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/editor.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/files-modal.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/files-modal.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-files.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-files.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-public.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)