@atlaskit/editor-core 150.0.1 → 151.1.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 +69 -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 +8 -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-bidi-warning/index.js +25 -0
- package/dist/cjs/plugins/code-bidi-warning/plugin-key.js +11 -0
- package/dist/cjs/plugins/code-bidi-warning/pm-plugins/main.js +43 -0
- package/dist/cjs/plugins/code-bidi-warning/pm-plugins/plugin-factory.js +118 -0
- package/dist/cjs/plugins/code-bidi-warning/pm-plugins/reducer.js +12 -0
- package/dist/cjs/plugins/code-bidi-warning/pm-plugins/types.js +5 -0
- package/dist/cjs/plugins/code-block/index.js +10 -6
- package/dist/cjs/plugins/code-block/nodeviews/highlighting-code-block.js +16 -5
- package/dist/cjs/plugins/code-block/pm-plugins/main.js +12 -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 +9 -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/index.js +8 -0
- 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/rank.js +1 -1
- 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/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 +9 -3
- 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-bidi-warning/index.js +15 -0
- package/dist/es2019/plugins/code-bidi-warning/plugin-key.js +2 -0
- package/dist/es2019/plugins/code-bidi-warning/pm-plugins/main.js +31 -0
- package/dist/es2019/plugins/code-bidi-warning/pm-plugins/plugin-factory.js +88 -0
- package/dist/es2019/plugins/code-bidi-warning/pm-plugins/reducer.js +3 -0
- package/dist/es2019/plugins/code-bidi-warning/pm-plugins/types.js +1 -0
- package/dist/es2019/plugins/code-block/index.js +6 -1
- package/dist/es2019/plugins/code-block/nodeviews/highlighting-code-block.js +16 -4
- package/dist/es2019/plugins/code-block/pm-plugins/main.js +50 -39
- 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 +9 -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/index.js +2 -1
- 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/rank.js +1 -1
- 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/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 +9 -3
- 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-bidi-warning/index.js +17 -0
- package/dist/esm/plugins/code-bidi-warning/plugin-key.js +2 -0
- package/dist/esm/plugins/code-bidi-warning/pm-plugins/main.js +30 -0
- package/dist/esm/plugins/code-bidi-warning/pm-plugins/plugin-factory.js +96 -0
- package/dist/esm/plugins/code-bidi-warning/pm-plugins/reducer.js +3 -0
- package/dist/esm/plugins/code-bidi-warning/pm-plugins/types.js +1 -0
- package/dist/esm/plugins/code-block/index.js +10 -6
- package/dist/esm/plugins/code-block/nodeviews/highlighting-code-block.js +16 -5
- package/dist/esm/plugins/code-block/pm-plugins/main.js +11 -3
- 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 +9 -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/index.js +2 -1
- 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/rank.js +1 -1
- 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/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/code-bidi-warning/index.d.ts +3 -0
- package/dist/types/plugins/code-bidi-warning/plugin-key.d.ts +2 -0
- package/dist/types/plugins/code-bidi-warning/pm-plugins/main.d.ts +3 -0
- package/dist/types/plugins/code-bidi-warning/pm-plugins/plugin-factory.d.ts +7 -0
- package/dist/types/plugins/code-bidi-warning/pm-plugins/reducer.d.ts +3 -0
- package/dist/types/plugins/code-bidi-warning/pm-plugins/types.d.ts +5 -0
- package/dist/types/plugins/code-block/nodeviews/highlighting-code-block.d.ts +11 -2
- package/dist/types/plugins/code-block/pm-plugins/main.d.ts +5 -1
- 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/index.d.ts +1 -0
- 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 +17 -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 +22 -19
- 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,208 +0,0 @@
|
|
|
1
|
-
import { a, doc, media, mediaSingle } from '@atlaskit/editor-test-helpers/doc-builder';
|
|
2
|
-
import { flushPromises, getDefaultMediaClientConfig } from '@atlaskit/media-test-helpers';
|
|
3
|
-
import { createProsemirrorEditorFactory, Preset } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
4
|
-
import sendKeyToPm from '@atlaskit/editor-test-helpers/send-key-to-pm';
|
|
5
|
-
import { ProviderFactory } from '@atlaskit/editor-common';
|
|
6
|
-
import hyperlinkPlugin from '../../hyperlink';
|
|
7
|
-
import mediaPlugin from '../';
|
|
8
|
-
import { MediaLinkingActionsTypes } from '../pm-plugins/linking/actions';
|
|
9
|
-
import { checkMediaType } from '../utils/check-media-type';
|
|
10
|
-
import { mediaLinkingPluginKey } from '../pm-plugins/linking';
|
|
11
|
-
import * as linking from './linking';
|
|
12
|
-
import { INPUT_METHOD } from '../../analytics/types';
|
|
13
|
-
import * as analyticUtils from '../../analytics/utils';
|
|
14
|
-
import * as commands from '../../../commands';
|
|
15
|
-
const {
|
|
16
|
-
setUrlToMedia,
|
|
17
|
-
showLinkingToolbarWithMediaTypeCheck,
|
|
18
|
-
unlink
|
|
19
|
-
} = linking;
|
|
20
|
-
jest.mock('../utils/check-media-type', () => ({
|
|
21
|
-
checkMediaType: jest.fn()
|
|
22
|
-
}));
|
|
23
|
-
describe('image linking', () => {
|
|
24
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
25
|
-
const preset = new Preset();
|
|
26
|
-
const mediaProvider = Promise.resolve({
|
|
27
|
-
viewMediaClientConfig: getDefaultMediaClientConfig()
|
|
28
|
-
});
|
|
29
|
-
const providerFactory = ProviderFactory.create({
|
|
30
|
-
mediaProvider
|
|
31
|
-
});
|
|
32
|
-
preset.add([mediaPlugin, {
|
|
33
|
-
allowMediaSingle: true,
|
|
34
|
-
allowLinking: true
|
|
35
|
-
}]).add(hyperlinkPlugin);
|
|
36
|
-
|
|
37
|
-
const editor = doc => {
|
|
38
|
-
return createEditor({
|
|
39
|
-
doc,
|
|
40
|
-
preset,
|
|
41
|
-
providerFactory
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const document = doc('{<node>}', mediaSingle()(media({
|
|
46
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
47
|
-
type: 'file',
|
|
48
|
-
collection: 'MediaServicesSample'
|
|
49
|
-
})()), mediaSingle()(media({
|
|
50
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
51
|
-
type: 'file',
|
|
52
|
-
collection: 'MediaServicesSample'
|
|
53
|
-
})()));
|
|
54
|
-
const mockDispatch = jest.fn();
|
|
55
|
-
afterEach(() => {
|
|
56
|
-
mockDispatch.mockClear();
|
|
57
|
-
});
|
|
58
|
-
describe('analytics', () => {
|
|
59
|
-
const FIRST_CALL = 0;
|
|
60
|
-
const ANALYTIC_PAYLOAD = 2;
|
|
61
|
-
const analyticUtilsSpy = jest.spyOn(analyticUtils, 'addAnalytics');
|
|
62
|
-
beforeEach(() => {
|
|
63
|
-
analyticUtilsSpy.mockReset();
|
|
64
|
-
});
|
|
65
|
-
afterAll(() => {
|
|
66
|
-
jest.resetAllMocks();
|
|
67
|
-
});
|
|
68
|
-
it('should call analytic when creating a link', () => {
|
|
69
|
-
const {
|
|
70
|
-
editorView
|
|
71
|
-
} = editor(document);
|
|
72
|
-
setUrlToMedia('http://google.com', INPUT_METHOD.MANUAL)(editorView.state, mockDispatch, editorView);
|
|
73
|
-
expect(analyticUtilsSpy).toBeCalled();
|
|
74
|
-
expect(analyticUtilsSpy.mock.calls[FIRST_CALL][ANALYTIC_PAYLOAD]).toEqual({
|
|
75
|
-
action: 'added',
|
|
76
|
-
actionSubject: 'media',
|
|
77
|
-
actionSubjectId: 'link',
|
|
78
|
-
attributes: expect.objectContaining({
|
|
79
|
-
inputMethod: 'manual'
|
|
80
|
-
}),
|
|
81
|
-
eventType: 'track'
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
describe('existing links', () => {
|
|
85
|
-
const googleUrl = 'http://google.com';
|
|
86
|
-
const documentWithMediaWithLink = doc('{<node>}', mediaSingle()(a({
|
|
87
|
-
href: googleUrl
|
|
88
|
-
})(media({
|
|
89
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
90
|
-
type: 'file',
|
|
91
|
-
collection: 'MediaServicesSample'
|
|
92
|
-
})())));
|
|
93
|
-
it('should add edit analytic when modifying link', () => {
|
|
94
|
-
const {
|
|
95
|
-
editorView
|
|
96
|
-
} = editor(documentWithMediaWithLink);
|
|
97
|
-
setUrlToMedia('http://random-url.com', INPUT_METHOD.MANUAL)(editorView.state, editorView.dispatch, editorView);
|
|
98
|
-
expect(analyticUtilsSpy).toHaveBeenCalledTimes(1);
|
|
99
|
-
expect(analyticUtilsSpy.mock.calls[FIRST_CALL][ANALYTIC_PAYLOAD]).toEqual({
|
|
100
|
-
action: 'edited',
|
|
101
|
-
actionSubject: 'media',
|
|
102
|
-
actionSubjectId: 'link',
|
|
103
|
-
eventType: 'track'
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
it('should delete analytic when removing a link', () => {
|
|
107
|
-
const {
|
|
108
|
-
editorView
|
|
109
|
-
} = editor(documentWithMediaWithLink);
|
|
110
|
-
unlink(editorView.state, editorView.dispatch, editorView);
|
|
111
|
-
expect(analyticUtilsSpy).toBeCalledTimes(1);
|
|
112
|
-
expect(analyticUtilsSpy.mock.calls[FIRST_CALL][ANALYTIC_PAYLOAD]).toEqual({
|
|
113
|
-
action: 'deleted',
|
|
114
|
-
actionSubject: 'media',
|
|
115
|
-
actionSubjectId: 'link',
|
|
116
|
-
eventType: 'track'
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
it("shouldn't call an analytic if the url was modified to the same url", () => {
|
|
120
|
-
const {
|
|
121
|
-
editorView
|
|
122
|
-
} = editor(documentWithMediaWithLink);
|
|
123
|
-
setUrlToMedia(googleUrl, INPUT_METHOD.MANUAL)(editorView.state, mockDispatch, editorView);
|
|
124
|
-
expect(analyticUtilsSpy).not.toBeCalled();
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
describe('errors', () => {
|
|
128
|
-
beforeAll(() => {
|
|
129
|
-
jest.spyOn(commands, 'createToggleBlockMarkOnRange').mockImplementation(() => {
|
|
130
|
-
throw new Error('This error should be caught');
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
it("should call analytic if there's an error creating a link", () => {
|
|
134
|
-
const {
|
|
135
|
-
editorView
|
|
136
|
-
} = editor(document);
|
|
137
|
-
|
|
138
|
-
try {
|
|
139
|
-
setUrlToMedia('http://google.com', INPUT_METHOD.MANUAL)(editorView.state, mockDispatch, editorView);
|
|
140
|
-
} catch (e) {// noop
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
expect(analyticUtilsSpy.mock.calls[FIRST_CALL][ANALYTIC_PAYLOAD]).toEqual({
|
|
144
|
-
action: 'errored',
|
|
145
|
-
actionSubject: 'media',
|
|
146
|
-
actionSubjectId: 'link',
|
|
147
|
-
attributes: {
|
|
148
|
-
action: 'added'
|
|
149
|
-
},
|
|
150
|
-
eventType: 'track'
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
describe('show linking toolbar', () => {
|
|
156
|
-
describe('selected media is an image', () => {
|
|
157
|
-
beforeAll(() => {
|
|
158
|
-
checkMediaType.mockReturnValue(Promise.resolve('image'));
|
|
159
|
-
});
|
|
160
|
-
it('call dispatch with correct param with a media is selected', async () => {
|
|
161
|
-
const {
|
|
162
|
-
editorView
|
|
163
|
-
} = editor(document);
|
|
164
|
-
await flushPromises();
|
|
165
|
-
const result = showLinkingToolbarWithMediaTypeCheck(editorView.state, mockDispatch, editorView);
|
|
166
|
-
const expectTransaction = editorView.state.tr.setMeta(mediaLinkingPluginKey, {
|
|
167
|
-
type: MediaLinkingActionsTypes.showToolbar
|
|
168
|
-
});
|
|
169
|
-
await flushPromises();
|
|
170
|
-
expect(result).toEqual(true);
|
|
171
|
-
expect(mockDispatch).toHaveBeenCalledWith(expectTransaction);
|
|
172
|
-
});
|
|
173
|
-
it('does not call dispatch when selection is not a media single node', async () => {
|
|
174
|
-
const {
|
|
175
|
-
editorView
|
|
176
|
-
} = editor(document);
|
|
177
|
-
const result = showLinkingToolbarWithMediaTypeCheck(editorView.state, mockDispatch, editorView);
|
|
178
|
-
await flushPromises();
|
|
179
|
-
expect(result).toEqual(false);
|
|
180
|
-
expect(mockDispatch).not.toHaveBeenCalled();
|
|
181
|
-
});
|
|
182
|
-
it('does not call dispatch when selection has changed', async () => {
|
|
183
|
-
const {
|
|
184
|
-
editorView
|
|
185
|
-
} = editor(document);
|
|
186
|
-
const result = showLinkingToolbarWithMediaTypeCheck(editorView.state, mockDispatch, editorView);
|
|
187
|
-
sendKeyToPm(editorView, 'ArrowDown');
|
|
188
|
-
await flushPromises();
|
|
189
|
-
expect(result).toEqual(false);
|
|
190
|
-
expect(mockDispatch).not.toHaveBeenCalled();
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
describe('selected media is a video', () => {
|
|
194
|
-
beforeAll(() => {
|
|
195
|
-
checkMediaType.mockReturnValue(Promise.resolve('video'));
|
|
196
|
-
});
|
|
197
|
-
it('does not call dispatch', async () => {
|
|
198
|
-
const {
|
|
199
|
-
editorView
|
|
200
|
-
} = editor(document);
|
|
201
|
-
const result = showLinkingToolbarWithMediaTypeCheck(editorView.state, mockDispatch, editorView);
|
|
202
|
-
await flushPromises();
|
|
203
|
-
expect(result).toEqual(false);
|
|
204
|
-
expect(mockDispatch).not.toHaveBeenCalled();
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import { IntlProvider } from 'react-intl';
|
|
4
|
-
import { N200 } from '@atlaskit/theme/colors';
|
|
5
|
-
import { messages } from './messages';
|
|
6
|
-
import CaptionPlaceholder from './index';
|
|
7
|
-
|
|
8
|
-
const renderWithIntl = component => {
|
|
9
|
-
return render( /*#__PURE__*/React.createElement(IntlProvider, {
|
|
10
|
-
locale: "en"
|
|
11
|
-
}, component));
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const onClick = () => {};
|
|
15
|
-
|
|
16
|
-
describe('CaptionComponent', () => {
|
|
17
|
-
it('should show a placeholder by default', () => {
|
|
18
|
-
const {
|
|
19
|
-
getByText
|
|
20
|
-
} = renderWithIntl( /*#__PURE__*/React.createElement(CaptionPlaceholder, {
|
|
21
|
-
onClick: onClick
|
|
22
|
-
}));
|
|
23
|
-
expect(getByText(messages.placeholder.defaultMessage)).not.toBeNull();
|
|
24
|
-
});
|
|
25
|
-
it('should have the placeholder colour as N200', () => {
|
|
26
|
-
const {
|
|
27
|
-
container
|
|
28
|
-
} = renderWithIntl( /*#__PURE__*/React.createElement(CaptionPlaceholder, {
|
|
29
|
-
onClick: onClick
|
|
30
|
-
}));
|
|
31
|
-
expect(container.firstChild).toHaveStyle(`color: ${N200}`);
|
|
32
|
-
});
|
|
33
|
-
it('placeholder should be centered', () => {
|
|
34
|
-
const {
|
|
35
|
-
container
|
|
36
|
-
} = renderWithIntl( /*#__PURE__*/React.createElement(CaptionPlaceholder, {
|
|
37
|
-
onClick: onClick
|
|
38
|
-
}));
|
|
39
|
-
expect(container.firstChild).toHaveStyle(`text-align: center`);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import defaultSchema from '@atlaskit/editor-test-helpers/schema';
|
|
2
|
-
import { ProviderFactory } from '@atlaskit/editor-common';
|
|
3
|
-
import { getTestEmojiResource } from '@atlaskit/util-data-test/get-test-emoji-resource';
|
|
4
|
-
import { getToolbarItems } from './toolbar';
|
|
5
|
-
import * as actions from '../panel/actions';
|
|
6
|
-
import { DEFAULT_BORDER_COLOR } from '../../ui/ColorPalette/Palettes';
|
|
7
|
-
import { createProsemirrorEditorFactory, Preset } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
8
|
-
import panelPlugin from '.';
|
|
9
|
-
import { doc, p, panel } from '@atlaskit/editor-test-helpers/doc-builder';
|
|
10
|
-
import { PanelType } from '@atlaskit/adf-schema';
|
|
11
|
-
import analyticsPlugin from '../analytics';
|
|
12
|
-
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, ACTION_SUBJECT_ID } from '../analytics';
|
|
13
|
-
import { emojiPluginKey } from '../emoji';
|
|
14
|
-
|
|
15
|
-
const dummyFormatMessage = messageDescriptor => messageDescriptor.defaultMessage || '';
|
|
16
|
-
|
|
17
|
-
const changePanelTypespy = jest.spyOn(actions, 'changePanelType');
|
|
18
|
-
describe('getToolbarItems', () => {
|
|
19
|
-
const providerFactory = new ProviderFactory();
|
|
20
|
-
providerFactory.setProvider('emojiProvider', Promise.resolve(getTestEmojiResource()));
|
|
21
|
-
const panelPreset = new Preset().add([panelPlugin, {
|
|
22
|
-
UNSAFE_allowCustomPanel: true
|
|
23
|
-
}]);
|
|
24
|
-
const itemsWithCustomPanelEnabled = getToolbarItems(dummyFormatMessage, defaultSchema.nodes.panel, true, providerFactory, PanelType.INFO);
|
|
25
|
-
afterEach(() => {
|
|
26
|
-
jest.clearAllMocks();
|
|
27
|
-
});
|
|
28
|
-
it('should return 7 items when isCustomPanelEnabled is false', () => {
|
|
29
|
-
const items = getToolbarItems(dummyFormatMessage, defaultSchema.nodes.panel, false, providerFactory);
|
|
30
|
-
expect(items).toHaveLength(7);
|
|
31
|
-
});
|
|
32
|
-
describe('if isCustomPanelEnabled is true', () => {
|
|
33
|
-
it('should return 11 items', () => {
|
|
34
|
-
expect(itemsWithCustomPanelEnabled).toHaveLength(11);
|
|
35
|
-
});
|
|
36
|
-
it('should contain emoji and color picker button', () => {
|
|
37
|
-
const emojiButton = itemsWithCustomPanelEnabled.find(item => item.type === 'select' && item.selectType === 'emoji');
|
|
38
|
-
const colorButton = itemsWithCustomPanelEnabled.find(item => item.type === 'select' && item.selectType === 'color');
|
|
39
|
-
expect(emojiButton).not.toBeUndefined();
|
|
40
|
-
expect(colorButton).not.toBeUndefined();
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
describe('custom panel toolbar items', () => {
|
|
44
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
45
|
-
const {
|
|
46
|
-
editorView
|
|
47
|
-
} = createEditor({
|
|
48
|
-
doc: doc(panel({
|
|
49
|
-
panelType: 'info'
|
|
50
|
-
})(p('{<>}'))),
|
|
51
|
-
preset: panelPreset,
|
|
52
|
-
providerFactory
|
|
53
|
-
});
|
|
54
|
-
it(`should call changePanelType when clicked on emoji picker
|
|
55
|
-
with changed emoji`, () => {
|
|
56
|
-
const emojiPickerConfig = itemsWithCustomPanelEnabled.find(item => item.type === 'select' && item.selectType === 'emoji');
|
|
57
|
-
emojiPickerConfig.onChange(':smiley:')(editorView.state);
|
|
58
|
-
expect(changePanelTypespy).toBeCalledWith(PanelType.CUSTOM, {
|
|
59
|
-
emoji: ':smiley:'
|
|
60
|
-
}, true);
|
|
61
|
-
});
|
|
62
|
-
it(`should call changePanelType when clicked on color picker
|
|
63
|
-
with changed color`, () => {
|
|
64
|
-
const colorPickerConfig = itemsWithCustomPanelEnabled.find(item => item.type === 'select' && item.selectType === 'color');
|
|
65
|
-
colorPickerConfig.onChange({
|
|
66
|
-
label: 'Mintie',
|
|
67
|
-
value: '#ABF5D1',
|
|
68
|
-
border: DEFAULT_BORDER_COLOR
|
|
69
|
-
})(editorView.state);
|
|
70
|
-
expect(changePanelTypespy).toBeCalledWith(PanelType.CUSTOM, {
|
|
71
|
-
color: '#ABF5D1'
|
|
72
|
-
}, true);
|
|
73
|
-
});
|
|
74
|
-
it(`should call changePanelType when clicked on remove emoji`, () => {
|
|
75
|
-
const removeEmojiButton = itemsWithCustomPanelEnabled.find(item => item.type === 'button' && item.id === 'editor.panel.removeEmoji');
|
|
76
|
-
removeEmojiButton.onClick(editorView.state);
|
|
77
|
-
expect(changePanelTypespy).toBeCalledWith(PanelType.CUSTOM, {
|
|
78
|
-
emoji: undefined
|
|
79
|
-
}, true);
|
|
80
|
-
});
|
|
81
|
-
it(`should not call changePanelType when clicked on remove emoji when no emoji in panel`, () => {
|
|
82
|
-
const {
|
|
83
|
-
editorView
|
|
84
|
-
} = createEditor({
|
|
85
|
-
doc: doc(panel({
|
|
86
|
-
panelType: 'custom'
|
|
87
|
-
})(p('{<>}'))),
|
|
88
|
-
preset: panelPreset,
|
|
89
|
-
providerFactory
|
|
90
|
-
});
|
|
91
|
-
const toolbarItems = getToolbarItems(dummyFormatMessage, defaultSchema.nodes.panel, true, providerFactory, PanelType.CUSTOM);
|
|
92
|
-
const removeEmojiButton = toolbarItems.find(item => item.type === 'button' && item.id === 'editor.panel.removeEmoji');
|
|
93
|
-
changePanelTypespy.mockClear();
|
|
94
|
-
removeEmojiButton.onClick(editorView.state);
|
|
95
|
-
expect(changePanelTypespy).not.toBeCalled();
|
|
96
|
-
});
|
|
97
|
-
it(`should have remove emoji button disabled when focus on panel without emoji`, () => {
|
|
98
|
-
const toolbarItems = getToolbarItems(dummyFormatMessage, defaultSchema.nodes.panel, true, providerFactory, PanelType.CUSTOM, '#ABF5D1', '');
|
|
99
|
-
const removeEmojiButton = toolbarItems.find(item => item.type === 'button' && item.id === 'editor.panel.removeEmoji');
|
|
100
|
-
expect(removeEmojiButton.disabled).toBe(true);
|
|
101
|
-
});
|
|
102
|
-
it(`should have remove emoji button enabled when focus on panel with emoji`, () => {
|
|
103
|
-
const toolbarItems = getToolbarItems(dummyFormatMessage, defaultSchema.nodes.panel, true, providerFactory, PanelType.CUSTOM, '#ABF5D1', ':smiley:');
|
|
104
|
-
const removeEmojiButton = toolbarItems.find(item => item.type === 'button' && item.id === 'editor.panel.removeEmoji');
|
|
105
|
-
expect(removeEmojiButton.disabled).toBe(false);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
describe('analytics for custom panels', () => {
|
|
109
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
110
|
-
let createAnalyticsEvent = jest.fn(() => ({
|
|
111
|
-
fire() {}
|
|
112
|
-
|
|
113
|
-
}));
|
|
114
|
-
let editorView;
|
|
115
|
-
beforeEach(() => {
|
|
116
|
-
({
|
|
117
|
-
editorView
|
|
118
|
-
} = createEditor({
|
|
119
|
-
doc: doc(panel({
|
|
120
|
-
panelType: 'info'
|
|
121
|
-
})(p('{<>}'))),
|
|
122
|
-
preset: panelPreset.add([analyticsPlugin, {
|
|
123
|
-
createAnalyticsEvent
|
|
124
|
-
}]),
|
|
125
|
-
providerFactory,
|
|
126
|
-
pluginKey: emojiPluginKey
|
|
127
|
-
}));
|
|
128
|
-
});
|
|
129
|
-
it('Should trigger analytics when background color is changed', () => {
|
|
130
|
-
const colorPickerConfig = itemsWithCustomPanelEnabled.find(item => item.type === 'select' && item.selectType === 'color');
|
|
131
|
-
colorPickerConfig.onChange({
|
|
132
|
-
label: 'Mintie',
|
|
133
|
-
value: '#ABF5D1',
|
|
134
|
-
border: DEFAULT_BORDER_COLOR
|
|
135
|
-
})(editorView.state, editorView.dispatch);
|
|
136
|
-
const payload = {
|
|
137
|
-
action: ACTION.CHANGED_BACKGROUND_COLOR,
|
|
138
|
-
actionSubject: ACTION_SUBJECT.PANEL,
|
|
139
|
-
actionSubjectId: ACTION_SUBJECT_ID.PANEL,
|
|
140
|
-
attributes: expect.objectContaining({
|
|
141
|
-
newColor: '#ABF5D1',
|
|
142
|
-
previousColor: '#DEEBFF'
|
|
143
|
-
}),
|
|
144
|
-
eventType: EVENT_TYPE.TRACK
|
|
145
|
-
};
|
|
146
|
-
expect(createAnalyticsEvent).toHaveBeenCalledWith(payload);
|
|
147
|
-
});
|
|
148
|
-
it('Should trigger analytics when Icon is changed', () => {
|
|
149
|
-
const emojiPickerConfig = itemsWithCustomPanelEnabled.find(item => item.type === 'select' && item.selectType === 'emoji');
|
|
150
|
-
emojiPickerConfig.onChange(':smiley:')(editorView.state, editorView.dispatch);
|
|
151
|
-
const payload = {
|
|
152
|
-
action: ACTION.CHANGED_ICON,
|
|
153
|
-
actionSubject: ACTION_SUBJECT.PANEL,
|
|
154
|
-
actionSubjectId: ACTION_SUBJECT_ID.PANEL,
|
|
155
|
-
attributes: expect.objectContaining({
|
|
156
|
-
newIcon: ':smiley:',
|
|
157
|
-
previousIcon: ''
|
|
158
|
-
}),
|
|
159
|
-
eventType: EVENT_TYPE.TRACK
|
|
160
|
-
};
|
|
161
|
-
expect(createAnalyticsEvent).toHaveBeenCalledWith(payload);
|
|
162
|
-
});
|
|
163
|
-
it('Should trigger analytics when Icon is removed', () => {
|
|
164
|
-
const removeEmojiButton = itemsWithCustomPanelEnabled.find(item => item.type === 'button' && item.id === 'editor.panel.removeEmoji');
|
|
165
|
-
const emojiPickerConfig = itemsWithCustomPanelEnabled.find(item => item.type === 'select' && item.selectType === 'emoji');
|
|
166
|
-
emojiPickerConfig.onChange(':smiley:')(editorView.state, editorView.dispatch);
|
|
167
|
-
removeEmojiButton.onClick(editorView.state, editorView.dispatch);
|
|
168
|
-
const payload = {
|
|
169
|
-
action: ACTION.REMOVE_ICON,
|
|
170
|
-
actionSubject: ACTION_SUBJECT.PANEL,
|
|
171
|
-
actionSubjectId: ACTION_SUBJECT_ID.PANEL,
|
|
172
|
-
attributes: expect.objectContaining({
|
|
173
|
-
icon: ':smiley:'
|
|
174
|
-
}),
|
|
175
|
-
eventType: EVENT_TYPE.TRACK
|
|
176
|
-
};
|
|
177
|
-
expect(createAnalyticsEvent).nthCalledWith(4, payload);
|
|
178
|
-
});
|
|
179
|
-
it('Should not fire analytics when the same background color is selected', () => {
|
|
180
|
-
const colorPickerConfig = itemsWithCustomPanelEnabled.find(item => item.type === 'select' && item.selectType === 'color');
|
|
181
|
-
colorPickerConfig.onChange({
|
|
182
|
-
label: 'Mintie',
|
|
183
|
-
value: '#ABF5D1',
|
|
184
|
-
border: DEFAULT_BORDER_COLOR
|
|
185
|
-
})(editorView.state, editorView.dispatch);
|
|
186
|
-
colorPickerConfig.onChange({
|
|
187
|
-
label: 'Mintie',
|
|
188
|
-
value: '#ABF5D1',
|
|
189
|
-
border: DEFAULT_BORDER_COLOR
|
|
190
|
-
})(editorView.state, editorView.dispatch);
|
|
191
|
-
expect(createAnalyticsEvent).toHaveBeenCalledTimes(3);
|
|
192
|
-
});
|
|
193
|
-
it('Should not fire analtyics when same emoji is selected', () => {
|
|
194
|
-
const emojiPickerConfig = itemsWithCustomPanelEnabled.find(item => item.type === 'select' && item.selectType === 'emoji');
|
|
195
|
-
emojiPickerConfig.onChange(':smiley:')(editorView.state, editorView.dispatch);
|
|
196
|
-
emojiPickerConfig.onChange(':smiley:')(editorView.state, editorView.dispatch);
|
|
197
|
-
expect(createAnalyticsEvent).toHaveBeenCalledTimes(3);
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
});
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mountWithIntl } from '@atlaskit/editor-test-helpers/enzyme'; // AFP-2532 TODO: Fix automatic suppressions below
|
|
3
|
-
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
4
|
-
|
|
5
|
-
import { colors } from '@atlaskit/theme';
|
|
6
|
-
import { DEFAULT_BORDER_COLOR } from '../ColorPalette/Palettes';
|
|
7
|
-
import { panelBackgroundPalette } from '../ColorPalette/Palettes/panelBackgroundPalette';
|
|
8
|
-
import { mockCreateAnalyticsEvent, mockFire } from '@atlaskit/editor-test-helpers/mock-analytics-next';
|
|
9
|
-
import ColorPickerButton from './index';
|
|
10
|
-
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '../../plugins/analytics/types';
|
|
11
|
-
import { editorAnalyticsChannel } from '../../plugins/analytics/consts';
|
|
12
|
-
import { act } from 'react-dom/test-utils';
|
|
13
|
-
describe('color-picker-button', () => {
|
|
14
|
-
const onChangeMock = jest.fn();
|
|
15
|
-
|
|
16
|
-
const getWrapper = (placement = '') => mountWithIntl( /*#__PURE__*/React.createElement(ColorPickerButton, {
|
|
17
|
-
onChange: onChangeMock,
|
|
18
|
-
colorPalette: panelBackgroundPalette,
|
|
19
|
-
placement: placement
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
const selectColor = (wrapper, colorLabel) => {
|
|
23
|
-
// show popup
|
|
24
|
-
wrapper.find('button').simulate('click'); // select purple
|
|
25
|
-
|
|
26
|
-
wrapper.find('Color').findWhere(node => node.prop('label') === colorLabel).find('button').simulate('click');
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
jest.clearAllMocks();
|
|
31
|
-
});
|
|
32
|
-
it('should render a button', () => {
|
|
33
|
-
const wrapper = getWrapper();
|
|
34
|
-
expect(wrapper.find('button')).toHaveLength(1); // ensure no popup is rendered
|
|
35
|
-
|
|
36
|
-
expect(wrapper.find('Popup')).toHaveLength(0);
|
|
37
|
-
});
|
|
38
|
-
it('should show a ColorPalette popup after clicking button', () => {
|
|
39
|
-
const wrapper = getWrapper(); // show the popup
|
|
40
|
-
|
|
41
|
-
wrapper.find('button').simulate('click');
|
|
42
|
-
expect(wrapper.find('Popup')).toHaveLength(1);
|
|
43
|
-
expect(wrapper.find('ColorPalette')).toHaveLength(1);
|
|
44
|
-
expect(wrapper.find('Color')).toHaveLength(21);
|
|
45
|
-
});
|
|
46
|
-
it('should close ColorPalette popup after clicking outside', () => {
|
|
47
|
-
const wrapper = getWrapper(); // show the popup
|
|
48
|
-
|
|
49
|
-
wrapper.find('button').simulate('click'); // make sure the popup and picker are shown
|
|
50
|
-
|
|
51
|
-
expect(wrapper.find('Popup')).toHaveLength(1);
|
|
52
|
-
const colorPalette = wrapper.find('InjectIntl(ColorPalette)').instance();
|
|
53
|
-
act(() => {
|
|
54
|
-
colorPalette.props.handleClickOutside();
|
|
55
|
-
});
|
|
56
|
-
wrapper.update(); // make sure popup is hidden
|
|
57
|
-
|
|
58
|
-
expect(wrapper.find('Popup')).toHaveLength(0);
|
|
59
|
-
});
|
|
60
|
-
it('should hide popup and call onChange after selecting a color', () => {
|
|
61
|
-
const wrapper = getWrapper();
|
|
62
|
-
selectColor(wrapper, 'Mintie'); // ensure popup is hidden
|
|
63
|
-
|
|
64
|
-
expect(wrapper.find('Popup')).toHaveLength(0); // ensure callback was called
|
|
65
|
-
|
|
66
|
-
expect(onChangeMock).toBeCalledWith({
|
|
67
|
-
label: 'Mintie',
|
|
68
|
-
value: colors.G75,
|
|
69
|
-
border: DEFAULT_BORDER_COLOR
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
it('analytics', async () => {
|
|
73
|
-
const wrapper = getWrapper('ConfigPanel');
|
|
74
|
-
selectColor(wrapper, 'Doctor');
|
|
75
|
-
expect(mockCreateAnalyticsEvent).toHaveBeenCalledWith({
|
|
76
|
-
action: ACTION.UPDATED,
|
|
77
|
-
actionSubject: ACTION_SUBJECT.PICKER,
|
|
78
|
-
actionSubjectId: ACTION_SUBJECT_ID.PICKER_COLOR,
|
|
79
|
-
attributes: {
|
|
80
|
-
color: '#FFFFFF',
|
|
81
|
-
label: 'Doctor',
|
|
82
|
-
placement: 'ConfigPanel'
|
|
83
|
-
},
|
|
84
|
-
eventType: EVENT_TYPE.TRACK
|
|
85
|
-
});
|
|
86
|
-
expect(mockFire).toHaveBeenCalledWith(editorAnalyticsChannel);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
jest.mock('react-dom', () => ({ ...jest.requireActual('react-dom'),
|
|
2
|
-
unmountComponentAtNode: jest.fn()
|
|
3
|
-
}));
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import { unmountComponentAtNode } from 'react-dom';
|
|
6
|
-
import { mount } from 'enzyme';
|
|
7
|
-
import { AnalyticsListener, useAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
8
|
-
import { PortalProvider, PortalRenderer } from './';
|
|
9
|
-
import { ContextAdapter } from '../../nodeviews/context-adapter';
|
|
10
|
-
|
|
11
|
-
const Component = () => /*#__PURE__*/React.createElement("div", {
|
|
12
|
-
className: "component"
|
|
13
|
-
}, "My component");
|
|
14
|
-
|
|
15
|
-
const Component2 = () => {
|
|
16
|
-
const {
|
|
17
|
-
createAnalyticsEvent
|
|
18
|
-
} = useAnalyticsEvents();
|
|
19
|
-
const event = createAnalyticsEvent({});
|
|
20
|
-
event.fire('portalprovidertest');
|
|
21
|
-
return /*#__PURE__*/React.createElement("div", null, "Component 2");
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const ComponentWithAnalytics = () => /*#__PURE__*/React.createElement(Component2, null);
|
|
25
|
-
|
|
26
|
-
describe('PortalProvider', () => {
|
|
27
|
-
let portalProviderAPI;
|
|
28
|
-
let wrapper;
|
|
29
|
-
let place;
|
|
30
|
-
let place2;
|
|
31
|
-
let handleAnalyticsEvent;
|
|
32
|
-
let handleAnalyticsEventFromContext;
|
|
33
|
-
|
|
34
|
-
const initPortalProvider = () => {
|
|
35
|
-
handleAnalyticsEvent = jest.fn();
|
|
36
|
-
handleAnalyticsEventFromContext = jest.fn();
|
|
37
|
-
wrapper = mount( /*#__PURE__*/React.createElement(AnalyticsListener, {
|
|
38
|
-
channel: "portalprovidertest",
|
|
39
|
-
onEvent: handleAnalyticsEventFromContext
|
|
40
|
-
}, /*#__PURE__*/React.createElement(ContextAdapter, null, /*#__PURE__*/React.createElement(PortalProvider, {
|
|
41
|
-
onAnalyticsEvent: handleAnalyticsEvent,
|
|
42
|
-
useAnalyticsContext: true,
|
|
43
|
-
render: api => {
|
|
44
|
-
portalProviderAPI = api;
|
|
45
|
-
return /*#__PURE__*/React.createElement(PortalRenderer, {
|
|
46
|
-
portalProviderAPI: api
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}))));
|
|
50
|
-
portalProviderAPI.render(Component, place);
|
|
51
|
-
wrapper.update();
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
beforeEach(() => {
|
|
55
|
-
jest.resetAllMocks();
|
|
56
|
-
place = document.body.appendChild(document.createElement('div'));
|
|
57
|
-
place.classList.add('place');
|
|
58
|
-
place2 = document.body.appendChild(document.createElement('div'));
|
|
59
|
-
place2.classList.add('place2');
|
|
60
|
-
initPortalProvider();
|
|
61
|
-
});
|
|
62
|
-
afterEach(() => {
|
|
63
|
-
place.parentNode.removeChild(place);
|
|
64
|
-
place2.parentNode.removeChild(place2);
|
|
65
|
-
});
|
|
66
|
-
it('should render a component successfully', () => {
|
|
67
|
-
expect(mount( /*#__PURE__*/React.createElement(Component, null)).html()).toEqual(place.innerHTML);
|
|
68
|
-
});
|
|
69
|
-
it('should render several components successfully', () => {
|
|
70
|
-
portalProviderAPI.render(Component, place2);
|
|
71
|
-
wrapper.update();
|
|
72
|
-
const component = mount( /*#__PURE__*/React.createElement(Component, null));
|
|
73
|
-
expect(component.html()).toEqual(place.innerHTML);
|
|
74
|
-
expect(component.html()).toEqual(place2.innerHTML);
|
|
75
|
-
});
|
|
76
|
-
it('should destroy a component successfully', () => {
|
|
77
|
-
portalProviderAPI.remove(place);
|
|
78
|
-
wrapper.update();
|
|
79
|
-
expect(unmountComponentAtNode).toBeCalledWith(place);
|
|
80
|
-
});
|
|
81
|
-
describe('React throws an error while unmounting child component', () => {
|
|
82
|
-
const error = new Error('Something happened...');
|
|
83
|
-
beforeEach(() => {
|
|
84
|
-
unmountComponentAtNode.mockImplementation(() => {
|
|
85
|
-
throw error;
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
it('should not throw error', () => {
|
|
89
|
-
expect(() => portalProviderAPI.remove(place)).not.toThrowError();
|
|
90
|
-
});
|
|
91
|
-
it('should fire analytics if React throws an error when unmounting', () => {
|
|
92
|
-
portalProviderAPI.remove(place);
|
|
93
|
-
expect(handleAnalyticsEvent).toHaveBeenCalledWith({
|
|
94
|
-
payload: {
|
|
95
|
-
action: 'failedToUnmount',
|
|
96
|
-
actionSubject: 'editor',
|
|
97
|
-
actionSubjectId: 'reactNodeView',
|
|
98
|
-
attributes: {
|
|
99
|
-
error,
|
|
100
|
-
domNodes: {
|
|
101
|
-
container: 'place',
|
|
102
|
-
child: 'component'
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
eventType: 'operational'
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
it('should propogate events up from child component', () => {
|
|
111
|
-
portalProviderAPI.render(ComponentWithAnalytics, place);
|
|
112
|
-
wrapper.update();
|
|
113
|
-
expect(handleAnalyticsEventFromContext).toBeCalledTimes(1);
|
|
114
|
-
});
|
|
115
|
-
});
|