|
1 |
| -import { GeneralSteps, Logger, Pipeline, Assertions, Chain, Keyboard, Keys } from '@ephox/agar'; |
2 |
| -import { UnitTest } from '@ephox/bedrock-client'; |
| 1 | +import { Assertions, Keyboard, Keys } from '@ephox/agar'; |
| 2 | +import { pRender, remove } from '../alien/Loader'; |
3 | 3 | import { VersionLoader } from '@tinymce/miniature';
|
4 |
| -import { cRender, cRemove } from '../alien/Loader'; |
5 | 4 | import { SugarElement } from '@ephox/sugar';
|
| 5 | +import { describe, it, afterEach, before, context, after } from '@ephox/bedrock-client'; |
| 6 | +import { cleanupGlobalTinymce, VALID_API_KEY } from '../alien/TestHelper'; |
| 7 | +import { Arr } from '@ephox/katamari'; |
6 | 8 |
|
7 |
| -UnitTest.asynctest('InitTest', (success, failure) => { |
8 |
| - const cFakeType = (str: string) => Chain.op((context: any) => { |
9 |
| - context.editor.getBody().innerHTML = '<p>' + str + '</p>'; |
10 |
| - Keyboard.keystroke(Keys.space(), {}, SugarElement.fromDom(context.editor.getBody()) as SugarElement<Node>); |
11 |
| - }); |
| 9 | +describe('Editor Component Initialization Tests', () => { |
| 10 | + // eslint-disable-next-line @typescript-eslint/require-await |
| 11 | + const pFakeType = async (str: string, vmContext: any) => { |
| 12 | + vmContext.editor.getBody().innerHTML = '<p>' + str + '</p>'; |
| 13 | + Keyboard.keystroke(Keys.space(), {}, SugarElement.fromDom(vmContext.editor.getBody()) as SugarElement<Node>); |
| 14 | + }; |
| 15 | + |
| 16 | + Arr.each([ '4', '5', '6', '7' as const ], (version) => { |
| 17 | + context(`Version: ${version}`, () => { |
| 18 | + |
| 19 | + before(async () => { |
| 20 | + await VersionLoader.pLoadVersion(version); |
| 21 | + }); |
12 | 22 |
|
13 |
| - const sTestVersion = (version: '4' | '5' | '6' | '7') => VersionLoader.sWithVersion( |
14 |
| - version, |
15 |
| - GeneralSteps.sequence([ |
16 |
| - Logger.t('Should be able to setup editor', Chain.asStep({}, [ |
17 |
| - cRender(), |
18 |
| - Chain.op((context) => { |
19 |
| - Assertions.assertEq('Editor should not be inline', false, context.editor.inline); |
20 |
| - }), |
21 |
| - cRemove |
22 |
| - ])), |
| 23 | + after(() => { |
| 24 | + cleanupGlobalTinymce(); |
| 25 | + }); |
23 | 26 |
|
24 |
| - Logger.t('Should be able to setup editor', Chain.asStep({}, [ |
25 |
| - cRender({}, `<editor :init="init" :inline=true ></editor>`), |
26 |
| - Chain.op((context) => { |
27 |
| - Assertions.assertEq('Editor should be inline', true, context.editor.inline); |
28 |
| - }), |
29 |
| - cRemove |
30 |
| - ])), |
| 27 | + afterEach(() => { |
| 28 | + remove(); |
| 29 | + }); |
31 | 30 |
|
32 |
| - Logger.t('Should be able to setup editor', Chain.asStep({}, [ |
33 |
| - cRender({ init: { inline: true }}), |
34 |
| - Chain.op((context) => { |
35 |
| - Assertions.assertEq('Editor should be inline', true, context.editor.inline); |
36 |
| - }), |
37 |
| - cRemove |
38 |
| - ])), |
| 31 | + it('should not be inline by default', async () => { |
| 32 | + const vmContext = await pRender({}, ` |
| 33 | + <editor |
| 34 | + :init="init" |
| 35 | + ></editor>`); |
| 36 | + Assertions.assertEq('Editor should not be inline', false, vmContext.editor.inline); |
| 37 | + }); |
39 | 38 |
|
40 |
| - Logger.t('Test one way binding tinymce-vue -> variable', GeneralSteps.sequence([ |
41 |
| - Logger.t('Test outputFormat="text"', Chain.asStep({}, [ |
42 |
| - cRender({ |
43 |
| - content: undefined |
44 |
| - }, ` |
45 |
| - <editor |
46 |
| - :init="init" |
47 |
| - @update:modelValue="content = $event" |
48 |
| - output-format="text" |
49 |
| - ></editor> |
50 |
| - `), |
51 |
| - cFakeType('A'), |
52 |
| - Chain.op((context) => { |
53 |
| - Assertions.assertEq('Content emitted should be of format="text"', 'A', context.vm.content); |
54 |
| - }), |
55 |
| - cRemove |
56 |
| - ])), |
57 |
| - Logger.t('Test outputFormat="html"', Chain.asStep({}, [ |
58 |
| - cRender({ |
59 |
| - content: undefined |
60 |
| - }, ` |
61 |
| - <editor |
62 |
| - :init="init" |
63 |
| - v-model="content" |
64 |
| - output-format="html" |
65 |
| - ></editor> |
66 |
| - `), |
67 |
| - cFakeType('A'), |
68 |
| - Chain.op((context) => { |
69 |
| - Assertions.assertEq('Content emitted should be of format="html"', '<p>A</p>', context.vm.content); |
70 |
| - }), |
71 |
| - cRemove |
72 |
| - ])), |
73 |
| - ])), |
74 |
| - ]) |
75 |
| - ); |
| 39 | + it('should be inline with inline attribute in template', async () => { |
| 40 | + const vmContext = await pRender({}, ` |
| 41 | + <editor |
| 42 | + :init="init" |
| 43 | + :inline="true" |
| 44 | + ></editor>`); |
| 45 | + Assertions.assertEq('Editor should be inline', true, vmContext.editor.inline); |
| 46 | + }); |
76 | 47 |
|
77 |
| - Pipeline.async({}, [ |
78 |
| - sTestVersion('4'), |
79 |
| - sTestVersion('5'), |
80 |
| - sTestVersion('6'), |
81 |
| - sTestVersion('7'), |
82 |
| - ], success, failure); |
| 48 | + it('should be inline with inline option in init', async () => { |
| 49 | + const vmContext = await pRender({ init: { inline: true }}); |
| 50 | + Assertions.assertEq('Editor should be inline', true, vmContext.editor.inline); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should handle one-way binding with output-format="text"', async () => { |
| 54 | + const vmContext = await pRender({ |
| 55 | + content: undefined, |
| 56 | + }, ` |
| 57 | + <editor |
| 58 | + :init="init" |
| 59 | + api-key="${VALID_API_KEY}" |
| 60 | + @update:modelValue="content=$event" |
| 61 | + output-format="text" |
| 62 | + ></editor> |
| 63 | + `); |
| 64 | + await pFakeType('A', vmContext); |
| 65 | + Assertions.assertEq('Content emitted should be of format="text"', 'A', vmContext.vm.content); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should handle one-way binding with output-format="html"', async () => { |
| 69 | + const vmContext = await pRender({ |
| 70 | + content: undefined, |
| 71 | + }, ` |
| 72 | + <editor |
| 73 | + :init="init" |
| 74 | + api-key="${VALID_API_KEY}" |
| 75 | + @update:modelValue="content=$event" |
| 76 | + output-format="html" |
| 77 | + ></editor> |
| 78 | + `); |
| 79 | + await pFakeType('A', vmContext); |
| 80 | + Assertions.assertEq('Content emitted should be of format="html"', '<p>A</p>', vmContext.vm.content); |
| 81 | + }); |
| 82 | + }); |
| 83 | + }); |
83 | 84 | });
|
0 commit comments