-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INT-3303: Refactor InitTest.ts and related files.
- Loading branch information
1 parent
38ba52b
commit 105e1fa
Showing
1 changed file
with
56 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,68 @@ | ||
import { Assertions, Keyboard, Keys } from '@ephox/agar'; | ||
import { Assertions, Keyboard, Keys, Waiter } from '@ephox/agar'; | ||
import { pRender } from '../alien/Loader'; | ||
import { SugarElement } from '@ephox/sugar'; | ||
import { Assert, describe, it } from '@ephox/bedrock-client'; | ||
import { describe, it, afterEach } from '@ephox/bedrock-client'; | ||
import { cleanupTinymce, VALID_API_KEY } from '../alien/TestHelper'; | ||
|
||
describe('Editor Component Initialization Tests', () => { | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
const pFakeType = async (str: string, context: any) => { | ||
context.editor.getBody().innerHTML = '<p>' + str + '</p>'; | ||
Keyboard.keystroke(Keys.space(), {}, SugarElement.fromDom(context.editor.getBody()) as SugarElement<Node>); | ||
const pFakeType = async (str: string, vmContext: any) => { | ||
vmContext.editor.getBody().innerHTML = '<p>' + str + '</p>'; | ||
Keyboard.keystroke(Keys.space(), {}, SugarElement.fromDom(vmContext.editor.getBody()) as SugarElement<Node>); | ||
}; | ||
afterEach(() => { | ||
cleanupTinymce(); | ||
}); | ||
it('should not be inline by default', async () => { | ||
const vmContext = await pRender({}, ` | ||
<editor | ||
:init="init" | ||
></editor>`); | ||
Assertions.assertEq('Editor should not be inline', false, vmContext.editor.inline); | ||
}); | ||
|
||
const testVersion = (version: '4' | '5' | '6' | '7') => { | ||
describe(`Editor Initialization for Version ${version}`, () => { | ||
it('should not be inline by default', async () => { | ||
const context = await pRender(); | ||
Assertions.assertEq('Editor should not be inline', false, context.editor.inline); | ||
cleanupTinymce(); | ||
}); | ||
|
||
it('should be inline with inline attribute in template', async () => { | ||
const context = await pRender({}, ` | ||
<editor | ||
:init="init" | ||
:inline="true" | ||
></editor>`); | ||
Assertions.assertEq('Editor should be inline', true, context.editor.inline); | ||
cleanupTinymce(); | ||
}); | ||
|
||
it('should be inline with inline option in init', async () => { | ||
const context = await pRender({ init: { inline: true }}); | ||
Assertions.assertEq('Editor should be inline', true, context.editor.inline); | ||
cleanupTinymce(); | ||
}); | ||
it('should handle one-way binding with output-format="text"', async () => { | ||
const context = await pRender({ | ||
content: undefined, | ||
}, ` | ||
<editor | ||
:init="init" | ||
api-key="${VALID_API_KEY}" | ||
@update:modelValue="content =$event" | ||
output-format="text" | ||
></editor> | ||
`); | ||
await pFakeType('A', context); | ||
Assertions.assertEq('Content emitted should be of format="text"', 'A', context.vm.content); | ||
cleanupTinymce(); | ||
}); | ||
it('should be inline with inline attribute in template', async () => { | ||
const vmContext = await pRender({}, ` | ||
<editor | ||
:init="init" | ||
:inline="true" | ||
></editor>`); | ||
Assertions.assertEq('Editor should be inline', true, vmContext.editor.inline); | ||
}); | ||
|
||
it('should handle one-way binding with output-format="html"', async () => { | ||
const context = await pRender({ | ||
content: undefined, | ||
}, ` | ||
<editor | ||
:init="init" | ||
api-key="${VALID_API_KEY}" | ||
@update:modelValue="content =$event" | ||
output-format="html" | ||
></editor> | ||
`); | ||
await pFakeType('A', context); | ||
Assertions.assertEq('Content emitted should be of format="html"', '<p>A</p>', context.vm.content); | ||
cleanupTinymce(); | ||
}); | ||
}); | ||
}; | ||
it('should be inline with inline option in init', async () => { | ||
const vmContext = await pRender({ init: { inline: true }}); | ||
Assertions.assertEq('Editor should be inline', true, vmContext.editor.inline); | ||
}); | ||
it('should handle one-way binding with output-format="text"', async () => { | ||
const vmContext = await pRender({ | ||
content: undefined, | ||
}, ` | ||
<editor | ||
:init="init" | ||
api-key="${VALID_API_KEY}" | ||
@update:modelValue="content =$event" | ||
output-format="text" | ||
></editor> | ||
`); | ||
await pFakeType('A', vmContext); | ||
await Waiter.pWait(100); | ||
Assertions.assertEq('Content emitted should be of format="text"', 'A', vmContext.vm.content); | ||
}); | ||
|
||
Assert.succeeds('should test all versions', () => { | ||
Promise.all([ | ||
testVersion('4'), | ||
testVersion('5'), | ||
testVersion('6'), | ||
testVersion('7'), | ||
]).then(() => { | ||
// | ||
}).catch((error) => { | ||
// eslint-disable-next-line no-console | ||
console.error('this is a error', error); | ||
}); | ||
it('should handle one-way binding with output-format="html"', async () => { | ||
const vmContext = await pRender({ | ||
content: undefined, | ||
}, ` | ||
<editor | ||
:init="init" | ||
api-key="${VALID_API_KEY}" | ||
@update:modelValue="content =$event" | ||
output-format="html" | ||
></editor> | ||
`); | ||
await pFakeType('A', vmContext); | ||
await Waiter.pWait(100); | ||
Assertions.assertEq('Content emitted should be of format="html"', '<p>A</p>', vmContext.vm.content); | ||
}); | ||
}); |