|
| 1 | +import React from 'react'; |
| 2 | + |
| 3 | +import {EditableText} from 'frontend'; |
| 4 | +import {renderEntry, useInlineEditingPageObjects} from 'support/pageObjects/inlineEditing'; |
| 5 | + |
| 6 | +import {waitFor} from '@testing-library/react'; |
| 7 | +import '@testing-library/jest-dom/extend-expect'; |
| 8 | + |
| 9 | +describe('inline editing EditableText selection transient state', () => { |
| 10 | + useInlineEditingPageObjects(); |
| 11 | + |
| 12 | + beforeEach(() => { |
| 13 | + Range.prototype.getBoundingClientRect = () => document.body.getBoundingClientRect(); |
| 14 | + Range.prototype.getClientRects = () => []; |
| 15 | + }); |
| 16 | + |
| 17 | + afterEach(() => { |
| 18 | + delete Range.prototype.getBoundingClientRect; |
| 19 | + delete Range.prototype.getClientRects; |
| 20 | + }); |
| 21 | + |
| 22 | + const value = [ |
| 23 | + {type: 'paragraph', children: [{text: 'First paragraph'}]}, |
| 24 | + {type: 'paragraph', children: [{text: 'Second paragraph'}]} |
| 25 | + ]; |
| 26 | + |
| 27 | + it('reports selection covering all blocks', async () => { |
| 28 | + const entry = renderEntry({ |
| 29 | + contentElement: { |
| 30 | + ui: <EditableText value={value} contentElementId={1} selectionRect={true} />, |
| 31 | + typeOptions: {customSelectionRect: true} |
| 32 | + } |
| 33 | + }); |
| 34 | + |
| 35 | + entry.simulateSelectMessage({type: 'contentElement', id: 1, range: [0, 2]}); |
| 36 | + |
| 37 | + await waitFor(() => |
| 38 | + expect(entry.getTransientContentElementState(1)).toMatchObject({ |
| 39 | + editableTextSelectionCoversAllBlocks: true |
| 40 | + }) |
| 41 | + ); |
| 42 | + }); |
| 43 | + |
| 44 | + it('reports selection not covering all blocks', async () => { |
| 45 | + const entry = renderEntry({ |
| 46 | + contentElement: { |
| 47 | + ui: <EditableText value={value} contentElementId={1} selectionRect={true} />, |
| 48 | + typeOptions: {customSelectionRect: true} |
| 49 | + } |
| 50 | + }); |
| 51 | + |
| 52 | + entry.simulateSelectMessage({type: 'contentElement', id: 1, range: [1, 2]}); |
| 53 | + |
| 54 | + await waitFor(() => |
| 55 | + expect(entry.getTransientContentElementState(1)).toMatchObject({ |
| 56 | + editableTextSelectionCoversAllBlocks: false |
| 57 | + }) |
| 58 | + ); |
| 59 | + }); |
| 60 | +}); |
0 commit comments