Browse Source

TINY-3775: Add basic tests

pull/118/head
Simon Fjeldså 6 years ago
parent
commit
e9c6a11121
  1. 3
      .gitignore
  2. 59
      src/test/ts/alien/Setup.ts
  3. 25
      src/test/ts/browser/InitTest.ts
  4. 2
      tslint.json

3
.gitignore

@ -6,4 +6,5 @@ storybook-static
.rpt2_cache
tinymce-tinymce-vue-*.tgz
.idea
.cache
.cache
scratch

59
src/test/ts/alien/Setup.ts

@ -0,0 +1,59 @@
import { Step } from '@ephox/agar';
import { Fun } from '@ephox/katamari';
import { Body, Element, Insert, Remove } from '@ephox/sugar';
import { IPropTypes } from 'src/main/ts/components/EditorPropTypes';
import Editor from 'src/main/ts/index';
import { getTinymce } from 'src/main/ts/TinyMCE';
import 'tinymce';
import Vue from 'vue';
const setTinymceBaseUrl = (baseUrl: string) => {
const tinymce = getTinymce();
const prefix = document.location.protocol + '//' + document.location.host;
tinymce.baseURL = baseUrl.indexOf('://') === -1 ? prefix + baseUrl : baseUrl;
tinymce.baseURI = new tinymce.util.URI(tinymce.baseURL);
};
type SetupCallback = (editor: any, viewModel: any, done: any) => void;
const setup = (props: Partial<IPropTypes>, onLoaded: SetupCallback) => {
return Step.async((done) => {
const root = Element.fromTag('div');
const mountPoint = Element.fromTag('div');
Insert.append(root, mountPoint);
Insert.append(Body.body(), root);
// TODO: use editor base_url init config
setTinymceBaseUrl(`/project/node_modules/tinymce`);
const originalInit = props.init || {};
const originalSetup = originalInit.setup || Fun.noop;
const propsData = {
...props,
init: {
...originalInit,
setup: (editor: any) => {
originalSetup(editor);
editor.on('SkinLoaded', () => {
setTimeout(() => {
onLoaded(editor, viewModel, teardown);
}, 0);
});
}
}
};
const EditorConstructor = Vue.extend(Editor);
const viewModel = new EditorConstructor({ propsData }).$mount(mountPoint.dom());
const teardown = () => {
viewModel.$destroy();
Remove.remove(root);
done();
};
});
};
export { setup };

25
src/test/ts/browser/InitTest.ts

@ -0,0 +1,25 @@
import { Assertions, GeneralSteps, Logger, Pipeline } from '@ephox/agar';
import { UnitTest } from '@ephox/bedrock';
import { setup } from '../alien/Setup';
UnitTest.asynctest('InitTest', (success, failure) => {
Pipeline.async({}, [
Logger.t('Should be able to setup editor', GeneralSteps.sequence([
setup({}, (editor, viewModel, done) => {
done();
})
])),
Logger.t('Should be able to setup editor in inline mode via inline prop', GeneralSteps.sequence([
setup({ inline: true } , (editor, viewModel, done) => {
Assertions.assertEq('Editor should be inline', true, editor.inline);
done();
})
])),
Logger.t('Should be able to setup editor in inline mode via init data', GeneralSteps.sequence([
setup({ init: { inline: true } } , (editor, viewModel, done) => {
Assertions.assertEq('Editor should be inline', true, editor.inline);
done();
})
])),
], success, failure);
});

2
tslint.json

@ -5,6 +5,6 @@
"semicolon": true
},
"rules": {
"variable-name": false,
"variable-name": false
}
}
Loading…
Cancel
Save