@atlaskit/editor-plugin-table 0.1.0 → 0.1.2
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 +14 -0
- package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
- package/dist/esm/version.json +1 -1
- package/examples/99-testing.tsx +35 -30
- package/package.json +3 -12
- package/src/__tests__/integration/__fixtures__/auto-size-documents.ts +5 -10
- package/src/__tests__/integration/__fixtures__/layout-documents.ts +1 -2
- package/src/__tests__/integration/__fixtures__/resize-documents.ts +5 -10
- package/src/__tests__/integration/resize.ts +1 -2
- package/src/__tests__/unit/analytics.ts +33 -32
- package/src/__tests__/unit/collab.ts +12 -9
- package/src/__tests__/unit/commands/sort.ts +28 -28
- package/src/__tests__/unit/copy-paste.ts +6 -8
- package/src/__tests__/unit/event-handlers.ts +7 -10
- package/src/__tests__/unit/fix-tables.ts +17 -23
- package/src/__tests__/unit/get-toolbar-config.ts +0 -5
- package/src/__tests__/unit/hover-selection.ts +1 -66
- package/src/__tests__/unit/index-with-fake-timers.ts +1 -1
- package/src/__tests__/unit/index.ts +5 -5
- package/src/__tests__/unit/nodeviews/TableComponent.tsx +11 -218
- package/src/__tests__/unit/nodeviews/cell.ts +12 -10
- package/src/__tests__/unit/nodeviews/table.ts +25 -26
- package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +11 -8
- package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +11 -12
- package/src/__tests__/unit/toolbar.ts +18 -5
- package/src/__tests__/unit/ui/ContextualMenu.tsx +55 -0
- package/src/__tests__/unit/ui/CornerControls.tsx +7 -7
- package/src/__tests__/unit/ui/FloatingContextualButton.tsx +45 -49
- package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +49 -0
- package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +30 -2
- package/src/__tests__/unit/ui/FloatingInsertButton.tsx +143 -111
- package/src/__tests__/unit/ui/RowControls.tsx +112 -141
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +18 -15
- package/src/__tests__/unit/undo-redo.ts +10 -9
- package/src/__tests__/unit/utils/nodes.ts +8 -4
- package/src/__tests__/unit/utils/row-controls.ts +8 -4
- package/src/plugins/table/commands/clear.ts +30 -29
- package/src/plugins/table/commands/go-to-next-cell.ts +41 -38
- package/src/plugins/table/commands/insert.ts +91 -91
- package/src/plugins/table/commands/misc.ts +123 -125
- package/src/plugins/table/commands/selection.ts +329 -319
- package/src/plugins/table/commands-with-analytics.ts +299 -294
- package/src/plugins/table/event-handlers.ts +111 -111
- package/src/plugins/table/handlers.ts +95 -94
- package/src/plugins/table/nodeviews/OverflowShadowsObserver.ts +4 -3
- package/src/plugins/table/nodeviews/TableComponent.tsx +6 -9
- package/src/plugins/table/nodeviews/update-overflow-shadows.ts +39 -39
- package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +7 -9
- package/src/plugins/table/pm-plugins/decorations/utils/column-resizing.ts +30 -30
- package/src/plugins/table/pm-plugins/decorations/utils/compose-decorations.ts +7 -7
- package/src/plugins/table/pm-plugins/plugin-factory.ts +33 -33
- package/src/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.ts +6 -9
- package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.ts +3 -2
- package/src/plugins/table/pm-plugins/table-resizing/commands.ts +98 -90
- package/src/plugins/table/pm-plugins/table-resizing/utils/dom.ts +46 -47
- package/src/plugins/table/toolbar.tsx +116 -113
- package/src/plugins/table/transforms/column-width.ts +143 -146
- package/src/plugins/table/transforms/delete-columns.ts +144 -142
- package/src/plugins/table/transforms/delete-rows.ts +110 -111
- package/src/plugins/table/transforms/metadata.ts +9 -9
- package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +7 -6
- package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +3 -2
- package/src/plugins/table/ui/FloatingInsertButton/index.tsx +2 -5
- package/src/plugins/table/ui/LayoutButton/index.tsx +2 -6
- package/src/plugins/table/ui/common-styles.ts +1 -3
- package/src/plugins/table/utils/analytics.ts +24 -25
- package/src/plugins/table/utils/dom.ts +3 -3
- package/src/plugins/table/utils/row-controls.ts +92 -93
- package/dist/types-ts4.0/index.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/commands/clear.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/commands/collapse.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/commands/go-to-next-cell.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/commands/hover.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/commands/index.d.ts +0 -7
- package/dist/types-ts4.0/plugins/table/commands/insert.d.ts +0 -10
- package/dist/types-ts4.0/plugins/table/commands/misc.d.ts +0 -27
- package/dist/types-ts4.0/plugins/table/commands/selection.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/commands/sort.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/commands/split-cell.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/commands/toggle.d.ts +0 -12
- package/dist/types-ts4.0/plugins/table/commands-with-analytics.d.ts +0 -26
- package/dist/types-ts4.0/plugins/table/create-plugin-config.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/event-handlers.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/handlers.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/index.d.ts +0 -17
- package/dist/types-ts4.0/plugins/table/nodeviews/OverflowShadowsObserver.d.ts +0 -26
- package/dist/types-ts4.0/plugins/table/nodeviews/TableComponent.d.ts +0 -72
- package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverflowShadowsObserver.d.ts +0 -9
- package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverridableMock.d.ts +0 -9
- package/dist/types-ts4.0/plugins/table/nodeviews/table.d.ts +0 -31
- package/dist/types-ts4.0/plugins/table/nodeviews/tableCell.d.ts +0 -19
- package/dist/types-ts4.0/plugins/table/nodeviews/types.d.ts +0 -24
- package/dist/types-ts4.0/plugins/table/nodeviews/update-overflow-shadows.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/plugin.d.ts +0 -7
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/index.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/types.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/pm-plugins/default-table-selection.d.ts +0 -5
- package/dist/types-ts4.0/plugins/table/pm-plugins/keymap.d.ts +0 -5
- package/dist/types-ts4.0/plugins/table/pm-plugins/main.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-factory.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-key.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delayed-dom-selection-syncing-workaround.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.d.ts +0 -15
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/commands.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -65
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-key.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-state.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/types.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/util.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-local-id.d.ts +0 -22
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/commands.d.ts +0 -25
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/event-handlers.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-factory.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-key.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/reducer.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/colgroup.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/column-state.d.ts +0 -14
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/content-width.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/dom.d.ts +0 -13
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +0 -12
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -22
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-column.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-logic.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-state.d.ts +0 -29
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +0 -17
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/types.d.ts +0 -22
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/unit-to-number.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-selection-keymap.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/reducer.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/toolbar.d.ts +0 -36
- package/dist/types-ts4.0/plugins/table/transforms/column-width.d.ts +0 -18
- package/dist/types-ts4.0/plugins/table/transforms/delete-columns.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/transforms/delete-rows.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/transforms/fix-tables.d.ts +0 -10
- package/dist/types-ts4.0/plugins/table/transforms/index.d.ts +0 -7
- package/dist/types-ts4.0/plugins/table/transforms/merge.d.ts +0 -5
- package/dist/types-ts4.0/plugins/table/transforms/metadata.d.ts +0 -21
- package/dist/types-ts4.0/plugins/table/transforms/replace-table.d.ts +0 -5
- package/dist/types-ts4.0/plugins/table/transforms/split.d.ts +0 -9
- package/dist/types-ts4.0/plugins/table/types.d.ts +0 -328
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/index.d.ts +0 -29
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/styles.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/ContextualMenu.d.ts +0 -87
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/index.d.ts +0 -22
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/styles.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/DeleteButton.d.ts +0 -14
- package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/getPopUpOptions.d.ts +0 -10
- package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/index.d.ts +0 -54
- package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/types.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +0 -12
- package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/index.d.ts +0 -35
- package/dist/types-ts4.0/plugins/table/ui/LayoutButton/index.d.ts +0 -21
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +0 -21
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +0 -17
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/index.d.ts +0 -40
- package/dist/types-ts4.0/plugins/table/ui/common-styles.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/ui/consts.d.ts +0 -39
- package/dist/types-ts4.0/plugins/table/ui/messages.d.ts +0 -38
- package/dist/types-ts4.0/plugins/table/ui/ui-styles.d.ts +0 -15
- package/dist/types-ts4.0/plugins/table/utils/analytics.d.ts +0 -18
- package/dist/types-ts4.0/plugins/table/utils/collapse.d.ts +0 -29
- package/dist/types-ts4.0/plugins/table/utils/column-controls.d.ts +0 -10
- package/dist/types-ts4.0/plugins/table/utils/decoration.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/utils/dom.d.ts +0 -20
- package/dist/types-ts4.0/plugins/table/utils/get-allow-add-column-custom-step.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/utils/index.d.ts +0 -11
- package/dist/types-ts4.0/plugins/table/utils/nodes.d.ts +0 -12
- package/dist/types-ts4.0/plugins/table/utils/paste.d.ts +0 -14
- package/dist/types-ts4.0/plugins/table/utils/referentiality.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/utils/row-controls.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/utils/selection.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/utils/table.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/utils/update-plugin-state-decorations.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table-plugin.d.ts +0 -2
- package/src/plugins/table/ui/FloatingContextualMenu/__tests__/ContextualMenu.tsx +0 -56
- 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 {
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
56
|
-
let
|
|
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
|
|
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
|
-
|
|
70
|
+
tableNode = findParentNodeOfTypeClosestToPos(
|
|
74
71
|
editorView.state.selection.$from,
|
|
75
72
|
editorView.state.schema.nodes.table,
|
|
76
73
|
);
|
|
77
74
|
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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('
|
|
98
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
pluginKey,
|
|
146
|
-
});
|
|
153
|
+
describe('Floating Insert Button', () => {
|
|
154
|
+
const createAnalyticsEvent = jest.fn(
|
|
155
|
+
() => ({ fire() {} } as UIAnalyticsEvent),
|
|
156
|
+
);
|
|
147
157
|
|
|
148
|
-
let
|
|
149
|
-
let
|
|
150
|
-
let
|
|
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
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
+
tableRef = getPluginState(editorView.state).tableRef;
|
|
183
|
+
tableEditorView = editorView;
|
|
182
184
|
});
|
|
183
185
|
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
190
|
-
|
|
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
|
-
|
|
195
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
217
|
-
|
|
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(
|
|
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
|
-
|
|
256
|
+
component({
|
|
227
257
|
insertColumnButtonIndex: 0,
|
|
228
258
|
isHeaderColumnEnabled: false,
|
|
259
|
+
editorView: tableEditorView,
|
|
260
|
+
getEditorContainerWidth,
|
|
229
261
|
});
|
|
230
262
|
|
|
231
|
-
expect(
|
|
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)(
|
|
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
|
|
246
|
-
selectColumns([1])(
|
|
276
|
+
it('should no render insert button when a whole column is selected', () => {
|
|
277
|
+
selectColumns([1])(tableEditorView.state, tableEditorView.dispatch);
|
|
247
278
|
|
|
248
|
-
|
|
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
|
|
257
|
-
selectRows([1])(
|
|
287
|
+
it('should not render insert button when a whole row is selected', () => {
|
|
288
|
+
selectRows([1])(tableEditorView.state, tableEditorView.dispatch);
|
|
258
289
|
|
|
259
|
-
|
|
290
|
+
component({
|
|
260
291
|
insertRowButtonIndex: 0,
|
|
261
|
-
editorView,
|
|
292
|
+
editorView: tableEditorView,
|
|
293
|
+
getEditorContainerWidth,
|
|
262
294
|
});
|
|
263
295
|
|
|
264
|
-
expect(
|
|
296
|
+
expect(screen.queryByLabelText('Popup')).toBeFalsy();
|
|
265
297
|
});
|
|
266
298
|
});
|