@atlaskit/editor-plugin-table 0.1.0 → 0.1.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.
Files changed (190) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  3. package/dist/cjs/version.json +1 -1
  4. package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  5. package/dist/es2019/version.json +1 -1
  6. package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  7. package/dist/esm/version.json +1 -1
  8. package/examples/99-testing.tsx +35 -30
  9. package/package.json +2 -11
  10. package/src/__tests__/integration/__fixtures__/auto-size-documents.ts +5 -10
  11. package/src/__tests__/integration/__fixtures__/layout-documents.ts +1 -2
  12. package/src/__tests__/integration/__fixtures__/resize-documents.ts +5 -10
  13. package/src/__tests__/integration/resize.ts +1 -2
  14. package/src/__tests__/unit/analytics.ts +33 -32
  15. package/src/__tests__/unit/collab.ts +12 -9
  16. package/src/__tests__/unit/commands/sort.ts +28 -28
  17. package/src/__tests__/unit/copy-paste.ts +6 -8
  18. package/src/__tests__/unit/event-handlers.ts +7 -10
  19. package/src/__tests__/unit/fix-tables.ts +17 -23
  20. package/src/__tests__/unit/get-toolbar-config.ts +0 -5
  21. package/src/__tests__/unit/hover-selection.ts +1 -66
  22. package/src/__tests__/unit/index-with-fake-timers.ts +1 -1
  23. package/src/__tests__/unit/index.ts +5 -5
  24. package/src/__tests__/unit/nodeviews/TableComponent.tsx +11 -218
  25. package/src/__tests__/unit/nodeviews/cell.ts +12 -10
  26. package/src/__tests__/unit/nodeviews/table.ts +25 -26
  27. package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +11 -8
  28. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +11 -12
  29. package/src/__tests__/unit/toolbar.ts +18 -5
  30. package/src/__tests__/unit/ui/ContextualMenu.tsx +55 -0
  31. package/src/__tests__/unit/ui/CornerControls.tsx +7 -7
  32. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +45 -49
  33. package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +49 -0
  34. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +30 -2
  35. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +143 -111
  36. package/src/__tests__/unit/ui/RowControls.tsx +112 -141
  37. package/src/__tests__/unit/ui/TableFloatingControls.tsx +18 -15
  38. package/src/__tests__/unit/undo-redo.ts +10 -9
  39. package/src/__tests__/unit/utils/nodes.ts +8 -4
  40. package/src/__tests__/unit/utils/row-controls.ts +8 -4
  41. package/src/plugins/table/commands/clear.ts +30 -29
  42. package/src/plugins/table/commands/go-to-next-cell.ts +41 -38
  43. package/src/plugins/table/commands/insert.ts +91 -91
  44. package/src/plugins/table/commands/misc.ts +123 -125
  45. package/src/plugins/table/commands/selection.ts +329 -319
  46. package/src/plugins/table/commands-with-analytics.ts +299 -294
  47. package/src/plugins/table/event-handlers.ts +111 -111
  48. package/src/plugins/table/handlers.ts +95 -94
  49. package/src/plugins/table/nodeviews/OverflowShadowsObserver.ts +4 -3
  50. package/src/plugins/table/nodeviews/TableComponent.tsx +6 -9
  51. package/src/plugins/table/nodeviews/update-overflow-shadows.ts +39 -39
  52. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +7 -9
  53. package/src/plugins/table/pm-plugins/decorations/utils/column-resizing.ts +30 -30
  54. package/src/plugins/table/pm-plugins/decorations/utils/compose-decorations.ts +7 -7
  55. package/src/plugins/table/pm-plugins/plugin-factory.ts +33 -33
  56. package/src/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.ts +6 -9
  57. package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.ts +3 -2
  58. package/src/plugins/table/pm-plugins/table-resizing/commands.ts +98 -90
  59. package/src/plugins/table/pm-plugins/table-resizing/utils/dom.ts +46 -47
  60. package/src/plugins/table/toolbar.tsx +116 -113
  61. package/src/plugins/table/transforms/column-width.ts +143 -146
  62. package/src/plugins/table/transforms/delete-columns.ts +144 -142
  63. package/src/plugins/table/transforms/delete-rows.ts +110 -111
  64. package/src/plugins/table/transforms/metadata.ts +9 -9
  65. package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +7 -6
  66. package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +3 -2
  67. package/src/plugins/table/ui/FloatingInsertButton/index.tsx +2 -5
  68. package/src/plugins/table/ui/LayoutButton/index.tsx +2 -6
  69. package/src/plugins/table/ui/common-styles.ts +1 -3
  70. package/src/plugins/table/utils/analytics.ts +24 -25
  71. package/src/plugins/table/utils/dom.ts +3 -3
  72. package/src/plugins/table/utils/row-controls.ts +92 -93
  73. package/dist/types-ts4.0/index.d.ts +0 -1
  74. package/dist/types-ts4.0/plugins/table/commands/clear.d.ts +0 -3
  75. package/dist/types-ts4.0/plugins/table/commands/collapse.d.ts +0 -2
  76. package/dist/types-ts4.0/plugins/table/commands/go-to-next-cell.d.ts +0 -4
  77. package/dist/types-ts4.0/plugins/table/commands/hover.d.ts +0 -8
  78. package/dist/types-ts4.0/plugins/table/commands/index.d.ts +0 -7
  79. package/dist/types-ts4.0/plugins/table/commands/insert.d.ts +0 -10
  80. package/dist/types-ts4.0/plugins/table/commands/misc.d.ts +0 -27
  81. package/dist/types-ts4.0/plugins/table/commands/selection.d.ts +0 -8
  82. package/dist/types-ts4.0/plugins/table/commands/sort.d.ts +0 -3
  83. package/dist/types-ts4.0/plugins/table/commands/split-cell.d.ts +0 -6
  84. package/dist/types-ts4.0/plugins/table/commands/toggle.d.ts +0 -12
  85. package/dist/types-ts4.0/plugins/table/commands-with-analytics.d.ts +0 -26
  86. package/dist/types-ts4.0/plugins/table/create-plugin-config.d.ts +0 -2
  87. package/dist/types-ts4.0/plugins/table/event-handlers.d.ts +0 -16
  88. package/dist/types-ts4.0/plugins/table/handlers.d.ts +0 -3
  89. package/dist/types-ts4.0/plugins/table/index.d.ts +0 -17
  90. package/dist/types-ts4.0/plugins/table/nodeviews/OverflowShadowsObserver.d.ts +0 -26
  91. package/dist/types-ts4.0/plugins/table/nodeviews/TableComponent.d.ts +0 -72
  92. package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverflowShadowsObserver.d.ts +0 -9
  93. package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverridableMock.d.ts +0 -9
  94. package/dist/types-ts4.0/plugins/table/nodeviews/table.d.ts +0 -31
  95. package/dist/types-ts4.0/plugins/table/nodeviews/tableCell.d.ts +0 -19
  96. package/dist/types-ts4.0/plugins/table/nodeviews/types.d.ts +0 -24
  97. package/dist/types-ts4.0/plugins/table/nodeviews/update-overflow-shadows.d.ts +0 -8
  98. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/plugin.d.ts +0 -7
  99. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +0 -3
  100. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +0 -2
  101. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +0 -2
  102. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/index.d.ts +0 -3
  103. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/types.d.ts +0 -6
  104. package/dist/types-ts4.0/plugins/table/pm-plugins/default-table-selection.d.ts +0 -5
  105. package/dist/types-ts4.0/plugins/table/pm-plugins/keymap.d.ts +0 -5
  106. package/dist/types-ts4.0/plugins/table/pm-plugins/main.d.ts +0 -8
  107. package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-factory.d.ts +0 -1
  108. package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-key.d.ts +0 -3
  109. package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delayed-dom-selection-syncing-workaround.d.ts +0 -4
  110. package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.d.ts +0 -15
  111. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/commands.d.ts +0 -3
  112. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -6
  113. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
  114. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -65
  115. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-key.d.ts +0 -3
  116. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-state.d.ts +0 -3
  117. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +0 -4
  118. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/types.d.ts +0 -16
  119. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/util.d.ts +0 -2
  120. package/dist/types-ts4.0/plugins/table/pm-plugins/table-local-id.d.ts +0 -22
  121. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/commands.d.ts +0 -25
  122. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/event-handlers.d.ts +0 -4
  123. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -4
  124. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-factory.d.ts +0 -4
  125. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-key.d.ts +0 -3
  126. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin.d.ts +0 -6
  127. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/reducer.d.ts +0 -3
  128. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/colgroup.d.ts +0 -8
  129. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/column-state.d.ts +0 -14
  130. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/content-width.d.ts +0 -4
  131. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/dom.d.ts +0 -13
  132. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +0 -12
  133. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -22
  134. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-column.d.ts +0 -2
  135. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-logic.d.ts +0 -4
  136. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-state.d.ts +0 -29
  137. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +0 -17
  138. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/types.d.ts +0 -22
  139. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/unit-to-number.d.ts +0 -1
  140. package/dist/types-ts4.0/plugins/table/pm-plugins/table-selection-keymap.d.ts +0 -4
  141. package/dist/types-ts4.0/plugins/table/reducer.d.ts +0 -3
  142. package/dist/types-ts4.0/plugins/table/toolbar.d.ts +0 -36
  143. package/dist/types-ts4.0/plugins/table/transforms/column-width.d.ts +0 -18
  144. package/dist/types-ts4.0/plugins/table/transforms/delete-columns.d.ts +0 -3
  145. package/dist/types-ts4.0/plugins/table/transforms/delete-rows.d.ts +0 -3
  146. package/dist/types-ts4.0/plugins/table/transforms/fix-tables.d.ts +0 -10
  147. package/dist/types-ts4.0/plugins/table/transforms/index.d.ts +0 -7
  148. package/dist/types-ts4.0/plugins/table/transforms/merge.d.ts +0 -5
  149. package/dist/types-ts4.0/plugins/table/transforms/metadata.d.ts +0 -21
  150. package/dist/types-ts4.0/plugins/table/transforms/replace-table.d.ts +0 -5
  151. package/dist/types-ts4.0/plugins/table/transforms/split.d.ts +0 -9
  152. package/dist/types-ts4.0/plugins/table/types.d.ts +0 -328
  153. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/index.d.ts +0 -29
  154. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/styles.d.ts +0 -1
  155. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/ContextualMenu.d.ts +0 -87
  156. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/index.d.ts +0 -22
  157. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/styles.d.ts +0 -2
  158. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/DeleteButton.d.ts +0 -14
  159. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/getPopUpOptions.d.ts +0 -10
  160. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/index.d.ts +0 -54
  161. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/types.d.ts +0 -1
  162. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +0 -12
  163. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +0 -3
  164. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/index.d.ts +0 -35
  165. package/dist/types-ts4.0/plugins/table/ui/LayoutButton/index.d.ts +0 -21
  166. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +0 -16
  167. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +0 -21
  168. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +0 -17
  169. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/index.d.ts +0 -40
  170. package/dist/types-ts4.0/plugins/table/ui/common-styles.d.ts +0 -4
  171. package/dist/types-ts4.0/plugins/table/ui/consts.d.ts +0 -39
  172. package/dist/types-ts4.0/plugins/table/ui/messages.d.ts +0 -38
  173. package/dist/types-ts4.0/plugins/table/ui/ui-styles.d.ts +0 -15
  174. package/dist/types-ts4.0/plugins/table/utils/analytics.d.ts +0 -18
  175. package/dist/types-ts4.0/plugins/table/utils/collapse.d.ts +0 -29
  176. package/dist/types-ts4.0/plugins/table/utils/column-controls.d.ts +0 -10
  177. package/dist/types-ts4.0/plugins/table/utils/decoration.d.ts +0 -16
  178. package/dist/types-ts4.0/plugins/table/utils/dom.d.ts +0 -20
  179. package/dist/types-ts4.0/plugins/table/utils/get-allow-add-column-custom-step.d.ts +0 -2
  180. package/dist/types-ts4.0/plugins/table/utils/index.d.ts +0 -11
  181. package/dist/types-ts4.0/plugins/table/utils/nodes.d.ts +0 -12
  182. package/dist/types-ts4.0/plugins/table/utils/paste.d.ts +0 -14
  183. package/dist/types-ts4.0/plugins/table/utils/referentiality.d.ts +0 -2
  184. package/dist/types-ts4.0/plugins/table/utils/row-controls.d.ts +0 -16
  185. package/dist/types-ts4.0/plugins/table/utils/selection.d.ts +0 -6
  186. package/dist/types-ts4.0/plugins/table/utils/table.d.ts +0 -4
  187. package/dist/types-ts4.0/plugins/table/utils/update-plugin-state-decorations.d.ts +0 -4
  188. package/dist/types-ts4.0/plugins/table-plugin.d.ts +0 -2
  189. package/src/plugins/table/ui/FloatingContextualMenu/__tests__/ContextualMenu.tsx +0 -56
  190. package/src/plugins/table/ui/FloatingContextualMenu/__tests__/FloatingContextualMenu.tsx +0 -50
@@ -1,5 +1,4 @@
1
1
  import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
2
- import { mountWithIntl } from '@atlaskit/editor-test-helpers/enzyme';
3
2
  import {
4
3
  doc,
5
4
  table,
@@ -9,12 +8,12 @@ import {
9
8
  tr,
10
9
  DocBuilder,
11
10
  } from '@atlaskit/editor-test-helpers/doc-builder';
11
+ import { render, screen } from '@testing-library/react';
12
12
  import {
13
13
  selectCell,
14
14
  selectColumns,
15
15
  selectRows,
16
16
  } from '@atlaskit/editor-test-helpers/table';
17
- import { mount, ReactWrapper } from 'enzyme';
18
17
  import { findParentNodeOfTypeClosestToPos } from 'prosemirror-utils';
19
18
  import { EditorView } from 'prosemirror-view';
20
19
  import React from 'react';
@@ -23,7 +22,6 @@ import {
23
22
  FloatingInsertButton,
24
23
  Props as FloatingInsertButtonProps,
25
24
  } from '../../../plugins/table/ui/FloatingInsertButton';
26
- import InsertButton from '../../../plugins/table/ui/FloatingInsertButton/InsertButton';
27
25
  import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
28
26
  import tablePlugin from '../../../plugins/table-plugin';
29
27
  import * as prosemirrorUtils from 'prosemirror-utils';
@@ -34,33 +32,32 @@ import {
34
32
  EVENT_TYPE,
35
33
  CONTENT_COMPONENT,
36
34
  } from '@atlaskit/editor-common/analytics';
37
- import { createIntl, IntlShape } from 'react-intl-next';
35
+ import { getPluginState } from '../../../plugins/table/pm-plugins/plugin-factory';
36
+ import { createIntl } from 'react-intl-next';
37
+ import { setTableRef, setEditorFocus } from '../../../plugins/table/commands';
38
+ import { IntlProvider } from 'react-intl-next';
38
39
 
39
40
  const getEditorContainerWidth = () => ({ width: 500 });
40
- describe('Floating Insert Button when findDomRefAtPos fails', () => {
41
- const createEditor = createEditorFactory<TablePluginState>();
42
- let createAnalyticsEvent = jest.fn(() => ({ fire() {} } as UIAnalyticsEvent));
43
-
44
- const editor = (doc: DocBuilder) =>
45
- createEditor({
46
- doc,
47
- editorProps: {
48
- allowTables: false,
49
- dangerouslyAppendPlugins: { __plugins: [tablePlugin()] },
50
- },
51
- pluginKey,
52
- createAnalyticsEvent,
53
- });
41
+ const createEditor = createEditorFactory<TablePluginState>();
42
+ const createAnalyticsEvent = jest.fn(() => ({ fire() {} } as UIAnalyticsEvent));
43
+
44
+ const editor = (doc: DocBuilder) =>
45
+ createEditor({
46
+ doc,
47
+ editorProps: {
48
+ allowTables: false,
49
+ dangerouslyAppendPlugins: { __plugins: [tablePlugin()] },
50
+ },
51
+ pluginKey,
52
+ });
54
53
 
55
- let wrapper: ReactWrapper<FloatingInsertButtonProps>;
56
- let editorView: EditorView;
54
+ describe('Floating Insert Button when findDomRefAtPos fails', () => {
55
+ let tableRef: HTMLTableElement | undefined;
56
+ let tableNode: prosemirrorUtils.ContentNodeWithPos | undefined;
57
+ let tableEditorView: EditorView;
57
58
 
58
59
  beforeEach(() => {
59
- const mock = jest.spyOn(prosemirrorUtils, 'findDomRefAtPos');
60
- mock.mockImplementation((pos, domAtPos) => {
61
- throw new Error('Error message from mock');
62
- });
63
- ({ editorView } = editor(
60
+ const { editorView } = editor(
64
61
  doc(
65
62
  table()(
66
63
  tr(thEmpty, thEmpty, thEmpty),
@@ -68,38 +65,52 @@ describe('Floating Insert Button when findDomRefAtPos fails', () => {
68
65
  tr(tdEmpty, tdEmpty, tdEmpty),
69
66
  ),
70
67
  ),
71
- ));
68
+ );
72
69
 
73
- const tableNode = findParentNodeOfTypeClosestToPos(
70
+ tableNode = findParentNodeOfTypeClosestToPos(
74
71
  editorView.state.selection.$from,
75
72
  editorView.state.schema.nodes.table,
76
73
  );
77
74
 
78
- const intl = createIntl({ locale: 'en' });
79
-
80
- wrapper = mount(
81
- <FloatingInsertButton
82
- intl={intl}
83
- tableRef={document.querySelector('table')!}
84
- tableNode={tableNode && tableNode.node}
85
- editorView={editorView}
86
- dispatchAnalyticsEvent={createAnalyticsEvent}
87
- getEditorContainerWidth={getEditorContainerWidth}
88
- />,
89
- );
75
+ const ref = editorView.dom.querySelector('table');
76
+ setEditorFocus(true)(editorView.state, editorView.dispatch);
77
+ setTableRef(ref!)(editorView.state, editorView.dispatch);
78
+
79
+ tableRef = getPluginState(editorView.state).tableRef;
80
+ tableEditorView = editorView;
81
+
82
+ const mock = jest.spyOn(prosemirrorUtils, 'findDomRefAtPos');
83
+ mock.mockImplementation(() => {
84
+ throw new Error('Error message from mock');
85
+ });
90
86
  });
91
87
 
88
+ const intl = createIntl({ locale: 'en' });
89
+
90
+ const component = (props: FloatingInsertButtonProps) =>
91
+ render(
92
+ <IntlProvider locale="en">
93
+ <FloatingInsertButton
94
+ intl={intl}
95
+ tableRef={tableRef}
96
+ tableNode={tableNode && tableNode.node}
97
+ {...props}
98
+ />
99
+ </IntlProvider>,
100
+ );
101
+
92
102
  afterEach(() => {
93
- wrapper.unmount();
94
103
  jest.restoreAllMocks();
95
104
  });
96
105
 
97
- it('sends error analytics event after attempting to render for second column', () => {
98
- // We need to set the props here, as by default insertColumnButtonIndex is undefined (in
99
- // mountWithIntl()) and rendering halts when it's undefined
100
- wrapper.setProps({
106
+ it('should send error analytics event', () => {
107
+ component({
101
108
  insertColumnButtonIndex: 1,
109
+ editorView: tableEditorView,
110
+ getEditorContainerWidth,
111
+ dispatchAnalyticsEvent: createAnalyticsEvent,
102
112
  });
113
+
103
114
  expect(createAnalyticsEvent).toHaveBeenCalledTimes(1);
104
115
  expect(createAnalyticsEvent).toHaveBeenCalledWith({
105
116
  action: ACTION.ERRORED,
@@ -116,42 +127,40 @@ describe('Floating Insert Button when findDomRefAtPos fails', () => {
116
127
  });
117
128
 
118
129
  it('should not render insert button by default', () => {
119
- expect(wrapper.find(InsertButton).length).toBe(0);
130
+ component({ editorView: tableEditorView, getEditorContainerWidth });
131
+ expect(screen.queryByLabelText('Popup')).toBeFalsy();
120
132
  });
121
133
 
122
134
  it("shouldn't render insert button for second column", () => {
123
- wrapper.setProps({
135
+ component({
124
136
  insertColumnButtonIndex: 1,
137
+ editorView: tableEditorView,
138
+ getEditorContainerWidth,
125
139
  });
126
-
127
- expect(wrapper.find(InsertButton).length).toBe(0);
140
+ expect(screen.queryByLabelText('Popup')).toBeFalsy();
128
141
  });
129
142
 
130
143
  it("shouldn't render insert button for second row", () => {
131
- wrapper.setProps({
144
+ component({
132
145
  insertRowButtonIndex: 1,
146
+ editorView: tableEditorView,
147
+ getEditorContainerWidth,
133
148
  });
134
-
135
- expect(wrapper.find(InsertButton).length).toBe(0);
149
+ expect(screen.queryByLabelText('Popup')).toBeFalsy();
136
150
  });
137
151
  });
138
- describe('Floating Insert Button', () => {
139
- const createEditor = createEditorFactory<TablePluginState>();
140
152
 
141
- const editor = (doc: DocBuilder) =>
142
- createEditor({
143
- doc,
144
- editorProps: { allowTables: true },
145
- pluginKey,
146
- });
153
+ describe('Floating Insert Button', () => {
154
+ const createAnalyticsEvent = jest.fn(
155
+ () => ({ fire() {} } as UIAnalyticsEvent),
156
+ );
147
157
 
148
- let wrapper: ReactWrapper<FloatingInsertButtonProps>;
149
- let editorView: EditorView;
150
- let tableNode: ReturnType<typeof findParentNodeOfTypeClosestToPos>;
151
- let intl: IntlShape;
158
+ let tableRef: HTMLTableElement | undefined;
159
+ let tableNode: prosemirrorUtils.ContentNodeWithPos | undefined;
160
+ let tableEditorView: EditorView;
152
161
 
153
162
  beforeEach(() => {
154
- ({ editorView } = editor(
163
+ const { editorView } = editor(
155
164
  doc(
156
165
  table()(
157
166
  tr(thEmpty, thEmpty, thEmpty),
@@ -159,108 +168,131 @@ describe('Floating Insert Button', () => {
159
168
  tr(tdEmpty, tdEmpty, tdEmpty),
160
169
  ),
161
170
  ),
162
- ));
171
+ );
163
172
 
164
173
  tableNode = findParentNodeOfTypeClosestToPos(
165
174
  editorView.state.selection.$from,
166
175
  editorView.state.schema.nodes.table,
167
176
  );
168
177
 
169
- wrapper = (mountWithIntl(
170
- <FloatingInsertButton
171
- intl={intl}
172
- tableRef={document.querySelector('table')!}
173
- tableNode={tableNode && tableNode.node}
174
- editorView={editorView}
175
- getEditorContainerWidth={getEditorContainerWidth}
176
- />,
177
- ) as unknown) as ReactWrapper<FloatingInsertButtonProps>;
178
- });
178
+ const ref = editorView.dom.querySelector('table');
179
+ setEditorFocus(true)(editorView.state, editorView.dispatch);
180
+ setTableRef(ref!)(editorView.state, editorView.dispatch);
179
181
 
180
- afterEach(() => {
181
- wrapper.unmount();
182
+ tableRef = getPluginState(editorView.state).tableRef;
183
+ tableEditorView = editorView;
182
184
  });
183
185
 
184
- it('should not render insert button by default', () => {
185
- expect(wrapper.find(InsertButton).length).toBe(0);
186
+ const intl = createIntl({ locale: 'en' });
187
+
188
+ const component = (props: FloatingInsertButtonProps) =>
189
+ render(
190
+ <IntlProvider locale="en">
191
+ <FloatingInsertButton
192
+ intl={intl}
193
+ tableRef={tableRef}
194
+ tableNode={tableNode && tableNode.node}
195
+ dispatchAnalyticsEvent={createAnalyticsEvent}
196
+ {...props}
197
+ />
198
+ </IntlProvider>,
199
+ );
200
+
201
+ it('should not render insert button with index', () => {
202
+ component({ editorView: tableEditorView, getEditorContainerWidth });
203
+ expect(screen.queryByLabelText('Popup')).toBeFalsy();
186
204
  });
187
205
 
188
206
  it('should render insert button for second column', () => {
189
- wrapper.setProps({ insertColumnButtonIndex: 1 });
190
- expect(wrapper.find(InsertButton).length).toBe(1);
207
+ component({
208
+ insertColumnButtonIndex: 1,
209
+ editorView: tableEditorView,
210
+ getEditorContainerWidth,
211
+ });
212
+ expect(screen.getByLabelText('Popup')).toBeInTheDocument();
191
213
  });
192
214
 
193
215
  it('should render insert button for second row', () => {
194
- wrapper.setProps({ insertRowButtonIndex: 1 });
195
- expect(wrapper.find(InsertButton).length).toBe(1);
216
+ component({
217
+ insertRowButtonIndex: 1,
218
+ editorView: tableEditorView,
219
+ getEditorContainerWidth,
220
+ });
221
+ expect(screen.getByLabelText('Popup')).toBeInTheDocument();
196
222
  });
197
223
 
198
224
  it('should not render insert button for first row when row header is enabled', () => {
199
- wrapper.setProps({
225
+ component({
200
226
  insertRowButtonIndex: 0,
201
227
  isHeaderRowEnabled: true,
228
+ editorView: tableEditorView,
229
+ getEditorContainerWidth,
202
230
  });
203
-
204
- expect(wrapper.find(InsertButton).length).toBe(0);
231
+ expect(screen.queryByLabelText('Popup')).toBeFalsy();
205
232
  });
206
233
 
207
234
  it('should render insert button for first row when row header is disabled', () => {
208
- wrapper.setProps({
235
+ component({
209
236
  insertRowButtonIndex: 0,
210
237
  isHeaderRowEnabled: false,
238
+ editorView: tableEditorView,
239
+ getEditorContainerWidth,
211
240
  });
212
-
213
- expect(wrapper.find(InsertButton).length).toBe(1);
241
+ expect(screen.getByLabelText('Popup')).toBeInTheDocument();
214
242
  });
215
243
 
216
- it('should not render insert button for first col when column header is enabled', () => {
217
- wrapper.setProps({
244
+ it('should no render insert button for first col when column header is enabled', () => {
245
+ component({
218
246
  insertColumnButtonIndex: 0,
219
247
  isHeaderColumnEnabled: true,
248
+ editorView: tableEditorView,
249
+ getEditorContainerWidth,
220
250
  });
221
251
 
222
- expect(wrapper.find(InsertButton).length).toBe(0);
252
+ expect(screen.queryByLabelText('Popup')).toBeFalsy();
223
253
  });
224
254
 
225
255
  it('should render insert button for first col when column header is disabled', () => {
226
- wrapper.setProps({
256
+ component({
227
257
  insertColumnButtonIndex: 0,
228
258
  isHeaderColumnEnabled: false,
259
+ editorView: tableEditorView,
260
+ getEditorContainerWidth,
229
261
  });
230
262
 
231
- expect(wrapper.find(InsertButton).length).toBe(1);
263
+ expect(screen.getByLabelText('Popup')).toBeInTheDocument();
232
264
  });
233
265
 
234
266
  it('should render insert button when a single cell is selected', () => {
235
- selectCell(1, 1)(editorView.state, editorView.dispatch);
236
-
237
- wrapper.setProps({
267
+ selectCell(1, 1)(tableEditorView.state, tableEditorView.dispatch);
268
+ component({
238
269
  insertColumnButtonIndex: 0,
239
- editorView,
270
+ editorView: tableEditorView,
271
+ getEditorContainerWidth,
240
272
  });
241
-
242
- expect(wrapper.find(InsertButton).length).toBe(1);
273
+ expect(screen.getByLabelText('Popup')).toBeInTheDocument();
243
274
  });
244
275
 
245
- it('should not render insert button when a whole column is selected', () => {
246
- selectColumns([1])(editorView.state, editorView.dispatch);
276
+ it('should no render insert button when a whole column is selected', () => {
277
+ selectColumns([1])(tableEditorView.state, tableEditorView.dispatch);
247
278
 
248
- wrapper.setProps({
279
+ component({
249
280
  insertColumnButtonIndex: 0,
250
- editorView,
281
+ editorView: tableEditorView,
282
+ getEditorContainerWidth,
251
283
  });
252
-
253
- expect(wrapper.find(InsertButton).length).toBe(0);
284
+ expect(screen.queryByLabelText('Popup')).toBeFalsy();
254
285
  });
255
286
 
256
- it('should no render insert button when a whole row is selected', () => {
257
- selectRows([1])(editorView.state, editorView.dispatch);
287
+ it('should not render insert button when a whole row is selected', () => {
288
+ selectRows([1])(tableEditorView.state, tableEditorView.dispatch);
258
289
 
259
- wrapper.setProps({
290
+ component({
260
291
  insertRowButtonIndex: 0,
261
- editorView,
292
+ editorView: tableEditorView,
293
+ getEditorContainerWidth,
262
294
  });
263
295
 
264
- expect(wrapper.find(InsertButton).length).toBe(0);
296
+ expect(screen.queryByLabelText('Popup')).toBeFalsy();
265
297
  });
266
298
  });