@atlaskit/adf-schema 28.1.11 → 28.1.13

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.
Files changed (218) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +1 -1
  3. package/build/tsconfig.json +0 -18
  4. package/index.ts +0 -275
  5. package/src/__tests__/unit/json-schema/v1.ts +0 -55
  6. package/src/__tests__/unit/schema/create-schema.ts +0 -214
  7. package/src/__tests__/unit/schema/default-schema.ts +0 -192
  8. package/src/__tests__/unit/schema/marks/annotation.ts +0 -46
  9. package/src/__tests__/unit/schema/marks/border.ts +0 -76
  10. package/src/__tests__/unit/schema/marks/breakout.ts +0 -24
  11. package/src/__tests__/unit/schema/marks/code.ts +0 -44
  12. package/src/__tests__/unit/schema/marks/confluence-inline-comment.ts +0 -25
  13. package/src/__tests__/unit/schema/marks/data-consumer.ts +0 -52
  14. package/src/__tests__/unit/schema/marks/em.ts +0 -37
  15. package/src/__tests__/unit/schema/marks/link.ts +0 -188
  16. package/src/__tests__/unit/schema/marks/strike.ts +0 -37
  17. package/src/__tests__/unit/schema/marks/strong.ts +0 -43
  18. package/src/__tests__/unit/schema/marks/subsup.ts +0 -50
  19. package/src/__tests__/unit/schema/marks/text-color.ts +0 -61
  20. package/src/__tests__/unit/schema/marks/underline.ts +0 -36
  21. package/src/__tests__/unit/schema/nodes/_consts.ts +0 -964
  22. package/src/__tests__/unit/schema/nodes/block-card.ts +0 -184
  23. package/src/__tests__/unit/schema/nodes/blockquote.ts +0 -44
  24. package/src/__tests__/unit/schema/nodes/bodied-extension.ts +0 -101
  25. package/src/__tests__/unit/schema/nodes/code-block.ts +0 -221
  26. package/src/__tests__/unit/schema/nodes/confluence-unsupported-block.ts +0 -32
  27. package/src/__tests__/unit/schema/nodes/confluence-unsupported-inline.ts +0 -35
  28. package/src/__tests__/unit/schema/nodes/date.ts +0 -51
  29. package/src/__tests__/unit/schema/nodes/decision-item.ts +0 -46
  30. package/src/__tests__/unit/schema/nodes/decision-list.ts +0 -52
  31. package/src/__tests__/unit/schema/nodes/embed-card.ts +0 -60
  32. package/src/__tests__/unit/schema/nodes/emoji.ts +0 -71
  33. package/src/__tests__/unit/schema/nodes/expand.ts +0 -51
  34. package/src/__tests__/unit/schema/nodes/extension.ts +0 -101
  35. package/src/__tests__/unit/schema/nodes/hard-break.ts +0 -24
  36. package/src/__tests__/unit/schema/nodes/heading.ts +0 -56
  37. package/src/__tests__/unit/schema/nodes/image.ts +0 -32
  38. package/src/__tests__/unit/schema/nodes/inline-card.ts +0 -106
  39. package/src/__tests__/unit/schema/nodes/inline-extension.ts +0 -79
  40. package/src/__tests__/unit/schema/nodes/layout-column.ts +0 -54
  41. package/src/__tests__/unit/schema/nodes/layout-section.ts +0 -95
  42. package/src/__tests__/unit/schema/nodes/list-item.ts +0 -49
  43. package/src/__tests__/unit/schema/nodes/media-group.ts +0 -67
  44. package/src/__tests__/unit/schema/nodes/media-single.ts +0 -171
  45. package/src/__tests__/unit/schema/nodes/media.ts +0 -384
  46. package/src/__tests__/unit/schema/nodes/mention.ts +0 -115
  47. package/src/__tests__/unit/schema/nodes/nestedExpand.ts +0 -72
  48. package/src/__tests__/unit/schema/nodes/ordered-list.ts +0 -49
  49. package/src/__tests__/unit/schema/nodes/panel.ts +0 -180
  50. package/src/__tests__/unit/schema/nodes/paragraph.ts +0 -25
  51. package/src/__tests__/unit/schema/nodes/placeholder.ts +0 -46
  52. package/src/__tests__/unit/schema/nodes/rule.ts +0 -24
  53. package/src/__tests__/unit/schema/nodes/status.ts +0 -120
  54. package/src/__tests__/unit/schema/nodes/tableNodes.ts +0 -555
  55. package/src/__tests__/unit/schema/nodes/task-item.ts +0 -39
  56. package/src/__tests__/unit/schema/nodes/task-list.ts +0 -45
  57. package/src/__tests__/unit/schema/nodes/unknown-block.ts +0 -42
  58. package/src/__tests__/unit/schema/nodes/unsupported-block.ts +0 -42
  59. package/src/__tests__/unit/schema/nodes/unsupported-inline.ts +0 -38
  60. package/src/__tests__/unit/utils/colors.ts +0 -42
  61. package/src/__tests__/unit/utils/url.ts +0 -209
  62. package/src/index.ts +0 -297
  63. package/src/json-schema/index.ts +0 -2
  64. package/src/schema/bitbucket-schema.ts +0 -43
  65. package/src/schema/confluence-schema.ts +0 -76
  66. package/src/schema/create-schema.ts +0 -337
  67. package/src/schema/default-schema.ts +0 -180
  68. package/src/schema/groups.ts +0 -30
  69. package/src/schema/index.ts +0 -238
  70. package/src/schema/inline-nodes.ts +0 -9
  71. package/src/schema/jira-schema.ts +0 -158
  72. package/src/schema/marks/__tests__/unit/annotation.ts +0 -18
  73. package/src/schema/marks/alignment.ts +0 -48
  74. package/src/schema/marks/annotation.ts +0 -107
  75. package/src/schema/marks/border.ts +0 -74
  76. package/src/schema/marks/breakout.ts +0 -42
  77. package/src/schema/marks/code.ts +0 -45
  78. package/src/schema/marks/confluence-inline-comment.ts +0 -32
  79. package/src/schema/marks/data-consumer.ts +0 -100
  80. package/src/schema/marks/em.ts +0 -19
  81. package/src/schema/marks/fragment.ts +0 -77
  82. package/src/schema/marks/indentation.ts +0 -47
  83. package/src/schema/marks/index.ts +0 -61
  84. package/src/schema/marks/link.ts +0 -139
  85. package/src/schema/marks/strike.ts +0 -26
  86. package/src/schema/marks/strong.ts +0 -45
  87. package/src/schema/marks/subsup.ts +0 -53
  88. package/src/schema/marks/text-color.ts +0 -172
  89. package/src/schema/marks/type-ahead-query.ts +0 -22
  90. package/src/schema/marks/underline.ts +0 -24
  91. package/src/schema/marks/unsupported-mark.ts +0 -9
  92. package/src/schema/marks/unsupported-node-attributes.ts +0 -8
  93. package/src/schema/nodes/block-card.ts +0 -121
  94. package/src/schema/nodes/blockquote.ts +0 -25
  95. package/src/schema/nodes/bodied-extension.ts +0 -75
  96. package/src/schema/nodes/bullet-list.ts +0 -17
  97. package/src/schema/nodes/caption.ts +0 -51
  98. package/src/schema/nodes/code-block.ts +0 -176
  99. package/src/schema/nodes/confluence-jira-issue.ts +0 -43
  100. package/src/schema/nodes/confluence-unsupported-block.ts +0 -29
  101. package/src/schema/nodes/confluence-unsupported-inline.ts +0 -30
  102. package/src/schema/nodes/date.ts +0 -38
  103. package/src/schema/nodes/decision-item.ts +0 -50
  104. package/src/schema/nodes/decision-list.ts +0 -56
  105. package/src/schema/nodes/doc.ts +0 -30
  106. package/src/schema/nodes/embed-card.ts +0 -62
  107. package/src/schema/nodes/emoji.ts +0 -89
  108. package/src/schema/nodes/expand.ts +0 -101
  109. package/src/schema/nodes/extension.ts +0 -60
  110. package/src/schema/nodes/hard-break.ts +0 -21
  111. package/src/schema/nodes/heading.ts +0 -64
  112. package/src/schema/nodes/image.ts +0 -32
  113. package/src/schema/nodes/index.ts +0 -184
  114. package/src/schema/nodes/inline-card.ts +0 -70
  115. package/src/schema/nodes/inline-extension.ts +0 -57
  116. package/src/schema/nodes/layout-column.ts +0 -68
  117. package/src/schema/nodes/layout-section.ts +0 -93
  118. package/src/schema/nodes/list-item.ts +0 -13
  119. package/src/schema/nodes/media-group.ts +0 -44
  120. package/src/schema/nodes/media-inline.ts +0 -19
  121. package/src/schema/nodes/media-single.ts +0 -179
  122. package/src/schema/nodes/media.ts +0 -253
  123. package/src/schema/nodes/mention.ts +0 -86
  124. package/src/schema/nodes/nested-expand.ts +0 -77
  125. package/src/schema/nodes/ordered-list.ts +0 -62
  126. package/src/schema/nodes/panel.ts +0 -133
  127. package/src/schema/nodes/paragraph.ts +0 -79
  128. package/src/schema/nodes/placeholder.ts +0 -40
  129. package/src/schema/nodes/rule.ts +0 -17
  130. package/src/schema/nodes/status.ts +0 -58
  131. package/src/schema/nodes/tableNodes.ts +0 -478
  132. package/src/schema/nodes/task-item.ts +0 -51
  133. package/src/schema/nodes/task-list.ts +0 -61
  134. package/src/schema/nodes/text.ts +0 -19
  135. package/src/schema/nodes/types/block-content.ts +0 -51
  136. package/src/schema/nodes/types/extensions.ts +0 -36
  137. package/src/schema/nodes/types/inline-content.ts +0 -56
  138. package/src/schema/nodes/types/list.ts +0 -54
  139. package/src/schema/nodes/types/mark.ts +0 -16
  140. package/src/schema/nodes/types/non-nestable-block-content.ts +0 -39
  141. package/src/schema/nodes/types/rich-media-common.ts +0 -51
  142. package/src/schema/nodes/unknown-block.ts +0 -13
  143. package/src/schema/nodes/unsupported-block.ts +0 -28
  144. package/src/schema/nodes/unsupported-inline.ts +0 -27
  145. package/src/schema/unsupported.ts +0 -4
  146. package/src/steps/__tests__/unit/analytics.ts +0 -72
  147. package/src/steps/__tests__/unit/link-meta-step.ts +0 -64
  148. package/src/steps/__tests__/unit/override-document-step.ts +0 -174
  149. package/src/steps/__tests__/unit/set-attrs.ts +0 -71
  150. package/src/steps/analytics.ts +0 -189
  151. package/src/steps/link-meta-step.ts +0 -105
  152. package/src/steps/override-document-step.ts +0 -97
  153. package/src/steps/set-attrs.tsx +0 -74
  154. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-0.json +0 -15
  155. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-1.json +0 -15
  156. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-2.json +0 -15
  157. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-3.json +0 -15
  158. package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-0.json +0 -9
  159. package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-1.json +0 -9
  160. package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-2.json +0 -9
  161. package/src/steps/table/__tests__/__fixtures__/basic/remove-table/remove-last-row-inverted.json +0 -98
  162. package/src/steps/table/__tests__/__fixtures__/basic/remove-table/remove-last-row.json +0 -71
  163. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-0-inverted.json +0 -19
  164. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-0.json +0 -19
  165. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-1-inverted.json +0 -21
  166. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-1.json +0 -21
  167. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-2-inverted.json +0 -21
  168. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-2.json +0 -21
  169. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-3-inverted.json +0 -19
  170. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-3.json +0 -19
  171. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-0-inverted.json +0 -63
  172. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-0.json +0 -21
  173. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-1-inverted.json +0 -64
  174. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-1.json +0 -22
  175. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-2-inverted.json +0 -63
  176. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-2.json +0 -21
  177. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-0-inverted.json +0 -19
  178. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-0.json +0 -19
  179. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-1-inverted.json +0 -19
  180. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-1.json +0 -19
  181. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-2-inverted.json +0 -19
  182. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-2.json +0 -19
  183. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-3-inverted.json +0 -19
  184. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-3.json +0 -19
  185. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-0-inverted.json +0 -52
  186. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-0.json +0 -38
  187. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-1-inverted.json +0 -52
  188. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-1.json +0 -38
  189. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-2-inverted.json +0 -25
  190. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-2.json +0 -11
  191. package/src/steps/table/__tests__/_utils.ts +0 -102
  192. package/src/steps/table/__tests__/add-column-merge-columns.ts +0 -509
  193. package/src/steps/table/__tests__/add-column-merge-rows.ts +0 -466
  194. package/src/steps/table/__tests__/add-column.ts +0 -638
  195. package/src/steps/table/add-column.ts +0 -443
  196. package/src/steps/table/constants.ts +0 -4
  197. package/src/steps/table/sort-column.ts +0 -57
  198. package/src/steps/table/types.ts +0 -48
  199. package/src/steps/table/utils/cell-step.ts +0 -239
  200. package/src/steps/table/utils/cells-at-column.ts +0 -75
  201. package/src/steps/table/utils/find-column.ts +0 -90
  202. package/src/steps/table/utils/get-table-rect-from-doc.ts +0 -37
  203. package/src/steps/table/utils/side-effects/rows.ts +0 -327
  204. package/src/steps/table/utils/side-effects/side-effects.ts +0 -90
  205. package/src/steps/table/utils/side-effects/table.ts +0 -112
  206. package/src/steps/table/utils/side-effects/types.ts +0 -34
  207. package/src/steps/table/utils/table-map.ts +0 -28
  208. package/src/steps/type-ahead.ts +0 -100
  209. package/src/steps.ts +0 -16
  210. package/src/utils/colors.ts +0 -171
  211. package/src/utils/confluence/emoji.ts +0 -99
  212. package/src/utils/extensions.ts +0 -32
  213. package/src/utils/index.ts +0 -69
  214. package/src/utils/parseDOM.ts +0 -2
  215. package/src/utils/url.ts +0 -173
  216. package/src/utils/uuid.ts +0 -19
  217. package/src/version.json +0 -6
  218. package/tsconfig.json +0 -13
@@ -1,384 +0,0 @@
1
- import {
2
- media,
3
- camelCaseToKebabCase,
4
- defaultAttrs,
5
- toJSON,
6
- createMediaSpec,
7
- } from '../../../../schema/nodes/media';
8
- import { image as ImageNodeSpec } from '../../../../schema/nodes/image';
9
- import { fromHTML, toDOM, schema } from 'adf-test-helpers/src/adf-schema';
10
-
11
- // Note: We can't use dom.dataset in jest until it's upgraded to use latest version
12
- // of jsdom. In the meantime we can use this helper-method.
13
- const getDataSet = (dom: HTMLElement) => {
14
- return Object.keys({
15
- ...defaultAttrs,
16
- fileName: '',
17
- fileSize: '',
18
- fileMimeType: '',
19
- displayType: '',
20
- url: '',
21
- }).reduce<Record<string, any>>((accum, k) => {
22
- const key = camelCaseToKebabCase(k).replace(/^__/, '');
23
- const value = dom.getAttribute(`data-${key}`);
24
- if (value) {
25
- accum[k] = value;
26
- }
27
-
28
- return accum;
29
- }, {});
30
- };
31
- const packageName = process.env._PACKAGE_NAME_ as string;
32
-
33
- describe(`${packageName}/schema media node`, () => {
34
- it('should parse html', () => {
35
- const doc = fromHTML(
36
- `
37
- <div
38
- data-node-type="media"
39
- data-id="id"
40
- data-type="file"
41
- data-collection="collection"
42
- data-file-name="file.jpg"
43
- data-file-size="123456"
44
- data-file-mime-type="image/jpeg"
45
- />
46
- `,
47
- schema,
48
- );
49
- const mediaGroup = doc.firstChild!;
50
- const mediaNode = mediaGroup.firstChild!;
51
-
52
- expect(mediaNode.type.spec).toEqual(media);
53
- expect(mediaNode.attrs.id).toEqual('id');
54
- expect(mediaNode.attrs.type).toEqual('file');
55
- expect(mediaNode.attrs.collection).toEqual('collection');
56
- expect(mediaNode.attrs.__fileName).toEqual('file.jpg');
57
- expect(mediaNode.attrs.__fileSize).toEqual(123456);
58
- expect(mediaNode.attrs.__fileMimeType).toEqual('image/jpeg');
59
- expect(mediaNode.attrs.__displayType).toEqual(null);
60
- });
61
-
62
- it('should parse width/height as number', () => {
63
- const doc = fromHTML(
64
- `
65
- <div
66
- data-node-type="media"
67
- data-width="456"
68
- data-height="956"
69
- />
70
- `,
71
- schema,
72
- );
73
- const mediaGroup = doc.firstChild!;
74
- const mediaNode = mediaGroup.firstChild!;
75
-
76
- expect(mediaNode.attrs.width).toEqual(456);
77
- expect(mediaNode.attrs.height).toEqual(956);
78
- });
79
-
80
- it('should parse html (with occurrenceKey)', () => {
81
- const doc = fromHTML(
82
- `
83
- <div
84
- data-node-type="media"
85
- data-id="id"
86
- data-type="file"
87
- data-collection="collection"
88
- data-occurrence-key="key"
89
- />
90
- `,
91
- schema,
92
- );
93
- const mediaGroup = doc.firstChild!;
94
- const mediaNode = mediaGroup.firstChild!;
95
-
96
- expect(mediaNode.type.spec).toEqual(media);
97
- expect(mediaNode.attrs.id).toEqual('id');
98
- expect(mediaNode.attrs.type).toEqual('file');
99
- expect(mediaNode.attrs.collection).toEqual('collection');
100
- expect(mediaNode.attrs.occurrenceKey).toEqual('key');
101
- });
102
-
103
- it('should encode to html', () => {
104
- const mediaNode = schema.nodes.media.create({
105
- id: 'id',
106
- type: 'file',
107
- collection: 'collection',
108
- __fileName: 'file.jpg',
109
- __fileSize: 123456,
110
- __fileMimeType: 'image/jpeg',
111
- __displayType: 'thumbnail',
112
- });
113
-
114
- const domNode = toDOM(mediaNode, schema).firstChild as HTMLElement;
115
- const {
116
- id,
117
- type,
118
- collection,
119
- occurrenceKey,
120
- fileName,
121
- fileSize,
122
- fileMimeType,
123
- displayType,
124
- } = getDataSet(domNode);
125
-
126
- expect(id).toEqual('id');
127
- expect(type).toEqual('file');
128
- expect(collection).toEqual('collection');
129
- expect(occurrenceKey).toEqual(undefined);
130
- expect(fileName).toEqual('file.jpg');
131
- expect(fileSize).toEqual('123456');
132
- expect(fileMimeType).toEqual('image/jpeg');
133
- expect(displayType).toEqual('thumbnail');
134
- });
135
-
136
- it('should encode to html (with occurrenceKey)', () => {
137
- const mediaNode = schema.nodes.media.create({
138
- id: 'id',
139
- type: 'file',
140
- collection: 'collection',
141
- occurrenceKey: 'key',
142
- });
143
-
144
- const domNode = toDOM(mediaNode, schema).firstChild as HTMLElement;
145
- const { id, type, collection, occurrenceKey } = getDataSet(domNode);
146
- expect(id).toEqual('id');
147
- expect(type).toEqual('file');
148
- expect(collection).toEqual('collection');
149
- expect(occurrenceKey).toEqual('key');
150
- });
151
-
152
- it('should strip optional attrs during JSON serialization', () => {
153
- const mediaNode = schema.nodes.media.create({
154
- id: 'id',
155
- type: 'file',
156
- collection: 'collection',
157
- __fileName: 'file.jpg',
158
- __fileSize: 123456,
159
- __fileMimeType: 'image/jpeg',
160
- __displayType: 'thumbnail',
161
- });
162
-
163
- expect(toJSON(mediaNode)).toEqual({
164
- attrs: {
165
- collection: 'collection',
166
- id: 'id',
167
- type: 'file',
168
- },
169
- });
170
- });
171
-
172
- it('should strip optional attrs during JSON serialization for inline media', () => {
173
- const mediaInlineNode = schema.nodes.mediaInline.create({
174
- id: 'id',
175
- type: 'file',
176
- collection: 'collection',
177
- alt: '',
178
- __fileName: 'file.jpg',
179
- __fileSize: 123456,
180
- __fileMimeType: 'image/jpeg',
181
- __displayType: 'thumbnail',
182
- });
183
-
184
- expect(toJSON(mediaInlineNode)).toEqual({
185
- attrs: {
186
- collection: 'collection',
187
- id: 'id',
188
- type: 'file',
189
- },
190
- });
191
- });
192
-
193
- describe.each<['alt' | 'occurrenceKey']>([['alt'], ['occurrenceKey']])(
194
- '%s attribute',
195
- (attributeKey: string) => {
196
- let mediaNodeConfig: { [key: string]: any };
197
- beforeEach(() => {
198
- mediaNodeConfig = {
199
- id: 'id',
200
- type: 'file',
201
- collection: 'collection',
202
- };
203
- });
204
-
205
- it(`should serialize ${attributeKey} when available`, () => {
206
- mediaNodeConfig[attributeKey] = 'key_value';
207
- const mediaNode = schema.nodes.media.create(mediaNodeConfig);
208
-
209
- const expectedObj: any = {
210
- attrs: {
211
- collection: 'collection',
212
- id: 'id',
213
- type: 'file',
214
- },
215
- };
216
- expectedObj.attrs[attributeKey] = 'key_value';
217
-
218
- expect(toJSON(mediaNode)).toEqual(expectedObj);
219
- });
220
-
221
- it(`should not serialize optional ${attributeKey} with null value`, () => {
222
- mediaNodeConfig[attributeKey] = null;
223
- const mediaNode = schema.nodes.media.create(mediaNodeConfig);
224
-
225
- expect(toJSON(mediaNode)).toEqual({
226
- attrs: {
227
- collection: 'collection',
228
- id: 'id',
229
- type: 'file',
230
- },
231
- });
232
- });
233
-
234
- it(`should not serialize optional ${attributeKey} with empty string`, () => {
235
- mediaNodeConfig[attributeKey] = '';
236
- const mediaNode = schema.nodes.media.create(mediaNodeConfig);
237
-
238
- expect(toJSON(mediaNode)).toEqual({
239
- attrs: {
240
- collection: 'collection',
241
- id: 'id',
242
- type: 'file',
243
- },
244
- });
245
- });
246
- },
247
- );
248
-
249
- it('should serialize optional number keys with value 0', () => {
250
- const mediaNode = schema.nodes.media.create({
251
- id: 'id',
252
- type: 'file',
253
- collection: 'collection',
254
- width: 0,
255
- });
256
-
257
- expect(toJSON(mediaNode)).toEqual({
258
- attrs: {
259
- collection: 'collection',
260
- id: 'id',
261
- type: 'file',
262
- width: 0,
263
- },
264
- });
265
- });
266
-
267
- it('should serialize width/height as number', () => {
268
- const mediaNode = schema.nodes.media.create({
269
- id: 'id',
270
- type: 'file',
271
- collection: 'collection',
272
- width: '100',
273
- height: '150',
274
- });
275
-
276
- expect(toJSON(mediaNode)).toEqual({
277
- attrs: {
278
- collection: 'collection',
279
- id: 'id',
280
- type: 'file',
281
- width: 100,
282
- height: 150,
283
- },
284
- });
285
- });
286
-
287
- describe('external images', () => {
288
- it('should parse html for external images', () => {
289
- const doc = fromHTML(
290
- `
291
- <div
292
- data-node-type="media"
293
- data-type="external"
294
- data-url="http://image.jpg"
295
- />
296
- `,
297
- schema,
298
- );
299
- const mediaGroup = doc.firstChild!;
300
- const mediaNode = mediaGroup.firstChild!;
301
-
302
- expect(mediaNode.type.spec).toEqual(media);
303
- expect(mediaNode.attrs.type).toEqual('external');
304
- expect(mediaNode.attrs.url).toEqual('http://image.jpg');
305
- });
306
-
307
- it('should encode to html', () => {
308
- const mediaNode = schema.nodes.media.create({
309
- type: 'external',
310
- alt: 'alt text',
311
- url: 'http://image.jpg',
312
- });
313
-
314
- const domNode = toDOM(mediaNode, schema).firstChild as HTMLElement;
315
- const { type, url, alt } = getDataSet(domNode);
316
- expect(type).toEqual('external');
317
- expect(alt).toEqual('alt text');
318
- expect(url).toEqual('http://image.jpg');
319
- });
320
-
321
- it('should strip optional attrs during JSON serialization', () => {
322
- const mediaNode = schema.nodes.media.create({
323
- type: 'external',
324
- url: 'http://image.jpg',
325
- alt: 'alt text',
326
- });
327
-
328
- expect(toJSON(mediaNode)).toEqual({
329
- attrs: {
330
- type: 'external',
331
- alt: 'alt text',
332
- url: 'http://image.jpg',
333
- },
334
- });
335
- });
336
-
337
- it('should parse html for images with alt text', () => {
338
- const doc = fromHTML(
339
- `<img src="https://image.jpg" alt="Summer Rolls are the best" />`,
340
- schema,
341
- );
342
- const paragraph = doc.firstChild!;
343
- const imageNode = paragraph.firstChild!;
344
-
345
- expect(imageNode.type.spec).toEqual(ImageNodeSpec);
346
- expect(imageNode.attrs.src).toEqual('https://image.jpg');
347
- expect(imageNode.attrs.alt).toEqual('Summer Rolls are the best');
348
- });
349
-
350
- it('should parse html for images without alt text', () => {
351
- const doc = fromHTML(`<img src="https://no.ch/ocolate.jpg" />`, schema);
352
- const paragraph = doc.firstChild!;
353
- const imageNode = paragraph.firstChild!;
354
-
355
- expect(imageNode.type.spec).toEqual(ImageNodeSpec);
356
- expect(imageNode.attrs.src).toEqual('https://no.ch/ocolate.jpg');
357
- expect(imageNode.attrs.alt).toEqual(null);
358
- });
359
- });
360
-
361
- describe('createMediaSpec', () => {
362
- it('should return a media node spec supporting attributes provided', () => {
363
- const el = document.createElement('div');
364
- el.setAttribute('data-foo', 'test');
365
-
366
- const attributes = {
367
- ...defaultAttrs,
368
- foo: 'test',
369
- } as any;
370
-
371
- const mediaNodeSpec = createMediaSpec(attributes);
372
- expect(mediaNodeSpec.attrs).toBe(attributes);
373
-
374
- const parseRule =
375
- mediaNodeSpec.parseDOM &&
376
- mediaNodeSpec.parseDOM.find(({ tag }) => 'div[data-node-type="media"]');
377
- expect(parseRule && parseRule.getAttrs && parseRule.getAttrs(el)).toEqual(
378
- {
379
- foo: 'test',
380
- },
381
- );
382
- });
383
- });
384
- });
@@ -1,115 +0,0 @@
1
- import { createSchema } from '../../../../schema/create-schema';
2
- import {
3
- toHTML,
4
- fromHTML as fromHTML_,
5
- } from 'adf-test-helpers/src/adf-schema/html-helpers';
6
-
7
- const schema = makeSchema();
8
- const fromHTML = (html: string) => fromHTML_(html, schema);
9
- const packageName = process.env._PACKAGE_NAME_ as string;
10
-
11
- describe(`${packageName}/schema mention node`, () => {
12
- it('should have mention id and display name when serializing to DOM', () => {
13
- const html = toHTML(
14
- schema.nodes.mention.create({ id: '@bar', text: 'foo bar' }),
15
- schema,
16
- );
17
- expect(html).toContain('data-mention-id="@bar"');
18
- expect(html).toContain('contenteditable="false"');
19
- expect(html).toContain('foo bar');
20
- });
21
-
22
- it('should extract the correct values of mention id and display name', () => {
23
- const doc = fromHTML("<span data-mention-id='@user-1'>foo bar</span>");
24
- const mention = doc.firstChild!.firstChild!;
25
-
26
- expect(mention.type.name).toEqual('mention');
27
- expect(mention.attrs.id).toEqual('@user-1');
28
- expect(mention.attrs.text).toEqual('foo bar');
29
- });
30
-
31
- it('should ignore if userType is DEFAULT', () => {
32
- const html = toHTML(
33
- schema.nodes.mention.create({
34
- id: 'id-foo-bar',
35
- text: '@foo bar',
36
- userType: 'DEFAULT',
37
- }),
38
- schema,
39
- );
40
- expect(html).toContain('data-mention-id="id-foo-bar"');
41
- expect(html).toContain('contenteditable="false"');
42
- expect(html).toContain('data-user-type="DEFAULT"');
43
- expect(html).toContain('@foo bar');
44
- });
45
-
46
- it('should have userType if it is SPECIAL', () => {
47
- const html = toHTML(
48
- schema.nodes.mention.create({
49
- id: 'id-rick',
50
- text: '@rick',
51
- userType: 'SPECIAL',
52
- }),
53
- schema,
54
- );
55
- expect(html).toContain('data-mention-id="id-rick"');
56
- expect(html).toContain('data-user-type="SPECIAL"');
57
- expect(html).toContain('@rick');
58
- });
59
-
60
- it('should have userType if it is APP', () => {
61
- const html = toHTML(
62
- schema.nodes.mention.create({
63
- id: 'id-coffee',
64
- text: '@coffee',
65
- userType: 'APP',
66
- }),
67
- schema,
68
- );
69
- expect(html).toContain('data-mention-id="id-coffee"');
70
- expect(html).toContain('data-user-type="APP"');
71
- expect(html).toContain('@coffee');
72
- });
73
-
74
- it('should extract the valid userTypes - SPECIAL', () => {
75
- const doc = fromHTML(
76
- '<span data-mention-id="id-rick" data-user-type="SPECIAL">@Rick Sanchez</span>',
77
- );
78
- const mention = doc.firstChild!.firstChild!;
79
-
80
- expect(mention.type.name).toEqual('mention');
81
- expect(mention.attrs.id).toEqual('id-rick');
82
- expect(mention.attrs.text).toEqual('@Rick Sanchez');
83
- expect(mention.attrs.userType).toEqual('SPECIAL');
84
- });
85
-
86
- it('should extract the valid userTypes - APP', () => {
87
- const doc = fromHTML(
88
- '<span data-mention-id="id-coffee" data-user-type="APP">@coffee</span>',
89
- );
90
- const mention = doc.firstChild!.firstChild!;
91
-
92
- expect(mention.type.name).toEqual('mention');
93
- expect(mention.attrs.id).toEqual('id-coffee');
94
- expect(mention.attrs.text).toEqual('@coffee');
95
- expect(mention.attrs.userType).toEqual('APP');
96
- });
97
-
98
- it('should not extract invalid value of userType', () => {
99
- const doc = fromHTML(
100
- '<span data-mention-id="id-morty" data-user-type="SIDEKICK">@Morty Smith</span>',
101
- );
102
- const mention = doc.firstChild!.firstChild!;
103
-
104
- expect(mention.type.name).toEqual('mention');
105
- expect(mention.attrs.id).toEqual('id-morty');
106
- expect(mention.attrs.text).toEqual('@Morty Smith');
107
- expect(mention.attrs.userType).toEqual(null);
108
- });
109
- });
110
-
111
- function makeSchema() {
112
- return createSchema({
113
- nodes: ['doc', 'paragraph', 'text', 'mention'],
114
- });
115
- }
@@ -1,72 +0,0 @@
1
- import { toDOM, fromHTML } from 'adf-test-helpers/src/adf-schema/html-helpers';
2
- import { nestedExpand } from '../../../..';
3
- import { Schema, Node } from '@atlaskit/editor-prosemirror/model';
4
- import { schema } from 'adf-test-helpers/src/adf-schema';
5
-
6
- const findNestedExpand = (doc: Node, schema: Schema) => {
7
- let expand: Node | null = null;
8
- doc.nodesBetween(0, doc.nodeSize - 2, (node) => {
9
- if (!expand && node.type === schema.nodes.nestedExpand) {
10
- expand = node;
11
- }
12
- });
13
-
14
- return expand as Node | null;
15
- };
16
- const packageName = process.env._PACKAGE_NAME_ as string;
17
-
18
- describe(`${packageName}/schema nestedExpand node`, () => {
19
- describe('parse html', () => {
20
- it('converts to PM node', () => {
21
- const doc = fromHTML('<div data-node-type="nestedExpand" />', schema);
22
- const node = findNestedExpand(doc, schema)!;
23
- expect(node.type.spec).toEqual(nestedExpand);
24
- });
25
-
26
- it('gets attributes from html', () => {
27
- const title = 'Homer Simpson';
28
- const doc = fromHTML(
29
- `
30
- <div
31
- data-node-type="nestedExpand"
32
- data-title="${title}"
33
- ><p>hello</p></div>
34
- `,
35
- schema,
36
- );
37
-
38
- const node = findNestedExpand(doc, schema)!;
39
- expect(node.attrs.title).toEqual(title);
40
- });
41
- });
42
-
43
- describe('encode html', () => {
44
- it('converts html data attributes to node attributes', () => {
45
- const title = 'Homer Simpson';
46
- const content = schema.nodes.paragraph.create(schema.text('hello'));
47
- const node = schema.nodes.nestedExpand.create({ title }, content);
48
- const dom = toDOM(node, schema).firstChild as HTMLElement;
49
-
50
- expect(dom.getAttribute('data-node-type')).toEqual('nestedExpand');
51
- expect(dom.getAttribute('data-title')).toEqual(title);
52
- });
53
-
54
- it('encodes and decodes to the same node', () => {
55
- const { paragraph, nestedExpand, table, tableRow, tableCell } =
56
- schema.nodes;
57
-
58
- const title = 'Homer Simpson';
59
- const content = paragraph.create(schema.text('hello'));
60
- const node = nestedExpand.create({ title }, content);
61
-
62
- // We must create a table wrapper since nestedExpands are only allow inside tables.
63
- const cell = tableCell.createChecked(undefined, node);
64
- const row = tableRow.createChecked(undefined, cell);
65
- const tableWrapper = table.createChecked(undefined, row);
66
-
67
- const dom = toDOM(node, schema).firstChild as HTMLElement;
68
- const parsedNode = fromHTML(dom.outerHTML, schema).firstChild!;
69
- expect(parsedNode).toEqual(tableWrapper);
70
- });
71
- });
72
- });
@@ -1,49 +0,0 @@
1
- import { toHTML } from 'adf-test-helpers/src/adf-schema/html-helpers';
2
- import { schema } from 'adf-test-helpers/src/adf-schema';
3
- const packageName = process.env._PACKAGE_NAME_ as string;
4
-
5
- describe(`${packageName}/schema orderedList node`, () => {
6
- it('should be possible to create an ordered list item with an order attribute', () => {
7
- const html = toHTML(
8
- schema.nodes.orderedList.create(
9
- { order: 6 },
10
- schema.nodes.listItem.create({}, schema.nodes.paragraph.create()),
11
- ),
12
- schema,
13
- );
14
- expect(html).toContain('<ol start="6" class="ak-ol"><li><p></p></li></ol>');
15
- });
16
-
17
- it('should not be possible to have an ordered list starting from a negative number', () => {
18
- const html = toHTML(
19
- schema.nodes.orderedList.create(
20
- { order: -6 },
21
- schema.nodes.listItem.create({}, schema.nodes.paragraph.create()),
22
- ),
23
- schema,
24
- );
25
- expect(html).toContain('<ol class="ak-ol"><li><p></p></li></ol>');
26
- });
27
-
28
- it('should not be possible to have an ordered list with order of a string', () => {
29
- const html = toHTML(
30
- schema.nodes.orderedList.create(
31
- { order: 'string' },
32
- schema.nodes.listItem.create({}, schema.nodes.paragraph.create()),
33
- ),
34
- schema,
35
- );
36
- expect(html).toContain('<ol class="ak-ol"><li><p></p></li></ol>');
37
- });
38
-
39
- it('should not be possible to have an ordered list with order of a decimal number', () => {
40
- const html = toHTML(
41
- schema.nodes.orderedList.create(
42
- { order: 2.9 },
43
- schema.nodes.listItem.create({}, schema.nodes.paragraph.create()),
44
- ),
45
- schema,
46
- );
47
- expect(html).toContain('<ol start="2" class="ak-ol"><li><p></p></li></ol>');
48
- });
49
- });