@atlaskit/editor-core 150.0.0 → 151.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/dist/cjs/actions/index.js +5 -23
- package/dist/cjs/create-editor/ErrorBoundary.js +113 -79
- package/dist/cjs/create-editor/ReactEditorView.js +145 -31
- package/dist/cjs/create-editor/create-plugins-list.js +4 -2
- package/dist/cjs/editor.js +101 -40
- package/dist/cjs/labs/next/presets/cxhtml.js +2 -1
- package/dist/cjs/plugins/analytics/types/enums.js +3 -1
- package/dist/cjs/plugins/base/index.js +4 -3
- package/dist/cjs/plugins/base/pm-plugins/frozen-editor.js +66 -36
- package/dist/cjs/plugins/block-type/ui/ToolbarBlockType/styled.js +3 -1
- package/dist/cjs/plugins/card/index.js +13 -2
- package/dist/cjs/plugins/card/nodeviews/embedCard.js +1 -0
- package/dist/cjs/plugins/card/pm-plugins/main.js +7 -2
- package/dist/cjs/plugins/card/pm-plugins/util/resolve.js +10 -3
- package/dist/cjs/plugins/code-block/toolbar.js +1 -1
- package/dist/cjs/plugins/collab-edit/ui/to-avatar.js +4 -8
- package/dist/cjs/plugins/emoji/styles.js +1 -1
- package/dist/cjs/plugins/extension/pm-plugins/main.js +1 -4
- package/dist/cjs/plugins/extension/toolbar.js +28 -23
- package/dist/cjs/plugins/feature-flags-context/feature-flags-from-props.js +8 -3
- package/dist/cjs/plugins/find-replace/ui/Find.js +27 -7
- package/dist/cjs/plugins/hyperlink/pm-plugins/keymap.js +3 -3
- package/dist/cjs/plugins/hyperlink/ui/HyperlinkAddToolbar/HyperlinkAddToolbar.js +7 -4
- package/dist/cjs/plugins/hyperlink/utils.js +6 -69
- package/dist/cjs/plugins/media/index.js +14 -3
- package/dist/cjs/plugins/media/nodeviews/mediaGroup.js +24 -10
- package/dist/cjs/plugins/media/nodeviews/mediaInline.js +179 -0
- package/dist/cjs/plugins/media/pm-plugins/main.js +18 -9
- package/dist/cjs/plugins/media/toolbar/index.js +49 -17
- package/dist/cjs/plugins/media/toolbar/utils.js +20 -2
- package/dist/cjs/plugins/media/utils/media-files.js +67 -1
- package/dist/cjs/plugins/mentions/type-ahead/index.js +39 -3
- package/dist/cjs/plugins/panel/index.js +2 -3
- package/dist/cjs/plugins/panel/message.js +47 -0
- package/dist/cjs/plugins/panel/toolbar.js +64 -84
- package/dist/cjs/plugins/panel/utils.js +2 -2
- package/dist/cjs/plugins/paste/linkify-md-plugin.js +3 -3
- package/dist/cjs/plugins/status/styles.js +1 -1
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +18 -2
- package/dist/cjs/plugins/type-ahead/transforms/open-typeahead-at-cursor.js +20 -3
- package/dist/cjs/profiler/render-count.js +82 -0
- package/dist/cjs/ui/Appearance/Comment/Comment.js +6 -5
- package/dist/cjs/utils/react-hooks/use-component-renderer-tracking/index.js +55 -19
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/actions/index.js +6 -28
- package/dist/es2019/create-editor/ErrorBoundary.js +73 -60
- package/dist/es2019/create-editor/ReactEditorView.js +130 -23
- package/dist/es2019/create-editor/create-plugins-list.js +4 -2
- package/dist/es2019/editor.js +74 -35
- package/dist/es2019/labs/next/presets/cxhtml.js +2 -1
- package/dist/es2019/plugins/analytics/types/enums.js +3 -1
- package/dist/es2019/plugins/base/index.js +4 -3
- package/dist/es2019/plugins/base/pm-plugins/frozen-editor.js +63 -35
- package/dist/es2019/plugins/block-type/ui/ToolbarBlockType/styled.js +2 -1
- package/dist/es2019/plugins/card/index.js +7 -2
- package/dist/es2019/plugins/card/nodeviews/embedCard.js +1 -0
- package/dist/es2019/plugins/card/pm-plugins/main.js +9 -2
- package/dist/es2019/plugins/card/pm-plugins/util/resolve.js +12 -5
- package/dist/es2019/plugins/code-block/toolbar.js +1 -1
- package/dist/es2019/plugins/collab-edit/ui/to-avatar.js +2 -6
- package/dist/es2019/plugins/emoji/styles.js +2 -0
- package/dist/es2019/plugins/extension/pm-plugins/main.js +1 -4
- package/dist/es2019/plugins/extension/toolbar.js +30 -25
- package/dist/es2019/plugins/feature-flags-context/feature-flags-from-props.js +8 -4
- package/dist/es2019/plugins/find-replace/ui/Find.js +27 -6
- package/dist/es2019/plugins/hyperlink/pm-plugins/keymap.js +1 -1
- package/dist/es2019/plugins/hyperlink/ui/HyperlinkAddToolbar/HyperlinkAddToolbar.js +7 -4
- package/dist/es2019/plugins/hyperlink/utils.js +3 -59
- package/dist/es2019/plugins/media/index.js +13 -4
- package/dist/es2019/plugins/media/nodeviews/mediaGroup.js +16 -7
- package/dist/es2019/plugins/media/nodeviews/mediaInline.js +88 -0
- package/dist/es2019/plugins/media/pm-plugins/main.js +20 -11
- package/dist/es2019/plugins/media/toolbar/index.js +44 -15
- package/dist/es2019/plugins/media/toolbar/utils.js +16 -0
- package/dist/es2019/plugins/media/utils/media-files.js +68 -2
- package/dist/es2019/plugins/mentions/type-ahead/index.js +21 -2
- package/dist/es2019/plugins/panel/index.js +3 -4
- package/dist/es2019/plugins/panel/message.js +38 -0
- package/dist/es2019/plugins/panel/toolbar.js +52 -71
- package/dist/es2019/plugins/panel/utils.js +2 -2
- package/dist/es2019/plugins/paste/linkify-md-plugin.js +2 -2
- package/dist/es2019/plugins/status/styles.js +2 -0
- package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +18 -2
- package/dist/es2019/plugins/type-ahead/transforms/open-typeahead-at-cursor.js +20 -3
- package/dist/es2019/profiler/render-count.js +60 -0
- package/dist/es2019/ui/Appearance/Comment/Comment.js +4 -2
- package/dist/es2019/utils/react-hooks/use-component-renderer-tracking/index.js +51 -18
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/actions/index.js +6 -24
- package/dist/esm/create-editor/ErrorBoundary.js +113 -78
- package/dist/esm/create-editor/ReactEditorView.js +146 -31
- package/dist/esm/create-editor/create-plugins-list.js +4 -2
- package/dist/esm/editor.js +100 -40
- package/dist/esm/labs/next/presets/cxhtml.js +2 -1
- package/dist/esm/plugins/analytics/types/enums.js +3 -1
- package/dist/esm/plugins/base/index.js +4 -3
- package/dist/esm/plugins/base/pm-plugins/frozen-editor.js +64 -36
- package/dist/esm/plugins/block-type/ui/ToolbarBlockType/styled.js +3 -1
- package/dist/esm/plugins/card/index.js +13 -2
- package/dist/esm/plugins/card/nodeviews/embedCard.js +1 -0
- package/dist/esm/plugins/card/pm-plugins/main.js +7 -2
- package/dist/esm/plugins/card/pm-plugins/util/resolve.js +12 -5
- package/dist/esm/plugins/code-block/toolbar.js +1 -1
- package/dist/esm/plugins/collab-edit/ui/to-avatar.js +4 -8
- package/dist/esm/plugins/emoji/styles.js +1 -1
- package/dist/esm/plugins/extension/pm-plugins/main.js +1 -4
- package/dist/esm/plugins/extension/toolbar.js +28 -23
- package/dist/esm/plugins/feature-flags-context/feature-flags-from-props.js +8 -4
- package/dist/esm/plugins/find-replace/ui/Find.js +27 -7
- package/dist/esm/plugins/hyperlink/pm-plugins/keymap.js +1 -1
- package/dist/esm/plugins/hyperlink/ui/HyperlinkAddToolbar/HyperlinkAddToolbar.js +7 -4
- package/dist/esm/plugins/hyperlink/utils.js +3 -59
- package/dist/esm/plugins/media/index.js +14 -4
- package/dist/esm/plugins/media/nodeviews/mediaGroup.js +24 -10
- package/dist/esm/plugins/media/nodeviews/mediaInline.js +147 -0
- package/dist/esm/plugins/media/pm-plugins/main.js +19 -11
- package/dist/esm/plugins/media/toolbar/index.js +47 -19
- package/dist/esm/plugins/media/toolbar/utils.js +15 -1
- package/dist/esm/plugins/media/utils/media-files.js +60 -2
- package/dist/esm/plugins/mentions/type-ahead/index.js +39 -3
- package/dist/esm/plugins/panel/index.js +3 -4
- package/dist/esm/plugins/panel/message.js +38 -0
- package/dist/esm/plugins/panel/toolbar.js +57 -77
- package/dist/esm/plugins/panel/utils.js +2 -2
- package/dist/esm/plugins/paste/linkify-md-plugin.js +2 -2
- package/dist/esm/plugins/status/styles.js +1 -1
- package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +18 -2
- package/dist/esm/plugins/type-ahead/transforms/open-typeahead-at-cursor.js +20 -3
- package/dist/esm/profiler/render-count.js +57 -0
- package/dist/esm/ui/Appearance/Comment/Comment.js +6 -5
- package/dist/esm/utils/react-hooks/use-component-renderer-tracking/index.js +53 -20
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/create-editor/ErrorBoundary.d.ts +6 -6
- package/dist/types/create-editor/ReactEditorView.d.ts +15 -3
- package/dist/types/editor.d.ts +3 -1
- package/dist/types/plugins/analytics/analytics-queue.d.ts +1 -1
- package/dist/types/plugins/analytics/index.d.ts +1 -1
- package/dist/types/plugins/analytics/types/enums.d.ts +4 -2
- package/dist/types/plugins/analytics/types/events.d.ts +7 -2
- package/dist/types/plugins/analytics/types/general-events.d.ts +4 -1
- package/dist/types/plugins/analytics/types/index.d.ts +1 -1
- package/dist/types/plugins/analytics/types/insert-events.d.ts +6 -1
- package/dist/types/plugins/analytics/types/link-tool-bar-events.d.ts +1 -0
- package/dist/types/plugins/base/index.d.ts +1 -0
- package/dist/types/plugins/base/pm-plugins/frozen-editor.d.ts +3 -2
- package/dist/types/plugins/card/pm-plugins/main.d.ts +2 -3
- package/dist/types/plugins/card/pm-plugins/util/resolve.d.ts +2 -1
- package/dist/types/plugins/card/types.d.ts +6 -0
- package/dist/types/plugins/collab-edit/ui/to-avatar.d.ts +1 -1
- package/dist/types/plugins/extension/types.d.ts +0 -2
- package/dist/types/plugins/extension/ui/Extension/ExtensionComponent.d.ts +2 -2
- package/dist/types/plugins/feature-flags-context/get-enabled-feature-flag-keys.d.ts +1 -1
- package/dist/types/plugins/floating-toolbar/types.d.ts +1 -1
- package/dist/types/plugins/floating-toolbar/ui/Select.d.ts +1 -1
- package/dist/types/plugins/hyperlink/utils.d.ts +0 -21
- package/dist/types/plugins/insert-block/ui/ToolbarInsertBlock/create-items.d.ts +1 -1
- package/dist/types/plugins/media/nodeviews/mediaInline.d.ts +27 -0
- package/dist/types/plugins/media/pm-plugins/main.d.ts +2 -2
- package/dist/types/plugins/media/toolbar/utils.d.ts +2 -0
- package/dist/types/plugins/media/utils/media-files.d.ts +8 -0
- package/dist/types/plugins/panel/message.d.ts +37 -0
- package/dist/types/plugins/panel/toolbar.d.ts +4 -37
- package/dist/types/plugins/panel/types.d.ts +1 -0
- package/dist/types/plugins/quick-insert/index.d.ts +1 -1
- package/dist/types/profiler/render-count.d.ts +14 -0
- package/dist/types/types/feature-flags.d.ts +8 -0
- package/dist/types/ui/LinkSearch/types.d.ts +1 -0
- package/dist/types/utils/react-hooks/use-component-renderer-tracking/index.d.ts +17 -1
- package/package.json +20 -17
- package/dist/cjs/plugins/caption/nodeviews/index.test.js +0 -135
- package/dist/cjs/plugins/caption/pm-plugins/keymap.test.js +0 -203
- package/dist/cjs/plugins/caption/pm-plugins/main.test.js +0 -141
- package/dist/cjs/plugins/code-block/language-list.test.js +0 -74
- package/dist/cjs/plugins/extension/ui/SaveIndicator/SaveIndicator.test.js +0 -101
- package/dist/cjs/plugins/floating-toolbar/ui/EmojiPickerButton.test.js +0 -98
- package/dist/cjs/plugins/media/commands/captions.test.js +0 -149
- package/dist/cjs/plugins/media/commands/linking.test.js +0 -296
- package/dist/cjs/plugins/media/ui/CaptionPlaceholder/index.test.js +0 -50
- package/dist/cjs/plugins/panel/toolbar.test.js +0 -250
- package/dist/cjs/ui/ColorPickerButton/index.test.js +0 -123
- package/dist/cjs/ui/PortalProvider/index.test.js +0 -139
- package/dist/es2019/plugins/caption/nodeviews/index.test.js +0 -122
- package/dist/es2019/plugins/caption/pm-plugins/keymap.test.js +0 -193
- package/dist/es2019/plugins/caption/pm-plugins/main.test.js +0 -132
- package/dist/es2019/plugins/code-block/language-list.test.js +0 -69
- package/dist/es2019/plugins/extension/ui/SaveIndicator/SaveIndicator.test.js +0 -83
- package/dist/es2019/plugins/floating-toolbar/ui/EmojiPickerButton.test.js +0 -85
- package/dist/es2019/plugins/media/commands/captions.test.js +0 -126
- package/dist/es2019/plugins/media/commands/linking.test.js +0 -208
- package/dist/es2019/plugins/media/ui/CaptionPlaceholder/index.test.js +0 -41
- package/dist/es2019/plugins/panel/toolbar.test.js +0 -200
- package/dist/es2019/ui/ColorPickerButton/index.test.js +0 -88
- package/dist/es2019/ui/PortalProvider/index.test.js +0 -115
- package/dist/esm/plugins/caption/nodeviews/index.test.js +0 -125
- package/dist/esm/plugins/caption/pm-plugins/keymap.test.js +0 -195
- package/dist/esm/plugins/caption/pm-plugins/main.test.js +0 -124
- package/dist/esm/plugins/code-block/language-list.test.js +0 -71
- package/dist/esm/plugins/extension/ui/SaveIndicator/SaveIndicator.test.js +0 -92
- package/dist/esm/plugins/floating-toolbar/ui/EmojiPickerButton.test.js +0 -85
- package/dist/esm/plugins/media/commands/captions.test.js +0 -135
- package/dist/esm/plugins/media/commands/linking.test.js +0 -268
- package/dist/esm/plugins/media/ui/CaptionPlaceholder/index.test.js +0 -41
- package/dist/esm/plugins/panel/toolbar.test.js +0 -230
- package/dist/esm/ui/ColorPickerButton/index.test.js +0 -107
- package/dist/esm/ui/PortalProvider/index.test.js +0 -129
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { sendKeyToPm } from '@atlaskit/editor-test-helpers/send-key-to-pm';
|
|
2
|
-
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
3
|
-
import { caption, doc, media, mediaSingle, p, panel } from '@atlaskit/editor-test-helpers/doc-builder';
|
|
4
|
-
import { NodeSelection, TextSelection } from 'prosemirror-state';
|
|
5
|
-
import { findParentNodeOfType } from 'prosemirror-utils';
|
|
6
|
-
import { GapCursorSelection } from '../../selection/gap-cursor/selection';
|
|
7
|
-
const createEditorTestingLibrary = createEditorFactory();
|
|
8
|
-
|
|
9
|
-
const editor = doc => createEditorTestingLibrary({
|
|
10
|
-
doc,
|
|
11
|
-
editorProps: {
|
|
12
|
-
allowPanel: true,
|
|
13
|
-
media: {
|
|
14
|
-
allowMediaSingle: true,
|
|
15
|
-
featureFlags: {
|
|
16
|
-
captions: true
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe('caption keymap', () => {
|
|
23
|
-
it('should go to caption on tab', () => {
|
|
24
|
-
const {
|
|
25
|
-
editorView
|
|
26
|
-
} = editor(doc('{<node>}', mediaSingle()(media({
|
|
27
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
28
|
-
type: 'file',
|
|
29
|
-
collection: 'MediaServicesSample'
|
|
30
|
-
})(), caption('Hello'))));
|
|
31
|
-
sendKeyToPm(editorView, 'Tab');
|
|
32
|
-
const captionParentNode = findParentNodeOfType(editorView.state.schema.nodes.caption)(editorView.state.selection);
|
|
33
|
-
expect(editorView.state.selection instanceof TextSelection).toBe(true);
|
|
34
|
-
expect(captionParentNode).toBeDefined();
|
|
35
|
-
});
|
|
36
|
-
it('should select caption on arrow down', () => {
|
|
37
|
-
const {
|
|
38
|
-
editorView
|
|
39
|
-
} = editor(doc('{<node>}', mediaSingle()(media({
|
|
40
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
41
|
-
type: 'file',
|
|
42
|
-
collection: 'MediaServicesSample'
|
|
43
|
-
})(), caption('Hello')), p('')));
|
|
44
|
-
sendKeyToPm(editorView, 'ArrowDown');
|
|
45
|
-
const captionParentNode = findParentNodeOfType(editorView.state.schema.nodes.caption)(editorView.state.selection);
|
|
46
|
-
expect(editorView.state.selection instanceof TextSelection).toBe(true);
|
|
47
|
-
expect(captionParentNode).toBeDefined();
|
|
48
|
-
});
|
|
49
|
-
it('should select media from paragraph below on arrow up', () => {
|
|
50
|
-
const {
|
|
51
|
-
editorView
|
|
52
|
-
} = editor(doc(mediaSingle({
|
|
53
|
-
layout: 'center'
|
|
54
|
-
})(media({
|
|
55
|
-
id: 'abc',
|
|
56
|
-
type: 'file',
|
|
57
|
-
collection: 'xyz'
|
|
58
|
-
})(), caption('hello')), p('{<>}something')));
|
|
59
|
-
sendKeyToPm(editorView, 'ArrowUp');
|
|
60
|
-
expect(editorView.state.selection instanceof NodeSelection).toBe(true);
|
|
61
|
-
expect(editorView.state.selection.from).toBe(0);
|
|
62
|
-
});
|
|
63
|
-
it('should select media from caption on arrow up', () => {
|
|
64
|
-
const {
|
|
65
|
-
editorView
|
|
66
|
-
} = editor(doc(mediaSingle({
|
|
67
|
-
layout: 'center'
|
|
68
|
-
})(media({
|
|
69
|
-
id: 'abc',
|
|
70
|
-
type: 'file',
|
|
71
|
-
collection: 'xyz'
|
|
72
|
-
})(), caption('he{<>}llo')), p('something')));
|
|
73
|
-
sendKeyToPm(editorView, 'ArrowUp');
|
|
74
|
-
expect(editorView.state.selection instanceof NodeSelection).toBe(true);
|
|
75
|
-
expect(editorView.state.selection.from).toBe(0);
|
|
76
|
-
});
|
|
77
|
-
it('should select media from caption on shift + tab', () => {
|
|
78
|
-
const {
|
|
79
|
-
editorView
|
|
80
|
-
} = editor(doc(mediaSingle({
|
|
81
|
-
layout: 'center'
|
|
82
|
-
})(media({
|
|
83
|
-
id: 'abc',
|
|
84
|
-
type: 'file',
|
|
85
|
-
collection: 'xyz'
|
|
86
|
-
})(), caption('he{<>}llo')), p('something')));
|
|
87
|
-
sendKeyToPm(editorView, 'Shift-Tab');
|
|
88
|
-
expect(editorView.state.selection instanceof NodeSelection).toBe(true);
|
|
89
|
-
expect(editorView.state.selection.from).toBe(0);
|
|
90
|
-
});
|
|
91
|
-
it('should create paragraph below caption on arrow down', () => {
|
|
92
|
-
const {
|
|
93
|
-
editorView
|
|
94
|
-
} = editor(doc(mediaSingle({
|
|
95
|
-
layout: 'center'
|
|
96
|
-
})(media({
|
|
97
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
98
|
-
type: 'file',
|
|
99
|
-
collection: 'MediaServicesSample'
|
|
100
|
-
})(), caption('hello{<>}'))));
|
|
101
|
-
sendKeyToPm(editorView, 'ArrowDown');
|
|
102
|
-
expect(editorView.state.doc).toEqualDocument(doc(mediaSingle()(media({
|
|
103
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
104
|
-
type: 'file',
|
|
105
|
-
collection: 'MediaServicesSample'
|
|
106
|
-
})(), caption('hello')), p()));
|
|
107
|
-
});
|
|
108
|
-
it('should create paragraph below caption on enter', () => {
|
|
109
|
-
const {
|
|
110
|
-
editorView
|
|
111
|
-
} = editor(doc(mediaSingle({
|
|
112
|
-
layout: 'center'
|
|
113
|
-
})(media({
|
|
114
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
115
|
-
type: 'file',
|
|
116
|
-
collection: 'MediaServicesSample'
|
|
117
|
-
})(), caption('hello{<>}'))));
|
|
118
|
-
sendKeyToPm(editorView, 'Enter');
|
|
119
|
-
expect(editorView.state.doc).toEqualDocument(doc(mediaSingle()(media({
|
|
120
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
121
|
-
type: 'file',
|
|
122
|
-
collection: 'MediaServicesSample'
|
|
123
|
-
})(), caption('hello')), p()));
|
|
124
|
-
});
|
|
125
|
-
it('should not create paragraph below panel on enter', () => {
|
|
126
|
-
const {
|
|
127
|
-
editorView
|
|
128
|
-
} = editor(doc(panel()(p('text{<>}'))));
|
|
129
|
-
sendKeyToPm(editorView, 'Enter');
|
|
130
|
-
expect(editorView.state.doc).toEqualDocument(doc(panel()(p('text'), p())));
|
|
131
|
-
});
|
|
132
|
-
it('should move to paragraph below caption on arrow down', () => {
|
|
133
|
-
const {
|
|
134
|
-
editorView
|
|
135
|
-
} = editor(doc(mediaSingle({
|
|
136
|
-
layout: 'center'
|
|
137
|
-
})(media({
|
|
138
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
139
|
-
type: 'file',
|
|
140
|
-
collection: 'MediaServicesSample'
|
|
141
|
-
})(), caption('hel{<>}lo')), p('something')));
|
|
142
|
-
sendKeyToPm(editorView, 'ArrowDown');
|
|
143
|
-
expect(editorView.state).toEqualDocumentAndSelection(doc(mediaSingle()(media({
|
|
144
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
145
|
-
type: 'file',
|
|
146
|
-
collection: 'MediaServicesSample'
|
|
147
|
-
})(), caption('hello')), p('{<>}something')));
|
|
148
|
-
});
|
|
149
|
-
it('should move to paragraph below caption on enter', () => {
|
|
150
|
-
const {
|
|
151
|
-
editorView
|
|
152
|
-
} = editor(doc(mediaSingle({
|
|
153
|
-
layout: 'center'
|
|
154
|
-
})(media({
|
|
155
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
156
|
-
type: 'file',
|
|
157
|
-
collection: 'MediaServicesSample'
|
|
158
|
-
})(), caption('he{<>}llo')), p('something')));
|
|
159
|
-
sendKeyToPm(editorView, 'Enter');
|
|
160
|
-
expect(editorView.state).toEqualDocumentAndSelection(doc(mediaSingle()(media({
|
|
161
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
162
|
-
type: 'file',
|
|
163
|
-
collection: 'MediaServicesSample'
|
|
164
|
-
})(), caption('hello')), p('{<>}something')));
|
|
165
|
-
});
|
|
166
|
-
it('should gap cursor parent media single on left arrow', () => {
|
|
167
|
-
const {
|
|
168
|
-
editorView
|
|
169
|
-
} = editor(doc(mediaSingle()(media({
|
|
170
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
171
|
-
type: 'file',
|
|
172
|
-
collection: 'MediaServicesSample'
|
|
173
|
-
})(), caption('{<>}Hello')), p('')));
|
|
174
|
-
sendKeyToPm(editorView, 'ArrowLeft');
|
|
175
|
-
expect(editorView.state.selection).toBeInstanceOf(GapCursorSelection);
|
|
176
|
-
expect(editorView.state).toEqualDocumentAndSelection(doc('{<gap|>}', mediaSingle()(media({
|
|
177
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
178
|
-
type: 'file',
|
|
179
|
-
collection: 'MediaServicesSample'
|
|
180
|
-
})(), caption('Hello')), p('')));
|
|
181
|
-
});
|
|
182
|
-
it('should not gap cursor parent media single on left arrow when not at start', () => {
|
|
183
|
-
const {
|
|
184
|
-
editorView
|
|
185
|
-
} = editor(doc(mediaSingle()(media({
|
|
186
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
187
|
-
type: 'file',
|
|
188
|
-
collection: 'MediaServicesSample'
|
|
189
|
-
})(), caption('H{<>}ello')), p('')));
|
|
190
|
-
sendKeyToPm(editorView, 'ArrowLeft');
|
|
191
|
-
expect(editorView.state.selection).not.toBeInstanceOf(GapCursorSelection);
|
|
192
|
-
});
|
|
193
|
-
});
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { createProsemirrorEditorFactory, Preset } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
2
|
-
import mediaPlugin from '../../media';
|
|
3
|
-
import captionPlugin from '../';
|
|
4
|
-
import { caption, doc, media, mediaSingle, p } from '@atlaskit/editor-test-helpers/doc-builder';
|
|
5
|
-
import { pluginKey } from './plugin-key';
|
|
6
|
-
import { setTextSelection } from '../../../utils/selection';
|
|
7
|
-
import * as analyticsUtils from '../../analytics/utils';
|
|
8
|
-
describe('Caption plugin', () => {
|
|
9
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
10
|
-
|
|
11
|
-
const editor = doc => createEditor({
|
|
12
|
-
doc,
|
|
13
|
-
pluginKey: pluginKey,
|
|
14
|
-
preset: new Preset().add([mediaPlugin, {
|
|
15
|
-
allowMediaSingle: true,
|
|
16
|
-
featureFlags: {
|
|
17
|
-
captions: true
|
|
18
|
-
}
|
|
19
|
-
}]).add(captionPlugin)
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should not remove caption when there is content', () => {
|
|
23
|
-
const {
|
|
24
|
-
editorView,
|
|
25
|
-
refs: {
|
|
26
|
-
movePos
|
|
27
|
-
}
|
|
28
|
-
} = editor(doc(mediaSingle()(media({
|
|
29
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
30
|
-
type: 'file',
|
|
31
|
-
collection: 'MediaServicesSample'
|
|
32
|
-
})(), caption('Test{<>}')), p('Line {movePos}two')));
|
|
33
|
-
setTextSelection(editorView, movePos);
|
|
34
|
-
expect(editorView.state.doc).toEqualDocument(doc(mediaSingle()(media({
|
|
35
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
36
|
-
type: 'file',
|
|
37
|
-
collection: 'MediaServicesSample'
|
|
38
|
-
})(), caption('Test')), p('Line two')));
|
|
39
|
-
});
|
|
40
|
-
it('should remove caption when there is no content', () => {
|
|
41
|
-
const {
|
|
42
|
-
editorView,
|
|
43
|
-
refs: {
|
|
44
|
-
movePos
|
|
45
|
-
}
|
|
46
|
-
} = editor(doc(mediaSingle()(media({
|
|
47
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
48
|
-
type: 'file',
|
|
49
|
-
collection: 'MediaServicesSample'
|
|
50
|
-
})(), caption('{<>}')), p('Line {movePos}two')));
|
|
51
|
-
setTextSelection(editorView, movePos);
|
|
52
|
-
expect(editorView.state.doc).toEqualDocument(doc(mediaSingle()(media({
|
|
53
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
54
|
-
type: 'file',
|
|
55
|
-
collection: 'MediaServicesSample'
|
|
56
|
-
})()), p('Line two')));
|
|
57
|
-
});
|
|
58
|
-
it('should remove caption when clicking onto another caption', () => {
|
|
59
|
-
const {
|
|
60
|
-
editorView,
|
|
61
|
-
refs: {
|
|
62
|
-
movePos
|
|
63
|
-
}
|
|
64
|
-
} = editor(doc(mediaSingle()(media({
|
|
65
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
66
|
-
type: 'file',
|
|
67
|
-
collection: 'MediaServicesSample'
|
|
68
|
-
})(), caption('{<>}')), mediaSingle()(media({
|
|
69
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
70
|
-
type: 'file',
|
|
71
|
-
collection: 'MediaServicesSample'
|
|
72
|
-
})(), caption('second {movePos}caption'))));
|
|
73
|
-
setTextSelection(editorView, movePos);
|
|
74
|
-
expect(editorView.state.doc).toEqualDocument(doc(mediaSingle()(media({
|
|
75
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
76
|
-
type: 'file',
|
|
77
|
-
collection: 'MediaServicesSample'
|
|
78
|
-
})()), mediaSingle()(media({
|
|
79
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
80
|
-
type: 'file',
|
|
81
|
-
collection: 'MediaServicesSample'
|
|
82
|
-
})(), caption('second caption'))));
|
|
83
|
-
});
|
|
84
|
-
describe('analytics', () => {
|
|
85
|
-
const addAnalyticsSpy = jest.spyOn(analyticsUtils, 'addAnalytics');
|
|
86
|
-
const FIRST_CALL = 0;
|
|
87
|
-
const PAYLOAD_ARGUMENT = 2;
|
|
88
|
-
beforeEach(() => {
|
|
89
|
-
addAnalyticsSpy.mockReset();
|
|
90
|
-
});
|
|
91
|
-
it('should fire deleted analytic when removing caption', () => {
|
|
92
|
-
const {
|
|
93
|
-
editorView,
|
|
94
|
-
refs: {
|
|
95
|
-
movePos
|
|
96
|
-
}
|
|
97
|
-
} = editor(doc(mediaSingle()(media({
|
|
98
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
99
|
-
type: 'file',
|
|
100
|
-
collection: 'MediaServicesSample'
|
|
101
|
-
})(), caption('{<>}')), p('Line {movePos}two')));
|
|
102
|
-
setTextSelection(editorView, movePos);
|
|
103
|
-
expect(addAnalyticsSpy).toBeCalled();
|
|
104
|
-
expect(addAnalyticsSpy.mock.calls[FIRST_CALL][PAYLOAD_ARGUMENT]).toEqual({
|
|
105
|
-
action: 'deleted',
|
|
106
|
-
actionSubject: 'mediaSingle',
|
|
107
|
-
actionSubjectId: 'caption',
|
|
108
|
-
eventType: 'track'
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
it('should fire edited analytic when moving away from a non empty caption', () => {
|
|
112
|
-
const {
|
|
113
|
-
editorView,
|
|
114
|
-
refs: {
|
|
115
|
-
movePos
|
|
116
|
-
}
|
|
117
|
-
} = editor(doc(mediaSingle()(media({
|
|
118
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
119
|
-
type: 'file',
|
|
120
|
-
collection: 'MediaServicesSample'
|
|
121
|
-
})(), caption('Test{<>}')), p('Line {movePos}two')));
|
|
122
|
-
setTextSelection(editorView, movePos);
|
|
123
|
-
expect(addAnalyticsSpy).toBeCalled();
|
|
124
|
-
expect(addAnalyticsSpy.mock.calls[FIRST_CALL][PAYLOAD_ARGUMENT]).toEqual({
|
|
125
|
-
action: 'edited',
|
|
126
|
-
actionSubject: 'mediaSingle',
|
|
127
|
-
actionSubjectId: 'caption',
|
|
128
|
-
eventType: 'track'
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_LANGUAGES, findMatchedLanguage, filterSupportedLanguages, getLanguageIdentifier, createLanguageList } from './language-list';
|
|
2
|
-
const mockSupportedLanguages = [{
|
|
3
|
-
name: 'JSON',
|
|
4
|
-
alias: ['json'],
|
|
5
|
-
value: 'json'
|
|
6
|
-
}, {
|
|
7
|
-
name: 'JavaScript',
|
|
8
|
-
alias: ['javascript', 'js'],
|
|
9
|
-
value: 'javascript'
|
|
10
|
-
}, {
|
|
11
|
-
name: 'Python',
|
|
12
|
-
alias: ['python', 'py'],
|
|
13
|
-
value: 'python'
|
|
14
|
-
}];
|
|
15
|
-
describe('languageList utils', () => {
|
|
16
|
-
it('should find matched language', () => {
|
|
17
|
-
expect(findMatchedLanguage(mockSupportedLanguages, 'JavaScript')).toEqual({
|
|
18
|
-
name: 'JavaScript',
|
|
19
|
-
alias: ['javascript', 'js'],
|
|
20
|
-
value: 'javascript'
|
|
21
|
-
});
|
|
22
|
-
expect(findMatchedLanguage(mockSupportedLanguages, 'Python')).toEqual({
|
|
23
|
-
name: 'Python',
|
|
24
|
-
alias: ['python', 'py'],
|
|
25
|
-
value: 'python'
|
|
26
|
-
});
|
|
27
|
-
expect(findMatchedLanguage(mockSupportedLanguages, 'GiBBeRish')).toBeUndefined();
|
|
28
|
-
});
|
|
29
|
-
it('should filter supported languages', () => {
|
|
30
|
-
const mockSupportedLanguageStrings = mockSupportedLanguages.map(language => language.name.toLowerCase());
|
|
31
|
-
expect(filterSupportedLanguages([])).toEqual(DEFAULT_LANGUAGES);
|
|
32
|
-
expect(filterSupportedLanguages(mockSupportedLanguageStrings)).toEqual([{
|
|
33
|
-
name: 'Python',
|
|
34
|
-
alias: ['python', 'py'],
|
|
35
|
-
value: 'python'
|
|
36
|
-
}, {
|
|
37
|
-
name: 'JavaScript',
|
|
38
|
-
alias: ['javascript', 'js'],
|
|
39
|
-
value: 'javascript'
|
|
40
|
-
}, {
|
|
41
|
-
name: 'JSON',
|
|
42
|
-
alias: ['json'],
|
|
43
|
-
value: 'json'
|
|
44
|
-
} // '(None)' is not an actual language and should not be 'supported'
|
|
45
|
-
]);
|
|
46
|
-
});
|
|
47
|
-
it('should get language identifier', () => {
|
|
48
|
-
expect(getLanguageIdentifier({
|
|
49
|
-
name: 'MyLanguage',
|
|
50
|
-
alias: ['myalias'],
|
|
51
|
-
value: 'myalias'
|
|
52
|
-
})).toEqual('myalias');
|
|
53
|
-
});
|
|
54
|
-
it('should create language list sorted as case insensitive', () => {
|
|
55
|
-
expect(createLanguageList(mockSupportedLanguages)).toEqual([{
|
|
56
|
-
name: 'JavaScript',
|
|
57
|
-
alias: ['javascript', 'js'],
|
|
58
|
-
value: 'javascript'
|
|
59
|
-
}, {
|
|
60
|
-
name: 'JSON',
|
|
61
|
-
alias: ['json'],
|
|
62
|
-
value: 'json'
|
|
63
|
-
}, {
|
|
64
|
-
name: 'Python',
|
|
65
|
-
alias: ['python', 'py'],
|
|
66
|
-
value: 'python'
|
|
67
|
-
}]);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { render, act } from '@testing-library/react';
|
|
4
|
-
import { IntlProvider } from 'react-intl';
|
|
5
|
-
import { SaveIndicator } from './SaveIndicator';
|
|
6
|
-
jest.useFakeTimers();
|
|
7
|
-
|
|
8
|
-
function setup(props = {}) {
|
|
9
|
-
let onSaveStarted = () => {};
|
|
10
|
-
|
|
11
|
-
const result = render( /*#__PURE__*/React.createElement(IntlProvider, {
|
|
12
|
-
locale: "en"
|
|
13
|
-
}, /*#__PURE__*/React.createElement(SaveIndicator, _extends({
|
|
14
|
-
duration: 2000
|
|
15
|
-
}, props), ({
|
|
16
|
-
onSaveStarted: _onSaveStarted
|
|
17
|
-
}) => {
|
|
18
|
-
onSaveStarted = _onSaveStarted;
|
|
19
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
20
|
-
"data-testid": "my-component"
|
|
21
|
-
});
|
|
22
|
-
})));
|
|
23
|
-
return { ...result,
|
|
24
|
-
onSaveStarted
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe('Extension Context Panel - Save Indicator', () => {
|
|
29
|
-
it('should call the render function ', () => {
|
|
30
|
-
const renderFunction = jest.fn().mockImplementation(() => {
|
|
31
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
32
|
-
"data-testid": "my-component"
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
const {
|
|
36
|
-
queryByTestId
|
|
37
|
-
} = render( /*#__PURE__*/React.createElement(IntlProvider, {
|
|
38
|
-
locale: "en"
|
|
39
|
-
}, /*#__PURE__*/React.createElement(SaveIndicator, {
|
|
40
|
-
duration: 1000
|
|
41
|
-
}, renderFunction)));
|
|
42
|
-
expect(queryByTestId('my-component')).not.toBeNull();
|
|
43
|
-
});
|
|
44
|
-
it('should show the save indicator when is saving ', () => {
|
|
45
|
-
const {
|
|
46
|
-
onSaveStarted,
|
|
47
|
-
queryByTestId
|
|
48
|
-
} = setup();
|
|
49
|
-
act(() => {
|
|
50
|
-
onSaveStarted();
|
|
51
|
-
});
|
|
52
|
-
expect(queryByTestId('save-indicator-content')).not.toBeNull();
|
|
53
|
-
});
|
|
54
|
-
it('should hide once the duration is over ', () => {
|
|
55
|
-
jest.clearAllTimers();
|
|
56
|
-
const duration = 2000;
|
|
57
|
-
const {
|
|
58
|
-
onSaveStarted,
|
|
59
|
-
queryByTestId
|
|
60
|
-
} = setup({
|
|
61
|
-
duration
|
|
62
|
-
});
|
|
63
|
-
act(() => {
|
|
64
|
-
onSaveStarted();
|
|
65
|
-
});
|
|
66
|
-
act(() => {
|
|
67
|
-
jest.advanceTimersByTime(duration);
|
|
68
|
-
});
|
|
69
|
-
expect(queryByTestId('save-indicator-content')).toBeNull();
|
|
70
|
-
});
|
|
71
|
-
it('should not show the save indicator after saving when visible is false ', () => {
|
|
72
|
-
const {
|
|
73
|
-
onSaveStarted,
|
|
74
|
-
queryByTestId
|
|
75
|
-
} = setup({
|
|
76
|
-
visible: false
|
|
77
|
-
});
|
|
78
|
-
act(() => {
|
|
79
|
-
onSaveStarted();
|
|
80
|
-
});
|
|
81
|
-
expect(queryByTestId('save-indicator-content')).toBeNull();
|
|
82
|
-
});
|
|
83
|
-
});
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mountWithIntl } from '@atlaskit/editor-test-helpers/enzyme';
|
|
3
|
-
import { createProsemirrorEditorFactory, Preset } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
4
|
-
import { doc, p, panel } from '@atlaskit/editor-test-helpers/doc-builder';
|
|
5
|
-
import { EmojiPickerButton } from './EmojiPickerButton';
|
|
6
|
-
import panelPlugin from '../../panel';
|
|
7
|
-
import { ProviderFactory } from '@atlaskit/editor-common';
|
|
8
|
-
import { getTestEmojiResource } from '@atlaskit/util-data-test/get-test-emoji-resource';
|
|
9
|
-
import { act } from 'react-dom/test-utils';
|
|
10
|
-
describe('emoji-picker-button', () => {
|
|
11
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
12
|
-
let wrapper;
|
|
13
|
-
let onChangeMock;
|
|
14
|
-
const providerFactory = new ProviderFactory();
|
|
15
|
-
const panelPreset = new Preset().add([panelPlugin, {
|
|
16
|
-
UNSAFE_allowCustomPanel: true
|
|
17
|
-
}]);
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
const {
|
|
20
|
-
editorView
|
|
21
|
-
} = createEditor({
|
|
22
|
-
doc: doc(panel({
|
|
23
|
-
panelType: 'info'
|
|
24
|
-
})(p('{<>}'))),
|
|
25
|
-
preset: panelPreset,
|
|
26
|
-
providerFactory
|
|
27
|
-
});
|
|
28
|
-
providerFactory.setProvider('emojiProvider', Promise.resolve(getTestEmojiResource()));
|
|
29
|
-
onChangeMock = jest.fn();
|
|
30
|
-
wrapper = mountWithIntl( /*#__PURE__*/React.createElement(EmojiPickerButton, {
|
|
31
|
-
view: editorView,
|
|
32
|
-
providerFactory: providerFactory,
|
|
33
|
-
onChange: onChangeMock
|
|
34
|
-
}));
|
|
35
|
-
});
|
|
36
|
-
afterEach(() => {
|
|
37
|
-
providerFactory.removeProvider('emojiProvider');
|
|
38
|
-
wrapper && wrapper.unmount();
|
|
39
|
-
});
|
|
40
|
-
it('should render a button', () => {
|
|
41
|
-
expect(wrapper.find('button')).toHaveLength(1); // ensure no popup is rendered
|
|
42
|
-
|
|
43
|
-
expect(wrapper.find('Popup')).toHaveLength(0);
|
|
44
|
-
});
|
|
45
|
-
it('should show a EmojiPicker popup after clicking button', () => {
|
|
46
|
-
// popup still not shown before the click
|
|
47
|
-
wrapper.find('button').simulate('click'); // show the popup
|
|
48
|
-
|
|
49
|
-
expect(wrapper.find('Popup')).toHaveLength(1);
|
|
50
|
-
});
|
|
51
|
-
it('should close EmojiPicker popup after clicking outside', () => {
|
|
52
|
-
// clicking on the button to open the popup
|
|
53
|
-
wrapper.find('button').simulate('click'); // make sure the popup and picker are shown
|
|
54
|
-
|
|
55
|
-
expect(wrapper.find('Popup')).toHaveLength(1);
|
|
56
|
-
const emojiPicker = wrapper.find('EmojiPickerInternal').instance(); // calling click outside
|
|
57
|
-
|
|
58
|
-
act(() => {
|
|
59
|
-
emojiPicker.props.handleClickOutside();
|
|
60
|
-
});
|
|
61
|
-
wrapper.update(); // make sure popup is hidden
|
|
62
|
-
|
|
63
|
-
expect(wrapper.find('Popup')).toHaveLength(0);
|
|
64
|
-
});
|
|
65
|
-
it('should hide popup and call onChange after selecting an emoji', () => {
|
|
66
|
-
// click the button
|
|
67
|
-
wrapper.find('button').simulate('click'); // make sure the popup and picker are shown
|
|
68
|
-
|
|
69
|
-
expect(wrapper.find('Popup')).toHaveLength(1);
|
|
70
|
-
const emojiPicker = wrapper.find('EmojiPickerInternal').instance(); // calling mock callback
|
|
71
|
-
|
|
72
|
-
act(() => {
|
|
73
|
-
emojiPicker.props.onSelection({
|
|
74
|
-
shortName: ':smiley:'
|
|
75
|
-
});
|
|
76
|
-
}); // make sure the on change callback is called
|
|
77
|
-
|
|
78
|
-
expect(onChangeMock).toBeCalledWith({
|
|
79
|
-
shortName: ':smiley:'
|
|
80
|
-
});
|
|
81
|
-
wrapper.update(); // make sure popup is hidden
|
|
82
|
-
|
|
83
|
-
expect(wrapper.find('Popup')).toHaveLength(0);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
2
|
-
import { caption, doc, media, mediaSingle, p } from '@atlaskit/editor-test-helpers/doc-builder';
|
|
3
|
-
import * as analyticsUtils from '../../analytics/utils';
|
|
4
|
-
import { insertAndSelectCaptionFromMediaSinglePos, selectCaptionFromMediaSinglePos } from './captions';
|
|
5
|
-
describe('Caption plugin', () => {
|
|
6
|
-
const createEditor = createEditorFactory();
|
|
7
|
-
|
|
8
|
-
const editor = (doc, opts = {}) => createEditor({
|
|
9
|
-
doc,
|
|
10
|
-
...opts
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should insert the caption node and select it', () => {
|
|
14
|
-
const {
|
|
15
|
-
editorView
|
|
16
|
-
} = editor(doc('{<node>}', mediaSingle()(media({
|
|
17
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
18
|
-
type: 'file',
|
|
19
|
-
collection: 'MediaServicesSample'
|
|
20
|
-
})()), p('Line two')), {
|
|
21
|
-
editorProps: {
|
|
22
|
-
media: {
|
|
23
|
-
allowMediaSingle: true,
|
|
24
|
-
featureFlags: {
|
|
25
|
-
captions: true
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
insertAndSelectCaptionFromMediaSinglePos(0, editorView.state.doc.child(0))(editorView.state, editorView.dispatch);
|
|
31
|
-
expect(editorView.state).toEqualDocumentAndSelection(doc(mediaSingle()(media({
|
|
32
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
33
|
-
type: 'file',
|
|
34
|
-
collection: 'MediaServicesSample'
|
|
35
|
-
})(), caption('{<>}')), p('Line two')));
|
|
36
|
-
});
|
|
37
|
-
it('should not insert the caption node when it exists already', () => {
|
|
38
|
-
const {
|
|
39
|
-
editorView
|
|
40
|
-
} = editor(doc('{<node>}', mediaSingle()(media({
|
|
41
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
42
|
-
type: 'file',
|
|
43
|
-
collection: 'MediaServicesSample'
|
|
44
|
-
})(), caption('test')), p('Line two')), {
|
|
45
|
-
editorProps: {
|
|
46
|
-
media: {
|
|
47
|
-
allowMediaSingle: true,
|
|
48
|
-
featureFlags: {
|
|
49
|
-
captions: true
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
expect(insertAndSelectCaptionFromMediaSinglePos(0, editorView.state.doc.child(0))(editorView.state, editorView.dispatch)).toBeFalsy();
|
|
55
|
-
});
|
|
56
|
-
it('create an added analytic for captions', () => {
|
|
57
|
-
const addAnalyticsSpy = jest.spyOn(analyticsUtils, 'addAnalytics');
|
|
58
|
-
const {
|
|
59
|
-
editorView
|
|
60
|
-
} = editor(doc('{<node>}', mediaSingle()(media({
|
|
61
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
62
|
-
type: 'file',
|
|
63
|
-
collection: 'MediaServicesSample'
|
|
64
|
-
})()), p('Line two')), {
|
|
65
|
-
editorProps: {
|
|
66
|
-
media: {
|
|
67
|
-
allowMediaSingle: true,
|
|
68
|
-
featureFlags: {
|
|
69
|
-
captions: true
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
insertAndSelectCaptionFromMediaSinglePos(0, editorView.state.doc.child(0))(editorView.state, editorView.dispatch);
|
|
75
|
-
expect(addAnalyticsSpy).toBeCalled();
|
|
76
|
-
expect(addAnalyticsSpy.mock.calls[0][2]).toEqual({
|
|
77
|
-
action: 'added',
|
|
78
|
-
actionSubject: 'mediaSingle',
|
|
79
|
-
actionSubjectId: 'caption',
|
|
80
|
-
eventType: 'track'
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
it('should move selection to an existing caption node', () => {
|
|
84
|
-
const {
|
|
85
|
-
editorView
|
|
86
|
-
} = editor(doc('{<node>}', mediaSingle()(media({
|
|
87
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
88
|
-
type: 'file',
|
|
89
|
-
collection: 'MediaServicesSample'
|
|
90
|
-
})(), caption('hello world')), p('Line two')), {
|
|
91
|
-
editorProps: {
|
|
92
|
-
media: {
|
|
93
|
-
allowMediaSingle: true,
|
|
94
|
-
featureFlags: {
|
|
95
|
-
captions: true
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
selectCaptionFromMediaSinglePos(0, editorView.state.doc.child(0))(editorView.state, editorView.dispatch);
|
|
101
|
-
expect(editorView.state).toEqualDocumentAndSelection(doc(mediaSingle()(media({
|
|
102
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
103
|
-
type: 'file',
|
|
104
|
-
collection: 'MediaServicesSample'
|
|
105
|
-
})(), caption('hello world{<>}')), p('Line two')));
|
|
106
|
-
});
|
|
107
|
-
it('should not move selection to a non existing caption node', () => {
|
|
108
|
-
const {
|
|
109
|
-
editorView
|
|
110
|
-
} = editor(doc('{<node>}', mediaSingle()(media({
|
|
111
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
112
|
-
type: 'file',
|
|
113
|
-
collection: 'MediaServicesSample'
|
|
114
|
-
})()), p('Line two')), {
|
|
115
|
-
editorProps: {
|
|
116
|
-
media: {
|
|
117
|
-
allowMediaSingle: true,
|
|
118
|
-
featureFlags: {
|
|
119
|
-
captions: true
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
expect(selectCaptionFromMediaSinglePos(0, editorView.state.doc.child(0))(editorView.state, editorView.dispatch)).toBeFalsy();
|
|
125
|
-
});
|
|
126
|
-
});
|