|
| 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('Cut', () => { |
| 8 | + test.beforeEach(async ({mount}) => { |
| 9 | + const initialMarkup = dd` |
| 10 | + ## YFM Cut |
| 11 | +
|
| 12 | + {% cut "Cut header" %} |
| 13 | +
|
| 14 | + Content displayed when clicked. |
| 15 | +
|
| 16 | + {% endcut %} |
| 17 | +
|
| 18 | + {% cut "Cut with nested сut header" %} |
| 19 | +
|
| 20 | + {% cut "Cut inside cut header" %} |
| 21 | +
|
| 22 | + Content displayed when clicked. |
| 23 | +
|
| 24 | + {% endcut %} |
| 25 | +
|
| 26 | + {% endcut %} |
| 27 | + `; |
| 28 | + |
| 29 | + await mount(<Playground initial={initialMarkup} />); |
| 30 | + }); |
| 31 | + |
| 32 | + test('should open second cut', async ({expectScreenshot, editor, page}) => { |
| 33 | + await editor.switchMode('wysiwyg'); |
| 34 | + |
| 35 | + const nestedCut = page.getByText('Cut with nested сut header').first().locator('..'); |
| 36 | + await expect(nestedCut).toBeVisible(); |
| 37 | + |
| 38 | + // Clicking by MouseEvent because YfmCutController relies on event bubbling to document |
| 39 | + // https://github.com/diplodoc-platform/cut-extension/blob/master/src/runtime/controller.ts#L9 |
| 40 | + await nestedCut.dispatchEvent('click', { |
| 41 | + bubbles: true, |
| 42 | + cancelable: true, |
| 43 | + composed: true, |
| 44 | + }); |
| 45 | + await page.waitForTimeout(100); |
| 46 | + |
| 47 | + await expectScreenshot(); |
| 48 | + }); |
| 49 | + |
| 50 | + test('should cut inside open second cut', async ({expectScreenshot, editor, page}) => { |
| 51 | + await editor.switchMode('wysiwyg'); |
| 52 | + |
| 53 | + const nestedCut = page.getByText('Cut with nested сut header').first().locator('..'); |
| 54 | + await expect(nestedCut).toBeVisible(); |
| 55 | + |
| 56 | + await nestedCut.dispatchEvent('click', { |
| 57 | + bubbles: true, |
| 58 | + cancelable: true, |
| 59 | + composed: true, |
| 60 | + }); |
| 61 | + await page.waitForTimeout(100); |
| 62 | + |
| 63 | + // click to cut inside |
| 64 | + const cutInsideNestedCut = page.getByText('Cut inside cut header').first().locator('..'); |
| 65 | + await expect(cutInsideNestedCut).toBeVisible(); |
| 66 | + |
| 67 | + await cutInsideNestedCut.dispatchEvent('click', { |
| 68 | + bubbles: true, |
| 69 | + cancelable: true, |
| 70 | + composed: true, |
| 71 | + }); |
| 72 | + await page.waitForTimeout(100); |
| 73 | + |
| 74 | + await expectScreenshot(); |
| 75 | + }); |
| 76 | +}); |
0 commit comments