-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INT-3303: Update Vue integration tests to use BDD style. (#434)
* INT-3303: Convert existing test.ts files to use bdd-styling conventions. * create TestHelper.ts to isolate variables update imports * remove async from cFakeType function. * Add test to LoadTinyTest.ts for loading from scriptSrc and Cloud. * INT-3303: Convert cFakeType to asynchronous. * INT-3303: Refactor InitTest.ts and related files. * add loop to iterate each editor version for tests. * afterEach function was added inside the loop for different versions. * INT-3303: Fix defaultValue warning. update cleanupTinymce to cleanupGlobalTinymce to be more specific. fix spacing between tests. add afterEach to context function. * INT-3303: add remove() tinymce instance back to LoadTinyTests. * Refactor EditorLoadTest.ts and related files * Removed EditorLoadTest.ts * Update src/stories/Editor.stories.tsx Co-authored-by: tiny-ben-tran <[email protected]> * Update src/test/ts/browser/InitTest.ts Co-authored-by: tiny-ben-tran <[email protected]> * Refactor event name validation tests in UtilsTest, included comments. Removed Waiter from tests. Wrapped various func into beforeEach() to improve readability. * INT-3303: refine type definitions and standardize array iteration methods. * Update src/test/ts/alien/TestHelper.ts --------- Co-authored-by: tiny-ben-tran <[email protected]>
- Loading branch information
1 parent
28169fa
commit ccc0099
Showing
7 changed files
with
244 additions
and
210 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"cSpell.words": [ | ||
"asynctest" | ||
], | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Global, Strings, Arr } from '@ephox/katamari'; | ||
import { SugarElement, Attribute, SelectorFilter, Remove } from '@ephox/sugar'; | ||
import { ScriptLoader } from '../../../main/ts/ScriptLoader'; | ||
|
||
const VALID_API_KEY = 'qagffr3pkuv17a8on1afax661irst1hbr4e6tbv888sz91jc'; | ||
|
||
// Function to clean up and remove TinyMCE-related scripts and links from the document | ||
const cleanupGlobalTinymce = () => { | ||
ScriptLoader.reinitialize(); | ||
// This deletes global references to TinyMCE, to ensure a clean slate for each initialization when tests are switching to a different editor versions. | ||
delete Global.tinymce; | ||
delete Global.tinyMCE; | ||
// Helper function to check if an element has a TinyMCE-related URI in a specific attribute | ||
const hasTinymceUri = (attrName: string) => (elm: SugarElement<Element>) => | ||
Attribute.getOpt(elm, attrName).exists((src) => Strings.contains(src, 'tinymce')); | ||
// Find all script and link elements that have a TinyMCE-related URI | ||
const elements = Arr.flatten([ | ||
Arr.filter(SelectorFilter.all('script'), hasTinymceUri('src')), | ||
Arr.filter(SelectorFilter.all('link'), hasTinymceUri('href')), | ||
]); | ||
Arr.each(elements, Remove.remove); | ||
}; | ||
|
||
export { | ||
VALID_API_KEY, | ||
cleanupGlobalTinymce, | ||
}; |
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,15 +1,31 @@ | ||
import { Assertions } from '@ephox/agar'; | ||
import { UnitTest } from '@ephox/bedrock-client'; | ||
import { describe, it } from '@ephox/bedrock-client'; | ||
import { Arr } from '@ephox/katamari'; | ||
import { isValidKey } from 'src/main/ts/Utils'; | ||
|
||
UnitTest.test('UtilsTest', () => { | ||
|
||
describe('UtilsTest', () => { | ||
const checkValidKey = (key: string, expected: boolean) => { | ||
const actual = isValidKey(key); | ||
Assertions.assertEq('Key is valid', expected, actual); | ||
Assertions.assertEq('Key should be valid in both camelCase and lowercase', expected, actual); | ||
}; | ||
|
||
checkValidKey('onKeyUp', true); | ||
checkValidKey('onkeyup', true); | ||
checkValidKey('onDisable', false); | ||
// eslint-disable-next-line max-len | ||
// v-on event listeners inside DOM templates will be automatically transformed to lowercase (due to HTML’s case-insensitivity), so v-on:myEvent would become v-on:myevent. ref: https://eslint.vuejs.org/rules/custom-event-name-casing | ||
|
||
describe('Valid event name tests', () => { | ||
const validKeys = [ | ||
{ key: 'onKeyUp', description: 'camelCase event name "onKeyUp"' }, | ||
{ key: 'onkeyup', description: 'lowercase event name "onkeyup"' } | ||
]; | ||
|
||
Arr.each(validKeys, ({ key, description }) => { | ||
it(`should validate ${description}`, () => { | ||
checkValidKey(key, true); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should invalidate unknown event name "onDisable"', () => { | ||
checkValidKey('onDisable', false); | ||
}); | ||
}); |
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,83 +1,84 @@ | ||
import { GeneralSteps, Logger, Pipeline, Assertions, Chain, Keyboard, Keys } from '@ephox/agar'; | ||
import { UnitTest } from '@ephox/bedrock-client'; | ||
import { Assertions, Keyboard, Keys } from '@ephox/agar'; | ||
import { pRender, remove } from '../alien/Loader'; | ||
import { VersionLoader } from '@tinymce/miniature'; | ||
import { cRender, cRemove } from '../alien/Loader'; | ||
import { SugarElement } from '@ephox/sugar'; | ||
import { describe, it, afterEach, before, context, after } from '@ephox/bedrock-client'; | ||
import { cleanupGlobalTinymce, VALID_API_KEY } from '../alien/TestHelper'; | ||
import { Arr } from '@ephox/katamari'; | ||
|
||
UnitTest.asynctest('InitTest', (success, failure) => { | ||
const cFakeType = (str: string) => Chain.op((context: any) => { | ||
context.editor.getBody().innerHTML = '<p>' + str + '</p>'; | ||
Keyboard.keystroke(Keys.space(), {}, SugarElement.fromDom(context.editor.getBody()) as SugarElement<Node>); | ||
}); | ||
describe('Editor Component Initialization Tests', () => { | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
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>); | ||
}; | ||
|
||
Arr.each([ '4', '5', '6', '7' as const ], (version) => { | ||
context(`Version: ${version}`, () => { | ||
|
||
before(async () => { | ||
await VersionLoader.pLoadVersion(version); | ||
}); | ||
|
||
const sTestVersion = (version: '4' | '5' | '6' | '7') => VersionLoader.sWithVersion( | ||
version, | ||
GeneralSteps.sequence([ | ||
Logger.t('Should be able to setup editor', Chain.asStep({}, [ | ||
cRender(), | ||
Chain.op((context) => { | ||
Assertions.assertEq('Editor should not be inline', false, context.editor.inline); | ||
}), | ||
cRemove | ||
])), | ||
after(() => { | ||
cleanupGlobalTinymce(); | ||
}); | ||
|
||
Logger.t('Should be able to setup editor', Chain.asStep({}, [ | ||
cRender({}, `<editor :init="init" :inline=true ></editor>`), | ||
Chain.op((context) => { | ||
Assertions.assertEq('Editor should be inline', true, context.editor.inline); | ||
}), | ||
cRemove | ||
])), | ||
afterEach(() => { | ||
remove(); | ||
}); | ||
|
||
Logger.t('Should be able to setup editor', Chain.asStep({}, [ | ||
cRender({ init: { inline: true }}), | ||
Chain.op((context) => { | ||
Assertions.assertEq('Editor should be inline', true, context.editor.inline); | ||
}), | ||
cRemove | ||
])), | ||
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); | ||
}); | ||
|
||
Logger.t('Test one way binding tinymce-vue -> variable', GeneralSteps.sequence([ | ||
Logger.t('Test outputFormat="text"', Chain.asStep({}, [ | ||
cRender({ | ||
content: undefined | ||
}, ` | ||
<editor | ||
:init="init" | ||
@update:modelValue="content = $event" | ||
output-format="text" | ||
></editor> | ||
`), | ||
cFakeType('A'), | ||
Chain.op((context) => { | ||
Assertions.assertEq('Content emitted should be of format="text"', 'A', context.vm.content); | ||
}), | ||
cRemove | ||
])), | ||
Logger.t('Test outputFormat="html"', Chain.asStep({}, [ | ||
cRender({ | ||
content: undefined | ||
}, ` | ||
<editor | ||
:init="init" | ||
v-model="content" | ||
output-format="html" | ||
></editor> | ||
`), | ||
cFakeType('A'), | ||
Chain.op((context) => { | ||
Assertions.assertEq('Content emitted should be of format="html"', '<p>A</p>', context.vm.content); | ||
}), | ||
cRemove | ||
])), | ||
])), | ||
]) | ||
); | ||
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); | ||
}); | ||
|
||
Pipeline.async({}, [ | ||
sTestVersion('4'), | ||
sTestVersion('5'), | ||
sTestVersion('6'), | ||
sTestVersion('7'), | ||
], success, failure); | ||
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); | ||
Assertions.assertEq('Content emitted should be of format="text"', 'A', vmContext.vm.content); | ||
}); | ||
|
||
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); | ||
Assertions.assertEq('Content emitted should be of format="html"', '<p>A</p>', vmContext.vm.content); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.