@atlaskit/editor-plugin-table 7.2.2 → 7.3.0
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/commands/column-resize.js +115 -45
- package/dist/cjs/commands/go-to-next-cell.js +7 -11
- package/dist/cjs/commands/misc.js +3 -2
- package/dist/cjs/commands/selection.js +3 -3
- package/dist/cjs/event-handlers.js +38 -25
- package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +3 -19
- package/dist/cjs/pm-plugins/keymap.js +1 -0
- package/dist/cjs/pm-plugins/main.js +43 -9
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +37 -7
- package/dist/cjs/pm-plugins/table-resizing/plugin.js +20 -6
- package/dist/cjs/reducer.js +5 -2
- package/dist/cjs/utils/drag-menu.js +37 -23
- package/dist/cjs/utils/merged-cells.js +66 -1
- package/dist/es2019/commands/column-resize.js +100 -35
- package/dist/es2019/commands/go-to-next-cell.js +7 -9
- package/dist/es2019/commands/misc.js +3 -2
- package/dist/es2019/commands/selection.js +5 -5
- package/dist/es2019/event-handlers.js +17 -3
- package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
- package/dist/es2019/pm-plugins/keymap.js +3 -2
- package/dist/es2019/pm-plugins/main.js +41 -5
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +37 -4
- package/dist/es2019/pm-plugins/table-resizing/plugin.js +16 -1
- package/dist/es2019/reducer.js +5 -2
- package/dist/es2019/utils/drag-menu.js +38 -14
- package/dist/es2019/utils/merged-cells.js +73 -0
- package/dist/esm/commands/column-resize.js +105 -35
- package/dist/esm/commands/go-to-next-cell.js +7 -11
- package/dist/esm/commands/misc.js +3 -2
- package/dist/esm/commands/selection.js +5 -5
- package/dist/esm/event-handlers.js +38 -25
- package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
- package/dist/esm/pm-plugins/keymap.js +3 -2
- package/dist/esm/pm-plugins/main.js +38 -4
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +34 -4
- package/dist/esm/pm-plugins/table-resizing/plugin.js +15 -1
- package/dist/esm/reducer.js +5 -2
- package/dist/esm/utils/drag-menu.js +36 -22
- package/dist/esm/utils/merged-cells.js +65 -0
- package/dist/types/commands/column-resize.d.ts +2 -0
- package/dist/types/commands/misc.d.ts +1 -1
- package/dist/types/types.d.ts +16 -0
- package/dist/types/utils/drag-menu.d.ts +4 -1
- package/dist/types/utils/merged-cells.d.ts +2 -0
- package/dist/types-ts4.5/commands/column-resize.d.ts +2 -0
- package/dist/types-ts4.5/commands/misc.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +16 -0
- package/dist/types-ts4.5/utils/drag-menu.d.ts +4 -1
- package/dist/types-ts4.5/utils/merged-cells.d.ts +2 -0
- package/package.json +10 -17
- package/src/commands/column-resize.ts +155 -40
- package/src/commands/go-to-next-cell.ts +6 -15
- package/src/commands/misc.ts +2 -0
- package/src/commands/selection.ts +5 -5
- package/src/event-handlers.ts +21 -4
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -32
- package/src/pm-plugins/keymap.ts +3 -0
- package/src/pm-plugins/main.ts +47 -2
- package/src/pm-plugins/table-resizing/event-handlers.ts +33 -5
- package/src/pm-plugins/table-resizing/plugin.ts +18 -1
- package/src/reducer.ts +5 -2
- package/src/types.ts +16 -0
- package/src/utils/drag-menu.ts +94 -20
- package/src/utils/merged-cells.ts +78 -0
- package/tsconfig.dev.json +0 -69
- package/tsconfig.json +2 -877
- package/examples/99-testing.tsx +0 -140
- package/examples/config.jsonc +0 -14
- package/src/__tests__/unit/analytics.ts +0 -888
- package/src/__tests__/unit/collab.ts +0 -93
- package/src/__tests__/unit/commands/go-to-next-cell.ts +0 -173
- package/src/__tests__/unit/commands/insert.ts +0 -137
- package/src/__tests__/unit/commands/misc.ts +0 -185
- package/src/__tests__/unit/commands/sort.ts +0 -128
- package/src/__tests__/unit/commands.ts +0 -745
- package/src/__tests__/unit/copy-button.ts +0 -22
- package/src/__tests__/unit/copy-paste.ts +0 -677
- package/src/__tests__/unit/event-handlers/index.ts +0 -125
- package/src/__tests__/unit/event-handlers.ts +0 -296
- package/src/__tests__/unit/fix-tables.ts +0 -164
- package/src/__tests__/unit/get-toolbar-config.ts +0 -127
- package/src/__tests__/unit/handlers.ts +0 -98
- package/src/__tests__/unit/hover-selection.ts +0 -230
- package/src/__tests__/unit/index-with-fake-timers.ts +0 -111
- package/src/__tests__/unit/index.ts +0 -912
- package/src/__tests__/unit/layout.ts +0 -146
- package/src/__tests__/unit/nodeviews/OverflowShadowsObserver.ts +0 -162
- package/src/__tests__/unit/nodeviews/TableComponent.tsx +0 -280
- package/src/__tests__/unit/nodeviews/TableContainer.tsx +0 -525
- package/src/__tests__/unit/nodeviews/cell.ts +0 -132
- package/src/__tests__/unit/nodeviews/table.ts +0 -129
- package/src/__tests__/unit/pm-plugins/analytics.ts +0 -327
- package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +0 -94
- package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +0 -176
- package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +0 -211
- package/src/__tests__/unit/pm-plugins/main.ts +0 -214
- package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -101
- package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +0 -562
- package/src/__tests__/unit/pm-plugins/table-local-id.ts +0 -507
- package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +0 -269
- package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +0 -192
- package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +0 -33
- package/src/__tests__/unit/pm-plugins/table-width.ts +0 -292
- package/src/__tests__/unit/sort-column.ts +0 -399
- package/src/__tests__/unit/toolbar.ts +0 -512
- package/src/__tests__/unit/transforms/delete-columns.ts +0 -597
- package/src/__tests__/unit/transforms/delete-rows.ts +0 -620
- package/src/__tests__/unit/transforms/merging.ts +0 -392
- package/src/__tests__/unit/ui/ContextualMenu.tsx +0 -71
- package/src/__tests__/unit/ui/CornerControls.tsx +0 -99
- package/src/__tests__/unit/ui/DeleteButton.tsx +0 -38
- package/src/__tests__/unit/ui/FixedButton.tsx +0 -217
- package/src/__tests__/unit/ui/FloatingContextualButton.tsx +0 -123
- package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +0 -68
- package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +0 -178
- package/src/__tests__/unit/ui/FloatingDragMenu.tsx +0 -511
- package/src/__tests__/unit/ui/FloatingInsertButton.tsx +0 -322
- package/src/__tests__/unit/ui/NumberColumn.tsx +0 -146
- package/src/__tests__/unit/ui/RowControls.tsx +0 -294
- package/src/__tests__/unit/ui/RowDragControls.tsx +0 -129
- package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +0 -189
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +0 -118
- package/src/__tests__/unit/undo-redo.ts +0 -220
- package/src/__tests__/unit/utils/analytics.ts +0 -98
- package/src/__tests__/unit/utils/collapse.ts +0 -57
- package/src/__tests__/unit/utils/column-controls.ts +0 -205
- package/src/__tests__/unit/utils/dom.ts +0 -180
- package/src/__tests__/unit/utils/merged-cells.ts +0 -156
- package/src/__tests__/unit/utils/nodes.ts +0 -79
- package/src/__tests__/unit/utils/row-controls.ts +0 -195
- package/src/__tests__/unit/utils/table.ts +0 -96
- package/src/__tests__/unit/utils.ts +0 -670
- package/src/__tests__/visual-regression/__fixtures__/sticky-header-with-horizontal-scroll.json +0 -5228
- package/src/__tests__/visual-regression/__fixtures__/table-with-100-numbered-list-items.json +0 -20272
- package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-column-menu-item-should-remove-the-table-column-on-click-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-column-menu-item-visual-hints-should-be-added-to-the-table-column-on-hover-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-row-menu-item-should-remove-the-table-row-on-click-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-row-menu-item-visual-hints-should-be-added-to-the-table-row-on-hover-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/copy-button-ts-floating-toolbar-copy-button-table-target-node-displays-blue-border-when-copy-button-is-hovered-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-2-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-3-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-2-snap.png +0 -3
- package/src/__tests__/visual-regression/cell-options-menu.ts +0 -101
- package/src/__tests__/visual-regression/copy-button.ts +0 -181
- package/src/__tests__/visual-regression/index.ts +0 -62
- package/src/__tests__/visual-regression/sticky-header.ts +0 -61
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import { render, screen } from '@testing-library/react';
|
|
4
|
-
import { createIntl, IntlProvider } from 'react-intl-next';
|
|
5
|
-
|
|
6
|
-
import type { UIAnalyticsEvent } from '@atlaskit/analytics-next';
|
|
7
|
-
import {
|
|
8
|
-
ACTION,
|
|
9
|
-
ACTION_SUBJECT,
|
|
10
|
-
CONTENT_COMPONENT,
|
|
11
|
-
EVENT_TYPE,
|
|
12
|
-
} from '@atlaskit/editor-common/analytics';
|
|
13
|
-
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
14
|
-
import { findParentNodeOfTypeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
|
|
15
|
-
import * as prosemirrorUtils from '@atlaskit/editor-prosemirror/utils';
|
|
16
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
17
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
18
|
-
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
19
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
20
|
-
import {
|
|
21
|
-
doc,
|
|
22
|
-
table,
|
|
23
|
-
tdCursor,
|
|
24
|
-
tdEmpty,
|
|
25
|
-
thEmpty,
|
|
26
|
-
tr,
|
|
27
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
28
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
29
|
-
import {
|
|
30
|
-
selectCell,
|
|
31
|
-
selectColumns,
|
|
32
|
-
selectRows,
|
|
33
|
-
} from '@atlaskit/editor-test-helpers/table';
|
|
34
|
-
|
|
35
|
-
import { setEditorFocus, setTableRef } from '../../../commands';
|
|
36
|
-
import tablePlugin from '../../../plugin';
|
|
37
|
-
import { getPluginState } from '../../../pm-plugins/plugin-factory';
|
|
38
|
-
import { pluginKey } from '../../../pm-plugins/plugin-key';
|
|
39
|
-
import type { TablePluginState } from '../../../types';
|
|
40
|
-
import type { Props as FloatingInsertButtonProps } from '../../../ui/FloatingInsertButton';
|
|
41
|
-
import { FloatingInsertButton } from '../../../ui/FloatingInsertButton';
|
|
42
|
-
|
|
43
|
-
jest.mock('@atlaskit/editor-prosemirror/utils', () => {
|
|
44
|
-
// Unblock prosemirror bump:
|
|
45
|
-
// Workaround to enable spy on prosemirror-utils cjs bundle
|
|
46
|
-
const originalModule = jest.requireActual(
|
|
47
|
-
'@atlaskit/editor-prosemirror/utils',
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
__esModule: true,
|
|
52
|
-
...originalModule,
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const getEditorContainerWidth = () => ({ width: 500 });
|
|
57
|
-
const createEditor = createEditorFactory<TablePluginState>();
|
|
58
|
-
const createAnalyticsEvent = jest.fn(() => ({ fire() {} } as UIAnalyticsEvent));
|
|
59
|
-
|
|
60
|
-
const editor = (doc: DocBuilder) =>
|
|
61
|
-
createEditor({
|
|
62
|
-
doc,
|
|
63
|
-
editorProps: {
|
|
64
|
-
allowTables: false,
|
|
65
|
-
dangerouslyAppendPlugins: {
|
|
66
|
-
__plugins: [tablePlugin({ config: undefined })],
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
pluginKey,
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe('Floating Insert Button when findDomRefAtPos fails', () => {
|
|
73
|
-
let tableRef: HTMLTableElement | undefined;
|
|
74
|
-
let tableNode: prosemirrorUtils.ContentNodeWithPos | undefined;
|
|
75
|
-
let tableEditorView: EditorView;
|
|
76
|
-
|
|
77
|
-
beforeEach(() => {
|
|
78
|
-
const { editorView } = editor(
|
|
79
|
-
doc(
|
|
80
|
-
table()(
|
|
81
|
-
tr(thEmpty, thEmpty, thEmpty),
|
|
82
|
-
tr(tdCursor, tdEmpty, tdEmpty),
|
|
83
|
-
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
84
|
-
),
|
|
85
|
-
),
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
tableNode = findParentNodeOfTypeClosestToPos(
|
|
89
|
-
editorView.state.selection.$from,
|
|
90
|
-
editorView.state.schema.nodes.table,
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
const ref = editorView.dom.querySelector('table');
|
|
94
|
-
setEditorFocus(true)(editorView.state, editorView.dispatch);
|
|
95
|
-
setTableRef(ref!)(editorView.state, editorView.dispatch);
|
|
96
|
-
|
|
97
|
-
tableRef = getPluginState(editorView.state).tableRef;
|
|
98
|
-
tableEditorView = editorView;
|
|
99
|
-
|
|
100
|
-
const mock = jest.spyOn(prosemirrorUtils, 'findDomRefAtPos');
|
|
101
|
-
mock.mockImplementation(() => {
|
|
102
|
-
const error = new Error('Error message from mock');
|
|
103
|
-
error.stack = 'stack trace';
|
|
104
|
-
|
|
105
|
-
throw error;
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
const intl = createIntl({ locale: 'en' });
|
|
110
|
-
|
|
111
|
-
const component = (props: FloatingInsertButtonProps) =>
|
|
112
|
-
render(
|
|
113
|
-
<IntlProvider locale="en">
|
|
114
|
-
<FloatingInsertButton
|
|
115
|
-
intl={intl}
|
|
116
|
-
tableRef={tableRef}
|
|
117
|
-
tableNode={tableNode && tableNode.node}
|
|
118
|
-
{...props}
|
|
119
|
-
/>
|
|
120
|
-
</IntlProvider>,
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
afterEach(() => {
|
|
124
|
-
jest.restoreAllMocks();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('should send error analytics event', () => {
|
|
128
|
-
component({
|
|
129
|
-
insertColumnButtonIndex: 1,
|
|
130
|
-
editorView: tableEditorView,
|
|
131
|
-
getEditorContainerWidth,
|
|
132
|
-
dispatchAnalyticsEvent: createAnalyticsEvent,
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
expect(createAnalyticsEvent).toHaveBeenCalledTimes(1);
|
|
136
|
-
expect(createAnalyticsEvent).toHaveBeenCalledWith({
|
|
137
|
-
action: ACTION.ERRORED,
|
|
138
|
-
actionSubject: ACTION_SUBJECT.CONTENT_COMPONENT,
|
|
139
|
-
eventType: EVENT_TYPE.OPERATIONAL,
|
|
140
|
-
attributes: expect.objectContaining({
|
|
141
|
-
component: CONTENT_COMPONENT.FLOATING_INSERT_BUTTON,
|
|
142
|
-
selection: { type: 'text', anchor: 18, head: 18 },
|
|
143
|
-
position: 3,
|
|
144
|
-
docSize: 46,
|
|
145
|
-
error: 'Error: Error message from mock',
|
|
146
|
-
}),
|
|
147
|
-
});
|
|
148
|
-
expect(createAnalyticsEvent).not.toHaveBeenCalledWith({
|
|
149
|
-
nonPrivacySafeAttributes: expect.any(Object),
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('should not render insert button by default', () => {
|
|
154
|
-
component({ editorView: tableEditorView, getEditorContainerWidth });
|
|
155
|
-
expect(screen.queryByLabelText('Popup')).toBeFalsy();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("shouldn't render insert button for second column", () => {
|
|
159
|
-
component({
|
|
160
|
-
insertColumnButtonIndex: 1,
|
|
161
|
-
editorView: tableEditorView,
|
|
162
|
-
getEditorContainerWidth,
|
|
163
|
-
});
|
|
164
|
-
expect(screen.queryByLabelText('Popup')).toBeFalsy();
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it("shouldn't render insert button for second row", () => {
|
|
168
|
-
component({
|
|
169
|
-
insertRowButtonIndex: 1,
|
|
170
|
-
editorView: tableEditorView,
|
|
171
|
-
getEditorContainerWidth,
|
|
172
|
-
});
|
|
173
|
-
expect(screen.queryByLabelText('Popup')).toBeFalsy();
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
describe('Floating Insert Button', () => {
|
|
178
|
-
const createAnalyticsEvent = jest.fn(
|
|
179
|
-
() => ({ fire() {} } as UIAnalyticsEvent),
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
let tableRef: HTMLTableElement | undefined;
|
|
183
|
-
let tableNode: prosemirrorUtils.ContentNodeWithPos | undefined;
|
|
184
|
-
let tableEditorView: EditorView;
|
|
185
|
-
|
|
186
|
-
beforeEach(() => {
|
|
187
|
-
const { editorView } = editor(
|
|
188
|
-
doc(
|
|
189
|
-
table()(
|
|
190
|
-
tr(thEmpty, thEmpty, thEmpty),
|
|
191
|
-
tr(tdCursor, tdEmpty, tdEmpty),
|
|
192
|
-
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
193
|
-
),
|
|
194
|
-
),
|
|
195
|
-
);
|
|
196
|
-
|
|
197
|
-
tableNode = findParentNodeOfTypeClosestToPos(
|
|
198
|
-
editorView.state.selection.$from,
|
|
199
|
-
editorView.state.schema.nodes.table,
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
const ref = editorView.dom.querySelector('table');
|
|
203
|
-
setEditorFocus(true)(editorView.state, editorView.dispatch);
|
|
204
|
-
setTableRef(ref!)(editorView.state, editorView.dispatch);
|
|
205
|
-
|
|
206
|
-
tableRef = getPluginState(editorView.state).tableRef;
|
|
207
|
-
tableEditorView = editorView;
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
const intl = createIntl({ locale: 'en' });
|
|
211
|
-
|
|
212
|
-
const component = (props: FloatingInsertButtonProps) =>
|
|
213
|
-
render(
|
|
214
|
-
<IntlProvider locale="en">
|
|
215
|
-
<FloatingInsertButton
|
|
216
|
-
intl={intl}
|
|
217
|
-
tableRef={tableRef}
|
|
218
|
-
tableNode={tableNode && tableNode.node}
|
|
219
|
-
dispatchAnalyticsEvent={createAnalyticsEvent}
|
|
220
|
-
{...props}
|
|
221
|
-
/>
|
|
222
|
-
</IntlProvider>,
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
it('should not render insert button with index', () => {
|
|
226
|
-
component({ editorView: tableEditorView, getEditorContainerWidth });
|
|
227
|
-
expect(screen.queryByLabelText('Popup')).toBeFalsy();
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('should render insert button for second column', () => {
|
|
231
|
-
component({
|
|
232
|
-
insertColumnButtonIndex: 1,
|
|
233
|
-
editorView: tableEditorView,
|
|
234
|
-
getEditorContainerWidth,
|
|
235
|
-
});
|
|
236
|
-
expect(screen.getByLabelText('Popup')).toBeInTheDocument();
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it('should render insert button for second row', () => {
|
|
240
|
-
component({
|
|
241
|
-
insertRowButtonIndex: 1,
|
|
242
|
-
editorView: tableEditorView,
|
|
243
|
-
getEditorContainerWidth,
|
|
244
|
-
});
|
|
245
|
-
expect(screen.getByLabelText('Popup')).toBeInTheDocument();
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it('should not render insert button for first row when row header is enabled', () => {
|
|
249
|
-
component({
|
|
250
|
-
insertRowButtonIndex: 0,
|
|
251
|
-
isHeaderRowEnabled: true,
|
|
252
|
-
editorView: tableEditorView,
|
|
253
|
-
getEditorContainerWidth,
|
|
254
|
-
});
|
|
255
|
-
expect(screen.queryByLabelText('Popup')).toBeFalsy();
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
it('should render insert button for first row when row header is disabled', () => {
|
|
259
|
-
component({
|
|
260
|
-
insertRowButtonIndex: 0,
|
|
261
|
-
isHeaderRowEnabled: false,
|
|
262
|
-
editorView: tableEditorView,
|
|
263
|
-
getEditorContainerWidth,
|
|
264
|
-
});
|
|
265
|
-
expect(screen.getByLabelText('Popup')).toBeInTheDocument();
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it('should no render insert button for first col when column header is enabled', () => {
|
|
269
|
-
component({
|
|
270
|
-
insertColumnButtonIndex: 0,
|
|
271
|
-
isHeaderColumnEnabled: true,
|
|
272
|
-
editorView: tableEditorView,
|
|
273
|
-
getEditorContainerWidth,
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
expect(screen.queryByLabelText('Popup')).toBeFalsy();
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it('should render insert button for first col when column header is disabled', () => {
|
|
280
|
-
component({
|
|
281
|
-
insertColumnButtonIndex: 0,
|
|
282
|
-
isHeaderColumnEnabled: false,
|
|
283
|
-
editorView: tableEditorView,
|
|
284
|
-
getEditorContainerWidth,
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
expect(screen.getByLabelText('Popup')).toBeInTheDocument();
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
it('should render insert button when a single cell is selected', () => {
|
|
291
|
-
selectCell(1, 1)(tableEditorView.state, tableEditorView.dispatch);
|
|
292
|
-
component({
|
|
293
|
-
insertColumnButtonIndex: 0,
|
|
294
|
-
editorView: tableEditorView,
|
|
295
|
-
getEditorContainerWidth,
|
|
296
|
-
});
|
|
297
|
-
expect(screen.getByLabelText('Popup')).toBeInTheDocument();
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
it('should no render insert button when a whole column is selected', () => {
|
|
301
|
-
selectColumns([1])(tableEditorView.state, tableEditorView.dispatch);
|
|
302
|
-
|
|
303
|
-
component({
|
|
304
|
-
insertColumnButtonIndex: 0,
|
|
305
|
-
editorView: tableEditorView,
|
|
306
|
-
getEditorContainerWidth,
|
|
307
|
-
});
|
|
308
|
-
expect(screen.queryByLabelText('Popup')).toBeFalsy();
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
it('should not render insert button when a whole row is selected', () => {
|
|
312
|
-
selectRows([1])(tableEditorView.state, tableEditorView.dispatch);
|
|
313
|
-
|
|
314
|
-
component({
|
|
315
|
-
insertRowButtonIndex: 0,
|
|
316
|
-
editorView: tableEditorView,
|
|
317
|
-
getEditorContainerWidth,
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
expect(screen.queryByLabelText('Popup')).toBeFalsy();
|
|
321
|
-
});
|
|
322
|
-
});
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import { fireEvent, render } from '@testing-library/react';
|
|
4
|
-
import { IntlProvider } from 'react-intl-next';
|
|
5
|
-
|
|
6
|
-
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
7
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
8
|
-
import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
9
|
-
import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
10
|
-
import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
11
|
-
import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
|
|
12
|
-
import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
13
|
-
import { widthPlugin } from '@atlaskit/editor-plugin-width';
|
|
14
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
15
|
-
import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
16
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
17
|
-
import {
|
|
18
|
-
createProsemirrorEditorFactory,
|
|
19
|
-
Preset,
|
|
20
|
-
} from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
21
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
22
|
-
import {
|
|
23
|
-
doc,
|
|
24
|
-
p,
|
|
25
|
-
table,
|
|
26
|
-
tdEmpty,
|
|
27
|
-
tr,
|
|
28
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
29
|
-
|
|
30
|
-
import tablePlugin from '../../../plugin';
|
|
31
|
-
import { pluginKey } from '../../../pm-plugins/plugin-key';
|
|
32
|
-
import { TableCssClassName as ClassName } from '../../../types';
|
|
33
|
-
import NumberColumn from '../../../ui/TableFloatingControls/NumberColumn';
|
|
34
|
-
|
|
35
|
-
describe('NumberColumn', () => {
|
|
36
|
-
const createEditor = createProsemirrorEditorFactory();
|
|
37
|
-
|
|
38
|
-
const editor = (doc: DocBuilder, tableOptions = {}) =>
|
|
39
|
-
createEditor({
|
|
40
|
-
doc,
|
|
41
|
-
preset: new Preset<LightEditorPlugin>()
|
|
42
|
-
.add([featureFlagsPlugin, {}])
|
|
43
|
-
.add([analyticsPlugin, {}])
|
|
44
|
-
.add(contentInsertionPlugin)
|
|
45
|
-
.add(widthPlugin)
|
|
46
|
-
.add(guidelinePlugin)
|
|
47
|
-
.add(selectionPlugin)
|
|
48
|
-
.add([tablePlugin, { tableOptions }]),
|
|
49
|
-
pluginKey: pluginKey,
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should update plugin state for hovered cell - when drag and drop is enabled', () => {
|
|
53
|
-
const { editorView } = editor(
|
|
54
|
-
doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
|
|
55
|
-
{ dragAndDropEnabled: true },
|
|
56
|
-
);
|
|
57
|
-
const hoverCellLocationMock = jest.fn();
|
|
58
|
-
const ref = editorView.dom.querySelector('table');
|
|
59
|
-
|
|
60
|
-
const { container } = render(
|
|
61
|
-
<IntlProvider locale="en">
|
|
62
|
-
<NumberColumn
|
|
63
|
-
tableRef={ref!}
|
|
64
|
-
tableActive
|
|
65
|
-
editorView={editorView}
|
|
66
|
-
hoverRows={jest.fn()}
|
|
67
|
-
selectRow={jest.fn()}
|
|
68
|
-
updateCellHoverLocation={hoverCellLocationMock}
|
|
69
|
-
isDragAndDropEnabled
|
|
70
|
-
/>
|
|
71
|
-
</IntlProvider>,
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
const firstNumberedCell = container.querySelector(
|
|
75
|
-
`.${ClassName.NUMBERED_COLUMN} > div`,
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
fireEvent.mouseOver(firstNumberedCell!);
|
|
79
|
-
|
|
80
|
-
expect(hoverCellLocationMock).toHaveBeenCalledWith(0);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('should render button disabled numbered column cells - when drag and drop is enabled', () => {
|
|
84
|
-
const { editorView } = editor(
|
|
85
|
-
doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
|
|
86
|
-
{ dragAndDropEnabled: true },
|
|
87
|
-
);
|
|
88
|
-
const ref = editorView.dom.querySelector('table');
|
|
89
|
-
|
|
90
|
-
const { container } = render(
|
|
91
|
-
<IntlProvider locale="en">
|
|
92
|
-
<NumberColumn
|
|
93
|
-
tableRef={ref!}
|
|
94
|
-
tableActive
|
|
95
|
-
editorView={editorView}
|
|
96
|
-
hoverRows={jest.fn()}
|
|
97
|
-
selectRow={jest.fn()}
|
|
98
|
-
updateCellHoverLocation={jest.fn()}
|
|
99
|
-
isDragAndDropEnabled
|
|
100
|
-
/>
|
|
101
|
-
</IntlProvider>,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const firstNumberedCells = container.querySelectorAll(
|
|
105
|
-
`.${ClassName.NUMBERED_COLUMN} > div`,
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
firstNumberedCells.forEach((cell) => {
|
|
109
|
-
expect(
|
|
110
|
-
cell.classList.contains(ClassName.NUMBERED_COLUMN_BUTTON_DISABLED),
|
|
111
|
-
).toBeTruthy();
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('should render buttons for numbered column cells - when drag and drop is disabled', () => {
|
|
116
|
-
const { editorView } = editor(
|
|
117
|
-
doc(p('text'), table()(tr(tdEmpty, tdEmpty, tdEmpty))),
|
|
118
|
-
{ dragAndDropEnabled: false },
|
|
119
|
-
);
|
|
120
|
-
const ref = editorView.dom.querySelector('table');
|
|
121
|
-
|
|
122
|
-
const { container } = render(
|
|
123
|
-
<IntlProvider locale="en">
|
|
124
|
-
<NumberColumn
|
|
125
|
-
tableRef={ref!}
|
|
126
|
-
tableActive
|
|
127
|
-
editorView={editorView}
|
|
128
|
-
hoverRows={jest.fn()}
|
|
129
|
-
selectRow={jest.fn()}
|
|
130
|
-
updateCellHoverLocation={jest.fn()}
|
|
131
|
-
isDragAndDropEnabled={false}
|
|
132
|
-
/>
|
|
133
|
-
</IntlProvider>,
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
const firstNumberedCells = container.querySelectorAll(
|
|
137
|
-
`.${ClassName.NUMBERED_COLUMN} > div`,
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
firstNumberedCells.forEach((cell) => {
|
|
141
|
-
expect(
|
|
142
|
-
cell.classList.contains(ClassName.NUMBERED_COLUMN_BUTTON_DISABLED),
|
|
143
|
-
).toBeFalsy();
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
});
|