@atlaskit/editor-core 150.0.3 → 151.1.2
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/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/HyperlinkToolbarAppearance.js +2 -2
- 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/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/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/HyperlinkToolbarAppearance.js +1 -1
- 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/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 +5 -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/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/HyperlinkToolbarAppearance.js +2 -2
- 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/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 +2 -0
- 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/extension/types.d.ts +0 -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/HyperlinkToolbarAppearance.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/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/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 +21 -18
- 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,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _react = _interopRequireDefault(require("react"));
|
|
6
|
-
|
|
7
|
-
var _react2 = require("@testing-library/react");
|
|
8
|
-
|
|
9
|
-
var _reactIntl = require("react-intl");
|
|
10
|
-
|
|
11
|
-
var _colors = require("@atlaskit/theme/colors");
|
|
12
|
-
|
|
13
|
-
var _messages = require("./messages");
|
|
14
|
-
|
|
15
|
-
var _index = _interopRequireDefault(require("./index"));
|
|
16
|
-
|
|
17
|
-
var renderWithIntl = function renderWithIntl(component) {
|
|
18
|
-
return (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_reactIntl.IntlProvider, {
|
|
19
|
-
locale: "en"
|
|
20
|
-
}, component));
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
var onClick = function onClick() {};
|
|
24
|
-
|
|
25
|
-
describe('CaptionComponent', function () {
|
|
26
|
-
it('should show a placeholder by default', function () {
|
|
27
|
-
var _renderWithIntl = renderWithIntl( /*#__PURE__*/_react.default.createElement(_index.default, {
|
|
28
|
-
onClick: onClick
|
|
29
|
-
})),
|
|
30
|
-
getByText = _renderWithIntl.getByText;
|
|
31
|
-
|
|
32
|
-
expect(getByText(_messages.messages.placeholder.defaultMessage)).not.toBeNull();
|
|
33
|
-
});
|
|
34
|
-
it('should have the placeholder colour as N200', function () {
|
|
35
|
-
var _renderWithIntl2 = renderWithIntl( /*#__PURE__*/_react.default.createElement(_index.default, {
|
|
36
|
-
onClick: onClick
|
|
37
|
-
})),
|
|
38
|
-
container = _renderWithIntl2.container;
|
|
39
|
-
|
|
40
|
-
expect(container.firstChild).toHaveStyle("color: ".concat(_colors.N200));
|
|
41
|
-
});
|
|
42
|
-
it('placeholder should be centered', function () {
|
|
43
|
-
var _renderWithIntl3 = renderWithIntl( /*#__PURE__*/_react.default.createElement(_index.default, {
|
|
44
|
-
onClick: onClick
|
|
45
|
-
})),
|
|
46
|
-
container = _renderWithIntl3.container;
|
|
47
|
-
|
|
48
|
-
expect(container.firstChild).toHaveStyle("text-align: center");
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
|
-
var _schema = _interopRequireDefault(require("@atlaskit/editor-test-helpers/schema"));
|
|
8
|
-
|
|
9
|
-
var _editorCommon = require("@atlaskit/editor-common");
|
|
10
|
-
|
|
11
|
-
var _getTestEmojiResource = require("@atlaskit/util-data-test/get-test-emoji-resource");
|
|
12
|
-
|
|
13
|
-
var _toolbar = require("./toolbar");
|
|
14
|
-
|
|
15
|
-
var actions = _interopRequireWildcard(require("../panel/actions"));
|
|
16
|
-
|
|
17
|
-
var _Palettes = require("../../ui/ColorPalette/Palettes");
|
|
18
|
-
|
|
19
|
-
var _createProsemirrorEditor = require("@atlaskit/editor-test-helpers/create-prosemirror-editor");
|
|
20
|
-
|
|
21
|
-
var _ = _interopRequireDefault(require("."));
|
|
22
|
-
|
|
23
|
-
var _docBuilder = require("@atlaskit/editor-test-helpers/doc-builder");
|
|
24
|
-
|
|
25
|
-
var _adfSchema = require("@atlaskit/adf-schema");
|
|
26
|
-
|
|
27
|
-
var _analytics = _interopRequireWildcard(require("../analytics"));
|
|
28
|
-
|
|
29
|
-
var _emoji = require("../emoji");
|
|
30
|
-
|
|
31
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
32
|
-
|
|
33
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
34
|
-
|
|
35
|
-
var dummyFormatMessage = function dummyFormatMessage(messageDescriptor) {
|
|
36
|
-
return messageDescriptor.defaultMessage || '';
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
var changePanelTypespy = jest.spyOn(actions, 'changePanelType');
|
|
40
|
-
describe('getToolbarItems', function () {
|
|
41
|
-
var providerFactory = new _editorCommon.ProviderFactory();
|
|
42
|
-
providerFactory.setProvider('emojiProvider', Promise.resolve((0, _getTestEmojiResource.getTestEmojiResource)()));
|
|
43
|
-
var panelPreset = new _createProsemirrorEditor.Preset().add([_.default, {
|
|
44
|
-
UNSAFE_allowCustomPanel: true
|
|
45
|
-
}]);
|
|
46
|
-
var itemsWithCustomPanelEnabled = (0, _toolbar.getToolbarItems)(dummyFormatMessage, _schema.default.nodes.panel, true, providerFactory, _adfSchema.PanelType.INFO);
|
|
47
|
-
afterEach(function () {
|
|
48
|
-
jest.clearAllMocks();
|
|
49
|
-
});
|
|
50
|
-
it('should return 7 items when isCustomPanelEnabled is false', function () {
|
|
51
|
-
var items = (0, _toolbar.getToolbarItems)(dummyFormatMessage, _schema.default.nodes.panel, false, providerFactory);
|
|
52
|
-
expect(items).toHaveLength(7);
|
|
53
|
-
});
|
|
54
|
-
describe('if isCustomPanelEnabled is true', function () {
|
|
55
|
-
it('should return 11 items', function () {
|
|
56
|
-
expect(itemsWithCustomPanelEnabled).toHaveLength(11);
|
|
57
|
-
});
|
|
58
|
-
it('should contain emoji and color picker button', function () {
|
|
59
|
-
var emojiButton = itemsWithCustomPanelEnabled.find(function (item) {
|
|
60
|
-
return item.type === 'select' && item.selectType === 'emoji';
|
|
61
|
-
});
|
|
62
|
-
var colorButton = itemsWithCustomPanelEnabled.find(function (item) {
|
|
63
|
-
return item.type === 'select' && item.selectType === 'color';
|
|
64
|
-
});
|
|
65
|
-
expect(emojiButton).not.toBeUndefined();
|
|
66
|
-
expect(colorButton).not.toBeUndefined();
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
describe('custom panel toolbar items', function () {
|
|
70
|
-
var createEditor = (0, _createProsemirrorEditor.createProsemirrorEditorFactory)();
|
|
71
|
-
|
|
72
|
-
var _createEditor = createEditor({
|
|
73
|
-
doc: (0, _docBuilder.doc)((0, _docBuilder.panel)({
|
|
74
|
-
panelType: 'info'
|
|
75
|
-
})((0, _docBuilder.p)('{<>}'))),
|
|
76
|
-
preset: panelPreset,
|
|
77
|
-
providerFactory: providerFactory
|
|
78
|
-
}),
|
|
79
|
-
editorView = _createEditor.editorView;
|
|
80
|
-
|
|
81
|
-
it("should call changePanelType when clicked on emoji picker\n with changed emoji", function () {
|
|
82
|
-
var emojiPickerConfig = itemsWithCustomPanelEnabled.find(function (item) {
|
|
83
|
-
return item.type === 'select' && item.selectType === 'emoji';
|
|
84
|
-
});
|
|
85
|
-
emojiPickerConfig.onChange(':smiley:')(editorView.state);
|
|
86
|
-
expect(changePanelTypespy).toBeCalledWith(_adfSchema.PanelType.CUSTOM, {
|
|
87
|
-
emoji: ':smiley:'
|
|
88
|
-
}, true);
|
|
89
|
-
});
|
|
90
|
-
it("should call changePanelType when clicked on color picker\n with changed color", function () {
|
|
91
|
-
var colorPickerConfig = itemsWithCustomPanelEnabled.find(function (item) {
|
|
92
|
-
return item.type === 'select' && item.selectType === 'color';
|
|
93
|
-
});
|
|
94
|
-
colorPickerConfig.onChange({
|
|
95
|
-
label: 'Mintie',
|
|
96
|
-
value: '#ABF5D1',
|
|
97
|
-
border: _Palettes.DEFAULT_BORDER_COLOR
|
|
98
|
-
})(editorView.state);
|
|
99
|
-
expect(changePanelTypespy).toBeCalledWith(_adfSchema.PanelType.CUSTOM, {
|
|
100
|
-
color: '#ABF5D1'
|
|
101
|
-
}, true);
|
|
102
|
-
});
|
|
103
|
-
it("should call changePanelType when clicked on remove emoji", function () {
|
|
104
|
-
var removeEmojiButton = itemsWithCustomPanelEnabled.find(function (item) {
|
|
105
|
-
return item.type === 'button' && item.id === 'editor.panel.removeEmoji';
|
|
106
|
-
});
|
|
107
|
-
removeEmojiButton.onClick(editorView.state);
|
|
108
|
-
expect(changePanelTypespy).toBeCalledWith(_adfSchema.PanelType.CUSTOM, {
|
|
109
|
-
emoji: undefined
|
|
110
|
-
}, true);
|
|
111
|
-
});
|
|
112
|
-
it("should not call changePanelType when clicked on remove emoji when no emoji in panel", function () {
|
|
113
|
-
var _createEditor2 = createEditor({
|
|
114
|
-
doc: (0, _docBuilder.doc)((0, _docBuilder.panel)({
|
|
115
|
-
panelType: 'custom'
|
|
116
|
-
})((0, _docBuilder.p)('{<>}'))),
|
|
117
|
-
preset: panelPreset,
|
|
118
|
-
providerFactory: providerFactory
|
|
119
|
-
}),
|
|
120
|
-
editorView = _createEditor2.editorView;
|
|
121
|
-
|
|
122
|
-
var toolbarItems = (0, _toolbar.getToolbarItems)(dummyFormatMessage, _schema.default.nodes.panel, true, providerFactory, _adfSchema.PanelType.CUSTOM);
|
|
123
|
-
var removeEmojiButton = toolbarItems.find(function (item) {
|
|
124
|
-
return item.type === 'button' && item.id === 'editor.panel.removeEmoji';
|
|
125
|
-
});
|
|
126
|
-
changePanelTypespy.mockClear();
|
|
127
|
-
removeEmojiButton.onClick(editorView.state);
|
|
128
|
-
expect(changePanelTypespy).not.toBeCalled();
|
|
129
|
-
});
|
|
130
|
-
it("should have remove emoji button disabled when focus on panel without emoji", function () {
|
|
131
|
-
var toolbarItems = (0, _toolbar.getToolbarItems)(dummyFormatMessage, _schema.default.nodes.panel, true, providerFactory, _adfSchema.PanelType.CUSTOM, '#ABF5D1', '');
|
|
132
|
-
var removeEmojiButton = toolbarItems.find(function (item) {
|
|
133
|
-
return item.type === 'button' && item.id === 'editor.panel.removeEmoji';
|
|
134
|
-
});
|
|
135
|
-
expect(removeEmojiButton.disabled).toBe(true);
|
|
136
|
-
});
|
|
137
|
-
it("should have remove emoji button enabled when focus on panel with emoji", function () {
|
|
138
|
-
var toolbarItems = (0, _toolbar.getToolbarItems)(dummyFormatMessage, _schema.default.nodes.panel, true, providerFactory, _adfSchema.PanelType.CUSTOM, '#ABF5D1', ':smiley:');
|
|
139
|
-
var removeEmojiButton = toolbarItems.find(function (item) {
|
|
140
|
-
return item.type === 'button' && item.id === 'editor.panel.removeEmoji';
|
|
141
|
-
});
|
|
142
|
-
expect(removeEmojiButton.disabled).toBe(false);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
describe('analytics for custom panels', function () {
|
|
146
|
-
var createEditor = (0, _createProsemirrorEditor.createProsemirrorEditorFactory)();
|
|
147
|
-
var createAnalyticsEvent = jest.fn(function () {
|
|
148
|
-
return {
|
|
149
|
-
fire: function fire() {}
|
|
150
|
-
};
|
|
151
|
-
});
|
|
152
|
-
var editorView;
|
|
153
|
-
beforeEach(function () {
|
|
154
|
-
var _createEditor3 = createEditor({
|
|
155
|
-
doc: (0, _docBuilder.doc)((0, _docBuilder.panel)({
|
|
156
|
-
panelType: 'info'
|
|
157
|
-
})((0, _docBuilder.p)('{<>}'))),
|
|
158
|
-
preset: panelPreset.add([_analytics.default, {
|
|
159
|
-
createAnalyticsEvent: createAnalyticsEvent
|
|
160
|
-
}]),
|
|
161
|
-
providerFactory: providerFactory,
|
|
162
|
-
pluginKey: _emoji.emojiPluginKey
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
editorView = _createEditor3.editorView;
|
|
166
|
-
});
|
|
167
|
-
it('Should trigger analytics when background color is changed', function () {
|
|
168
|
-
var colorPickerConfig = itemsWithCustomPanelEnabled.find(function (item) {
|
|
169
|
-
return item.type === 'select' && item.selectType === 'color';
|
|
170
|
-
});
|
|
171
|
-
colorPickerConfig.onChange({
|
|
172
|
-
label: 'Mintie',
|
|
173
|
-
value: '#ABF5D1',
|
|
174
|
-
border: _Palettes.DEFAULT_BORDER_COLOR
|
|
175
|
-
})(editorView.state, editorView.dispatch);
|
|
176
|
-
var payload = {
|
|
177
|
-
action: _analytics.ACTION.CHANGED_BACKGROUND_COLOR,
|
|
178
|
-
actionSubject: _analytics.ACTION_SUBJECT.PANEL,
|
|
179
|
-
actionSubjectId: _analytics.ACTION_SUBJECT_ID.PANEL,
|
|
180
|
-
attributes: expect.objectContaining({
|
|
181
|
-
newColor: '#ABF5D1',
|
|
182
|
-
previousColor: '#DEEBFF'
|
|
183
|
-
}),
|
|
184
|
-
eventType: _analytics.EVENT_TYPE.TRACK
|
|
185
|
-
};
|
|
186
|
-
expect(createAnalyticsEvent).toHaveBeenCalledWith(payload);
|
|
187
|
-
});
|
|
188
|
-
it('Should trigger analytics when Icon is changed', function () {
|
|
189
|
-
var emojiPickerConfig = itemsWithCustomPanelEnabled.find(function (item) {
|
|
190
|
-
return item.type === 'select' && item.selectType === 'emoji';
|
|
191
|
-
});
|
|
192
|
-
emojiPickerConfig.onChange(':smiley:')(editorView.state, editorView.dispatch);
|
|
193
|
-
var payload = {
|
|
194
|
-
action: _analytics.ACTION.CHANGED_ICON,
|
|
195
|
-
actionSubject: _analytics.ACTION_SUBJECT.PANEL,
|
|
196
|
-
actionSubjectId: _analytics.ACTION_SUBJECT_ID.PANEL,
|
|
197
|
-
attributes: expect.objectContaining({
|
|
198
|
-
newIcon: ':smiley:',
|
|
199
|
-
previousIcon: ''
|
|
200
|
-
}),
|
|
201
|
-
eventType: _analytics.EVENT_TYPE.TRACK
|
|
202
|
-
};
|
|
203
|
-
expect(createAnalyticsEvent).toHaveBeenCalledWith(payload);
|
|
204
|
-
});
|
|
205
|
-
it('Should trigger analytics when Icon is removed', function () {
|
|
206
|
-
var removeEmojiButton = itemsWithCustomPanelEnabled.find(function (item) {
|
|
207
|
-
return item.type === 'button' && item.id === 'editor.panel.removeEmoji';
|
|
208
|
-
});
|
|
209
|
-
var emojiPickerConfig = itemsWithCustomPanelEnabled.find(function (item) {
|
|
210
|
-
return item.type === 'select' && item.selectType === 'emoji';
|
|
211
|
-
});
|
|
212
|
-
emojiPickerConfig.onChange(':smiley:')(editorView.state, editorView.dispatch);
|
|
213
|
-
removeEmojiButton.onClick(editorView.state, editorView.dispatch);
|
|
214
|
-
var payload = {
|
|
215
|
-
action: _analytics.ACTION.REMOVE_ICON,
|
|
216
|
-
actionSubject: _analytics.ACTION_SUBJECT.PANEL,
|
|
217
|
-
actionSubjectId: _analytics.ACTION_SUBJECT_ID.PANEL,
|
|
218
|
-
attributes: expect.objectContaining({
|
|
219
|
-
icon: ':smiley:'
|
|
220
|
-
}),
|
|
221
|
-
eventType: _analytics.EVENT_TYPE.TRACK
|
|
222
|
-
};
|
|
223
|
-
expect(createAnalyticsEvent).nthCalledWith(4, payload);
|
|
224
|
-
});
|
|
225
|
-
it('Should not fire analytics when the same background color is selected', function () {
|
|
226
|
-
var colorPickerConfig = itemsWithCustomPanelEnabled.find(function (item) {
|
|
227
|
-
return item.type === 'select' && item.selectType === 'color';
|
|
228
|
-
});
|
|
229
|
-
colorPickerConfig.onChange({
|
|
230
|
-
label: 'Mintie',
|
|
231
|
-
value: '#ABF5D1',
|
|
232
|
-
border: _Palettes.DEFAULT_BORDER_COLOR
|
|
233
|
-
})(editorView.state, editorView.dispatch);
|
|
234
|
-
colorPickerConfig.onChange({
|
|
235
|
-
label: 'Mintie',
|
|
236
|
-
value: '#ABF5D1',
|
|
237
|
-
border: _Palettes.DEFAULT_BORDER_COLOR
|
|
238
|
-
})(editorView.state, editorView.dispatch);
|
|
239
|
-
expect(createAnalyticsEvent).toHaveBeenCalledTimes(3);
|
|
240
|
-
});
|
|
241
|
-
it('Should not fire analtyics when same emoji is selected', function () {
|
|
242
|
-
var emojiPickerConfig = itemsWithCustomPanelEnabled.find(function (item) {
|
|
243
|
-
return item.type === 'select' && item.selectType === 'emoji';
|
|
244
|
-
});
|
|
245
|
-
emojiPickerConfig.onChange(':smiley:')(editorView.state, editorView.dispatch);
|
|
246
|
-
emojiPickerConfig.onChange(':smiley:')(editorView.state, editorView.dispatch);
|
|
247
|
-
expect(createAnalyticsEvent).toHaveBeenCalledTimes(3);
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
});
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
6
|
-
|
|
7
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
8
|
-
|
|
9
|
-
var _react = _interopRequireDefault(require("react"));
|
|
10
|
-
|
|
11
|
-
var _enzyme = require("@atlaskit/editor-test-helpers/enzyme");
|
|
12
|
-
|
|
13
|
-
var _theme = require("@atlaskit/theme");
|
|
14
|
-
|
|
15
|
-
var _Palettes = require("../ColorPalette/Palettes");
|
|
16
|
-
|
|
17
|
-
var _panelBackgroundPalette = require("../ColorPalette/Palettes/panelBackgroundPalette");
|
|
18
|
-
|
|
19
|
-
var _mockAnalyticsNext = require("@atlaskit/editor-test-helpers/mock-analytics-next");
|
|
20
|
-
|
|
21
|
-
var _index = _interopRequireDefault(require("./index"));
|
|
22
|
-
|
|
23
|
-
var _types = require("../../plugins/analytics/types");
|
|
24
|
-
|
|
25
|
-
var _consts = require("../../plugins/analytics/consts");
|
|
26
|
-
|
|
27
|
-
var _testUtils = require("react-dom/test-utils");
|
|
28
|
-
|
|
29
|
-
// AFP-2532 TODO: Fix automatic suppressions below
|
|
30
|
-
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
31
|
-
describe('color-picker-button', function () {
|
|
32
|
-
var onChangeMock = jest.fn();
|
|
33
|
-
|
|
34
|
-
var getWrapper = function getWrapper() {
|
|
35
|
-
var placement = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
36
|
-
return (0, _enzyme.mountWithIntl)( /*#__PURE__*/_react.default.createElement(_index.default, {
|
|
37
|
-
onChange: onChangeMock,
|
|
38
|
-
colorPalette: _panelBackgroundPalette.panelBackgroundPalette,
|
|
39
|
-
placement: placement
|
|
40
|
-
}));
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
var selectColor = function selectColor(wrapper, colorLabel) {
|
|
44
|
-
// show popup
|
|
45
|
-
wrapper.find('button').simulate('click'); // select purple
|
|
46
|
-
|
|
47
|
-
wrapper.find('Color').findWhere(function (node) {
|
|
48
|
-
return node.prop('label') === colorLabel;
|
|
49
|
-
}).find('button').simulate('click');
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
afterEach(function () {
|
|
53
|
-
jest.clearAllMocks();
|
|
54
|
-
});
|
|
55
|
-
it('should render a button', function () {
|
|
56
|
-
var wrapper = getWrapper();
|
|
57
|
-
expect(wrapper.find('button')).toHaveLength(1); // ensure no popup is rendered
|
|
58
|
-
|
|
59
|
-
expect(wrapper.find('Popup')).toHaveLength(0);
|
|
60
|
-
});
|
|
61
|
-
it('should show a ColorPalette popup after clicking button', function () {
|
|
62
|
-
var wrapper = getWrapper(); // show the popup
|
|
63
|
-
|
|
64
|
-
wrapper.find('button').simulate('click');
|
|
65
|
-
expect(wrapper.find('Popup')).toHaveLength(1);
|
|
66
|
-
expect(wrapper.find('ColorPalette')).toHaveLength(1);
|
|
67
|
-
expect(wrapper.find('Color')).toHaveLength(21);
|
|
68
|
-
});
|
|
69
|
-
it('should close ColorPalette popup after clicking outside', function () {
|
|
70
|
-
var wrapper = getWrapper(); // show the popup
|
|
71
|
-
|
|
72
|
-
wrapper.find('button').simulate('click'); // make sure the popup and picker are shown
|
|
73
|
-
|
|
74
|
-
expect(wrapper.find('Popup')).toHaveLength(1);
|
|
75
|
-
var colorPalette = wrapper.find('InjectIntl(ColorPalette)').instance();
|
|
76
|
-
(0, _testUtils.act)(function () {
|
|
77
|
-
colorPalette.props.handleClickOutside();
|
|
78
|
-
});
|
|
79
|
-
wrapper.update(); // make sure popup is hidden
|
|
80
|
-
|
|
81
|
-
expect(wrapper.find('Popup')).toHaveLength(0);
|
|
82
|
-
});
|
|
83
|
-
it('should hide popup and call onChange after selecting a color', function () {
|
|
84
|
-
var wrapper = getWrapper();
|
|
85
|
-
selectColor(wrapper, 'Mintie'); // ensure popup is hidden
|
|
86
|
-
|
|
87
|
-
expect(wrapper.find('Popup')).toHaveLength(0); // ensure callback was called
|
|
88
|
-
|
|
89
|
-
expect(onChangeMock).toBeCalledWith({
|
|
90
|
-
label: 'Mintie',
|
|
91
|
-
value: _theme.colors.G75,
|
|
92
|
-
border: _Palettes.DEFAULT_BORDER_COLOR
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
it('analytics', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
96
|
-
var wrapper;
|
|
97
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
98
|
-
while (1) {
|
|
99
|
-
switch (_context.prev = _context.next) {
|
|
100
|
-
case 0:
|
|
101
|
-
wrapper = getWrapper('ConfigPanel');
|
|
102
|
-
selectColor(wrapper, 'Doctor');
|
|
103
|
-
expect(_mockAnalyticsNext.mockCreateAnalyticsEvent).toHaveBeenCalledWith({
|
|
104
|
-
action: _types.ACTION.UPDATED,
|
|
105
|
-
actionSubject: _types.ACTION_SUBJECT.PICKER,
|
|
106
|
-
actionSubjectId: _types.ACTION_SUBJECT_ID.PICKER_COLOR,
|
|
107
|
-
attributes: {
|
|
108
|
-
color: '#FFFFFF',
|
|
109
|
-
label: 'Doctor',
|
|
110
|
-
placement: 'ConfigPanel'
|
|
111
|
-
},
|
|
112
|
-
eventType: _types.EVENT_TYPE.TRACK
|
|
113
|
-
});
|
|
114
|
-
expect(_mockAnalyticsNext.mockFire).toHaveBeenCalledWith(_consts.editorAnalyticsChannel);
|
|
115
|
-
|
|
116
|
-
case 4:
|
|
117
|
-
case "end":
|
|
118
|
-
return _context.stop();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}, _callee);
|
|
122
|
-
})));
|
|
123
|
-
});
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
6
|
-
|
|
7
|
-
var _react = _interopRequireDefault(require("react"));
|
|
8
|
-
|
|
9
|
-
var _reactDom = require("react-dom");
|
|
10
|
-
|
|
11
|
-
var _enzyme = require("enzyme");
|
|
12
|
-
|
|
13
|
-
var _analyticsNext = require("@atlaskit/analytics-next");
|
|
14
|
-
|
|
15
|
-
var _ = require("./");
|
|
16
|
-
|
|
17
|
-
var _contextAdapter = require("../../nodeviews/context-adapter");
|
|
18
|
-
|
|
19
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
20
|
-
|
|
21
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
22
|
-
|
|
23
|
-
jest.mock('react-dom', function () {
|
|
24
|
-
return _objectSpread(_objectSpread({}, jest.requireActual('react-dom')), {}, {
|
|
25
|
-
unmountComponentAtNode: jest.fn()
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
var Component = function Component() {
|
|
30
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
31
|
-
className: "component"
|
|
32
|
-
}, "My component");
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
var Component2 = function Component2() {
|
|
36
|
-
var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
|
|
37
|
-
createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
|
|
38
|
-
|
|
39
|
-
var event = createAnalyticsEvent({});
|
|
40
|
-
event.fire('portalprovidertest');
|
|
41
|
-
return /*#__PURE__*/_react.default.createElement("div", null, "Component 2");
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
var ComponentWithAnalytics = function ComponentWithAnalytics() {
|
|
45
|
-
return /*#__PURE__*/_react.default.createElement(Component2, null);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
describe('PortalProvider', function () {
|
|
49
|
-
var portalProviderAPI;
|
|
50
|
-
var wrapper;
|
|
51
|
-
var place;
|
|
52
|
-
var place2;
|
|
53
|
-
var handleAnalyticsEvent;
|
|
54
|
-
var handleAnalyticsEventFromContext;
|
|
55
|
-
|
|
56
|
-
var initPortalProvider = function initPortalProvider() {
|
|
57
|
-
handleAnalyticsEvent = jest.fn();
|
|
58
|
-
handleAnalyticsEventFromContext = jest.fn();
|
|
59
|
-
wrapper = (0, _enzyme.mount)( /*#__PURE__*/_react.default.createElement(_analyticsNext.AnalyticsListener, {
|
|
60
|
-
channel: "portalprovidertest",
|
|
61
|
-
onEvent: handleAnalyticsEventFromContext
|
|
62
|
-
}, /*#__PURE__*/_react.default.createElement(_contextAdapter.ContextAdapter, null, /*#__PURE__*/_react.default.createElement(_.PortalProvider, {
|
|
63
|
-
onAnalyticsEvent: handleAnalyticsEvent,
|
|
64
|
-
useAnalyticsContext: true,
|
|
65
|
-
render: function render(api) {
|
|
66
|
-
portalProviderAPI = api;
|
|
67
|
-
return /*#__PURE__*/_react.default.createElement(_.PortalRenderer, {
|
|
68
|
-
portalProviderAPI: api
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}))));
|
|
72
|
-
portalProviderAPI.render(Component, place);
|
|
73
|
-
wrapper.update();
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
beforeEach(function () {
|
|
77
|
-
jest.resetAllMocks();
|
|
78
|
-
place = document.body.appendChild(document.createElement('div'));
|
|
79
|
-
place.classList.add('place');
|
|
80
|
-
place2 = document.body.appendChild(document.createElement('div'));
|
|
81
|
-
place2.classList.add('place2');
|
|
82
|
-
initPortalProvider();
|
|
83
|
-
});
|
|
84
|
-
afterEach(function () {
|
|
85
|
-
place.parentNode.removeChild(place);
|
|
86
|
-
place2.parentNode.removeChild(place2);
|
|
87
|
-
});
|
|
88
|
-
it('should render a component successfully', function () {
|
|
89
|
-
expect((0, _enzyme.mount)( /*#__PURE__*/_react.default.createElement(Component, null)).html()).toEqual(place.innerHTML);
|
|
90
|
-
});
|
|
91
|
-
it('should render several components successfully', function () {
|
|
92
|
-
portalProviderAPI.render(Component, place2);
|
|
93
|
-
wrapper.update();
|
|
94
|
-
var component = (0, _enzyme.mount)( /*#__PURE__*/_react.default.createElement(Component, null));
|
|
95
|
-
expect(component.html()).toEqual(place.innerHTML);
|
|
96
|
-
expect(component.html()).toEqual(place2.innerHTML);
|
|
97
|
-
});
|
|
98
|
-
it('should destroy a component successfully', function () {
|
|
99
|
-
portalProviderAPI.remove(place);
|
|
100
|
-
wrapper.update();
|
|
101
|
-
expect(_reactDom.unmountComponentAtNode).toBeCalledWith(place);
|
|
102
|
-
});
|
|
103
|
-
describe('React throws an error while unmounting child component', function () {
|
|
104
|
-
var error = new Error('Something happened...');
|
|
105
|
-
beforeEach(function () {
|
|
106
|
-
_reactDom.unmountComponentAtNode.mockImplementation(function () {
|
|
107
|
-
throw error;
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
it('should not throw error', function () {
|
|
111
|
-
expect(function () {
|
|
112
|
-
return portalProviderAPI.remove(place);
|
|
113
|
-
}).not.toThrowError();
|
|
114
|
-
});
|
|
115
|
-
it('should fire analytics if React throws an error when unmounting', function () {
|
|
116
|
-
portalProviderAPI.remove(place);
|
|
117
|
-
expect(handleAnalyticsEvent).toHaveBeenCalledWith({
|
|
118
|
-
payload: {
|
|
119
|
-
action: 'failedToUnmount',
|
|
120
|
-
actionSubject: 'editor',
|
|
121
|
-
actionSubjectId: 'reactNodeView',
|
|
122
|
-
attributes: {
|
|
123
|
-
error: error,
|
|
124
|
-
domNodes: {
|
|
125
|
-
container: 'place',
|
|
126
|
-
child: 'component'
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
eventType: 'operational'
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
it('should propogate events up from child component', function () {
|
|
135
|
-
portalProviderAPI.render(ComponentWithAnalytics, place);
|
|
136
|
-
wrapper.update();
|
|
137
|
-
expect(handleAnalyticsEventFromContext).toBeCalledTimes(1);
|
|
138
|
-
});
|
|
139
|
-
});
|
|
@@ -1,122 +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 { setNodeSelection, setTextSelection } from '../../../utils';
|
|
4
|
-
import { render } from '@testing-library/react';
|
|
5
|
-
import { getSchemaBasedOnStage } from '@atlaskit/adf-schema';
|
|
6
|
-
import captionNodeView from '.';
|
|
7
|
-
jest.mock('../../base/pm-plugins/react-nodeview', () => ({
|
|
8
|
-
stateKey: {
|
|
9
|
-
getState: () => ({
|
|
10
|
-
subscribe: jest.fn(),
|
|
11
|
-
unsubscribe: jest.fn()
|
|
12
|
-
})
|
|
13
|
-
}
|
|
14
|
-
}));
|
|
15
|
-
const createEditorTestingLibrary = createEditorFactory(render);
|
|
16
|
-
|
|
17
|
-
const editor = doc => createEditorTestingLibrary({
|
|
18
|
-
doc,
|
|
19
|
-
editorProps: {
|
|
20
|
-
media: {
|
|
21
|
-
allowMediaSingle: true,
|
|
22
|
-
featureFlags: {
|
|
23
|
-
captions: true
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const mediaNodeAttrs = {
|
|
30
|
-
id: 'a559980d-cd47-43e2-8377-27359fcb905f',
|
|
31
|
-
type: 'file',
|
|
32
|
-
collection: 'MediaServicesSample',
|
|
33
|
-
width: 250,
|
|
34
|
-
height: 250
|
|
35
|
-
};
|
|
36
|
-
describe('caption', () => {
|
|
37
|
-
it('should render caption children', () => {
|
|
38
|
-
const CAPTION_TEXT = 'this is a very cool caption';
|
|
39
|
-
const {
|
|
40
|
-
wrapper: {
|
|
41
|
-
getByText
|
|
42
|
-
}
|
|
43
|
-
} = editor(doc(mediaSingle()(media(mediaNodeAttrs)(), caption(CAPTION_TEXT))));
|
|
44
|
-
expect(getByText(CAPTION_TEXT)).not.toBeNull();
|
|
45
|
-
});
|
|
46
|
-
it("should show a placeholder if there's no children", () => {
|
|
47
|
-
const {
|
|
48
|
-
wrapper: {
|
|
49
|
-
getByText
|
|
50
|
-
}
|
|
51
|
-
} = editor(doc('{<node>}', // node selection
|
|
52
|
-
mediaSingle()(media(mediaNodeAttrs)())));
|
|
53
|
-
expect(getByText('Add a caption')).not.toBeNull();
|
|
54
|
-
});
|
|
55
|
-
it('should not show a placeholder when selecting away from media single', () => {
|
|
56
|
-
const {
|
|
57
|
-
wrapper: {
|
|
58
|
-
queryByText,
|
|
59
|
-
getByText
|
|
60
|
-
},
|
|
61
|
-
editorView
|
|
62
|
-
} = editor(doc('{<node>}', // node selection
|
|
63
|
-
mediaSingle()(media(mediaNodeAttrs)()), p('this is a random piece of text')));
|
|
64
|
-
expect(getByText('Add a caption')).not.toBeNull();
|
|
65
|
-
setTextSelection(editorView, 13, 14);
|
|
66
|
-
expect(queryByText('Add a caption')).toBeNull();
|
|
67
|
-
});
|
|
68
|
-
it('should show a placeholder when selecting a media single', () => {
|
|
69
|
-
const {
|
|
70
|
-
wrapper: {
|
|
71
|
-
queryByText,
|
|
72
|
-
getByText
|
|
73
|
-
},
|
|
74
|
-
editorView
|
|
75
|
-
} = editor(doc('{node}', // node selection
|
|
76
|
-
mediaSingle()(media(mediaNodeAttrs)()), p('this is a random p{<>}iece of text')));
|
|
77
|
-
expect(queryByText('Add a caption')).toBeNull();
|
|
78
|
-
setNodeSelection(editorView, 0);
|
|
79
|
-
expect(getByText('Add a caption')).not.toBeNull();
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
describe('nodeview updating based on child count', () => {
|
|
83
|
-
const portalProviderAPI = {
|
|
84
|
-
render(component) {
|
|
85
|
-
component();
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
remove() {}
|
|
89
|
-
|
|
90
|
-
};
|
|
91
|
-
const eventDispatcher = {};
|
|
92
|
-
const node = caption('hi')(getSchemaBasedOnStage('stage0'));
|
|
93
|
-
const view = {
|
|
94
|
-
state: {
|
|
95
|
-
selection: {
|
|
96
|
-
from: 0,
|
|
97
|
-
to: 0,
|
|
98
|
-
$anchor: {
|
|
99
|
-
pos: 0
|
|
100
|
-
},
|
|
101
|
-
$head: {
|
|
102
|
-
pos: 20
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
const getPos = jest.fn();
|
|
108
|
-
it('does not update if the childCount has not changed', () => {
|
|
109
|
-
const nodeView = captionNodeView(portalProviderAPI, eventDispatcher)(node, view, getPos); // ensure that if it falls through to the default it returns false
|
|
110
|
-
|
|
111
|
-
nodeView['_viewShouldUpdate'] = jest.fn(_node => false);
|
|
112
|
-
expect(nodeView.viewShouldUpdate(node)).toBeFalsy();
|
|
113
|
-
});
|
|
114
|
-
it('updates if the childCount has changed', () => {
|
|
115
|
-
const nodeView = captionNodeView(portalProviderAPI, eventDispatcher)(node, view, getPos); // when captions is in full schema, use defaultSchema
|
|
116
|
-
|
|
117
|
-
const newNode = caption()(getSchemaBasedOnStage('stage0')); // ensure that if it falls through to the default it returns false
|
|
118
|
-
|
|
119
|
-
nodeView['_viewShouldUpdate'] = jest.fn(_node => false);
|
|
120
|
-
expect(nodeView.viewShouldUpdate(newNode)).toBeTruthy();
|
|
121
|
-
});
|
|
122
|
-
});
|