@atlaskit/adf-schema 36.13.0 → 36.14.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/CHANGELOG.md +12 -0
- package/dist/cjs/next-schema/full-schema.adf.js +3 -2
- package/dist/cjs/next-schema/generated/markTypes.js +38 -21
- package/dist/cjs/next-schema/generated/nodeTypes.js +210 -226
- package/dist/cjs/next-schema/groups/blockGroup.js +5 -1
- package/dist/cjs/next-schema/groups/inlineGroup.js +1 -3
- package/dist/cjs/next-schema/nodes/blockCard.js +7 -3
- package/dist/cjs/next-schema/nodes/codeBlock.js +2 -2
- package/dist/cjs/next-schema/nodes/inlineExtension.js +5 -1
- package/dist/cjs/next-schema/nodes/layoutColumn.js +2 -1
- package/dist/cjs/next-schema/nodes/media.js +2 -2
- package/dist/cjs/next-schema/nodes/mediaInline.js +29 -12
- package/dist/cjs/next-schema/nodes/mediaSingle.js +2 -1
- package/dist/cjs/next-schema/nodes/mention.js +2 -1
- package/dist/cjs/next-schema/nodes/placeholder.js +1 -0
- package/dist/cjs/next-schema/nodes/table.js +1 -0
- package/dist/cjs/next-schema/nodes/tableCell.js +2 -2
- package/dist/cjs/next-schema/nodes/tableHeader.js +2 -2
- package/dist/cjs/next-schema/nodes/tableRow.js +2 -1
- package/dist/es2019/next-schema/full-schema.adf.js +3 -2
- package/dist/es2019/next-schema/generated/markTypes.js +37 -20
- package/dist/es2019/next-schema/generated/nodeTypes.js +209 -225
- package/dist/es2019/next-schema/groups/blockGroup.js +5 -1
- package/dist/es2019/next-schema/groups/inlineGroup.js +1 -3
- package/dist/es2019/next-schema/nodes/blockCard.js +7 -3
- package/dist/es2019/next-schema/nodes/codeBlock.js +1 -1
- package/dist/es2019/next-schema/nodes/inlineExtension.js +5 -1
- package/dist/es2019/next-schema/nodes/layoutColumn.js +2 -1
- package/dist/es2019/next-schema/nodes/media.js +2 -2
- package/dist/es2019/next-schema/nodes/mediaInline.js +29 -12
- package/dist/es2019/next-schema/nodes/mediaSingle.js +2 -1
- package/dist/es2019/next-schema/nodes/mention.js +2 -1
- package/dist/es2019/next-schema/nodes/placeholder.js +1 -0
- package/dist/es2019/next-schema/nodes/table.js +1 -0
- package/dist/es2019/next-schema/nodes/tableCell.js +2 -2
- package/dist/es2019/next-schema/nodes/tableHeader.js +2 -2
- package/dist/es2019/next-schema/nodes/tableRow.js +2 -1
- package/dist/esm/next-schema/full-schema.adf.js +3 -2
- package/dist/esm/next-schema/generated/markTypes.js +37 -20
- package/dist/esm/next-schema/generated/nodeTypes.js +209 -225
- package/dist/esm/next-schema/groups/blockGroup.js +5 -1
- package/dist/esm/next-schema/groups/inlineGroup.js +1 -3
- package/dist/esm/next-schema/nodes/blockCard.js +7 -3
- package/dist/esm/next-schema/nodes/codeBlock.js +1 -1
- package/dist/esm/next-schema/nodes/inlineExtension.js +5 -1
- package/dist/esm/next-schema/nodes/layoutColumn.js +2 -1
- package/dist/esm/next-schema/nodes/media.js +2 -2
- package/dist/esm/next-schema/nodes/mediaInline.js +29 -12
- package/dist/esm/next-schema/nodes/mediaSingle.js +2 -1
- package/dist/esm/next-schema/nodes/mention.js +2 -1
- package/dist/esm/next-schema/nodes/placeholder.js +1 -0
- package/dist/esm/next-schema/nodes/table.js +1 -0
- package/dist/esm/next-schema/nodes/tableCell.js +2 -2
- package/dist/esm/next-schema/nodes/tableHeader.js +2 -2
- package/dist/esm/next-schema/nodes/tableRow.js +2 -1
- package/dist/types/next-schema/generated/markTypes.d.ts +56 -33
- package/dist/types/next-schema/generated/nodeGroupTypes.d.ts +4 -4
- package/dist/types/next-schema/generated/nodeTypes.d.ts +165 -156
- package/dist/types/next-schema/nodes/codeBlock.d.ts +1 -1
- package/dist/types/next-schema/nodes/inlineExtension.d.ts +2 -0
- package/package.json +2 -2
- package/schema-generators/__tests__/helpers/_utils.ts +123 -0
- package/schema-generators/__tests__/helpers/utils.unit.ts +66 -0
- package/schema-generators/__tests__/unit/json-full-schema.unit.ts +1142 -1231
- package/schema-generators/__tests__/unit/validate-pm-schema.unit.ts +162 -36
@@ -6,11 +6,132 @@ import {
|
|
6
6
|
NodeSpecFactory,
|
7
7
|
} from '@atlaskit/adf-schema-generator/src/transforms/adfToPm/createPMSpecFactory';
|
8
8
|
import { defaultSchema } from '../../../src/schema/default-schema';
|
9
|
+
import { printExpected, printReceived, matcherHint } from 'jest-matcher-utils';
|
10
|
+
import { filterAndSortMarks, formatContent } from '../helpers/_utils';
|
11
|
+
|
12
|
+
/**
|
13
|
+
* TODO: The EXCLUDE and SKIPPED consts are defined to pass the test
|
14
|
+
* Once following ticket is done, will need to remove exclude and unskip tests.
|
15
|
+
* https://product-fabric.atlassian.net/browse/ED-23488
|
16
|
+
*/
|
17
|
+
const EXCLUDE_CONTENT_FROM_NODESPEC = [
|
18
|
+
'uknownBlock', // We won't have it in DSL
|
19
|
+
];
|
20
|
+
const EXCLUDE_MARKS_FROM_NODESPEC = [
|
21
|
+
'confluenceInlineComment', // not exist in ADF DSL
|
22
|
+
'typeAheadQuery', // not exist in ADF DSL
|
23
|
+
];
|
24
|
+
const SKIPPED_MARKSPEC_TESTS = [
|
25
|
+
'link', // new link mark is not matching old link mark
|
26
|
+
'confluenceInlineComment', // not exist in ADF DSL
|
27
|
+
'unsupportedMark', // exist in ADF DSL but have default value where old spec doesn't have
|
28
|
+
'unsupportedNodeAttribute', // exist in ADF DSL but have default value where old spec doesn't have
|
29
|
+
'typeAheadQuery', // not exist in ADF DSL
|
30
|
+
];
|
31
|
+
const SKIPPED_NODESPEC_TESTS = [
|
32
|
+
'doc', // defined in ADF DSL, but not matching old spec
|
33
|
+
'unknownBlock', // not exist in new ADF DSL
|
34
|
+
'confluenceUnsupportedBlock', // not exist in new ADF DSL
|
35
|
+
'confluenceUnsupportedInline', // not exist in new ADF DSL
|
36
|
+
'confluenceJiraIssue', // not exist in new ADF DSL
|
37
|
+
'expand', // in ADF DSL, only expand.use('with_no_marks') is in use. Old spec have marks with 'dataConsumer, fragment'
|
38
|
+
'status', // has uuid localId in old spec
|
39
|
+
'nestedExpandWithNoMarks', // old nodeSpec have blockCard, but not in type NestedExpandContent, new DSL doesn't have blockCard as to match NestedExpandContent.
|
40
|
+
'hardBreak', // not aligned with old spec due to attr.text
|
41
|
+
'mediaInline', // not aligned with old spec due to attr.data
|
42
|
+
'image', // not exist in new ADF DSL
|
43
|
+
'mediaSingleFull', // not aligned with old spec - content is different
|
44
|
+
'table', // displayMode is default in new ADF DSL, but having null in old spec
|
45
|
+
'codeBlockWithNoMarks', // codeBlock doesn't have uniqueID in new ADF DSL, but have it in old spec.
|
46
|
+
'bodiedExtensionWithMarks', // old spec defaults to use bodiedExtension_with_marks_node, new DSL
|
47
|
+
'paragraph', // new ADF DSL have unsupporedInline, but not in old nodeSpec
|
48
|
+
'decisionItem', // new ADF DSL have unsupporedInline, but not in old nodeSpec
|
49
|
+
'taskItem', // new ADF DSL have unsupporedInline, but not in old nodeSpec
|
50
|
+
'heading', // new ADF DSL have unsupporedInline, but not in old nodeSpec
|
51
|
+
'blockquoteWithList', // new ADF DSL have unsupportedMark unsupportedNodeAttribute, but not in old nodeSpec
|
52
|
+
'layoutSection', // new ADF DSL doesn't have unsupportedBlock*|unsupportedBlock+ in content
|
53
|
+
'mediaGroup', // old spec have attrs: {}, but not in new ADF DSL.
|
54
|
+
];
|
55
|
+
|
56
|
+
/**
|
57
|
+
*
|
58
|
+
* When the default schema is created, there's a nodesInOrder map being used to map node name to a node spec
|
59
|
+
* The mapped node spec could be a different variant, rather than the base one.
|
60
|
+
* https://bitbucket.org/atlassian/adf-schema/src/main/packages/adf-schema/src/schema/create-schema.ts#lines-143
|
61
|
+
*
|
62
|
+
* TODO: consider stage0 as well
|
63
|
+
*/
|
64
|
+
const defaultSchemaNodeSpecMap = () => {
|
65
|
+
return {
|
66
|
+
blockquote: 'blockquoteWithList',
|
67
|
+
extension: 'extensionWithMarks',
|
68
|
+
bodiedExtension: 'bodiedExtensionWithMarks',
|
69
|
+
inlineExtension: 'inlineExtensionWithMarks',
|
70
|
+
mediaSingle: 'mediaSingleFull',
|
71
|
+
nestedExpand: 'nestedExpandWithNoMarks',
|
72
|
+
codeBlock: 'codeBlockWithNoMarks',
|
73
|
+
};
|
74
|
+
};
|
75
|
+
|
76
|
+
const getDefaultSpecName = (nodeName: string) => {
|
77
|
+
const customNodeSpecName = defaultSchemaNodeSpecMap()[nodeName];
|
78
|
+
return customNodeSpecName ? customNodeSpecName : nodeName;
|
79
|
+
};
|
80
|
+
|
81
|
+
const failMessage = (actual, expected, not) => () =>
|
82
|
+
`${matcherHint(
|
83
|
+
`${not ? '.not' : ''}.toMatchNodeSpec`,
|
84
|
+
'received',
|
85
|
+
'expected',
|
86
|
+
)}
|
87
|
+
|
88
|
+
Expected nodeSpec${not ? ' not ' : ' '}to be equal:
|
89
|
+
|
90
|
+
Expected: ${printExpected(expected)}
|
91
|
+
Received: ${printReceived(actual)}`;
|
92
|
+
|
93
|
+
declare let expect: any;
|
94
|
+
expect.extend({
|
95
|
+
toMatchNodeSpec(actual: NodeSpec, expected: NodeSpec) {
|
96
|
+
const formattedActual = {
|
97
|
+
...actual,
|
98
|
+
...(actual.content && { content: formatContent(actual.content) }),
|
99
|
+
...(actual.marks && {
|
100
|
+
marks: filterAndSortMarks(actual.marks),
|
101
|
+
}),
|
102
|
+
};
|
103
|
+
|
104
|
+
const formattedExpected = {
|
105
|
+
...expected,
|
106
|
+
...(expected.content && {
|
107
|
+
content: formatContent(expected.content, EXCLUDE_CONTENT_FROM_NODESPEC),
|
108
|
+
}),
|
109
|
+
...(expected.marks && {
|
110
|
+
marks: filterAndSortMarks(expected.marks, EXCLUDE_MARKS_FROM_NODESPEC),
|
111
|
+
}),
|
112
|
+
};
|
113
|
+
|
114
|
+
if (formattedExpected.marks === '') {
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
116
|
+
delete formattedExpected['marks'];
|
117
|
+
}
|
118
|
+
|
119
|
+
const pass = this.equals(formattedActual, formattedExpected);
|
120
|
+
return {
|
121
|
+
pass,
|
122
|
+
message: failMessage(formattedActual, formattedExpected, pass),
|
123
|
+
};
|
124
|
+
},
|
125
|
+
});
|
9
126
|
|
10
127
|
function isMarkSpec(value: MarkSpec | NodeSpec): value is MarkSpec {
|
11
128
|
return true;
|
12
129
|
}
|
13
130
|
|
131
|
+
function isNodeSpec(value: MarkSpec | NodeSpec): value is NodeSpec {
|
132
|
+
return true;
|
133
|
+
}
|
134
|
+
|
14
135
|
/**
|
15
136
|
* Custom omit function, mainly used to filter out parseDOM and toDOM from old spec
|
16
137
|
* and some special logic to filter out certain field when compare spec
|
@@ -18,7 +139,7 @@ function isMarkSpec(value: MarkSpec | NodeSpec): value is MarkSpec {
|
|
18
139
|
* @param keys
|
19
140
|
* @returns
|
20
141
|
*/
|
21
|
-
function omit<T extends object>(data: T, keys
|
142
|
+
function omit<T extends object>(data: T, keys = []): T {
|
22
143
|
const result = { ...data };
|
23
144
|
for (const k of keys) {
|
24
145
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
@@ -31,31 +152,27 @@ function omit<T extends object>(data: T, keys: (keyof T)[]): T {
|
|
31
152
|
delete result['excludes'];
|
32
153
|
}
|
33
154
|
}
|
155
|
+
if (isNodeSpec(data)) {
|
156
|
+
// Treat inline: false same as no inline property
|
157
|
+
if (data.inline !== undefined && data.inline === false) {
|
158
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
159
|
+
delete result['inline'];
|
160
|
+
}
|
161
|
+
}
|
34
162
|
return result;
|
35
163
|
}
|
36
164
|
|
37
165
|
describe('validate PM schema', () => {
|
38
166
|
describe('marks', () => {
|
39
167
|
const { marks } = defaultSchema as Schema;
|
40
|
-
const skipLists =
|
41
|
-
'link', // TODO: new link mark is not matching old link mark
|
42
|
-
'confluenceInlineComment', // TODO: not exist in ADF DSL
|
43
|
-
'unsupportedMark', // TODO: not exist in ADF DSL
|
44
|
-
'unsupportedNodeAttribute', // TODO: not exist in ADF DSL
|
45
|
-
'typeAheadQuery', // TODO: not exist in ADF DSL
|
46
|
-
// Following marks not exported in adf-schema
|
47
|
-
'__colorGroupDeclaration',
|
48
|
-
'__fontStyleGroupDeclaration',
|
49
|
-
'__searchQueryGroupDeclaration',
|
50
|
-
'__linkGroupDeclaration',
|
51
|
-
];
|
168
|
+
const skipLists = SKIPPED_MARKSPEC_TESTS;
|
52
169
|
|
53
170
|
const testCases = Object.entries(marks).map(([key, value]) => {
|
54
171
|
return {
|
55
172
|
name: key,
|
56
173
|
legacyMarkSpec: value.spec,
|
57
|
-
newMarkSpecFn: newMarkSpecs[
|
58
|
-
skip: skipLists.includes(key),
|
174
|
+
newMarkSpecFn: newMarkSpecs[key] as MarkSpecFactory,
|
175
|
+
skip: skipLists.includes(key) || key.startsWith('__'),
|
59
176
|
};
|
60
177
|
});
|
61
178
|
|
@@ -69,7 +186,7 @@ describe('validate PM schema', () => {
|
|
69
186
|
testMethod(`validate markSpec for mark ${name}`, () => {
|
70
187
|
// check if there's any missing markSpec
|
71
188
|
expect(newMarkSpecFn).toBeDefined();
|
72
|
-
const newMarkSpec = newMarkSpecFn({});
|
189
|
+
const newMarkSpec = newMarkSpecFn<any>({});
|
73
190
|
expect(omit(newMarkSpec, ['parseDOM', 'toDOM'])).toEqual(
|
74
191
|
omit(legacyMarkSpec, ['parseDOM', 'toDOM']),
|
75
192
|
);
|
@@ -77,34 +194,43 @@ describe('validate PM schema', () => {
|
|
77
194
|
});
|
78
195
|
});
|
79
196
|
|
80
|
-
|
81
|
-
// TODO: marks are not matching, especially missing unsupportedBlock, unsupportedNodeAttribute
|
82
|
-
describe.skip('nodes', () => {
|
197
|
+
describe('nodes', () => {
|
83
198
|
const { nodes } = defaultSchema as Schema;
|
84
|
-
const skipLists =
|
199
|
+
const skipLists = SKIPPED_NODESPEC_TESTS;
|
85
200
|
const testCases = Object.entries(nodes).map(([key, value]) => {
|
201
|
+
const specName = getDefaultSpecName(key);
|
86
202
|
return {
|
87
|
-
name:
|
203
|
+
name: specName,
|
88
204
|
legacyNodeSpec: value.spec,
|
89
|
-
newNodeSpecFn: newNodeSpecs[
|
90
|
-
|
205
|
+
newNodeSpecFn: newNodeSpecs[specName] as NodeSpecFactory,
|
206
|
+
testingMethod: {
|
207
|
+
skip: skipLists.includes(specName),
|
208
|
+
},
|
91
209
|
};
|
92
210
|
});
|
93
211
|
|
94
|
-
const getTestingMethod = (skip
|
95
|
-
|
212
|
+
const getTestingMethod = ({ only = false, skip = false }) => {
|
213
|
+
if (skip) {
|
214
|
+
return it.skip;
|
215
|
+
}
|
216
|
+
if (only) {
|
217
|
+
return it.only;
|
218
|
+
}
|
219
|
+
return it;
|
96
220
|
};
|
97
221
|
|
98
|
-
testCases.forEach(
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
omit(
|
106
|
-
|
107
|
-
|
108
|
-
|
222
|
+
testCases.forEach(
|
223
|
+
({ name, legacyNodeSpec, newNodeSpecFn, testingMethod }) => {
|
224
|
+
const testMethod = getTestingMethod(testingMethod);
|
225
|
+
testMethod(`validate nodeSpec for node ${name}`, () => {
|
226
|
+
// check if there's any missing nodeSpec
|
227
|
+
expect(newNodeSpecFn).toBeDefined();
|
228
|
+
const newNodeSpec = newNodeSpecFn<any>({});
|
229
|
+
expect(omit(newNodeSpec, ['parseDOM', 'toDOM'])).toMatchNodeSpec(
|
230
|
+
omit(legacyNodeSpec, ['parseDOM', 'toDOM']),
|
231
|
+
);
|
232
|
+
});
|
233
|
+
},
|
234
|
+
);
|
109
235
|
});
|
110
236
|
});
|