Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/main/component/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,4 @@ export const bindHandlers = (editor: Editor, eventHandlers: Partial<EventHandler
eventHandlers[eventName.toLowerCase()]?.(e, editor);
});
});
};

export const injectTiny = (doc: any, url: string, cb: any): void => {
const script = doc.createElement('script');
script.referrerPolicy = 'origin';
script.type = 'application/javascript';
script.src = url;
script.onload = cb;
if (doc.head) {
doc.head.appendChild(script);
}
};
4 changes: 4 additions & 0 deletions src/test/ts/alien/Loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface SvelteEditorContext extends Disposable {
componentInstance: Record<string, any>;
/** Update any props on the live component instance and flush Svelte reactivity synchronously. */
setProps(patch: Partial<EditorProps>): void;
getProps(name: keyof EditorProps): unknown;
remove(): void;
}

Expand Down Expand Up @@ -86,6 +87,8 @@ export const render = async (props: EditorProps = {}): Promise<SvelteEditorConte
flushSync();
};

const getProps = (name: string): any => reactiveProps[name];

const remove = () => {
unmount(componentInstance).catch((reason) => {
// eslint-disable-next-line no-console
Expand All @@ -99,6 +102,7 @@ export const render = async (props: EditorProps = {}): Promise<SvelteEditorConte
DOMNode,
componentInstance,
setProps,
getProps,
remove,
[Symbol.dispose]: remove
};
Expand Down
23 changes: 23 additions & 0 deletions src/test/ts/browser/BindingTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Assertions } from '@ephox/agar';
import { describe, it } from '@ephox/bedrock-client';

import * as Loader from '../alien/Loader';
import { VALID_API_KEY, VERSIONS } from '../alien/TestHelpers';
import { TinyAssertions } from '@ephox/mcagar';

describe('BindingTest', () => {
VERSIONS.forEach((version) =>
Loader.withVersion(version, (render) => {
const defaultProps: Loader.EditorProps = { apiKey: VALID_API_KEY };

it('TINYINT-3435: value prop is bound to the editor\'s content', async () => {
const initialValue = '<p>Hello, World!</p>';
const newValue = '<p>New Content</p>';
using ctx = await render({ ...defaultProps, value: initialValue });
TinyAssertions.assertContent(ctx.editor, initialValue);
ctx.editor.execCommand('mceSetContent', false, newValue);
Assertions.assertEq('value prop should be updated', newValue, ctx.getProps('value'));
});
})
);
});
10 changes: 10 additions & 0 deletions src/test/ts/browser/EditorInitTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ describe('EditorInitTest', () => {
using ctx = await render({ ...defaultProps, value: '' });
TinyAssertions.assertContent(ctx.editor, '');
});

it('TINYINT-3435: cssClass is set to the container if provided', async () => {
using ctx = await render({ ...defaultProps, cssClass: 'test-class' });
Assertions.assertEq('className of containershould contain test-class', true, ctx.DOMNode.parentElement?.className === 'test-class');
});

it('TINYINT-3435: conf is passed as options to the editor', async () => {
using ctx = await render({ ...defaultProps, conf: { branding: false }});
Assertions.assertEq('branding option should be false', false, ctx.editor.options.get('branding'));
});
})
);
});
31 changes: 31 additions & 0 deletions src/test/ts/browser/EventsTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { TestStore } from '@ephox/agar';
import { describe, it } from '@ephox/bedrock-client';

import * as Loader from '../alien/Loader';
import { VALID_API_KEY, VERSIONS } from '../alien/TestHelpers';

describe('EventTest', () => {
VERSIONS.forEach((version) =>
Loader.withVersion(version, (render) => {
const store = TestStore<string>();
const eventHandlers = {
init: () => {
store.add('init');
},
loadcontent: () => {
store.add('loadcontent');
}
};
const defaultProps: Loader.EditorProps = { apiKey: VALID_API_KEY, ...eventHandlers };

it('TINYINT-3435: event handlers are handled correctly', async () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
using ctx = await render({ ...defaultProps });

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note test

Unused variable ctx.
Comment thread
tiny-ben-tran marked this conversation as resolved.
Dismissed
store.assertEq('Events should be fired', [
'loadcontent',
'init',
]);
});
})
);
});
Loading