@zipify/wysiwyg 3.1.2 → 4.0.0-vue3.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/.eslintrc.js +1 -1
- package/config/build/example.config.js +12 -2
- package/config/build/lib.config.js +10 -2
- package/config/jest/matchers/index.js +0 -2
- package/config/jest/setupTests.js +4 -7
- package/config/jest/typing.d.ts +1 -2
- package/dist/cli.js +2 -7
- package/dist/wysiwyg.css +153 -152
- package/dist/wysiwyg.mjs +3594 -3172
- package/example/example.js +34 -35
- package/jest.config.js +4 -1
- package/lib/Wysiwyg.vue +166 -190
- package/lib/__tests__/utils/buildTestExtensions.js +1 -1
- package/lib/components/base/Button.vue +31 -37
- package/lib/components/base/ButtonToggle.vue +11 -17
- package/lib/components/base/Checkbox.vue +14 -20
- package/lib/components/base/FieldLabel.vue +7 -11
- package/lib/components/base/Icon.vue +31 -43
- package/lib/components/base/Modal.vue +59 -74
- package/lib/components/base/NumberField.vue +65 -80
- package/lib/components/base/Range.vue +46 -56
- package/lib/components/base/ScrollView.vue +13 -21
- package/lib/components/base/TextField.vue +28 -33
- package/lib/components/base/__tests__/Button.test.js +1 -1
- package/lib/components/base/__tests__/Icon.test.js +1 -1
- package/lib/components/base/__tests__/Modal.test.js +21 -13
- package/lib/components/base/__tests__/Range.test.js +1 -1
- package/lib/components/base/__tests__/TextField.test.js +8 -7
- package/lib/components/base/colorPicker/ColorPicker.vue +33 -51
- package/lib/components/base/composables/__tests__/useDeselectionLock.test.js +4 -2
- package/lib/components/base/composables/__tests__/useModalToggler.test.js +3 -1
- package/lib/components/base/composables/__tests__/useScrollView.test.js +3 -1
- package/lib/components/base/dropdown/Dropdown.vue +35 -55
- package/lib/components/base/dropdown/DropdownActivator.vue +38 -66
- package/lib/components/base/dropdown/DropdownDivider.vue +0 -6
- package/lib/components/base/dropdown/DropdownGroup.vue +8 -20
- package/lib/components/base/dropdown/DropdownMenu.vue +8 -21
- package/lib/components/base/dropdown/DropdownOption.vue +27 -45
- package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +5 -3
- package/lib/components/base/dropdown/__tests__/DropdownOption.test.js +9 -7
- package/lib/components/toolbar/Toolbar.vue +26 -42
- package/lib/components/toolbar/__tests__/Toolbar.test.js +1 -1
- package/lib/components/toolbar/base/__tests__/ToolbarDivider.test.js +1 -1
- package/lib/components/toolbar/controls/AlignmentControl.vue +27 -46
- package/lib/components/toolbar/controls/BackgroundColorControl.vue +5 -26
- package/lib/components/toolbar/controls/CaseStyleControl.vue +10 -32
- package/lib/components/toolbar/controls/FontColorControl.vue +5 -27
- package/lib/components/toolbar/controls/FontFamilyControl.vue +27 -49
- package/lib/components/toolbar/controls/FontSizeControl.vue +9 -29
- package/lib/components/toolbar/controls/FontWeightControl.vue +7 -27
- package/lib/components/toolbar/controls/ItalicControl.vue +6 -27
- package/lib/components/toolbar/controls/LineHeightControl.vue +10 -37
- package/lib/components/toolbar/controls/ListControl.vue +18 -49
- package/lib/components/toolbar/controls/RemoveFormatControl.vue +4 -21
- package/lib/components/toolbar/controls/StrikeThroughControl.vue +5 -25
- package/lib/components/toolbar/controls/StylePresetControl.vue +34 -59
- package/lib/components/toolbar/controls/SuperscriptControl.vue +5 -25
- package/lib/components/toolbar/controls/UnderlineControl.vue +5 -26
- package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +15 -13
- package/lib/components/toolbar/controls/__tests__/BackgroundColorControl.test.js +17 -15
- package/lib/components/toolbar/controls/__tests__/CaseStyleControl.test.js +9 -8
- package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +17 -15
- package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +14 -12
- package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +5 -3
- package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +3 -1
- package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +3 -1
- package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +11 -9
- package/lib/components/toolbar/controls/__tests__/ListControl.test.js +16 -14
- package/lib/components/toolbar/controls/__tests__/RemoveFormatControl.test.js +3 -1
- package/lib/components/toolbar/controls/__tests__/StrikeThroughControl.test.js +3 -1
- package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +3 -1
- package/lib/components/toolbar/controls/__tests__/SuperscriptControl.test.js +3 -1
- package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +3 -1
- package/lib/components/toolbar/controls/composables/__tests__/useRecentFonts.test.js +6 -4
- package/lib/components/toolbar/controls/link/LinkControl.vue +75 -108
- package/lib/components/toolbar/controls/link/LinkControlHeader.vue +8 -14
- package/lib/components/toolbar/controls/link/__tests__/LinkControl.test.js +5 -3
- package/lib/components/toolbar/controls/link/__tests__/LinkControlHeader.test.js +3 -1
- package/lib/components/toolbar/controls/link/composables/__tests__/useLink.test.js +5 -4
- package/lib/components/toolbar/controls/link/destination/LinkControlDestination.vue +28 -47
- package/lib/components/toolbar/controls/link/destination/LinkControlPageBlock.vue +12 -20
- package/lib/components/toolbar/controls/link/destination/LinkControlUrl.vue +18 -26
- package/lib/components/toolbar/controls/link/destination/__tests__/LinkControlPageBlock.test.js +10 -10
- package/lib/components/toolbar/controls/link/destination/__tests__/LinkControlUrl.test.js +12 -10
- package/lib/components/toolbar/layouts/ToolbarDesktop.vue +36 -64
- package/lib/components/toolbar/layouts/ToolbarMobile.vue +38 -66
- package/lib/components/toolbar/layouts/ToolbarPopup.vue +36 -64
- package/lib/composables/__tests__/useEditor.test.js +3 -3
- package/lib/composables/useEditor.js +1 -1
- package/lib/directives/__tests__/outClick.test.js +9 -9
- package/lib/directives/outClick.js +3 -3
- package/lib/extensions/Alignment.js +1 -1
- package/lib/extensions/BackgroundColor.js +1 -1
- package/lib/extensions/CaseStyle.js +1 -1
- package/lib/extensions/DeviceManager.js +1 -1
- package/lib/extensions/FontColor.js +1 -1
- package/lib/extensions/FontFamily.js +2 -2
- package/lib/extensions/FontSize.js +3 -3
- package/lib/extensions/FontStyle.js +1 -1
- package/lib/extensions/FontWeight.js +1 -1
- package/lib/extensions/LineHeight.js +1 -1
- package/lib/extensions/Link.js +1 -1
- package/lib/extensions/Margin.js +1 -1
- package/lib/extensions/StylePreset.js +9 -9
- package/lib/extensions/Superscript.js +1 -1
- package/lib/extensions/TextDecoration.js +1 -1
- package/lib/extensions/__tests__/Alignment.test.js +1 -1
- package/lib/extensions/__tests__/BackgroundColor.test.js +1 -1
- package/lib/extensions/__tests__/CaseStyle.test.js +1 -1
- package/lib/extensions/__tests__/FontColor.test.js +1 -1
- package/lib/extensions/__tests__/FontFamily.test.js +1 -1
- package/lib/extensions/__tests__/FontSize.test.js +1 -1
- package/lib/extensions/__tests__/FontStyle.test.js +1 -1
- package/lib/extensions/__tests__/FontWeight.test.js +1 -1
- package/lib/extensions/__tests__/LineHeight.test.js +1 -1
- package/lib/extensions/__tests__/Link.test.js +1 -1
- package/lib/extensions/__tests__/StylePreset.test.js +1 -1
- package/lib/extensions/__tests__/Superscript.test.js +1 -1
- package/lib/extensions/__tests__/TextDecoration.test.js +1 -1
- package/lib/extensions/core/NodeProcessor.js +1 -1
- package/lib/extensions/core/SelectionProcessor.js +1 -1
- package/lib/extensions/core/TextProcessor.js +1 -1
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +1 -1
- package/lib/extensions/core/__tests__/SelectionProcessor.test.js +1 -1
- package/lib/extensions/core/__tests__/TextProcessor.test.js +1 -1
- package/lib/extensions/core/index.js +1 -1
- package/lib/extensions/index.js +1 -1
- package/lib/extensions/list/List.js +4 -4
- package/lib/extensions/list/__tests__/List.test.js +1 -1
- package/package.json +19 -20
- package/config/jest/matchers/toVueEmpty.js +0 -16
- package/config/jest/matchers/toVuexActionHasBeenDispatched.js +0 -19
- package/lib/components/base/__tests__/__snapshots__/TextField.test.js.snap +0 -9
- package/lib/components/base/dropdown/__tests__/DropdownMenu.test.js +0 -67
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Mark } from '@tiptap/vue-
|
|
1
|
+
import { Mark } from '@tiptap/vue-3';
|
|
2
2
|
import { computed, unref } from 'vue';
|
|
3
3
|
import { convertFontSize, createCommand, createKeyboardShortcut, renderMark } from '../utils';
|
|
4
4
|
import { MarkGroups, TextSettings } from '../enums';
|
|
@@ -63,14 +63,14 @@ export const FontSize = Mark.create({
|
|
|
63
63
|
|
|
64
64
|
increaseFontSize: createCommand(({ commands }) => {
|
|
65
65
|
const size = Number(unref(commands.getFontSize()));
|
|
66
|
-
const nextSize = Math.min(size + 1, this.options.maxSize);
|
|
66
|
+
const nextSize = Math.min(size + 1, unref(this.options.maxSize));
|
|
67
67
|
|
|
68
68
|
commands.applyFontSize(String(nextSize));
|
|
69
69
|
}),
|
|
70
70
|
|
|
71
71
|
decreaseFontSize: createCommand(({ commands }) => {
|
|
72
72
|
const size = Number(unref(commands.getFontSize()));
|
|
73
|
-
const nextSize = Math.max(size - 1, this.options.minSize);
|
|
73
|
+
const nextSize = Math.max(size - 1, unref(this.options.minSize));
|
|
74
74
|
|
|
75
75
|
commands.applyFontSize(String(nextSize));
|
|
76
76
|
})
|
package/lib/extensions/Link.js
CHANGED
|
@@ -78,7 +78,7 @@ export const Link = Base.extend({
|
|
|
78
78
|
}),
|
|
79
79
|
|
|
80
80
|
isLink: createCommand(({ commands }) => commands.hasMark(this.name)),
|
|
81
|
-
getLinkPreset: createCommand(() => computed(() => this.options.preset))
|
|
81
|
+
getLinkPreset: createCommand(() => computed(() => unref(this.options.preset)))
|
|
82
82
|
};
|
|
83
83
|
},
|
|
84
84
|
|
package/lib/extensions/Margin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Extension } from '@tiptap/vue-
|
|
1
|
+
import { Extension } from '@tiptap/vue-3';
|
|
2
2
|
import { computed, toRef, unref } from 'vue';
|
|
3
3
|
import { createCommand } from '../utils';
|
|
4
4
|
import { NodeTypes, TextSettings } from '../enums';
|
|
@@ -14,7 +14,7 @@ export const StylePreset = Extension.create({
|
|
|
14
14
|
attributes: {
|
|
15
15
|
preset: {
|
|
16
16
|
isRequired: false,
|
|
17
|
-
default: { id: this.options.defaultId },
|
|
17
|
+
default: { id: unref(this.options.defaultId) },
|
|
18
18
|
|
|
19
19
|
parseHTML: (element) => {
|
|
20
20
|
const presets = unref(this.options.presets);
|
|
@@ -26,20 +26,20 @@ export const StylePreset = Extension.create({
|
|
|
26
26
|
return { id };
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const presetSelector = this.options.styleRenderer.makePresetCssClass({ id });
|
|
29
|
+
const presetSelector = unref(this.options.styleRenderer).makePresetCssClass({ id });
|
|
30
30
|
|
|
31
31
|
if (element.matches(presetSelector)) return { id };
|
|
32
32
|
if (element.tagName === `H${node?.level}`) return { id };
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// Matches all paragraphs without classes to default preset
|
|
36
|
-
return element.tagName === 'P' ? { id: this.options.defaultId } : null;
|
|
36
|
+
return element.tagName === 'P' ? { id: unref(this.options.defaultId) } : null;
|
|
37
37
|
},
|
|
38
38
|
|
|
39
39
|
renderHTML: (attrs) => {
|
|
40
40
|
if (!attrs.preset) return null;
|
|
41
41
|
|
|
42
|
-
return { class: this.options.styleRenderer.makePresetHtmlClass(attrs.preset) };
|
|
42
|
+
return { class: unref(this.options.styleRenderer).makePresetHtmlClass(attrs.preset) };
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -68,11 +68,11 @@ export const StylePreset = Extension.create({
|
|
|
68
68
|
|
|
69
69
|
return {
|
|
70
70
|
getPresetList: createCommand(() => computed(() => {
|
|
71
|
-
return this.options.presets.filter((preset) => !preset.hidden);
|
|
71
|
+
return unref(this.options.presets).filter((preset) => !preset.hidden);
|
|
72
72
|
})),
|
|
73
73
|
|
|
74
74
|
getPreset: createCommand(({ commands }) => {
|
|
75
|
-
const selectionRef = commands.getBlockAttributes('preset', { id: this.options.defaultId });
|
|
75
|
+
const selectionRef = commands.getBlockAttributes('preset', { id: unref(this.options.defaultId) });
|
|
76
76
|
const presetsRef = commands.getPresetList();
|
|
77
77
|
const isLinkRef = commands.isLink();
|
|
78
78
|
const linkPresetRef = commands.getLinkPreset();
|
|
@@ -115,7 +115,7 @@ export const StylePreset = Extension.create({
|
|
|
115
115
|
}),
|
|
116
116
|
|
|
117
117
|
applyDefaultPreset: createCommand(({ commands }) => {
|
|
118
|
-
commands.applyPreset(this.options.defaultId);
|
|
118
|
+
commands.applyPreset(unref(this.options.defaultId));
|
|
119
119
|
}),
|
|
120
120
|
|
|
121
121
|
removePreset: createCommand(({ commands }) => {
|
|
@@ -198,6 +198,6 @@ export const StylePreset = Extension.create({
|
|
|
198
198
|
},
|
|
199
199
|
|
|
200
200
|
onCreate() {
|
|
201
|
-
this.options.styleRenderer.inject(ContextWindow.head, this.options.presets);
|
|
201
|
+
this.options.styleRenderer.inject(ContextWindow.head, unref(this.options.presets));
|
|
202
202
|
}
|
|
203
203
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ref } from 'vue';
|
|
2
|
-
import { Editor, Mark } from '@tiptap/vue-
|
|
2
|
+
import { Editor, Mark } from '@tiptap/vue-3';
|
|
3
3
|
import { buildTestExtensions } from '../../__tests__/utils';
|
|
4
4
|
import { ContentNormalizer, NodeFactory } from '../../services';
|
|
5
5
|
import { Link } from '../Link';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ref } from 'vue';
|
|
2
|
-
import { Editor, Extension, Mark } from '@tiptap/vue-
|
|
2
|
+
import { Editor, Extension, Mark } from '@tiptap/vue-3';
|
|
3
3
|
import { buildTestExtensions } from '../../../__tests__/utils';
|
|
4
4
|
import { Devices, ListTypes, MarkGroups, NodeTypes, TextSettings } from '../../../enums';
|
|
5
5
|
import { ContentNormalizer, NodeFactory } from '../../../services';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Editor, Mark, Extension } from '@tiptap/vue-
|
|
1
|
+
import { Editor, Mark, Extension } from '@tiptap/vue-3';
|
|
2
2
|
import { buildTestExtensions } from '../../../__tests__/utils';
|
|
3
3
|
import { ContentNormalizer, NodeFactory } from '../../../services';
|
|
4
4
|
import { NodeTypes, TextSettings } from '../../../enums';
|
package/lib/extensions/index.js
CHANGED
|
@@ -25,7 +25,7 @@ export function buildExtensions(options) {
|
|
|
25
25
|
watch(options.presetsRef, () => {
|
|
26
26
|
presetsMap.default = getPresetById(options.defaultPresetId);
|
|
27
27
|
presetsMap.link = getPresetById(options.linkPresetId);
|
|
28
|
-
}, { immediate: true });
|
|
28
|
+
}, { immediate: true, deep: true });
|
|
29
29
|
|
|
30
30
|
return buildCoreExtensions(options).concat([
|
|
31
31
|
StylePreset.configure({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Node, wrappingInputRule } from '@tiptap/vue-
|
|
1
|
+
import { Node, wrappingInputRule } from '@tiptap/vue-3';
|
|
2
2
|
import { computed, unref } from 'vue';
|
|
3
3
|
import { copyMark, createCommand } from '../../utils';
|
|
4
4
|
import { ListTypes, MarkGroups, NodeTypes, TextSettings } from '../../enums';
|
|
@@ -34,7 +34,7 @@ export const List = Node.create({
|
|
|
34
34
|
|
|
35
35
|
const getBulletType = (element) => {
|
|
36
36
|
for (const type of ListTypes.values) {
|
|
37
|
-
const bulletClass = `.${this.options.baseClass}${type}`;
|
|
37
|
+
const bulletClass = `.${unref(this.options.baseClass)}${type}`;
|
|
38
38
|
|
|
39
39
|
if (element.matches(bulletClass)) return type;
|
|
40
40
|
if (HTML_TYPES[element.type.toLowerCase()] === type) return type;
|
|
@@ -61,8 +61,8 @@ export const List = Node.create({
|
|
|
61
61
|
|
|
62
62
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
63
63
|
const classes = [
|
|
64
|
-
this.options.baseClass + attrs.bullet.type,
|
|
65
|
-
this.options.presetClass
|
|
64
|
+
unref(this.options.baseClass) + attrs.bullet.type,
|
|
65
|
+
unref(this.options.presetClass)
|
|
66
66
|
];
|
|
67
67
|
const isOrdered = ListTypes.ordered.includes(attrs.bullet.type);
|
|
68
68
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zipify/wysiwyg",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-vue3.0",
|
|
4
4
|
"description": "Zipify modification of TipTap text editor",
|
|
5
5
|
"main": "dist/wysiwyg.mjs",
|
|
6
6
|
"bin": {
|
|
@@ -40,15 +40,15 @@
|
|
|
40
40
|
"@tiptap/extension-list-item": "2.0.0-beta.209",
|
|
41
41
|
"@tiptap/extension-paragraph": "2.0.0-beta.209",
|
|
42
42
|
"@tiptap/extension-text": "2.0.0-beta.209",
|
|
43
|
-
"@tiptap/vue-
|
|
44
|
-
"commander": "^9.
|
|
45
|
-
"jsdom": "^
|
|
43
|
+
"@tiptap/vue-3": "2.0.0-beta.209",
|
|
44
|
+
"commander": "^9.5.0",
|
|
45
|
+
"jsdom": "^21.0.0",
|
|
46
46
|
"lodash": "^4.17.21",
|
|
47
47
|
"simplebar": "^5.3.9"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@zipify/colorpicker": "^2.2",
|
|
51
|
-
"vue": "^2.
|
|
51
|
+
"vue": "^3.2.45"
|
|
52
52
|
},
|
|
53
53
|
"peerDependenciesMeta": {
|
|
54
54
|
"@zipify/colorpicker": {
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@babel/core": "^7.20.
|
|
62
|
+
"@babel/core": "^7.20.12",
|
|
63
63
|
"@babel/eslint-parser": "^7.19.1",
|
|
64
64
|
"@babel/plugin-transform-runtime": "^7.19.6",
|
|
65
65
|
"@babel/preset-env": "^7.20.2",
|
|
@@ -70,30 +70,29 @@
|
|
|
70
70
|
"@rollup/plugin-json": "^6.0.0",
|
|
71
71
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
72
72
|
"@rollup/plugin-replace": "^5.0.2",
|
|
73
|
-
"@rollup/plugin-terser": "^0.
|
|
74
|
-
"@
|
|
75
|
-
"@vue/
|
|
73
|
+
"@rollup/plugin-terser": "^0.3.0",
|
|
74
|
+
"@vitejs/plugin-vue": "^4.0.0",
|
|
75
|
+
"@vue/test-utils": "^2.2.7",
|
|
76
|
+
"@vue/vue3-jest": "^29.2.2",
|
|
76
77
|
"@zipify/colorpicker": "^2.2.1",
|
|
77
|
-
"@zipify/eslint-config": "^1.
|
|
78
|
+
"@zipify/eslint-config": "^1.1.0",
|
|
78
79
|
"babel-jest": "^29.3.1",
|
|
79
|
-
"eslint": "8.
|
|
80
|
-
"eslint-plugin-import": "^2.
|
|
81
|
-
"eslint-plugin-jest": "^27.1
|
|
80
|
+
"eslint": "8.31.0",
|
|
81
|
+
"eslint-plugin-import": "^2.27.4",
|
|
82
|
+
"eslint-plugin-jest": "^27.2.1",
|
|
82
83
|
"eslint-plugin-vue": "^9.8.0",
|
|
83
84
|
"gzipper": "^7.2.0",
|
|
84
|
-
"husky": "^8.0.
|
|
85
|
+
"husky": "^8.0.3",
|
|
85
86
|
"jest": "^29.3.1",
|
|
86
87
|
"jest-environment-jsdom": "^29.3.1",
|
|
87
88
|
"lint-staged": "^13.1.0",
|
|
88
89
|
"postcss-html": "^1.5.0",
|
|
89
90
|
"release-it": "^15.6.0",
|
|
90
|
-
"rollup": "^3.
|
|
91
|
-
"stylelint": "^14.16.
|
|
91
|
+
"rollup": "^3.10.0",
|
|
92
|
+
"stylelint": "^14.16.1",
|
|
92
93
|
"svgo": "^3.0.2",
|
|
93
|
-
"vite": "^4.0.
|
|
94
|
-
"
|
|
95
|
-
"vue": "^2.7.14",
|
|
96
|
-
"vue-template-compiler": "^2.7.14"
|
|
94
|
+
"vite": "^4.0.4",
|
|
95
|
+
"vue": "^3.2.45"
|
|
97
96
|
},
|
|
98
97
|
"engines": {
|
|
99
98
|
"node": ">=18.12.0"
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param componentWrapper {Wrapper}
|
|
3
|
-
*/
|
|
4
|
-
export function toVueEmpty(componentWrapper) {
|
|
5
|
-
if (componentWrapper.vnode.isComment || !componentWrapper.html()) {
|
|
6
|
-
return {
|
|
7
|
-
pass: true,
|
|
8
|
-
message: () => 'Vue component is empty'
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
pass: false,
|
|
14
|
-
message: () => 'Vue component isn\'t empty'
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export function toVuexActionHasBeenDispatched(store, actionName) {
|
|
2
|
-
if (!store.dispatch || !jest.isMockFunction(store.dispatch)) {
|
|
3
|
-
throw new Error('You should mock "dispatch" method in component store');
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
const dispatchCalls = store.dispatch.mock.calls;
|
|
7
|
-
const isActionDispatched = dispatchCalls.some(([dispatchedAction]) => dispatchedAction === actionName);
|
|
8
|
-
|
|
9
|
-
if (isActionDispatched) {
|
|
10
|
-
return {
|
|
11
|
-
pass: true,
|
|
12
|
-
message: () => `Action "${actionName}" has been called`
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
return {
|
|
16
|
-
pass: false,
|
|
17
|
-
message: () => `Action "${actionName}" hasn't been called`
|
|
18
|
-
};
|
|
19
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { shallowMount } from '@vue/test-utils';
|
|
2
|
-
import { ref } from 'vue';
|
|
3
|
-
import { InjectionTokens } from '../injectionTokens';
|
|
4
|
-
import DropdownMenu from '../DropdownMenu';
|
|
5
|
-
|
|
6
|
-
const createToggler = (isOpened) => ({
|
|
7
|
-
close: jest.fn(),
|
|
8
|
-
isOpened: ref(isOpened ?? true)
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
function createComponent({ options, toggler } = {}) {
|
|
12
|
-
return shallowMount(DropdownMenu, {
|
|
13
|
-
stubs: {
|
|
14
|
-
transition: {
|
|
15
|
-
render() {
|
|
16
|
-
return this.$slots.default?.[0];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
propsData: {
|
|
21
|
-
options: options ?? []
|
|
22
|
-
},
|
|
23
|
-
provide: {
|
|
24
|
-
[InjectionTokens.TOGGLER]: toggler ?? createToggler()
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const SELECTORS = {
|
|
30
|
-
MENU: '[data-test-selector="dropdownMenu"]'
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
describe('rendering', () => {
|
|
34
|
-
const getChildEls = (wrapper) => Array.from(wrapper.element.children);
|
|
35
|
-
const getChildTagNames = (wrapper) => getChildEls(wrapper).map((el) => el.tagName);
|
|
36
|
-
|
|
37
|
-
test('should render plain options', () => {
|
|
38
|
-
const wrapper = createComponent({
|
|
39
|
-
options: [
|
|
40
|
-
{ id: 'one' },
|
|
41
|
-
{ id: 'two' }
|
|
42
|
-
]
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const menuWrapper = wrapper.find(SELECTORS.MENU);
|
|
46
|
-
const childTagNames = getChildTagNames(menuWrapper);
|
|
47
|
-
|
|
48
|
-
expect(childTagNames).toEqual(['DROPDOWNOPTION-STUB', 'DROPDOWNOPTION-STUB']);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('should render groups options', () => {
|
|
52
|
-
const wrapper = createComponent({
|
|
53
|
-
options: [
|
|
54
|
-
{ id: 'one', options: [] },
|
|
55
|
-
{ id: 'two', options: [] }
|
|
56
|
-
]
|
|
57
|
-
});
|
|
58
|
-
const menuWrapper = wrapper.find(SELECTORS.MENU);
|
|
59
|
-
const childTagNames = getChildTagNames(menuWrapper);
|
|
60
|
-
|
|
61
|
-
expect(childTagNames).toEqual([
|
|
62
|
-
'DROPDOWNGROUP-STUB',
|
|
63
|
-
'DROPDOWNDIVIDER-STUB',
|
|
64
|
-
'DROPDOWNGROUP-STUB'
|
|
65
|
-
]);
|
|
66
|
-
});
|
|
67
|
-
});
|