@atlaskit/editor-plugin-table 0.0.6 → 0.0.7

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 (57) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/cjs/plugins/table/event-handlers.js +7 -6
  3. package/dist/cjs/plugins/table/nodeviews/tableCell.js +4 -4
  4. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
  5. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
  6. package/dist/cjs/plugins/table/utils/column-controls.js +1 -1
  7. package/dist/cjs/version.json +1 -1
  8. package/dist/es2019/plugins/table/event-handlers.js +8 -7
  9. package/dist/es2019/plugins/table/nodeviews/tableCell.js +3 -4
  10. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
  11. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
  12. package/dist/es2019/plugins/table/utils/column-controls.js +1 -1
  13. package/dist/es2019/version.json +1 -1
  14. package/dist/esm/plugins/table/event-handlers.js +8 -7
  15. package/dist/esm/plugins/table/nodeviews/tableCell.js +3 -4
  16. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
  17. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
  18. package/dist/esm/plugins/table/utils/column-controls.js +1 -1
  19. package/dist/esm/version.json +1 -1
  20. package/package.json +4 -2
  21. package/src/__tests__/unit/analytics.ts +737 -0
  22. package/src/__tests__/unit/collab.ts +76 -0
  23. package/src/__tests__/unit/commands/sort.ts +230 -0
  24. package/src/__tests__/unit/copy-paste.ts +686 -0
  25. package/src/__tests__/unit/event-handlers/index.ts +106 -0
  26. package/src/__tests__/unit/event-handlers.ts +202 -0
  27. package/src/__tests__/unit/fix-tables.ts +156 -0
  28. package/src/__tests__/unit/floating-toolbar.ts +95 -0
  29. package/src/__tests__/unit/handlers.ts +81 -0
  30. package/src/__tests__/unit/hover-selection.ts +277 -0
  31. package/src/__tests__/unit/index-with-fake-timers.ts +106 -0
  32. package/src/__tests__/unit/index.ts +986 -0
  33. package/src/__tests__/unit/keymap.ts +602 -0
  34. package/src/__tests__/unit/layout.ts +196 -0
  35. package/src/__tests__/unit/nodeviews/cell.ts +167 -0
  36. package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +33 -0
  37. package/src/__tests__/unit/sort-column.ts +512 -0
  38. package/src/__tests__/unit/transforms/delete-columns.ts +499 -0
  39. package/src/__tests__/unit/transforms/delete-rows.ts +557 -0
  40. package/src/__tests__/unit/transforms/merging.ts +374 -0
  41. package/src/__tests__/unit/ui/CornerControls.tsx +80 -0
  42. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +95 -0
  43. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +175 -0
  44. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +266 -0
  45. package/src/__tests__/unit/ui/RowControls.tsx +301 -0
  46. package/src/__tests__/unit/ui/TableFloatingControls.tsx +93 -0
  47. package/src/__tests__/unit/undo-redo.ts +202 -0
  48. package/src/__tests__/unit/utils/dom.ts +286 -0
  49. package/src/__tests__/unit/utils/nodes.ts +59 -0
  50. package/src/__tests__/unit/utils/row-controls.ts +176 -0
  51. package/src/__tests__/unit/utils/table.ts +93 -0
  52. package/src/__tests__/unit/utils.ts +652 -0
  53. package/src/plugins/table/event-handlers.ts +5 -6
  54. package/src/plugins/table/nodeviews/tableCell.tsx +5 -4
  55. package/src/plugins/table/pm-plugins/table-resizing/utils/column-state.ts +1 -1
  56. package/src/plugins/table/pm-plugins/table-resizing/utils/resize-logic.ts +6 -2
  57. package/src/plugins/table/utils/column-controls.ts +1 -1
@@ -0,0 +1,374 @@
1
+ import {
2
+ createProsemirrorEditorFactory,
3
+ Preset,
4
+ LightEditorPlugin,
5
+ } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
6
+ import {
7
+ DocBuilder,
8
+ doc,
9
+ p,
10
+ table,
11
+ tr,
12
+ td,
13
+ tdEmpty,
14
+ } from '@atlaskit/editor-test-helpers/doc-builder';
15
+ import { uuid } from '@atlaskit/adf-schema';
16
+ import { TablePluginState } from '../../../plugins/table/types';
17
+ import { mergeCells } from '../../../plugins/table/transforms';
18
+ import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
19
+ import tablePlugin from '../../../plugins/table-plugin';
20
+ import { PluginKey } from 'prosemirror-state';
21
+
22
+ const TABLE_LOCAL_ID = 'test-table-local-id';
23
+
24
+ describe('table plugin -> transforms -> merge cells', () => {
25
+ beforeAll(() => {
26
+ uuid.setStatic(TABLE_LOCAL_ID);
27
+ });
28
+
29
+ afterAll(() => {
30
+ uuid.setStatic(false);
31
+ });
32
+
33
+ const createEditor = createProsemirrorEditorFactory();
34
+ const preset = new Preset<LightEditorPlugin>().add(tablePlugin);
35
+
36
+ const editor = (doc: DocBuilder) =>
37
+ createEditor<TablePluginState, PluginKey>({
38
+ doc,
39
+ preset,
40
+ pluginKey,
41
+ });
42
+
43
+ describe('#mergeCells', () => {
44
+ it('should merge columns and rows', () => {
45
+ const { editorView } = editor(
46
+ doc(
47
+ p('text'),
48
+ table()(
49
+ tr(td({})(p('{<cell}')), tdEmpty, tdEmpty),
50
+ tr(tdEmpty, tdEmpty, tdEmpty),
51
+ tr(tdEmpty, td({})(p('{cell>}')), tdEmpty),
52
+ ),
53
+ ),
54
+ );
55
+ const { state, dispatch } = editorView;
56
+ dispatch(mergeCells(state.tr));
57
+ expect(editorView.state.doc).toEqualDocument(
58
+ doc(
59
+ p('text'),
60
+ table({ localId: TABLE_LOCAL_ID })(
61
+ tr(td({ rowspan: 3 })(p('')), tdEmpty),
62
+ tr(tdEmpty),
63
+ tr(tdEmpty),
64
+ ),
65
+ ),
66
+ );
67
+ });
68
+
69
+ describe('when two rows gets merged column by column', () => {
70
+ describe('when last non-merged cell gets merged from the end of the row', () => {
71
+ it('should delete an empty row that gets created as a result', () => {
72
+ const { editorView } = editor(
73
+ doc(
74
+ p('text'),
75
+ table()(
76
+ tr(tdEmpty, tdEmpty, tdEmpty),
77
+ tr(
78
+ td({ rowspan: 2 })(p('b1')),
79
+ td({ rowspan: 2 })(p('b2')),
80
+ td({})(p('{<cell}b3')),
81
+ ),
82
+ tr(td({})(p('{cell>}c3'))),
83
+ ),
84
+ ),
85
+ );
86
+ const { state, dispatch } = editorView;
87
+ dispatch(mergeCells(state.tr));
88
+ expect(editorView.state.doc).toEqualDocument(
89
+ doc(
90
+ p('text'),
91
+ table({ localId: TABLE_LOCAL_ID })(
92
+ tr(tdEmpty, tdEmpty, tdEmpty),
93
+ tr(td({})(p('b1')), td({})(p('b2')), td({})(p('b3'), p('c3'))),
94
+ ),
95
+ ),
96
+ );
97
+ });
98
+ });
99
+ describe('when last non-merged cell gets merged from the start of the row', () => {
100
+ it('should delete an empty row that gets created as a result', () => {
101
+ const { editorView } = editor(
102
+ doc(
103
+ p('text'),
104
+ table()(
105
+ tr(tdEmpty, tdEmpty, tdEmpty),
106
+ tr(
107
+ td({})(p('{<cell}b1')),
108
+ td({ rowspan: 2 })(p('b2')),
109
+ td({ rowspan: 2 })(p('b3')),
110
+ ),
111
+ tr(td({})(p('{cell>}c1'))),
112
+ ),
113
+ ),
114
+ );
115
+ const { state, dispatch } = editorView;
116
+ dispatch(mergeCells(state.tr));
117
+ expect(editorView.state.doc).toEqualDocument(
118
+ doc(
119
+ p('text'),
120
+ table({ localId: TABLE_LOCAL_ID })(
121
+ tr(tdEmpty, tdEmpty, tdEmpty),
122
+ tr(td({})(p('b1'), p('c1')), td({})(p('b2')), td({})(p('b3'))),
123
+ ),
124
+ ),
125
+ );
126
+ });
127
+ });
128
+ });
129
+
130
+ describe('when more than two rows gets merged', () => {
131
+ describe('when last non-merged cell gets merged from the end of the row', () => {
132
+ it('should delete an empty row that gets created as a result', () => {
133
+ const { editorView } = editor(
134
+ doc(
135
+ p('text'),
136
+ table()(
137
+ tr(td({ rowspan: 4 })(p('a1')), td({})(p('{<cell}a2'))),
138
+ tr(tdEmpty),
139
+ tr(td({})(p('{cell>}c2'))),
140
+ tr(tdEmpty),
141
+ tr(tdEmpty, tdEmpty),
142
+ ),
143
+ ),
144
+ );
145
+ const { state, dispatch } = editorView;
146
+ dispatch(mergeCells(state.tr));
147
+ expect(editorView.state.doc).toEqualDocument(
148
+ doc(
149
+ p('text'),
150
+ table({ localId: TABLE_LOCAL_ID })(
151
+ tr(td({ rowspan: 2 })(p('a1')), td({})(p('a2'), p('c2'))),
152
+ tr(tdEmpty),
153
+ tr(tdEmpty, tdEmpty),
154
+ ),
155
+ ),
156
+ );
157
+ });
158
+ });
159
+ });
160
+
161
+ describe('when rows from the first columns get merged', () => {
162
+ describe('and table has merged rows in the next column', () => {
163
+ it('should delete an empty row and decrement rowspan of the next column', () => {
164
+ const { editorView } = editor(
165
+ doc(
166
+ p('text'),
167
+ table()(
168
+ tr(td({})(p('{<cell}a1')), td({ rowspan: 3 })(p('a2'))),
169
+ tr(td({})(p('{cell>}'))),
170
+ tr(tdEmpty),
171
+ ),
172
+ ),
173
+ );
174
+ const { state, dispatch } = editorView;
175
+ dispatch(mergeCells(state.tr));
176
+ expect(editorView.state.doc).toEqualDocument(
177
+ doc(
178
+ p('text'),
179
+ table({ localId: TABLE_LOCAL_ID })(
180
+ tr(td({})(p('a1')), td({ rowspan: 2 })(p('a2'))),
181
+ tr(tdEmpty),
182
+ ),
183
+ ),
184
+ );
185
+ });
186
+ });
187
+ });
188
+
189
+ describe('when rows from the last columns get merged', () => {
190
+ describe('and table has merged rows in the previous column', () => {
191
+ it('should delete an empty row and decrement rowspan of the previous column', () => {
192
+ const { editorView } = editor(
193
+ doc(
194
+ p('text'),
195
+ table()(
196
+ tr(td({ rowspan: 3 })(p('a1')), td({})(p('{<cell}a2'))),
197
+ tr(td({})(p('{cell>}'))),
198
+ tr(tdEmpty),
199
+ ),
200
+ ),
201
+ );
202
+ const { state, dispatch } = editorView;
203
+ dispatch(mergeCells(state.tr));
204
+ expect(editorView.state.doc).toEqualDocument(
205
+ doc(
206
+ p('text'),
207
+ table({ localId: TABLE_LOCAL_ID })(
208
+ tr(td({ rowspan: 2 })(p('a1')), td({})(p('a2'))),
209
+ tr(tdEmpty),
210
+ ),
211
+ ),
212
+ );
213
+ });
214
+ });
215
+ });
216
+
217
+ describe('when two empty cells are merged', () => {
218
+ it('should fill the merged cell with a paragraph', () => {
219
+ const { editorView } = editor(
220
+ doc(
221
+ p('text'),
222
+ table()(
223
+ tr(td({})(p('{<cell}')), td({})(p('{cell>}'))),
224
+ tr(tdEmpty, tdEmpty),
225
+ ),
226
+ ),
227
+ );
228
+ const { state, dispatch } = editorView;
229
+ dispatch(mergeCells(state.tr));
230
+ expect(editorView.state.doc).toEqualDocument(
231
+ doc(
232
+ p('text'),
233
+ table({ localId: TABLE_LOCAL_ID })(
234
+ tr(td({ colspan: 2 })(p(''))),
235
+ tr(tdEmpty, tdEmpty),
236
+ ),
237
+ ),
238
+ );
239
+ });
240
+ });
241
+
242
+ describe('when next column is invisible', () => {
243
+ it('should decrement colspans of the preceeding column', () => {
244
+ const { editorView } = editor(
245
+ doc(
246
+ p('text'),
247
+ table()(
248
+ tr(tdEmpty, td({})(p('{<cell}')), tdEmpty, td({})(p('{cell>}'))),
249
+ tr(tdEmpty, td({ colspan: 3 })(p(''))),
250
+ tr(tdEmpty, td({ colspan: 2 })(p('')), tdEmpty),
251
+ ),
252
+ ),
253
+ );
254
+ const { state, dispatch } = editorView;
255
+ dispatch(mergeCells(state.tr));
256
+ expect(editorView.state.doc).toEqualDocument(
257
+ doc(
258
+ p('text'),
259
+ table({ localId: TABLE_LOCAL_ID })(
260
+ tr(tdEmpty, td({ colspan: 2 })(p(''))),
261
+ tr(tdEmpty, td({ colspan: 2 })(p(''))),
262
+ tr(tdEmpty, tdEmpty, tdEmpty),
263
+ ),
264
+ ),
265
+ );
266
+ });
267
+ });
268
+
269
+ describe('when next column is not invisible', () => {
270
+ it('should not decrement colspans of the preceeding column', () => {
271
+ const { editorView } = editor(
272
+ doc(
273
+ p('text'),
274
+ table()(
275
+ tr(tdEmpty, td({})(p('{<cell}')), tdEmpty, td({})(p('{cell>}'))),
276
+ tr(tdEmpty, td({ colspan: 3 })(p(''))),
277
+ tr(tdEmpty, td({ colspan: 2 })(p('')), tdEmpty),
278
+ tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
279
+ ),
280
+ ),
281
+ );
282
+ const { state, dispatch } = editorView;
283
+ dispatch(mergeCells(state.tr));
284
+ expect(editorView.state.doc).toEqualDocument(
285
+ doc(
286
+ p('text'),
287
+ table({ localId: TABLE_LOCAL_ID })(
288
+ tr(tdEmpty, td({ colspan: 3 })(p(''))),
289
+ tr(tdEmpty, td({ colspan: 3 })(p(''))),
290
+ tr(tdEmpty, td({ colspan: 2 })(p('')), tdEmpty),
291
+ tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
292
+ ),
293
+ ),
294
+ );
295
+ });
296
+ });
297
+
298
+ describe('when empty cells and cells with content are merged together', () => {
299
+ it('should copy content from merged cells dropping empty cells', () => {
300
+ const { editorView } = editor(
301
+ doc(
302
+ p('text'),
303
+ table()(
304
+ tr(td({})(p('1')), td({})(p('2'))),
305
+ tr(td({ colspan: 2 })(p('{<cell}'))),
306
+ tr(td({})(p('1')), td({})(p('2{cell>}'))),
307
+ ),
308
+ ),
309
+ );
310
+ const { state, dispatch } = editorView;
311
+ dispatch(mergeCells(state.tr));
312
+ expect(editorView.state.doc).toEqualDocument(
313
+ doc(
314
+ p('text'),
315
+ table({ localId: TABLE_LOCAL_ID })(
316
+ tr(td({})(p('1')), td({})(p('2'))),
317
+ tr(td({ colspan: 2 })(p('1'), p('2'))),
318
+ ),
319
+ ),
320
+ );
321
+ });
322
+ });
323
+
324
+ describe('when table has columns where all cells have colspan > 1', () => {
325
+ it('should delete an empty column', () => {
326
+ const { editorView } = editor(
327
+ doc(
328
+ p('text'),
329
+ table()(
330
+ tr(
331
+ td({})(p('1')),
332
+ td({})(p('2')),
333
+ td({ colspan: 2, rowspan: 2 })(p('3')),
334
+ td({})(p('5')),
335
+ td({})(p('6')),
336
+ ),
337
+ tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
338
+ tr(
339
+ td({})(p('1')),
340
+ td({})(p('{<cell}2')),
341
+ td({})(p('3')),
342
+ td({})(p('4')),
343
+ td({})(p('5{cell>}')),
344
+ td({})(p('6')),
345
+ ),
346
+ ),
347
+ ),
348
+ );
349
+ const { state, dispatch } = editorView;
350
+ dispatch(mergeCells(state.tr));
351
+ expect(editorView.state.doc).toEqualDocument(
352
+ doc(
353
+ p('text'),
354
+ table({ localId: TABLE_LOCAL_ID })(
355
+ tr(
356
+ td({})(p('1')),
357
+ td({})(p('2')),
358
+ td({ rowspan: 2 })(p('3')),
359
+ td({})(p('5')),
360
+ td({})(p('6')),
361
+ ),
362
+ tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
363
+ tr(
364
+ td({})(p('1')),
365
+ td({ colspan: 3 })(p('2'), p('3'), p('4'), p('5')),
366
+ td({})(p('6')),
367
+ ),
368
+ ),
369
+ ),
370
+ );
371
+ });
372
+ });
373
+ });
374
+ });
@@ -0,0 +1,80 @@
1
+ import React from 'react';
2
+ import { isTableSelected } from '@atlaskit/editor-tables/utils';
3
+ import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
4
+ import { mountWithIntl } from '@atlaskit/editor-test-helpers/enzyme';
5
+ import {
6
+ doc,
7
+ table,
8
+ tr,
9
+ thEmpty,
10
+ DocBuilder,
11
+ } from '@atlaskit/editor-test-helpers/doc-builder';
12
+
13
+ import {
14
+ TablePluginState,
15
+ TableCssClassName as ClassName,
16
+ } from '../../../plugins/table/types';
17
+ import CornerControls from '../../../plugins/table/ui/TableFloatingControls/CornerControls';
18
+ import { getPluginState } from '../../../plugins/table/pm-plugins/plugin-factory';
19
+ import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
20
+ import tablePlugin from '../../../plugins/table-plugin';
21
+
22
+ const CornerButton = `.${ClassName.CONTROLS_CORNER_BUTTON}`;
23
+
24
+ describe('CornerControls', () => {
25
+ const createEditor = createEditorFactory<TablePluginState>();
26
+
27
+ const editor = (doc: DocBuilder) =>
28
+ createEditor({
29
+ doc,
30
+ editorProps: {
31
+ allowTables: false,
32
+ dangerouslyAppendPlugins: { __plugins: [tablePlugin()] },
33
+ },
34
+ pluginKey,
35
+ });
36
+
37
+ describe('when button is clicked', () => {
38
+ it('should select the table', () => {
39
+ const { editorView } = editor(
40
+ doc(table()(tr(thEmpty, thEmpty, thEmpty))),
41
+ );
42
+
43
+ const controls = mountWithIntl(
44
+ <CornerControls
45
+ tableRef={document.querySelector('table')!}
46
+ editorView={editorView}
47
+ />,
48
+ );
49
+
50
+ controls.find(CornerButton).simulate('click');
51
+
52
+ expect(isTableSelected(editorView.state.selection)).toBe(true);
53
+ controls.unmount();
54
+ });
55
+ });
56
+
57
+ describe('when button is hovered', () => {
58
+ it('should highlight the table with hover decoration', () => {
59
+ const { editorView } = editor(
60
+ doc(
61
+ table()(tr(thEmpty, thEmpty, thEmpty), tr(thEmpty, thEmpty, thEmpty)),
62
+ ),
63
+ );
64
+
65
+ const controls = mountWithIntl(
66
+ <CornerControls
67
+ tableRef={document.querySelector('table')!}
68
+ editorView={editorView}
69
+ />,
70
+ );
71
+
72
+ controls.find(CornerButton).simulate('mouseover');
73
+
74
+ const { hoveredColumns, hoveredRows } = getPluginState(editorView.state);
75
+ expect(hoveredColumns).toEqual([0, 1, 2]);
76
+ expect(hoveredRows).toEqual([0, 1]);
77
+ controls.unmount();
78
+ });
79
+ });
80
+ });
@@ -0,0 +1,95 @@
1
+ import { ReactWrapper } from 'enzyme';
2
+ import { findParentNodeOfTypeClosestToPos } from 'prosemirror-utils';
3
+ import { EditorView } from 'prosemirror-view';
4
+ import React from 'react';
5
+ import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
6
+ import { mountWithIntl } from '@atlaskit/editor-test-helpers/enzyme';
7
+ import {
8
+ doc,
9
+ table,
10
+ tdCursor,
11
+ tdEmpty,
12
+ thEmpty,
13
+ tr,
14
+ DocBuilder,
15
+ } from '@atlaskit/editor-test-helpers/doc-builder';
16
+ import { UIAnalyticsEvent } from '@atlaskit/analytics-next';
17
+ import { TablePluginState } from '../../../plugins/table/types';
18
+ import FloatingContextualButton, {
19
+ Props as FloatingContextualButtonProps,
20
+ FloatingContextualButtonInner,
21
+ } from '../../../plugins/table/ui/FloatingContextualButton';
22
+ import tablePlugin from '../../../plugins/table-plugin';
23
+
24
+ describe('Floating Contextual Button', () => {
25
+ const createEditor = createEditorFactory<TablePluginState>();
26
+ let createAnalyticsEvent = jest.fn(() => ({ fire() {} } as UIAnalyticsEvent));
27
+ const editor = (doc: DocBuilder) =>
28
+ createEditor({
29
+ doc,
30
+ editorProps: {
31
+ allowTables: false,
32
+ dangerouslyAppendPlugins: { __plugins: [tablePlugin()] },
33
+ },
34
+ createAnalyticsEvent,
35
+ });
36
+
37
+ let wrapper: ReactWrapper<FloatingContextualButtonProps>;
38
+ let editorView: EditorView;
39
+ let refs: { [name: string]: number };
40
+
41
+ beforeEach(() => {
42
+ ({ editorView, refs } = editor(
43
+ doc(
44
+ table()(
45
+ tr('{firstCell}', thEmpty, thEmpty, thEmpty),
46
+ tr(tdCursor, tdEmpty, tdEmpty),
47
+ tr(tdEmpty, tdEmpty, tdEmpty),
48
+ ),
49
+ ),
50
+ ));
51
+
52
+ const tableNode = findParentNodeOfTypeClosestToPos(
53
+ editorView.state.selection.$from,
54
+ editorView.state.schema.nodes.table,
55
+ );
56
+
57
+ wrapper = mountWithIntl(
58
+ <FloatingContextualButton
59
+ editorView={editorView}
60
+ tableNode={tableNode && tableNode.node}
61
+ targetCellPosition={refs.firstCell}
62
+ dispatchAnalyticsEvent={createAnalyticsEvent}
63
+ />,
64
+ );
65
+ });
66
+
67
+ describe('when an error is thrown in the component', () => {
68
+ it('handles it gracefully', () => {
69
+ const buttonWrapper = wrapper.find(FloatingContextualButtonInner);
70
+ expect(() =>
71
+ buttonWrapper.simulateError(new Error('Oh no!')),
72
+ ).not.toThrow();
73
+ });
74
+
75
+ it('dispatches an analytics event', () => {
76
+ wrapper
77
+ .find(FloatingContextualButtonInner)
78
+ .simulateError(new Error('Oh no!'));
79
+ expect(createAnalyticsEvent).toHaveBeenCalledWith({
80
+ action: 'unhandledErrorCaught',
81
+ actionSubject: 'floatingContextualButton',
82
+ eventType: 'operational',
83
+ attributes: {
84
+ error: new Error('Oh no!'),
85
+ errorInfo: expect.objectContaining({
86
+ componentStack: expect.stringContaining(
87
+ 'in FloatingContextualButton',
88
+ ),
89
+ }),
90
+ errorRethrown: false,
91
+ },
92
+ });
93
+ });
94
+ });
95
+ });