|
1 | | - |
2 | 1 | import Header from '@editorjs/header'; |
3 | | -import type { MenuConfig } from '../../../../types/tools'; |
| 2 | +import type { InlineTool, MenuConfig } from '../../../../types/tools'; |
| 3 | +import { createEditorWithTextBlocks } from '../../support/utils/createEditorWithTextBlocks'; |
4 | 4 |
|
5 | 5 | describe('Inline Toolbar', () => { |
6 | 6 | describe('Separators', () => { |
@@ -174,4 +174,58 @@ describe('Inline Toolbar', () => { |
174 | 174 | .should('have.attr', 'data-item-name', 'test-tool'); |
175 | 175 | }); |
176 | 176 | }); |
| 177 | + |
| 178 | + describe('Shortcuts', () => { |
| 179 | + it('should work in read-only mode', () => { |
| 180 | + const toolSurround = cy.stub().as('toolSurround'); |
| 181 | + |
| 182 | + /* eslint-disable jsdoc/require-jsdoc */ |
| 183 | + class Marker implements InlineTool { |
| 184 | + public static isInline = true; |
| 185 | + public static shortcut = 'CMD+SHIFT+M'; |
| 186 | + public static isReadOnlySupported = true; |
| 187 | + public render(): MenuConfig { |
| 188 | + return { |
| 189 | + icon: 'm', |
| 190 | + title: 'Marker', |
| 191 | + onActivate: () => { |
| 192 | + toolSurround(); |
| 193 | + }, |
| 194 | + }; |
| 195 | + } |
| 196 | + } |
| 197 | + /* eslint-enable jsdoc/require-jsdoc */ |
| 198 | + |
| 199 | + createEditorWithTextBlocks([ |
| 200 | + 'some text', |
| 201 | + ], { |
| 202 | + tools: { |
| 203 | + marker: Marker, |
| 204 | + }, |
| 205 | + readOnly: true, |
| 206 | + }); |
| 207 | + |
| 208 | + cy.get('[data-cy=editorjs]') |
| 209 | + .find('.ce-paragraph') |
| 210 | + .selectText('text'); |
| 211 | + |
| 212 | + cy.wait(300); |
| 213 | + |
| 214 | + cy.document().then((doc) => { |
| 215 | + doc.dispatchEvent(new KeyboardEvent('keydown', { |
| 216 | + bubbles: true, |
| 217 | + cancelable: true, |
| 218 | + key: 'M', |
| 219 | + code: 'KeyM', |
| 220 | + keyCode: 77, |
| 221 | + which: 77, |
| 222 | + metaKey: true, |
| 223 | + shiftKey: true, |
| 224 | + })); |
| 225 | + }); |
| 226 | + |
| 227 | + cy.get('@toolSurround').should('have.been.called'); |
| 228 | + }); |
| 229 | + }); |
177 | 230 | }); |
| 231 | + |
0 commit comments