@contentful/field-editor-markdown 2.2.0 → 2.2.1
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/dist/cjs/MarkdownActions.spec.js +55 -54
- package/dist/cjs/components/MarkdownToolbar.spec.js +38 -38
- package/dist/cjs/utils/insertAssetLinks.spec.js +15 -14
- package/dist/cjs/utils/linkOrganizer.spec.js +31 -30
- package/dist/cjs/utils/replaceMailtoAmp.spec.js +8 -7
- package/dist/esm/MarkdownActions.spec.js +35 -34
- package/dist/esm/components/MarkdownToolbar.spec.js +26 -26
- package/dist/esm/utils/insertAssetLinks.spec.js +1 -0
- package/dist/esm/utils/linkOrganizer.spec.js +1 -0
- package/dist/esm/utils/replaceMailtoAmp.spec.js +1 -0
- package/dist/types/components/MarkdownToolbar.spec.d.ts +1 -1
- package/package.json +6 -6
|
@@ -2,22 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
+
const _vitest = require("vitest");
|
|
5
6
|
const _InsertLinkModalDialog = require("./dialogs/InsertLinkModalDialog");
|
|
6
7
|
const _InsertTableModalDialog = require("./dialogs/InsertTableModalDialog");
|
|
7
8
|
const _SpecialCharacterModalDialog = require("./dialogs/SpecialCharacterModalDialog");
|
|
8
9
|
const _ZenModeModalDialog = require("./dialogs/ZenModeModalDialog");
|
|
9
10
|
const _MarkdownActions = require("./MarkdownActions");
|
|
10
|
-
|
|
11
|
-
openInsertLinkDialog:
|
|
11
|
+
_vitest.vi.mock('./dialogs/InsertLinkModalDialog', ()=>({
|
|
12
|
+
openInsertLinkDialog: _vitest.vi.fn()
|
|
12
13
|
}));
|
|
13
|
-
|
|
14
|
-
openInsertSpecialCharacter:
|
|
14
|
+
_vitest.vi.mock('./dialogs/SpecialCharacterModalDialog', ()=>({
|
|
15
|
+
openInsertSpecialCharacter: _vitest.vi.fn()
|
|
15
16
|
}));
|
|
16
|
-
|
|
17
|
-
openInsertTableDialog:
|
|
17
|
+
_vitest.vi.mock('./dialogs/InsertTableModalDialog', ()=>({
|
|
18
|
+
openInsertTableDialog: _vitest.vi.fn()
|
|
18
19
|
}));
|
|
19
|
-
|
|
20
|
-
openZenMode:
|
|
20
|
+
_vitest.vi.mock('./dialogs/ZenModeModalDialog', ()=>({
|
|
21
|
+
openZenMode: _vitest.vi.fn()
|
|
21
22
|
}));
|
|
22
23
|
const mockedOpenInsertLinkDialog = _InsertLinkModalDialog.openInsertLinkDialog;
|
|
23
24
|
const mockedOpenInsertSpecialCharacter = _SpecialCharacterModalDialog.openInsertSpecialCharacter;
|
|
@@ -25,31 +26,31 @@ const mockedOpenInsertTableDialog = _InsertTableModalDialog.openInsertTableDialo
|
|
|
25
26
|
const mockedOpenZenMode = _ZenModeModalDialog.openZenMode;
|
|
26
27
|
const createEditor = ()=>({
|
|
27
28
|
actions: {
|
|
28
|
-
h1:
|
|
29
|
-
h2:
|
|
30
|
-
h3:
|
|
31
|
-
bold:
|
|
32
|
-
italic:
|
|
33
|
-
quote:
|
|
34
|
-
ol:
|
|
35
|
-
ul:
|
|
36
|
-
strike:
|
|
37
|
-
code:
|
|
38
|
-
hr:
|
|
39
|
-
indent:
|
|
40
|
-
dedent:
|
|
41
|
-
undo:
|
|
42
|
-
redo:
|
|
43
|
-
link:
|
|
44
|
-
table:
|
|
29
|
+
h1: _vitest.vi.fn(),
|
|
30
|
+
h2: _vitest.vi.fn(),
|
|
31
|
+
h3: _vitest.vi.fn(),
|
|
32
|
+
bold: _vitest.vi.fn(),
|
|
33
|
+
italic: _vitest.vi.fn(),
|
|
34
|
+
quote: _vitest.vi.fn(),
|
|
35
|
+
ol: _vitest.vi.fn(),
|
|
36
|
+
ul: _vitest.vi.fn(),
|
|
37
|
+
strike: _vitest.vi.fn(),
|
|
38
|
+
code: _vitest.vi.fn(),
|
|
39
|
+
hr: _vitest.vi.fn(),
|
|
40
|
+
indent: _vitest.vi.fn(),
|
|
41
|
+
dedent: _vitest.vi.fn(),
|
|
42
|
+
undo: _vitest.vi.fn(),
|
|
43
|
+
redo: _vitest.vi.fn(),
|
|
44
|
+
link: _vitest.vi.fn(),
|
|
45
|
+
table: _vitest.vi.fn()
|
|
45
46
|
},
|
|
46
|
-
usePrimarySelection:
|
|
47
|
-
getSelectedText:
|
|
48
|
-
insert:
|
|
49
|
-
getContent:
|
|
50
|
-
setContent:
|
|
51
|
-
setCursor:
|
|
52
|
-
focus:
|
|
47
|
+
usePrimarySelection: _vitest.vi.fn(),
|
|
48
|
+
getSelectedText: _vitest.vi.fn(),
|
|
49
|
+
insert: _vitest.vi.fn(),
|
|
50
|
+
getContent: _vitest.vi.fn(),
|
|
51
|
+
setContent: _vitest.vi.fn(),
|
|
52
|
+
setCursor: _vitest.vi.fn(),
|
|
53
|
+
focus: _vitest.vi.fn()
|
|
53
54
|
});
|
|
54
55
|
const createSdk = ()=>({
|
|
55
56
|
dialogs: {},
|
|
@@ -58,14 +59,14 @@ const createSdk = ()=>({
|
|
|
58
59
|
fallbacks: {}
|
|
59
60
|
},
|
|
60
61
|
notifier: {
|
|
61
|
-
success:
|
|
62
|
+
success: _vitest.vi.fn()
|
|
62
63
|
}
|
|
63
64
|
});
|
|
64
|
-
describe('createMarkdownActions', ()=>{
|
|
65
|
-
beforeEach(()=>{
|
|
66
|
-
|
|
65
|
+
(0, _vitest.describe)('createMarkdownActions', ()=>{
|
|
66
|
+
(0, _vitest.beforeEach)(()=>{
|
|
67
|
+
_vitest.vi.clearAllMocks();
|
|
67
68
|
});
|
|
68
|
-
it('dispatches toolbar actions to the editor', ()=>{
|
|
69
|
+
(0, _vitest.it)('dispatches toolbar actions to the editor', ()=>{
|
|
69
70
|
const editor = createEditor();
|
|
70
71
|
const actions = (0, _MarkdownActions.createMarkdownActions)({
|
|
71
72
|
sdk: createSdk(),
|
|
@@ -76,12 +77,12 @@ describe('createMarkdownActions', ()=>{
|
|
|
76
77
|
actions.simple.bold();
|
|
77
78
|
actions.simple.ul();
|
|
78
79
|
actions.history.undo();
|
|
79
|
-
expect(editor.actions.h2).toHaveBeenCalledTimes(1);
|
|
80
|
-
expect(editor.actions.bold).toHaveBeenCalledTimes(1);
|
|
81
|
-
expect(editor.actions.ul).toHaveBeenCalledTimes(1);
|
|
82
|
-
expect(editor.actions.undo).toHaveBeenCalledTimes(1);
|
|
80
|
+
(0, _vitest.expect)(editor.actions.h2).toHaveBeenCalledTimes(1);
|
|
81
|
+
(0, _vitest.expect)(editor.actions.bold).toHaveBeenCalledTimes(1);
|
|
82
|
+
(0, _vitest.expect)(editor.actions.ul).toHaveBeenCalledTimes(1);
|
|
83
|
+
(0, _vitest.expect)(editor.actions.undo).toHaveBeenCalledTimes(1);
|
|
83
84
|
});
|
|
84
|
-
it('opens the link dialog with the selected text and inserts a titled link', async ()=>{
|
|
85
|
+
(0, _vitest.it)('opens the link dialog with the selected text and inserts a titled link', async ()=>{
|
|
85
86
|
const editor = createEditor();
|
|
86
87
|
const sdk = createSdk();
|
|
87
88
|
editor.getSelectedText.mockReturnValue('Contentful');
|
|
@@ -96,13 +97,13 @@ describe('createMarkdownActions', ()=>{
|
|
|
96
97
|
locale: 'en-US'
|
|
97
98
|
});
|
|
98
99
|
await actions.insertLink();
|
|
99
|
-
expect(editor.usePrimarySelection).toHaveBeenCalledTimes(1);
|
|
100
|
-
expect(mockedOpenInsertLinkDialog).toHaveBeenCalledWith(sdk.dialogs, {
|
|
100
|
+
(0, _vitest.expect)(editor.usePrimarySelection).toHaveBeenCalledTimes(1);
|
|
101
|
+
(0, _vitest.expect)(mockedOpenInsertLinkDialog).toHaveBeenCalledWith(sdk.dialogs, {
|
|
101
102
|
selectedText: 'Contentful'
|
|
102
103
|
});
|
|
103
|
-
expect(editor.actions.link).toHaveBeenCalledWith('https://contentful.com', 'Contentful', 'The best headless CMS');
|
|
104
|
+
(0, _vitest.expect)(editor.actions.link).toHaveBeenCalledWith('https://contentful.com', 'Contentful', 'The best headless CMS');
|
|
104
105
|
});
|
|
105
|
-
it('falls back to dialog text when no editor selection exists', async ()=>{
|
|
106
|
+
(0, _vitest.it)('falls back to dialog text when no editor selection exists', async ()=>{
|
|
106
107
|
const editor = createEditor();
|
|
107
108
|
editor.getSelectedText.mockReturnValue('');
|
|
108
109
|
mockedOpenInsertLinkDialog.mockResolvedValue({
|
|
@@ -116,9 +117,9 @@ describe('createMarkdownActions', ()=>{
|
|
|
116
117
|
locale: 'en-US'
|
|
117
118
|
});
|
|
118
119
|
await actions.insertLink();
|
|
119
|
-
expect(editor.actions.link).toHaveBeenCalledWith('https://contentful.com', 'Contentful', '');
|
|
120
|
+
(0, _vitest.expect)(editor.actions.link).toHaveBeenCalledWith('https://contentful.com', 'Contentful', '');
|
|
120
121
|
});
|
|
121
|
-
it('inserts special characters and tables from dialog results', async ()=>{
|
|
122
|
+
(0, _vitest.it)('inserts special characters and tables from dialog results', async ()=>{
|
|
122
123
|
const editor = createEditor();
|
|
123
124
|
mockedOpenInsertSpecialCharacter.mockResolvedValue('€');
|
|
124
125
|
mockedOpenInsertTableDialog.mockResolvedValue({
|
|
@@ -132,13 +133,13 @@ describe('createMarkdownActions', ()=>{
|
|
|
132
133
|
});
|
|
133
134
|
await actions.insertSpecialCharacter();
|
|
134
135
|
await actions.insertTable();
|
|
135
|
-
expect(editor.insert).toHaveBeenCalledWith('€');
|
|
136
|
-
expect(editor.actions.table).toHaveBeenCalledWith({
|
|
136
|
+
(0, _vitest.expect)(editor.insert).toHaveBeenCalledWith('€');
|
|
137
|
+
(0, _vitest.expect)(editor.actions.table).toHaveBeenCalledWith({
|
|
137
138
|
rows: 2,
|
|
138
139
|
cols: 3
|
|
139
140
|
});
|
|
140
141
|
});
|
|
141
|
-
it('updates content and restores cursor when zen mode closes', async ()=>{
|
|
142
|
+
(0, _vitest.it)('updates content and restores cursor when zen mode closes', async ()=>{
|
|
142
143
|
const editor = createEditor();
|
|
143
144
|
mockedOpenZenMode.mockResolvedValue({
|
|
144
145
|
value: 'updated markdown',
|
|
@@ -153,11 +154,11 @@ describe('createMarkdownActions', ()=>{
|
|
|
153
154
|
locale: 'en-US'
|
|
154
155
|
});
|
|
155
156
|
await actions.openZenMode();
|
|
156
|
-
expect(editor.setContent).toHaveBeenCalledWith('updated markdown');
|
|
157
|
-
expect(editor.setCursor).toHaveBeenCalledWith({
|
|
157
|
+
(0, _vitest.expect)(editor.setContent).toHaveBeenCalledWith('updated markdown');
|
|
158
|
+
(0, _vitest.expect)(editor.setCursor).toHaveBeenCalledWith({
|
|
158
159
|
line: 2,
|
|
159
160
|
ch: 4
|
|
160
161
|
});
|
|
161
|
-
expect(editor.focus).toHaveBeenCalledTimes(1);
|
|
162
|
+
(0, _vitest.expect)(editor.focus).toHaveBeenCalledTimes(1);
|
|
162
163
|
});
|
|
163
164
|
});
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
6
|
-
require("@testing-library/jest-dom/extend-expect");
|
|
7
6
|
const _react1 = require("@testing-library/react");
|
|
8
7
|
const _userevent = /*#__PURE__*/ _interop_require_default(require("@testing-library/user-event"));
|
|
8
|
+
const _vitest = require("vitest");
|
|
9
9
|
const _MarkdownToolbar = require("./MarkdownToolbar");
|
|
10
10
|
function _interop_require_default(obj) {
|
|
11
11
|
return obj && obj.__esModule ? obj : {
|
|
@@ -62,42 +62,42 @@ const createProps = ()=>({
|
|
|
62
62
|
mode: 'default',
|
|
63
63
|
actions: {
|
|
64
64
|
headings: {
|
|
65
|
-
h1:
|
|
66
|
-
h2:
|
|
67
|
-
h3:
|
|
65
|
+
h1: _vitest.vi.fn(),
|
|
66
|
+
h2: _vitest.vi.fn(),
|
|
67
|
+
h3: _vitest.vi.fn()
|
|
68
68
|
},
|
|
69
69
|
simple: {
|
|
70
|
-
bold:
|
|
71
|
-
italic:
|
|
72
|
-
quote:
|
|
73
|
-
ol:
|
|
74
|
-
ul:
|
|
75
|
-
strike:
|
|
76
|
-
code:
|
|
77
|
-
hr:
|
|
78
|
-
indent:
|
|
79
|
-
dedent:
|
|
70
|
+
bold: _vitest.vi.fn(),
|
|
71
|
+
italic: _vitest.vi.fn(),
|
|
72
|
+
quote: _vitest.vi.fn(),
|
|
73
|
+
ol: _vitest.vi.fn(),
|
|
74
|
+
ul: _vitest.vi.fn(),
|
|
75
|
+
strike: _vitest.vi.fn(),
|
|
76
|
+
code: _vitest.vi.fn(),
|
|
77
|
+
hr: _vitest.vi.fn(),
|
|
78
|
+
indent: _vitest.vi.fn(),
|
|
79
|
+
dedent: _vitest.vi.fn()
|
|
80
80
|
},
|
|
81
81
|
history: {
|
|
82
|
-
undo:
|
|
83
|
-
redo:
|
|
82
|
+
undo: _vitest.vi.fn(),
|
|
83
|
+
redo: _vitest.vi.fn()
|
|
84
84
|
},
|
|
85
|
-
insertLink:
|
|
86
|
-
insertSpecialCharacter:
|
|
87
|
-
insertTable:
|
|
88
|
-
organizeLinks:
|
|
89
|
-
embedExternalContent:
|
|
90
|
-
linkExistingMedia:
|
|
91
|
-
addNewMedia:
|
|
92
|
-
openZenMode:
|
|
93
|
-
closeZenMode:
|
|
85
|
+
insertLink: _vitest.vi.fn(),
|
|
86
|
+
insertSpecialCharacter: _vitest.vi.fn(),
|
|
87
|
+
insertTable: _vitest.vi.fn(),
|
|
88
|
+
organizeLinks: _vitest.vi.fn(),
|
|
89
|
+
embedExternalContent: _vitest.vi.fn(),
|
|
90
|
+
linkExistingMedia: _vitest.vi.fn(),
|
|
91
|
+
addNewMedia: _vitest.vi.fn(),
|
|
92
|
+
openZenMode: _vitest.vi.fn(),
|
|
93
|
+
closeZenMode: _vitest.vi.fn()
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
|
-
describe('MarkdownToolbar', ()=>{
|
|
97
|
-
beforeEach(()=>{
|
|
98
|
-
|
|
96
|
+
(0, _vitest.describe)('MarkdownToolbar', ()=>{
|
|
97
|
+
(0, _vitest.beforeEach)(()=>{
|
|
98
|
+
_vitest.vi.clearAllMocks();
|
|
99
99
|
});
|
|
100
|
-
it('opens the heading menu and calls the selected heading action', async ()=>{
|
|
100
|
+
(0, _vitest.it)('opens the heading menu and calls the selected heading action', async ()=>{
|
|
101
101
|
const props = createProps();
|
|
102
102
|
(0, _react1.render)(/*#__PURE__*/ _react.createElement(_MarkdownToolbar.MarkdownToolbar, props));
|
|
103
103
|
await _userevent.default.click(_react1.screen.getByRole('button', {
|
|
@@ -106,32 +106,32 @@ describe('MarkdownToolbar', ()=>{
|
|
|
106
106
|
await _userevent.default.click(_react1.screen.getByRole('menuitem', {
|
|
107
107
|
name: 'Heading 1'
|
|
108
108
|
}));
|
|
109
|
-
expect(props.actions.headings.h1).toHaveBeenCalledTimes(1);
|
|
109
|
+
(0, _vitest.expect)(props.actions.headings.h1).toHaveBeenCalledTimes(1);
|
|
110
110
|
});
|
|
111
|
-
it('toggles additional actions and exposes the expanded state', async ()=>{
|
|
111
|
+
(0, _vitest.it)('toggles additional actions and exposes the expanded state', async ()=>{
|
|
112
112
|
const props = createProps();
|
|
113
113
|
(0, _react1.render)(/*#__PURE__*/ _react.createElement(_MarkdownToolbar.MarkdownToolbar, props));
|
|
114
114
|
const toggle = _react1.screen.getByRole('button', {
|
|
115
115
|
name: 'More actions'
|
|
116
116
|
});
|
|
117
|
-
expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
|
117
|
+
(0, _vitest.expect)(toggle).toHaveAttribute('aria-expanded', 'false');
|
|
118
118
|
await _userevent.default.click(toggle);
|
|
119
|
-
expect(_react1.screen.getByRole('button', {
|
|
119
|
+
(0, _vitest.expect)(_react1.screen.getByRole('button', {
|
|
120
120
|
name: 'Hide additional actions'
|
|
121
121
|
})).toHaveAttribute('aria-expanded', 'true');
|
|
122
|
-
expect(_react1.screen.getByRole('button', {
|
|
122
|
+
(0, _vitest.expect)(_react1.screen.getByRole('button', {
|
|
123
123
|
name: 'Undo'
|
|
124
124
|
})).toBeInTheDocument();
|
|
125
125
|
});
|
|
126
|
-
it('triggers a toolbar action once per click', async ()=>{
|
|
126
|
+
(0, _vitest.it)('triggers a toolbar action once per click', async ()=>{
|
|
127
127
|
const props = createProps();
|
|
128
128
|
(0, _react1.render)(/*#__PURE__*/ _react.createElement(_MarkdownToolbar.MarkdownToolbar, props));
|
|
129
129
|
await _userevent.default.click(_react1.screen.getByRole('button', {
|
|
130
130
|
name: 'Bold'
|
|
131
131
|
}));
|
|
132
|
-
expect(props.actions.simple.bold).toHaveBeenCalledTimes(1);
|
|
132
|
+
(0, _vitest.expect)(props.actions.simple.bold).toHaveBeenCalledTimes(1);
|
|
133
133
|
});
|
|
134
|
-
it('still supports keyboard-style activation', async ()=>{
|
|
134
|
+
(0, _vitest.it)('still supports keyboard-style activation', async ()=>{
|
|
135
135
|
const props = createProps();
|
|
136
136
|
(0, _react1.render)(/*#__PURE__*/ _react.createElement(_MarkdownToolbar.MarkdownToolbar, props));
|
|
137
137
|
const bold = _react1.screen.getByRole('button', {
|
|
@@ -139,6 +139,6 @@ describe('MarkdownToolbar', ()=>{
|
|
|
139
139
|
});
|
|
140
140
|
bold.focus();
|
|
141
141
|
await _userevent.default.keyboard('{Enter}');
|
|
142
|
-
expect(props.actions.simple.bold).toHaveBeenCalledTimes(1);
|
|
142
|
+
(0, _vitest.expect)(props.actions.simple.bold).toHaveBeenCalledTimes(1);
|
|
143
143
|
});
|
|
144
144
|
});
|
|
@@ -2,21 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
+
const _vitest = require("vitest");
|
|
5
6
|
const _insertAssetLinks = require("./insertAssetLinks");
|
|
6
|
-
describe('replaceAssetDomain', ()=>{
|
|
7
|
-
it('should replace contentful.com domains to ctfassets.net', ()=>{
|
|
8
|
-
expect((0, _insertAssetLinks.replaceAssetDomain)('//images.contentful.com/image.jpg')).toBe('//images.ctfassets.net/image.jpg');
|
|
9
|
-
expect((0, _insertAssetLinks.replaceAssetDomain)('//videos.contentful.com/video.mp4')).toBe('//videos.ctfassets.net/video.mp4');
|
|
10
|
-
expect((0, _insertAssetLinks.replaceAssetDomain)('//downloads.contentful.com/file.doc')).toBe('//downloads.ctfassets.net/file.doc');
|
|
11
|
-
expect((0, _insertAssetLinks.replaceAssetDomain)('//assets.contentful.com/file.doc')).toBe('//assets.ctfassets.net/file.doc');
|
|
12
|
-
expect((0, _insertAssetLinks.replaceAssetDomain)('https://images.contentful.com/image.jpg')).toBe('https://images.ctfassets.net/image.jpg');
|
|
13
|
-
expect((0, _insertAssetLinks.replaceAssetDomain)('https://videos.contentful.com/video.mp4')).toBe('https://videos.ctfassets.net/video.mp4');
|
|
14
|
-
expect((0, _insertAssetLinks.replaceAssetDomain)('https://downloads.contentful.com/file.doc')).toBe('https://downloads.ctfassets.net/file.doc');
|
|
15
|
-
expect((0, _insertAssetLinks.replaceAssetDomain)('https://assets.contentful.com/file.doc')).toBe('https://assets.ctfassets.net/file.doc');
|
|
7
|
+
(0, _vitest.describe)('replaceAssetDomain', ()=>{
|
|
8
|
+
(0, _vitest.it)('should replace contentful.com domains to ctfassets.net', ()=>{
|
|
9
|
+
(0, _vitest.expect)((0, _insertAssetLinks.replaceAssetDomain)('//images.contentful.com/image.jpg')).toBe('//images.ctfassets.net/image.jpg');
|
|
10
|
+
(0, _vitest.expect)((0, _insertAssetLinks.replaceAssetDomain)('//videos.contentful.com/video.mp4')).toBe('//videos.ctfassets.net/video.mp4');
|
|
11
|
+
(0, _vitest.expect)((0, _insertAssetLinks.replaceAssetDomain)('//downloads.contentful.com/file.doc')).toBe('//downloads.ctfassets.net/file.doc');
|
|
12
|
+
(0, _vitest.expect)((0, _insertAssetLinks.replaceAssetDomain)('//assets.contentful.com/file.doc')).toBe('//assets.ctfassets.net/file.doc');
|
|
13
|
+
(0, _vitest.expect)((0, _insertAssetLinks.replaceAssetDomain)('https://images.contentful.com/image.jpg')).toBe('https://images.ctfassets.net/image.jpg');
|
|
14
|
+
(0, _vitest.expect)((0, _insertAssetLinks.replaceAssetDomain)('https://videos.contentful.com/video.mp4')).toBe('https://videos.ctfassets.net/video.mp4');
|
|
15
|
+
(0, _vitest.expect)((0, _insertAssetLinks.replaceAssetDomain)('https://downloads.contentful.com/file.doc')).toBe('https://downloads.ctfassets.net/file.doc');
|
|
16
|
+
(0, _vitest.expect)((0, _insertAssetLinks.replaceAssetDomain)('https://assets.contentful.com/file.doc')).toBe('https://assets.ctfassets.net/file.doc');
|
|
16
17
|
});
|
|
17
|
-
it('should not replace domains not listed on the map', ()=>{
|
|
18
|
-
expect((0, _insertAssetLinks.replaceAssetDomain)('//documents.contentful.com/image.jpg')).toBe('//documents.contentful.com/image.jpg');
|
|
19
|
-
expect((0, _insertAssetLinks.replaceAssetDomain)('anyotherdomain.com/file.doc')).toBe('anyotherdomain.com/file.doc');
|
|
20
|
-
expect((0, _insertAssetLinks.replaceAssetDomain)('https://anyotherdomain.com/file.doc')).toBe('https://anyotherdomain.com/file.doc');
|
|
18
|
+
(0, _vitest.it)('should not replace domains not listed on the map', ()=>{
|
|
19
|
+
(0, _vitest.expect)((0, _insertAssetLinks.replaceAssetDomain)('//documents.contentful.com/image.jpg')).toBe('//documents.contentful.com/image.jpg');
|
|
20
|
+
(0, _vitest.expect)((0, _insertAssetLinks.replaceAssetDomain)('anyotherdomain.com/file.doc')).toBe('anyotherdomain.com/file.doc');
|
|
21
|
+
(0, _vitest.expect)((0, _insertAssetLinks.replaceAssetDomain)('https://anyotherdomain.com/file.doc')).toBe('https://anyotherdomain.com/file.doc');
|
|
21
22
|
});
|
|
22
23
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
+
const _vitest = require("vitest");
|
|
5
6
|
const _linkOrganizer = /*#__PURE__*/ _interop_require_wildcard(require("./linkOrganizer"));
|
|
6
7
|
function _getRequireWildcardCache(nodeInterop) {
|
|
7
8
|
if (typeof WeakMap !== "function") return null;
|
|
@@ -44,55 +45,55 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
44
45
|
}
|
|
45
46
|
return newObj;
|
|
46
47
|
}
|
|
47
|
-
describe('Link organizer', ()=>{
|
|
48
|
-
describe('Inline link finder', ()=>{
|
|
49
|
-
it('Finds all inline links in text', ()=>{
|
|
48
|
+
(0, _vitest.describe)('Link organizer', ()=>{
|
|
49
|
+
(0, _vitest.describe)('Inline link finder', ()=>{
|
|
50
|
+
(0, _vitest.it)('Finds all inline links in text', ()=>{
|
|
50
51
|
const subject = 'test [link](http://url.com) test [link2](http://url2.com) test [link3](http://url.com)';
|
|
51
52
|
const found = _linkOrganizer.findInline(subject);
|
|
52
|
-
expect(found).toHaveLength(3);
|
|
53
|
-
expect(found[0].match).toBe('[link](http://url.com)');
|
|
54
|
-
expect(found[0].text).toBe('link');
|
|
55
|
-
expect(found[0].href).toBe('http://url.com');
|
|
56
|
-
expect(found[0].title).toBe('');
|
|
53
|
+
(0, _vitest.expect)(found).toHaveLength(3);
|
|
54
|
+
(0, _vitest.expect)(found[0].match).toBe('[link](http://url.com)');
|
|
55
|
+
(0, _vitest.expect)(found[0].text).toBe('link');
|
|
56
|
+
(0, _vitest.expect)(found[0].href).toBe('http://url.com');
|
|
57
|
+
(0, _vitest.expect)(found[0].title).toBe('');
|
|
57
58
|
});
|
|
58
|
-
it('Finds and standardizes title', ()=>{
|
|
59
|
+
(0, _vitest.it)('Finds and standardizes title', ()=>{
|
|
59
60
|
const subject = 'test [x](http://url.com "title!") [y](http://xyz.com title 2 )';
|
|
60
61
|
const found = _linkOrganizer.findInline(subject);
|
|
61
|
-
expect(found).toHaveLength(2);
|
|
62
|
-
expect(found[0].title).toBe('title!');
|
|
63
|
-
expect(found[1].title).toBe('title 2');
|
|
62
|
+
(0, _vitest.expect)(found).toHaveLength(2);
|
|
63
|
+
(0, _vitest.expect)(found[0].title).toBe('title!');
|
|
64
|
+
(0, _vitest.expect)(found[1].title).toBe('title 2');
|
|
64
65
|
});
|
|
65
66
|
});
|
|
66
|
-
describe('Reference finder', ()=>{
|
|
67
|
-
it('Finds all references in text', ()=>{
|
|
67
|
+
(0, _vitest.describe)('Reference finder', ()=>{
|
|
68
|
+
(0, _vitest.it)('Finds all references in text', ()=>{
|
|
68
69
|
const subject = 'test [x][1] test [y][2] [with space separator] [3]';
|
|
69
70
|
const found = _linkOrganizer.findRefs(subject);
|
|
70
|
-
expect(found).toHaveLength(3);
|
|
71
|
-
expect(found[0].match).toBe('[x][1]');
|
|
72
|
-
expect(found[2].match).toBe('[with space separator] [3]');
|
|
73
|
-
expect(found[1].text).toBe('y');
|
|
74
|
-
expect(found[1].id).toBe('2');
|
|
71
|
+
(0, _vitest.expect)(found).toHaveLength(3);
|
|
72
|
+
(0, _vitest.expect)(found[0].match).toBe('[x][1]');
|
|
73
|
+
(0, _vitest.expect)(found[2].match).toBe('[with space separator] [3]');
|
|
74
|
+
(0, _vitest.expect)(found[1].text).toBe('y');
|
|
75
|
+
(0, _vitest.expect)(found[1].id).toBe('2');
|
|
75
76
|
});
|
|
76
77
|
});
|
|
77
|
-
describe('Label finder', ()=>{
|
|
78
|
+
(0, _vitest.describe)('Label finder', ()=>{
|
|
78
79
|
const subject = [
|
|
79
80
|
'[1]: http://test.com',
|
|
80
81
|
'[2]: http://url.com',
|
|
81
82
|
'[string]: http://url.com',
|
|
82
83
|
'[4]: http://test.com "Hello world"'
|
|
83
84
|
].join('\n');
|
|
84
|
-
it('Finds all labels', ()=>{
|
|
85
|
+
(0, _vitest.it)('Finds all labels', ()=>{
|
|
85
86
|
const found = _linkOrganizer.findLabels(subject);
|
|
86
|
-
expect(found).toHaveLength(4);
|
|
87
|
-
expect(found[0].id).toBe('1');
|
|
88
|
-
expect(found[2].id).toBe('string');
|
|
89
|
-
expect(found[0].href).toBe('http://test.com');
|
|
90
|
-
expect(found[3].href).toBe('http://test.com');
|
|
91
|
-
expect(found[1].title).toBe('');
|
|
92
|
-
expect(found[3].title).toBe('Hello world');
|
|
87
|
+
(0, _vitest.expect)(found).toHaveLength(4);
|
|
88
|
+
(0, _vitest.expect)(found[0].id).toBe('1');
|
|
89
|
+
(0, _vitest.expect)(found[2].id).toBe('string');
|
|
90
|
+
(0, _vitest.expect)(found[0].href).toBe('http://test.com');
|
|
91
|
+
(0, _vitest.expect)(found[3].href).toBe('http://test.com');
|
|
92
|
+
(0, _vitest.expect)(found[1].title).toBe('');
|
|
93
|
+
(0, _vitest.expect)(found[3].title).toBe('Hello world');
|
|
93
94
|
});
|
|
94
|
-
it('Finds max label id', ()=>{
|
|
95
|
-
expect(_linkOrganizer.findMaxLabelId(subject)).toBe(4);
|
|
95
|
+
(0, _vitest.it)('Finds max label id', ()=>{
|
|
96
|
+
(0, _vitest.expect)(_linkOrganizer.findMaxLabelId(subject)).toBe(4);
|
|
96
97
|
});
|
|
97
98
|
});
|
|
98
99
|
});
|
|
@@ -2,21 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
+
const _vitest = require("vitest");
|
|
5
6
|
const _replaceMailtoAmp = require("./replaceMailtoAmp");
|
|
6
|
-
describe('replace inside mailto', ()=>{
|
|
7
|
+
(0, _vitest.describe)('replace inside mailto', ()=>{
|
|
7
8
|
let str = '<a href="mailto:example@example.com?subject=Hello&body=Hello%20world">Send Email</a>';
|
|
8
|
-
test('replace & with &', ()=>{
|
|
9
|
+
(0, _vitest.test)('replace & with &', ()=>{
|
|
9
10
|
const newStr = (0, _replaceMailtoAmp.replaceMailtoAmp)(str);
|
|
10
|
-
expect(newStr).toBe('<a href="mailto:example@example.com?subject=Hello&body=Hello%20world">Send Email</a>');
|
|
11
|
+
(0, _vitest.expect)(newStr).toBe('<a href="mailto:example@example.com?subject=Hello&body=Hello%20world">Send Email</a>');
|
|
11
12
|
});
|
|
12
|
-
test('no replace if not inside mailto', ()=>{
|
|
13
|
+
(0, _vitest.test)('no replace if not inside mailto', ()=>{
|
|
13
14
|
str = '<a href="https://example.com?subject=Hello&body=Hello%20world">Visit Website</a>';
|
|
14
15
|
const newStr = (0, _replaceMailtoAmp.replaceMailtoAmp)(str);
|
|
15
|
-
expect(newStr).toBe('<a href="https://example.com?subject=Hello&body=Hello%20world">Visit Website</a>');
|
|
16
|
+
(0, _vitest.expect)(newStr).toBe('<a href="https://example.com?subject=Hello&body=Hello%20world">Visit Website</a>');
|
|
16
17
|
});
|
|
17
|
-
test('no replace if no &', ()=>{
|
|
18
|
+
(0, _vitest.test)('no replace if no &', ()=>{
|
|
18
19
|
str = '<a href="mailto:example@example.com?subject=Hello">Send Email</a>';
|
|
19
20
|
const newStr = (0, _replaceMailtoAmp.replaceMailtoAmp)(str);
|
|
20
|
-
expect(newStr).toBe('<a href="mailto:example@example.com?subject=Hello">Send Email</a>');
|
|
21
|
+
(0, _vitest.expect)(newStr).toBe('<a href="mailto:example@example.com?subject=Hello">Send Email</a>');
|
|
21
22
|
});
|
|
22
23
|
});
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
vi.mock('./dialogs/InsertLinkModalDialog', ()=>({
|
|
3
|
+
openInsertLinkDialog: vi.fn()
|
|
3
4
|
}));
|
|
4
|
-
|
|
5
|
-
openInsertSpecialCharacter:
|
|
5
|
+
vi.mock('./dialogs/SpecialCharacterModalDialog', ()=>({
|
|
6
|
+
openInsertSpecialCharacter: vi.fn()
|
|
6
7
|
}));
|
|
7
|
-
|
|
8
|
-
openInsertTableDialog:
|
|
8
|
+
vi.mock('./dialogs/InsertTableModalDialog', ()=>({
|
|
9
|
+
openInsertTableDialog: vi.fn()
|
|
9
10
|
}));
|
|
10
|
-
|
|
11
|
-
openZenMode:
|
|
11
|
+
vi.mock('./dialogs/ZenModeModalDialog', ()=>({
|
|
12
|
+
openZenMode: vi.fn()
|
|
12
13
|
}));
|
|
13
14
|
import { openInsertLinkDialog } from './dialogs/InsertLinkModalDialog';
|
|
14
15
|
import { openInsertTableDialog } from './dialogs/InsertTableModalDialog';
|
|
@@ -21,31 +22,31 @@ const mockedOpenInsertTableDialog = openInsertTableDialog;
|
|
|
21
22
|
const mockedOpenZenMode = openZenMode;
|
|
22
23
|
const createEditor = ()=>({
|
|
23
24
|
actions: {
|
|
24
|
-
h1:
|
|
25
|
-
h2:
|
|
26
|
-
h3:
|
|
27
|
-
bold:
|
|
28
|
-
italic:
|
|
29
|
-
quote:
|
|
30
|
-
ol:
|
|
31
|
-
ul:
|
|
32
|
-
strike:
|
|
33
|
-
code:
|
|
34
|
-
hr:
|
|
35
|
-
indent:
|
|
36
|
-
dedent:
|
|
37
|
-
undo:
|
|
38
|
-
redo:
|
|
39
|
-
link:
|
|
40
|
-
table:
|
|
25
|
+
h1: vi.fn(),
|
|
26
|
+
h2: vi.fn(),
|
|
27
|
+
h3: vi.fn(),
|
|
28
|
+
bold: vi.fn(),
|
|
29
|
+
italic: vi.fn(),
|
|
30
|
+
quote: vi.fn(),
|
|
31
|
+
ol: vi.fn(),
|
|
32
|
+
ul: vi.fn(),
|
|
33
|
+
strike: vi.fn(),
|
|
34
|
+
code: vi.fn(),
|
|
35
|
+
hr: vi.fn(),
|
|
36
|
+
indent: vi.fn(),
|
|
37
|
+
dedent: vi.fn(),
|
|
38
|
+
undo: vi.fn(),
|
|
39
|
+
redo: vi.fn(),
|
|
40
|
+
link: vi.fn(),
|
|
41
|
+
table: vi.fn()
|
|
41
42
|
},
|
|
42
|
-
usePrimarySelection:
|
|
43
|
-
getSelectedText:
|
|
44
|
-
insert:
|
|
45
|
-
getContent:
|
|
46
|
-
setContent:
|
|
47
|
-
setCursor:
|
|
48
|
-
focus:
|
|
43
|
+
usePrimarySelection: vi.fn(),
|
|
44
|
+
getSelectedText: vi.fn(),
|
|
45
|
+
insert: vi.fn(),
|
|
46
|
+
getContent: vi.fn(),
|
|
47
|
+
setContent: vi.fn(),
|
|
48
|
+
setCursor: vi.fn(),
|
|
49
|
+
focus: vi.fn()
|
|
49
50
|
});
|
|
50
51
|
const createSdk = ()=>({
|
|
51
52
|
dialogs: {},
|
|
@@ -54,12 +55,12 @@ const createSdk = ()=>({
|
|
|
54
55
|
fallbacks: {}
|
|
55
56
|
},
|
|
56
57
|
notifier: {
|
|
57
|
-
success:
|
|
58
|
+
success: vi.fn()
|
|
58
59
|
}
|
|
59
60
|
});
|
|
60
61
|
describe('createMarkdownActions', ()=>{
|
|
61
62
|
beforeEach(()=>{
|
|
62
|
-
|
|
63
|
+
vi.clearAllMocks();
|
|
63
64
|
});
|
|
64
65
|
it('dispatches toolbar actions to the editor', ()=>{
|
|
65
66
|
const editor = createEditor();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import '@testing-library/jest-dom/extend-expect';
|
|
3
2
|
import { configure, render, screen } from '@testing-library/react';
|
|
4
3
|
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
5
|
import { MarkdownToolbar } from './MarkdownToolbar';
|
|
6
6
|
configure({
|
|
7
7
|
testIdAttribute: 'data-test-id'
|
|
@@ -12,40 +12,40 @@ const createProps = ()=>({
|
|
|
12
12
|
mode: 'default',
|
|
13
13
|
actions: {
|
|
14
14
|
headings: {
|
|
15
|
-
h1:
|
|
16
|
-
h2:
|
|
17
|
-
h3:
|
|
15
|
+
h1: vi.fn(),
|
|
16
|
+
h2: vi.fn(),
|
|
17
|
+
h3: vi.fn()
|
|
18
18
|
},
|
|
19
19
|
simple: {
|
|
20
|
-
bold:
|
|
21
|
-
italic:
|
|
22
|
-
quote:
|
|
23
|
-
ol:
|
|
24
|
-
ul:
|
|
25
|
-
strike:
|
|
26
|
-
code:
|
|
27
|
-
hr:
|
|
28
|
-
indent:
|
|
29
|
-
dedent:
|
|
20
|
+
bold: vi.fn(),
|
|
21
|
+
italic: vi.fn(),
|
|
22
|
+
quote: vi.fn(),
|
|
23
|
+
ol: vi.fn(),
|
|
24
|
+
ul: vi.fn(),
|
|
25
|
+
strike: vi.fn(),
|
|
26
|
+
code: vi.fn(),
|
|
27
|
+
hr: vi.fn(),
|
|
28
|
+
indent: vi.fn(),
|
|
29
|
+
dedent: vi.fn()
|
|
30
30
|
},
|
|
31
31
|
history: {
|
|
32
|
-
undo:
|
|
33
|
-
redo:
|
|
32
|
+
undo: vi.fn(),
|
|
33
|
+
redo: vi.fn()
|
|
34
34
|
},
|
|
35
|
-
insertLink:
|
|
36
|
-
insertSpecialCharacter:
|
|
37
|
-
insertTable:
|
|
38
|
-
organizeLinks:
|
|
39
|
-
embedExternalContent:
|
|
40
|
-
linkExistingMedia:
|
|
41
|
-
addNewMedia:
|
|
42
|
-
openZenMode:
|
|
43
|
-
closeZenMode:
|
|
35
|
+
insertLink: vi.fn(),
|
|
36
|
+
insertSpecialCharacter: vi.fn(),
|
|
37
|
+
insertTable: vi.fn(),
|
|
38
|
+
organizeLinks: vi.fn(),
|
|
39
|
+
embedExternalContent: vi.fn(),
|
|
40
|
+
linkExistingMedia: vi.fn(),
|
|
41
|
+
addNewMedia: vi.fn(),
|
|
42
|
+
openZenMode: vi.fn(),
|
|
43
|
+
closeZenMode: vi.fn()
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
describe('MarkdownToolbar', ()=>{
|
|
47
47
|
beforeEach(()=>{
|
|
48
|
-
|
|
48
|
+
vi.clearAllMocks();
|
|
49
49
|
});
|
|
50
50
|
it('opens the heading menu and calls the selected heading action', async ()=>{
|
|
51
51
|
const props = createProps();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-markdown",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
"build:types": "tsc --outDir dist/types --emitDeclarationOnly",
|
|
32
32
|
"build:cjs": "swc src --config-file ../../.swcrc -d dist/cjs -C module.type=commonjs",
|
|
33
33
|
"build:esm": "swc src --config-file ../../.swcrc -d dist/esm",
|
|
34
|
-
"test": "
|
|
35
|
-
"test:ci": "
|
|
34
|
+
"test": "vitest",
|
|
35
|
+
"test:ci": "vitest run",
|
|
36
36
|
"tsc": "tsc -p ./ --noEmit"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@contentful/f36-components": "^6.7.1",
|
|
40
40
|
"@contentful/f36-icons": "^6.7.1",
|
|
41
41
|
"@contentful/f36-tokens": "^6.1.2",
|
|
42
|
-
"@contentful/field-editor-shared": "^4.4.
|
|
42
|
+
"@contentful/field-editor-shared": "^4.4.1",
|
|
43
43
|
"@emotion/css": "^11.13.5",
|
|
44
44
|
"@types/codemirror": "0.0.109",
|
|
45
45
|
"codemirror": "^5.65.11",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@babel/core": "^7.5.5",
|
|
54
54
|
"@contentful/app-sdk": "^4.29.0",
|
|
55
|
-
"@contentful/field-editor-test-utils": "^3.1.
|
|
55
|
+
"@contentful/field-editor-test-utils": "^3.1.1",
|
|
56
56
|
"@lingui/core": "5.3.0",
|
|
57
57
|
"@testing-library/user-event": "^13.1.9"
|
|
58
58
|
},
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"registry": "https://npm.pkg.github.com/"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "5fb6c32d2590e72e56a53cb180a155f84d6505d9"
|
|
69
69
|
}
|