-
Notifications
You must be signed in to change notification settings - Fork 168
Expand file tree
/
Copy pathTestHelpers.ts
More file actions
62 lines (49 loc) · 1.62 KB
/
TestHelpers.ts
File metadata and controls
62 lines (49 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { Assertions } from '@ephox/agar';
import { Cell, Obj } from '@ephox/katamari';
import { Version } from 'src/main/ts/components/Editor';
import { Editor as TinyMCEEditor } from 'tinymce';
interface EventHandlerArgs<T> {
editorEvent: T;
editor: TinyMCEEditor;
}
interface EventStore {
each: <T>(name: string, assertState: (state: EventHandlerArgs<T>[]) => void) => void;
createHandler: <T>(name: string) => HandlerType<T>;
clearState: () => void;
}
type HandlerType<A> = (a: A, editor: TinyMCEEditor) => unknown;
const VERSIONS: Version[] = [ '5', '6', '7', '8' ];
const CLOUD_VERSIONS: Version[] = [ '5', '6', '7', '8' ];
const VALID_API_KEY = 'qagffr3pkuv17a8on1afax661irst1hbr4e6tbv888sz91jc';
const EventStore = (): EventStore => {
const state: Cell<Record<string, EventHandlerArgs<unknown>[]>> = Cell({});
const createHandler = <T>(name: string): HandlerType<T> => (event: T, editor) => {
const oldState = state.get();
const eventHandlerState = Obj.get(oldState, name)
.getOr([] as EventHandlerArgs<unknown>[])
.concat([{ editorEvent: event, editor }]);
state.set({
...oldState,
[name]: eventHandlerState
});
};
const each = <T>(name: string, assertState: (state: EventHandlerArgs<T>[]) => void) => {
Assertions.assertEq('State from "' + name + '" handler should exist', true, name in state.get());
assertState(state.get()[name] as unknown as EventHandlerArgs<T>[]);
};
const clearState = () => {
state.set({});
};
return {
each,
createHandler,
clearState
};
};
export {
CLOUD_VERSIONS,
EventStore,
VALID_API_KEY,
Version,
VERSIONS
};