|
| 1 | +import { selectionChangeDebounceTimeout } from '../../../../src/components/constants'; |
| 2 | + |
| 3 | +describe('BlockTunes', function () { |
| 4 | + describe('Search', () => { |
| 5 | + it('should be focused after popover opened', () => { |
| 6 | + cy.createEditor({ |
| 7 | + data: { |
| 8 | + blocks: [ |
| 9 | + { |
| 10 | + type: 'paragraph', |
| 11 | + data: { |
| 12 | + text: 'Some text', |
| 13 | + }, |
| 14 | + }, |
| 15 | + ], |
| 16 | + }, |
| 17 | + }); |
| 18 | + |
| 19 | + cy.get('[data-cy=editorjs]') |
| 20 | + .find('.ce-paragraph') |
| 21 | + .click() |
| 22 | + .type('{cmd}/') |
| 23 | + .wait(selectionChangeDebounceTimeout); |
| 24 | + |
| 25 | + /** |
| 26 | + * Caret is set to the search input |
| 27 | + */ |
| 28 | + cy.window() |
| 29 | + .then((window) => { |
| 30 | + const selection = window.getSelection(); |
| 31 | + |
| 32 | + expect(selection.rangeCount).to.be.equal(1); |
| 33 | + |
| 34 | + const range = selection.getRangeAt(0); |
| 35 | + |
| 36 | + cy.get('[data-cy=editorjs]') |
| 37 | + .find('[data-cy="block-tunes"] .cdx-search-field') |
| 38 | + .should(($block) => { |
| 39 | + expect($block[0].contains(range.startContainer)).to.be.true; |
| 40 | + }); |
| 41 | + }); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + describe('Keyboard only', function () { |
| 46 | + it('should not delete the currently selected block when Enter pressed on a search input (or any block tune)', function () { |
| 47 | + const ENTER_KEY_CODE = 13; |
| 48 | + |
| 49 | + cy.createEditor({ |
| 50 | + data: { |
| 51 | + blocks: [ |
| 52 | + { |
| 53 | + type: 'paragraph', |
| 54 | + data: { |
| 55 | + text: 'Some text', |
| 56 | + }, |
| 57 | + }, |
| 58 | + ], |
| 59 | + }, |
| 60 | + }); |
| 61 | + |
| 62 | + cy.get('[data-cy=editorjs]') |
| 63 | + .find('.ce-paragraph') |
| 64 | + .click() |
| 65 | + .type('{cmd}/') |
| 66 | + .wait(selectionChangeDebounceTimeout) |
| 67 | + .keydown(ENTER_KEY_CODE); |
| 68 | + |
| 69 | + /** |
| 70 | + * Block should have same text |
| 71 | + */ |
| 72 | + cy.get('[data-cy="block-wrapper"') |
| 73 | + .should('have.text', 'Some text'); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should not unselect currently selected block when Enter pressed on a block tune', function () { |
| 77 | + const ENTER_KEY_CODE = 13; |
| 78 | + |
| 79 | + cy.createEditor({ |
| 80 | + data: { |
| 81 | + blocks: [ |
| 82 | + { |
| 83 | + type: 'paragraph', |
| 84 | + data: { |
| 85 | + text: 'Some text', |
| 86 | + }, |
| 87 | + }, |
| 88 | + ], |
| 89 | + }, |
| 90 | + }); |
| 91 | + |
| 92 | + cy.get('[data-cy=editorjs]') |
| 93 | + .find('.ce-paragraph') |
| 94 | + .click() |
| 95 | + .type('{cmd}/') |
| 96 | + .wait(selectionChangeDebounceTimeout) |
| 97 | + .keydown(ENTER_KEY_CODE); |
| 98 | + |
| 99 | + /** |
| 100 | + * Block should not be selected |
| 101 | + */ |
| 102 | + cy.get('[data-cy="block-wrapper"') |
| 103 | + .first() |
| 104 | + .should('have.class', 'ce-block--selected'); |
| 105 | + }); |
| 106 | + }); |
| 107 | +}); |
0 commit comments