|
| 1 | +import dd from 'ts-dedent'; |
| 2 | + |
| 3 | +import {expect, test} from 'playwright/core'; |
| 4 | + |
| 5 | +import {Playground} from './Playground.helpers'; |
| 6 | + |
| 7 | +test.describe('Italic', () => { |
| 8 | + test.beforeEach(async ({mount}) => { |
| 9 | + const initialMarkup = dd` |
| 10 | + some text |
| 11 | + `; |
| 12 | + |
| 13 | + await mount(<Playground initial={initialMarkup} />); |
| 14 | + }); |
| 15 | + |
| 16 | + test.describe('mark', () => { |
| 17 | + test('should mark via toolbar @wysiwyg', async ({editor, wait}) => { |
| 18 | + await editor.switchMode('wysiwyg'); |
| 19 | + await editor.assertToolbarButtonNotSelected('Italic'); |
| 20 | + |
| 21 | + await editor.focus(); |
| 22 | + await editor.press('ArrowDown'); |
| 23 | + await editor.press('Enter'); |
| 24 | + |
| 25 | + await editor.clickToolbarButton('Italic'); |
| 26 | + await wait.timeout(); |
| 27 | + |
| 28 | + await editor.pressSequentially('next'); |
| 29 | + await editor.assertToolbarButtonSelected('Italic'); |
| 30 | + |
| 31 | + await editor.press('ArrowUp'); |
| 32 | + await editor.assertToolbarButtonNotSelected('Italic'); |
| 33 | + }); |
| 34 | + |
| 35 | + test('should mark via input rule @wysiwyg', async ({editor, wait}) => { |
| 36 | + await editor.switchMode('wysiwyg'); |
| 37 | + await editor.assertToolbarButtonNotSelected('Italic'); |
| 38 | + |
| 39 | + await editor.focus(); |
| 40 | + await editor.press('ArrowDown'); |
| 41 | + await editor.press('Enter'); |
| 42 | + |
| 43 | + await editor.inputRule('*next*'); |
| 44 | + await wait.timeout(); |
| 45 | + await editor.press('ArrowLeft'); |
| 46 | + |
| 47 | + await editor.assertToolbarButtonSelected('Italic'); |
| 48 | + |
| 49 | + await editor.press('ArrowUp'); |
| 50 | + await editor.assertToolbarButtonNotSelected('Italic'); |
| 51 | + }); |
| 52 | + |
| 53 | + // key combo fails in headless mode |
| 54 | + test.skip('should mark via keyboard shortcut @wysiwyg', async ({editor, wait}) => { |
| 55 | + await editor.switchMode('wysiwyg'); |
| 56 | + await editor.assertToolbarButtonNotSelected('Italic'); |
| 57 | + |
| 58 | + await editor.focus(); |
| 59 | + await editor.press('ArrowDown'); |
| 60 | + await editor.press('Enter'); |
| 61 | + |
| 62 | + await editor.press('Control+I'); |
| 63 | + await wait.timeout(); |
| 64 | + |
| 65 | + await editor.pressSequentially('next'); |
| 66 | + await wait.timeout(); |
| 67 | + |
| 68 | + await editor.assertToolbarButtonSelected('Italic'); |
| 69 | + |
| 70 | + await editor.press('ArrowUp'); |
| 71 | + await editor.assertToolbarButtonNotSelected('Italic'); |
| 72 | + }); |
| 73 | + |
| 74 | + test('should mark via toolbar @markup', async ({editor, wait}) => { |
| 75 | + await editor.switchMode('markup'); |
| 76 | + |
| 77 | + await editor.focus(); |
| 78 | + await editor.press('ArrowDown'); |
| 79 | + await editor.press('Enter'); |
| 80 | + |
| 81 | + await editor.clickToolbarButton('Italic'); |
| 82 | + await wait.timeout(); |
| 83 | + await editor.pressSequentially('next'); |
| 84 | + |
| 85 | + await expect(editor.getByTextInContenteditable('_next_')).toBeVisible(); |
| 86 | + }); |
| 87 | + }); |
| 88 | + |
| 89 | + test.describe('mode switch', () => { |
| 90 | + test('should remain after mode switch @wysiwyg @markup', async ({editor, wait}) => { |
| 91 | + await editor.clearContent(); |
| 92 | + |
| 93 | + const markup = 'some text\n*next*'; |
| 94 | + await editor.switchMode('markup'); |
| 95 | + await editor.fill(markup); |
| 96 | + await wait.timeout(); |
| 97 | + |
| 98 | + await editor.switchMode('wysiwyg'); |
| 99 | + |
| 100 | + await editor.focus(); |
| 101 | + await editor.press('ArrowDown'); |
| 102 | + await wait.timeout(); |
| 103 | + |
| 104 | + await editor.assertToolbarButtonSelected('Italic'); |
| 105 | + |
| 106 | + await editor.press('ArrowUp'); |
| 107 | + await editor.assertToolbarButtonNotSelected('Italic'); |
| 108 | + |
| 109 | + await editor.switchMode('markup'); |
| 110 | + }); |
| 111 | + }); |
| 112 | + |
| 113 | + test.describe('interaction', () => { |
| 114 | + test('should add mark to selected text via toolbar @wysiwyg', async ({editor, wait}) => { |
| 115 | + await editor.switchMode('wysiwyg'); |
| 116 | + await editor.assertToolbarButtonNotSelected('Italic'); |
| 117 | + |
| 118 | + await editor.focus(); |
| 119 | + await editor.press('ArrowDown'); |
| 120 | + await editor.press('Enter'); |
| 121 | + |
| 122 | + await editor.pressSequentially('next'); |
| 123 | + await wait.timeout(); |
| 124 | + |
| 125 | + await editor.selectTextIn('p:nth-child(2)'); |
| 126 | + |
| 127 | + await editor.assertToolbarButtonNotSelected('Italic'); |
| 128 | + await editor.clickToolbarButton('Italic'); |
| 129 | + await wait.timeout(300); |
| 130 | + |
| 131 | + await editor.assertToolbarButtonSelected('Italic'); |
| 132 | + await editor.press('ArrowUp'); |
| 133 | + await wait.timeout(); |
| 134 | + |
| 135 | + await editor.assertToolbarButtonNotSelected('Italic'); |
| 136 | + }); |
| 137 | + |
| 138 | + test('should add mark to selected text via context toolbar @wysiwyg', async ({ |
| 139 | + editor, |
| 140 | + wait, |
| 141 | + }) => { |
| 142 | + await editor.switchMode('wysiwyg'); |
| 143 | + await editor.assertToolbarButtonNotSelected('Italic'); |
| 144 | + |
| 145 | + await editor.focus(); |
| 146 | + await editor.press('ArrowDown'); |
| 147 | + await editor.press('Enter'); |
| 148 | + |
| 149 | + await editor.pressSequentially('next'); |
| 150 | + await wait.timeout(); |
| 151 | + |
| 152 | + await editor.selectTextIn('p:nth-child(2)'); |
| 153 | + |
| 154 | + await editor.assertToolbarButtonNotSelected('Italic'); |
| 155 | + await editor.assertToolbarButtonNotSelected('Italic', true); |
| 156 | + await editor.clickToolbarButton('Italic', true); |
| 157 | + await wait.timeout(300); |
| 158 | + |
| 159 | + await editor.assertToolbarButtonSelected('Italic'); |
| 160 | + await editor.press('ArrowUp'); |
| 161 | + |
| 162 | + await editor.assertToolbarButtonNotSelected('Italic'); |
| 163 | + }); |
| 164 | + |
| 165 | + test('should delete mark to selected text via toolbar @wysiwyg', async ({editor, wait}) => { |
| 166 | + await editor.switchMode('wysiwyg'); |
| 167 | + |
| 168 | + await editor.focus(); |
| 169 | + await editor.press('ArrowDown'); |
| 170 | + await editor.press('Enter'); |
| 171 | + |
| 172 | + await editor.inputRule('*next*'); |
| 173 | + await wait.timeout(); |
| 174 | + |
| 175 | + await editor.selectTextIn('p:nth-child(2)'); |
| 176 | + await editor.assertToolbarButtonSelected('Italic'); |
| 177 | + |
| 178 | + await editor.clickToolbarButton('Italic'); |
| 179 | + await wait.timeout(); |
| 180 | + await editor.assertToolbarButtonNotSelected('Italic'); |
| 181 | + }); |
| 182 | + }); |
| 183 | +}); |
0 commit comments