Skip to content

Commit

Permalink
Refactor event name validation tests in UtilsTest, included comments.
Browse files Browse the repository at this point in the history
Removed Waiter from tests.
Wrapped various func into beforeEach() to improve readability.
  • Loading branch information
kemister85 committed Oct 16, 2024
1 parent 674abf6 commit 6bb5d8f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
22 changes: 15 additions & 7 deletions src/test/ts/atomic/UtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@ import { isValidKey } from 'src/main/ts/Utils';
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);
};

it('should check if key is valid onKeyUp', () => {
checkValidKey('onKeyUp', true);
});
// 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"' }
];

it('should check if key is valid onkeyup', () => {
checkValidKey('onkeyup', true);
validKeys.forEach(({ key, description }) => {
it(`should validate ${description}`, () => {
checkValidKey(key, true);
});
});
});

it('should check if key is valid onDisable', () => {
it('should invalidate unknown event name "onDisable"', () => {
checkValidKey('onDisable', false);
});
});
4 changes: 1 addition & 3 deletions src/test/ts/browser/InitTest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Assertions, Keyboard, Keys, Waiter } from '@ephox/agar';
import { Assertions, Keyboard, Keys } from '@ephox/agar';
import { pRender, remove } from '../alien/Loader';
import { VersionLoader } from '@tinymce/miniature';
import { SugarElement } from '@ephox/sugar';
Expand Down Expand Up @@ -62,7 +62,6 @@ describe('Editor Component Initialization Tests', () => {
></editor>
`);
await pFakeType('A', vmContext);
await Waiter.pWait(100);
Assertions.assertEq('Content emitted should be of format="text"', 'A', vmContext.vm.content);
});

Expand All @@ -78,7 +77,6 @@ describe('Editor Component Initialization Tests', () => {
></editor>
`);
await pFakeType('A', vmContext);
await Waiter.pWait(100);
Assertions.assertEq('Content emitted should be of format="html"', '<p>A</p>', vmContext.vm.content);
});
});
Expand Down
25 changes: 10 additions & 15 deletions src/test/ts/browser/LoadTinyTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Assertions } from '@ephox/agar';
import { context, describe, it } from '@ephox/bedrock-client';
import { beforeEach, context, describe, it } from '@ephox/bedrock-client';
import { Global } from '@ephox/katamari';
import { pRender, remove } from '../alien/Loader';
import { cleanupGlobalTinymce, VALID_API_KEY } from '../alien/TestHelper';
Expand All @@ -11,6 +11,12 @@ describe('LoadTinyTest', () => {
};

context('LoadTinyTest', () => {

beforeEach(() => {
remove();
cleanupGlobalTinymce();
});

it('Should be able to load local version of TinyMCE 7 using the tinymceScriptSrc prop', async () => {
await pRender({}, `
<editor
Expand All @@ -20,8 +26,6 @@ describe('LoadTinyTest', () => {
`);

AssertTinymceVersion('7');
remove();
cleanupGlobalTinymce();
});

it('Should be able to load local version of TinyMCE 6 using the tinymceScriptSrc prop', async () => {
Expand All @@ -33,8 +37,6 @@ describe('LoadTinyTest', () => {
`);

AssertTinymceVersion('6');
remove();
cleanupGlobalTinymce();
});

it('Should be able to load local version of TinyMCE 5 using the tinymceScriptSrc prop', async () => {
Expand All @@ -46,8 +48,6 @@ describe('LoadTinyTest', () => {
`);

AssertTinymceVersion('5');
remove();
cleanupGlobalTinymce();
});

it('Should be able to load local version of TinyMCE 4 using the tinymceScriptSrc prop', async () => {
Expand All @@ -59,8 +59,6 @@ describe('LoadTinyTest', () => {
`);

AssertTinymceVersion('4');
remove();
cleanupGlobalTinymce();
});

it('Should be able to load TinyMCE 7 from Cloud', async () => {
Expand All @@ -71,14 +69,13 @@ describe('LoadTinyTest', () => {
cloud-channel="7-stable"
></editor>
`);

AssertTinymceVersion('7');
Assertions.assertEq(
'TinyMCE 7 should have been loaded from Cloud',
`https://cdn.tiny.cloud/1/${VALID_API_KEY}/tinymce/7-stable`,
Global.tinymce.baseURI.source
);
remove();
cleanupGlobalTinymce();
});

it('Should be able to load TinyMCE 6 from Cloud', async () => {
Expand All @@ -89,14 +86,13 @@ describe('LoadTinyTest', () => {
cloud-channel="6-stable"
></editor>
`);

AssertTinymceVersion('6');
Assertions.assertEq(
'TinyMCE 6 should have been loaded from Cloud',
`https://cdn.tiny.cloud/1/${VALID_API_KEY}/tinymce/6-stable`,
Global.tinymce.baseURI.source
);
remove();
cleanupGlobalTinymce();
});

it('Should be able to load TinyMCE 5 from Cloud', async () => {
Expand All @@ -107,14 +103,13 @@ describe('LoadTinyTest', () => {
cloud-channel="5-stable"
></editor>
`);

AssertTinymceVersion('5');
Assertions.assertEq(
'TinyMCE 5 should have been loaded from Cloud',
`https://cdn.tiny.cloud/1/${VALID_API_KEY}/tinymce/5-stable`,
Global.tinymce.baseURI.source
);
remove();
cleanupGlobalTinymce();
});
});
});

0 comments on commit 6bb5d8f

Please sign in to comment.