|
| 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('File', () => { |
| 8 | + test.beforeEach(async ({mount, editor}) => { |
| 9 | + const initialMarkup = dd` |
| 10 | + some text |
| 11 | + `; |
| 12 | + |
| 13 | + await mount(<Playground initial={initialMarkup} width="100%" />); |
| 14 | + await editor.switchMode('wysiwyg'); |
| 15 | + }); |
| 16 | + |
| 17 | + test.describe('insert', () => { |
| 18 | + test('should insert via toolbar @wysiwyg', async ({ |
| 19 | + expectScreenshot, |
| 20 | + actions, |
| 21 | + page, |
| 22 | + editor, |
| 23 | + wait, |
| 24 | + }) => { |
| 25 | + await editor.assertAdditionalToolbarButtonEnabled('File'); |
| 26 | + |
| 27 | + await editor.focus(); |
| 28 | + await editor.press('ArrowDown', 2); |
| 29 | + await editor.press('Enter'); |
| 30 | + |
| 31 | + await editor.clickAdditionalToolbarButton('File'); |
| 32 | + await wait.timeout(); |
| 33 | + |
| 34 | + const addByLinkTab = page.getByText('Add by link').first().locator('..'); |
| 35 | + await wait.visible(addByLinkTab); |
| 36 | + |
| 37 | + await addByLinkTab.click(); |
| 38 | + await wait.timeout(); |
| 39 | + |
| 40 | + await actions.fillFocused(`/assets/test-image.jpg`); |
| 41 | + await actions.pressFocused('Tab'); |
| 42 | + await actions.fillFocused(`Background`); |
| 43 | + await wait.timeout(); |
| 44 | + |
| 45 | + await actions.pressFocused('Tab', 2); |
| 46 | + await actions.pressFocused('Enter'); |
| 47 | + await wait.timeout(500); |
| 48 | + |
| 49 | + await page.mouse.move(-1, -1); |
| 50 | + await expectScreenshot(); |
| 51 | + }); |
| 52 | + |
| 53 | + test('should insert via command menu @wysiwyg', async ({page, editor, actions, wait}) => { |
| 54 | + await editor.focus(); |
| 55 | + await editor.press('ArrowDown', 2); |
| 56 | + await editor.press('Enter'); |
| 57 | + |
| 58 | + await editor.pressSequentially('/fi'); |
| 59 | + await expect(page.getByTestId('g-md-toolbar-command-menu')).toBeVisible(); |
| 60 | + |
| 61 | + const fileMenu = editor.getByTextInCommandMenu('File').first(); |
| 62 | + await wait.visible(fileMenu); |
| 63 | + |
| 64 | + await fileMenu.click(); |
| 65 | + await wait.timeout(); |
| 66 | + |
| 67 | + const addByLinkTab = page.getByText('Add by link').first().locator('..'); |
| 68 | + await wait.visible(addByLinkTab); |
| 69 | + |
| 70 | + await addByLinkTab.click(); |
| 71 | + await wait.timeout(); |
| 72 | + |
| 73 | + await actions.fillFocused(`/assets/test-image.jpg`); |
| 74 | + await actions.pressFocused('Tab'); |
| 75 | + await actions.fillFocused(`Background`); |
| 76 | + await wait.timeout(); |
| 77 | + |
| 78 | + await actions.pressFocused('Tab', 2); |
| 79 | + await actions.pressFocused('Enter'); |
| 80 | + await wait.timeout(500); |
| 81 | + |
| 82 | + await expect(editor.getBySelectorInContenteditable('.yfm-file')).toBeVisible(); |
| 83 | + }); |
| 84 | + |
| 85 | + test('should insert via toolbar @markup', async ({editor, wait, actions, page}) => { |
| 86 | + await editor.switchMode('markup'); |
| 87 | + await editor.focus(); |
| 88 | + await editor.press('ArrowDown', 2); |
| 89 | + await editor.press('Enter'); |
| 90 | + |
| 91 | + await editor.clickAdditionalToolbarButton('File'); |
| 92 | + await wait.timeout(); |
| 93 | + |
| 94 | + const addByLinkTab = page.getByText('Add by link').first().locator('..'); |
| 95 | + await wait.visible(addByLinkTab); |
| 96 | + |
| 97 | + await addByLinkTab.click(); |
| 98 | + await wait.timeout(); |
| 99 | + |
| 100 | + await actions.fillFocused(`/assets/test-image.jpg`); |
| 101 | + await actions.pressFocused('Tab'); |
| 102 | + await actions.fillFocused(`Background`); |
| 103 | + await wait.timeout(); |
| 104 | + |
| 105 | + await actions.pressFocused('Tab', 2); |
| 106 | + await actions.pressFocused('Enter'); |
| 107 | + await wait.timeout(500); |
| 108 | + |
| 109 | + await expect( |
| 110 | + editor.getByTextInContenteditable( |
| 111 | + '{% file src="/assets/test-image.jpg" name="Background" %}', |
| 112 | + ), |
| 113 | + ).toBeVisible(); |
| 114 | + }); |
| 115 | + }); |
| 116 | + |
| 117 | + test.describe('mode switch', () => { |
| 118 | + test('should remain after mode switch @wysiwyg @markup', async ({ |
| 119 | + editor, |
| 120 | + wait, |
| 121 | + expectScreenshot, |
| 122 | + page, |
| 123 | + }) => { |
| 124 | + const markup = dd` |
| 125 | + some text |
| 126 | +
|
| 127 | + {% file src="/assets/test-image.jpg" name="Background" %} |
| 128 | +
|
| 129 | + text |
| 130 | + `; |
| 131 | + |
| 132 | + await editor.switchMode('markup'); |
| 133 | + await editor.clearContent(); |
| 134 | + await editor.fill(markup); |
| 135 | + await wait.timeout(); |
| 136 | + |
| 137 | + await expect(editor.getByTextInContenteditable('some text')).toBeVisible(); |
| 138 | + await expect(editor.getByTextInContenteditable('/assets/test-image.jpg')).toBeVisible(); |
| 139 | + |
| 140 | + await editor.switchMode('wysiwyg'); |
| 141 | + await wait.timeout(500); |
| 142 | + |
| 143 | + await page.mouse.move(-1, -1); |
| 144 | + await expectScreenshot(); |
| 145 | + }); |
| 146 | + }); |
| 147 | +}); |
0 commit comments