@atlaskit/editor-plugin-table 0.0.6 → 0.0.8
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 +17 -0
- package/dist/cjs/plugins/table/event-handlers.js +7 -6
- package/dist/cjs/plugins/table/nodeviews/table.js +4 -2
- package/dist/cjs/plugins/table/nodeviews/tableCell.js +4 -4
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
- package/dist/cjs/plugins/table/toolbar.js +0 -1
- package/dist/cjs/plugins/table/ui/TableFloatingControls/CornerControls/index.js +23 -10
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/index.js +23 -10
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +4 -4
- package/dist/cjs/plugins/table/utils/column-controls.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/event-handlers.js +8 -7
- package/dist/es2019/plugins/table/nodeviews/table.js +4 -2
- package/dist/es2019/plugins/table/nodeviews/tableCell.js +3 -4
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
- package/dist/es2019/plugins/table/toolbar.js +1 -2
- package/dist/es2019/plugins/table/ui/TableFloatingControls/CornerControls/index.js +18 -3
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/index.js +18 -3
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +2 -2
- package/dist/es2019/plugins/table/utils/column-controls.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/event-handlers.js +8 -7
- package/dist/esm/plugins/table/nodeviews/table.js +4 -2
- package/dist/esm/plugins/table/nodeviews/tableCell.js +3 -4
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
- package/dist/esm/plugins/table/toolbar.js +1 -2
- package/dist/esm/plugins/table/ui/TableFloatingControls/CornerControls/index.js +19 -9
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/index.js +19 -9
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +2 -2
- package/dist/esm/plugins/table/utils/column-controls.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/nodeviews/types.d.ts +1 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +5 -8
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +5 -5
- package/dist/types-ts4.0/plugins/table/nodeviews/types.d.ts +1 -0
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +5 -8
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +5 -5
- package/package.json +10 -3
- package/src/__tests__/unit/analytics.ts +737 -0
- package/src/__tests__/unit/collab.ts +76 -0
- package/src/__tests__/unit/commands/sort.ts +230 -0
- package/src/__tests__/unit/copy-paste.ts +686 -0
- package/src/__tests__/unit/event-handlers/index.ts +106 -0
- package/src/__tests__/unit/event-handlers.ts +202 -0
- package/src/__tests__/unit/fix-tables.ts +156 -0
- package/src/__tests__/unit/floating-toolbar.ts +95 -0
- package/src/__tests__/unit/handlers.ts +81 -0
- package/src/__tests__/unit/hover-selection.ts +277 -0
- package/src/__tests__/unit/index-with-fake-timers.ts +107 -0
- package/src/__tests__/unit/index.ts +986 -0
- package/src/__tests__/unit/keymap.ts +602 -0
- package/src/__tests__/unit/layout.ts +196 -0
- package/src/__tests__/unit/nodeviews/cell.ts +167 -0
- package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +33 -0
- package/src/__tests__/unit/sort-column.ts +512 -0
- package/src/__tests__/unit/transforms/delete-columns.ts +499 -0
- package/src/__tests__/unit/transforms/delete-rows.ts +557 -0
- package/src/__tests__/unit/transforms/merging.ts +374 -0
- package/src/__tests__/unit/ui/CornerControls.tsx +80 -0
- package/src/__tests__/unit/ui/FloatingContextualButton.tsx +95 -0
- package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +175 -0
- package/src/__tests__/unit/ui/FloatingInsertButton.tsx +266 -0
- package/src/__tests__/unit/ui/RowControls.tsx +301 -0
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +93 -0
- package/src/__tests__/unit/undo-redo.ts +202 -0
- package/src/__tests__/unit/utils/dom.ts +286 -0
- package/src/__tests__/unit/utils/nodes.ts +59 -0
- package/src/__tests__/unit/utils/row-controls.ts +176 -0
- package/src/__tests__/unit/utils/table.ts +93 -0
- package/src/__tests__/unit/utils.ts +652 -0
- package/src/plugins/table/__tests__/unit/commands/insert.ts +2 -2
- package/src/plugins/table/__tests__/unit/commands.ts +2 -2
- package/src/plugins/table/__tests__/unit/nodeviews/TableComponent.tsx +2 -2
- package/src/plugins/table/__tests__/unit/nodeviews/table.ts +1 -0
- package/src/plugins/table/event-handlers.ts +5 -6
- package/src/plugins/table/nodeviews/table.tsx +7 -0
- package/src/plugins/table/nodeviews/tableCell.tsx +5 -4
- package/src/plugins/table/nodeviews/types.ts +1 -0
- package/src/plugins/table/pm-plugins/table-resizing/utils/column-state.ts +1 -1
- package/src/plugins/table/pm-plugins/table-resizing/utils/resize-logic.ts +6 -2
- package/src/plugins/table/toolbar.ts +0 -1
- package/src/plugins/table/ui/FloatingContextualMenu/__tests__/ContextualMenu.tsx +1 -1
- package/src/plugins/table/ui/FloatingContextualMenu/__tests__/FloatingContextualMenu.tsx +1 -1
- package/src/plugins/table/ui/TableFloatingControls/CornerControls/index.tsx +19 -1
- package/src/plugins/table/ui/TableFloatingControls/RowControls/index.tsx +16 -1
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +2 -2
- package/src/plugins/table/utils/column-controls.ts +1 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
2
|
+
import { mountWithIntl } from '@atlaskit/editor-test-helpers/enzyme';
|
|
3
|
+
import {
|
|
4
|
+
doc,
|
|
5
|
+
table,
|
|
6
|
+
tdCursor,
|
|
7
|
+
tdEmpty,
|
|
8
|
+
thEmpty,
|
|
9
|
+
tr,
|
|
10
|
+
DocBuilder,
|
|
11
|
+
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
12
|
+
import { selectColumns, selectRows } from '@atlaskit/editor-test-helpers/table';
|
|
13
|
+
import { ReactWrapper } from 'enzyme';
|
|
14
|
+
import { selectTable } from '@atlaskit/editor-tables/utils';
|
|
15
|
+
import { EditorView } from 'prosemirror-view';
|
|
16
|
+
import React from 'react';
|
|
17
|
+
import {
|
|
18
|
+
TablePluginState,
|
|
19
|
+
TableCssClassName,
|
|
20
|
+
} from '../../../plugins/table/types';
|
|
21
|
+
import FloatingDeleteButton, {
|
|
22
|
+
Props as FloatingDeleteButtonProps,
|
|
23
|
+
} from '../../../plugins/table/ui/FloatingDeleteButton';
|
|
24
|
+
import DeleteButton from '../../../plugins/table/ui/FloatingDeleteButton/DeleteButton';
|
|
25
|
+
import tableMessages from '../../../plugins/table/ui/messages';
|
|
26
|
+
import * as tableColumnControlsUtils from '../../../plugins/table/utils/column-controls';
|
|
27
|
+
import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
|
|
28
|
+
import tablePlugin from '../../../plugins/table-plugin';
|
|
29
|
+
|
|
30
|
+
describe('Floating Delete Button', () => {
|
|
31
|
+
const createEditor = createEditorFactory<TablePluginState>();
|
|
32
|
+
|
|
33
|
+
const editor = (doc: DocBuilder) =>
|
|
34
|
+
createEditor({
|
|
35
|
+
doc,
|
|
36
|
+
editorProps: {
|
|
37
|
+
allowTables: false,
|
|
38
|
+
dangerouslyAppendPlugins: { __plugins: [tablePlugin()] },
|
|
39
|
+
},
|
|
40
|
+
pluginKey,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
let wrapper: ReactWrapper<FloatingDeleteButtonProps>;
|
|
44
|
+
let editorView: EditorView;
|
|
45
|
+
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
({ editorView } = editor(
|
|
48
|
+
doc(
|
|
49
|
+
table()(
|
|
50
|
+
tr(thEmpty, thEmpty, thEmpty),
|
|
51
|
+
tr(tdCursor, tdEmpty, tdEmpty),
|
|
52
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
53
|
+
),
|
|
54
|
+
),
|
|
55
|
+
));
|
|
56
|
+
|
|
57
|
+
wrapper = (mountWithIntl(
|
|
58
|
+
<FloatingDeleteButton
|
|
59
|
+
tableRef={document.querySelector('table')!}
|
|
60
|
+
editorView={editorView}
|
|
61
|
+
selection={editorView.state.selection}
|
|
62
|
+
/>,
|
|
63
|
+
) as unknown) as ReactWrapper<FloatingDeleteButtonProps>;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
afterEach(() => {
|
|
67
|
+
if (wrapper) {
|
|
68
|
+
wrapper.unmount();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should not render a delete button with no selection', () => {
|
|
73
|
+
expect(wrapper.find(DeleteButton).length).toBe(0);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should not render a delete button with whole table selected', () => {
|
|
77
|
+
// select the whole table
|
|
78
|
+
editorView.dispatch(selectTable(editorView.state.tr));
|
|
79
|
+
|
|
80
|
+
// We need to force renderer
|
|
81
|
+
wrapper.setProps({ selection: editorView.state.selection });
|
|
82
|
+
// set numberOfColumns prop to trick shouldComponentUpdate and force re-render
|
|
83
|
+
expect(wrapper.find(DeleteButton).length).toBe(0);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('Columns', () => {
|
|
87
|
+
beforeEach(() => {
|
|
88
|
+
const COLUMN_WIDTH = 33;
|
|
89
|
+
const tableWrapper = document.querySelector(
|
|
90
|
+
`.${TableCssClassName.TABLE_NODE_WRAPPER}`,
|
|
91
|
+
);
|
|
92
|
+
jest.spyOn(tableWrapper!, 'getBoundingClientRect').mockReturnValue({
|
|
93
|
+
width: COLUMN_WIDTH * 3,
|
|
94
|
+
} as DOMRect);
|
|
95
|
+
tableWrapper!.scrollLeft = 0;
|
|
96
|
+
jest
|
|
97
|
+
.spyOn(tableColumnControlsUtils, 'getColumnsWidths')
|
|
98
|
+
.mockReturnValue([COLUMN_WIDTH, COLUMN_WIDTH, COLUMN_WIDTH]);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test.each([[1], [2], [3]])(
|
|
102
|
+
'should renders a delete button with column %d selected',
|
|
103
|
+
(column) => {
|
|
104
|
+
// Select columns start from 0
|
|
105
|
+
selectColumns([column - 1])(editorView.state, editorView.dispatch);
|
|
106
|
+
|
|
107
|
+
// We need to force renderer
|
|
108
|
+
wrapper.setProps({ selection: editorView.state.selection });
|
|
109
|
+
|
|
110
|
+
// we should now have a delete button
|
|
111
|
+
expect(wrapper.find(DeleteButton).length).toBe(1);
|
|
112
|
+
},
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
it('should render a single delete button over multiple column selections', () => {
|
|
116
|
+
selectColumns([0, 1])(editorView.state, editorView.dispatch);
|
|
117
|
+
|
|
118
|
+
// We need to force renderer
|
|
119
|
+
wrapper.setProps({ selection: editorView.state.selection });
|
|
120
|
+
|
|
121
|
+
expect(wrapper.find(DeleteButton).length).toBe(1);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('Rows', () => {
|
|
126
|
+
test.each([[1], [2], [3]])(
|
|
127
|
+
'renders a delete button with row %d selected',
|
|
128
|
+
(row) => {
|
|
129
|
+
selectRows([row - 1])(editorView.state, editorView.dispatch);
|
|
130
|
+
|
|
131
|
+
wrapper.setProps({ selection: editorView.state.selection });
|
|
132
|
+
|
|
133
|
+
expect(wrapper.find(DeleteButton).length).toBe(1);
|
|
134
|
+
},
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
it('only renders a single delete button over multiple row selections', () => {
|
|
138
|
+
selectRows([0, 1])(editorView.state, editorView.dispatch);
|
|
139
|
+
|
|
140
|
+
// selecting the row mutates the editor state (which is inside editorView)
|
|
141
|
+
// we set tableHeight prop to trick shouldComponentUpdate and force re-render
|
|
142
|
+
wrapper.setProps({ selection: editorView.state.selection });
|
|
143
|
+
|
|
144
|
+
expect(wrapper.find(DeleteButton).length).toBe(1);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('<DeleteButton />', () => {
|
|
149
|
+
it('should fire the onMouseEnter callback', () => {
|
|
150
|
+
const onMouseEnter = jest.fn();
|
|
151
|
+
const button = mountWithIntl(
|
|
152
|
+
<DeleteButton
|
|
153
|
+
removeLabel={tableMessages.removeColumns}
|
|
154
|
+
onMouseEnter={onMouseEnter}
|
|
155
|
+
/>,
|
|
156
|
+
);
|
|
157
|
+
button.simulate('mouseenter');
|
|
158
|
+
expect(onMouseEnter).toBeCalled();
|
|
159
|
+
button.unmount();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('should fire the onMouseLeave callback', () => {
|
|
163
|
+
const onMouseLeave = jest.fn();
|
|
164
|
+
const button = mountWithIntl(
|
|
165
|
+
<DeleteButton
|
|
166
|
+
removeLabel={tableMessages.removeRows}
|
|
167
|
+
onMouseLeave={onMouseLeave}
|
|
168
|
+
/>,
|
|
169
|
+
);
|
|
170
|
+
button.simulate('mouseleave');
|
|
171
|
+
expect(onMouseLeave).toBeCalled();
|
|
172
|
+
button.unmount();
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
2
|
+
import { mountWithIntl } from '@atlaskit/editor-test-helpers/enzyme';
|
|
3
|
+
import {
|
|
4
|
+
doc,
|
|
5
|
+
table,
|
|
6
|
+
tdCursor,
|
|
7
|
+
tdEmpty,
|
|
8
|
+
thEmpty,
|
|
9
|
+
tr,
|
|
10
|
+
DocBuilder,
|
|
11
|
+
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
12
|
+
import {
|
|
13
|
+
selectCell,
|
|
14
|
+
selectColumns,
|
|
15
|
+
selectRows,
|
|
16
|
+
} from '@atlaskit/editor-test-helpers/table';
|
|
17
|
+
import { mount, ReactWrapper } from 'enzyme';
|
|
18
|
+
import { findParentNodeOfTypeClosestToPos } from 'prosemirror-utils';
|
|
19
|
+
import { EditorView } from 'prosemirror-view';
|
|
20
|
+
import React from 'react';
|
|
21
|
+
import { TablePluginState } from '../../../plugins/table/types';
|
|
22
|
+
import {
|
|
23
|
+
FloatingInsertButton,
|
|
24
|
+
Props as FloatingInsertButtonProps,
|
|
25
|
+
} from '../../../plugins/table/ui/FloatingInsertButton';
|
|
26
|
+
import InsertButton from '../../../plugins/table/ui/FloatingInsertButton/InsertButton';
|
|
27
|
+
import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
|
|
28
|
+
import tablePlugin from '../../../plugins/table-plugin';
|
|
29
|
+
import * as prosemirrorUtils from 'prosemirror-utils';
|
|
30
|
+
import { UIAnalyticsEvent } from '@atlaskit/analytics-next';
|
|
31
|
+
import {
|
|
32
|
+
ACTION,
|
|
33
|
+
ACTION_SUBJECT,
|
|
34
|
+
EVENT_TYPE,
|
|
35
|
+
CONTENT_COMPONENT,
|
|
36
|
+
} from '@atlaskit/editor-common/analytics';
|
|
37
|
+
import { createIntl, IntlShape } from 'react-intl-next';
|
|
38
|
+
|
|
39
|
+
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
|
+
});
|
|
54
|
+
|
|
55
|
+
let wrapper: ReactWrapper<FloatingInsertButtonProps>;
|
|
56
|
+
let editorView: EditorView;
|
|
57
|
+
|
|
58
|
+
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(
|
|
64
|
+
doc(
|
|
65
|
+
table()(
|
|
66
|
+
tr(thEmpty, thEmpty, thEmpty),
|
|
67
|
+
tr(tdCursor, tdEmpty, tdEmpty),
|
|
68
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
69
|
+
),
|
|
70
|
+
),
|
|
71
|
+
));
|
|
72
|
+
|
|
73
|
+
const tableNode = findParentNodeOfTypeClosestToPos(
|
|
74
|
+
editorView.state.selection.$from,
|
|
75
|
+
editorView.state.schema.nodes.table,
|
|
76
|
+
);
|
|
77
|
+
|
|
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
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
afterEach(() => {
|
|
93
|
+
wrapper.unmount();
|
|
94
|
+
jest.restoreAllMocks();
|
|
95
|
+
});
|
|
96
|
+
|
|
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({
|
|
101
|
+
insertColumnButtonIndex: 1,
|
|
102
|
+
});
|
|
103
|
+
expect(createAnalyticsEvent).toHaveBeenCalledTimes(1);
|
|
104
|
+
expect(createAnalyticsEvent).toHaveBeenCalledWith({
|
|
105
|
+
action: ACTION.ERRORED,
|
|
106
|
+
actionSubject: ACTION_SUBJECT.CONTENT_COMPONENT,
|
|
107
|
+
eventType: EVENT_TYPE.OPERATIONAL,
|
|
108
|
+
attributes: expect.objectContaining({
|
|
109
|
+
component: CONTENT_COMPONENT.FLOATING_INSERT_BUTTON,
|
|
110
|
+
selection: { type: 'text', anchor: 18, head: 18 },
|
|
111
|
+
position: 3,
|
|
112
|
+
docSize: 46,
|
|
113
|
+
error: 'Error: Error message from mock',
|
|
114
|
+
}),
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should not render insert button by default', () => {
|
|
119
|
+
expect(wrapper.find(InsertButton).length).toBe(0);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("shouldn't render insert button for second column", () => {
|
|
123
|
+
wrapper.setProps({
|
|
124
|
+
insertColumnButtonIndex: 1,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
expect(wrapper.find(InsertButton).length).toBe(0);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("shouldn't render insert button for second row", () => {
|
|
131
|
+
wrapper.setProps({
|
|
132
|
+
insertRowButtonIndex: 1,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
expect(wrapper.find(InsertButton).length).toBe(0);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
describe('Floating Insert Button', () => {
|
|
139
|
+
const createEditor = createEditorFactory<TablePluginState>();
|
|
140
|
+
|
|
141
|
+
const editor = (doc: DocBuilder) =>
|
|
142
|
+
createEditor({
|
|
143
|
+
doc,
|
|
144
|
+
editorProps: { allowTables: true },
|
|
145
|
+
pluginKey,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
let wrapper: ReactWrapper<FloatingInsertButtonProps>;
|
|
149
|
+
let editorView: EditorView;
|
|
150
|
+
let tableNode: ReturnType<typeof findParentNodeOfTypeClosestToPos>;
|
|
151
|
+
let intl: IntlShape;
|
|
152
|
+
|
|
153
|
+
beforeEach(() => {
|
|
154
|
+
({ editorView } = editor(
|
|
155
|
+
doc(
|
|
156
|
+
table()(
|
|
157
|
+
tr(thEmpty, thEmpty, thEmpty),
|
|
158
|
+
tr(tdCursor, tdEmpty, tdEmpty),
|
|
159
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
160
|
+
),
|
|
161
|
+
),
|
|
162
|
+
));
|
|
163
|
+
|
|
164
|
+
tableNode = findParentNodeOfTypeClosestToPos(
|
|
165
|
+
editorView.state.selection.$from,
|
|
166
|
+
editorView.state.schema.nodes.table,
|
|
167
|
+
);
|
|
168
|
+
|
|
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
|
+
});
|
|
179
|
+
|
|
180
|
+
afterEach(() => {
|
|
181
|
+
wrapper.unmount();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('should not render insert button by default', () => {
|
|
185
|
+
expect(wrapper.find(InsertButton).length).toBe(0);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('should render insert button for second column', () => {
|
|
189
|
+
wrapper.setProps({ insertColumnButtonIndex: 1 });
|
|
190
|
+
expect(wrapper.find(InsertButton).length).toBe(1);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('should render insert button for second row', () => {
|
|
194
|
+
wrapper.setProps({ insertRowButtonIndex: 1 });
|
|
195
|
+
expect(wrapper.find(InsertButton).length).toBe(1);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('should not render insert button for first row when row header is enabled', () => {
|
|
199
|
+
wrapper.setProps({
|
|
200
|
+
insertRowButtonIndex: 0,
|
|
201
|
+
isHeaderRowEnabled: true,
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
expect(wrapper.find(InsertButton).length).toBe(0);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('should render insert button for first row when row header is disabled', () => {
|
|
208
|
+
wrapper.setProps({
|
|
209
|
+
insertRowButtonIndex: 0,
|
|
210
|
+
isHeaderRowEnabled: false,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
expect(wrapper.find(InsertButton).length).toBe(1);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('should not render insert button for first col when column header is enabled', () => {
|
|
217
|
+
wrapper.setProps({
|
|
218
|
+
insertColumnButtonIndex: 0,
|
|
219
|
+
isHeaderColumnEnabled: true,
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
expect(wrapper.find(InsertButton).length).toBe(0);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('should render insert button for first col when column header is disabled', () => {
|
|
226
|
+
wrapper.setProps({
|
|
227
|
+
insertColumnButtonIndex: 0,
|
|
228
|
+
isHeaderColumnEnabled: false,
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
expect(wrapper.find(InsertButton).length).toBe(1);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('should render insert button when a single cell is selected', () => {
|
|
235
|
+
selectCell(1, 1)(editorView.state, editorView.dispatch);
|
|
236
|
+
|
|
237
|
+
wrapper.setProps({
|
|
238
|
+
insertColumnButtonIndex: 0,
|
|
239
|
+
editorView,
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
expect(wrapper.find(InsertButton).length).toBe(1);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('should not render insert button when a whole column is selected', () => {
|
|
246
|
+
selectColumns([1])(editorView.state, editorView.dispatch);
|
|
247
|
+
|
|
248
|
+
wrapper.setProps({
|
|
249
|
+
insertColumnButtonIndex: 0,
|
|
250
|
+
editorView,
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
expect(wrapper.find(InsertButton).length).toBe(0);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('should no render insert button when a whole row is selected', () => {
|
|
257
|
+
selectRows([1])(editorView.state, editorView.dispatch);
|
|
258
|
+
|
|
259
|
+
wrapper.setProps({
|
|
260
|
+
insertRowButtonIndex: 0,
|
|
261
|
+
editorView,
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
expect(wrapper.find(InsertButton).length).toBe(0);
|
|
265
|
+
});
|
|
266
|
+
});
|