@atlaskit/editor-plugin-table 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/cjs/plugins/table/commands-with-analytics.js +6 -0
- package/dist/cjs/plugins/table/event-handlers.js +7 -6
- 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/utils/column-controls.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/commands-with-analytics.js +6 -0
- package/dist/es2019/plugins/table/event-handlers.js +8 -7
- 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/utils/column-controls.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/commands-with-analytics.js +6 -0
- package/dist/esm/plugins/table/event-handlers.js +8 -7
- 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/utils/column-controls.js +1 -1
- package/dist/esm/version.json +1 -1
- package/package.json +9 -7
- package/report.api.md +13 -6
- 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 +106 -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/commands-with-analytics.ts +3 -0
- package/src/plugins/table/event-handlers.ts +5 -6
- package/src/plugins/table/nodeviews/tableCell.tsx +5 -4
- 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/utils/column-controls.ts +1 -1
- package/tmp/api-report-tmp.d.ts +91 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
2
|
+
import {
|
|
3
|
+
createProsemirrorEditorFactory,
|
|
4
|
+
Preset,
|
|
5
|
+
LightEditorPlugin,
|
|
6
|
+
} from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
7
|
+
import { bodiedExtensionData } from '@atlaskit/editor-test-helpers/mock-extension-data';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
doc,
|
|
11
|
+
p,
|
|
12
|
+
table,
|
|
13
|
+
tr,
|
|
14
|
+
td,
|
|
15
|
+
th,
|
|
16
|
+
tdCursor,
|
|
17
|
+
tdEmpty,
|
|
18
|
+
bodiedExtension,
|
|
19
|
+
layoutSection,
|
|
20
|
+
layoutColumn,
|
|
21
|
+
DocBuilder,
|
|
22
|
+
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
23
|
+
|
|
24
|
+
import { TableLayout } from '@atlaskit/adf-schema';
|
|
25
|
+
import {
|
|
26
|
+
PermittedLayoutsDescriptor,
|
|
27
|
+
TablePluginState,
|
|
28
|
+
} from '../../plugins/table/types';
|
|
29
|
+
import { toggleTableLayout } from '../../plugins/table/commands';
|
|
30
|
+
import { isLayoutSupported } from '../../plugins/table/utils';
|
|
31
|
+
import { getPluginState } from '../../plugins/table/pm-plugins/plugin-factory';
|
|
32
|
+
import { pluginKey as tablePluginKey } from '../../plugins/table/pm-plugins/plugin-key';
|
|
33
|
+
import tablePlugin from '../../plugins/table-plugin';
|
|
34
|
+
import expandPlugin from '@atlaskit/editor-core/src/plugins/expand';
|
|
35
|
+
import extensionPlugin from '@atlaskit/editor-core/src/plugins/extension';
|
|
36
|
+
import layoutPlugin from '@atlaskit/editor-core/src/plugins/layout';
|
|
37
|
+
import { PluginKey } from 'prosemirror-state';
|
|
38
|
+
|
|
39
|
+
describe('table toolbar', () => {
|
|
40
|
+
const tableOptions = {
|
|
41
|
+
allowNumberColumn: true,
|
|
42
|
+
allowHeaderRow: true,
|
|
43
|
+
allowHeaderColumn: true,
|
|
44
|
+
permittedLayouts: 'all' as PermittedLayoutsDescriptor,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const createEditor = createProsemirrorEditorFactory();
|
|
48
|
+
const preset = new Preset<LightEditorPlugin>()
|
|
49
|
+
.add([tablePlugin, { tableOptions }])
|
|
50
|
+
.add(expandPlugin)
|
|
51
|
+
.add(extensionPlugin)
|
|
52
|
+
.add(layoutPlugin);
|
|
53
|
+
|
|
54
|
+
const editor = (doc: DocBuilder) => {
|
|
55
|
+
return createEditor<TablePluginState, PluginKey>({
|
|
56
|
+
doc,
|
|
57
|
+
preset,
|
|
58
|
+
pluginKey: tablePluginKey,
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
describe('table layouts', () => {
|
|
63
|
+
it('should update the table node layout attribute', () => {
|
|
64
|
+
const { editorView } = editor(
|
|
65
|
+
doc(table()(tr(tdCursor, tdEmpty, tdEmpty))),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const nodeInitial = findTable(editorView.state.selection)!.node;
|
|
69
|
+
expect(nodeInitial).toBeDefined();
|
|
70
|
+
expect(nodeInitial!.attrs.layout).toBe('default');
|
|
71
|
+
|
|
72
|
+
toggleTableLayout(editorView.state, editorView.dispatch);
|
|
73
|
+
|
|
74
|
+
const { node } = findTable(editorView.state.selection)!;
|
|
75
|
+
|
|
76
|
+
expect(node).toBeDefined();
|
|
77
|
+
expect(node!.attrs.layout).toBe('wide');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('can set the data-layout attribute on the table DOM element', () => {
|
|
81
|
+
const { editorView } = editor(
|
|
82
|
+
doc(table()(tr(tdCursor, tdEmpty, tdEmpty))),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
let tableElement = editorView.dom.querySelector('table');
|
|
86
|
+
expect(tableElement!.getAttribute('data-layout')).toBe('default');
|
|
87
|
+
|
|
88
|
+
toggleTableLayout(editorView.state, editorView.dispatch);
|
|
89
|
+
tableElement = editorView.dom.querySelector('table');
|
|
90
|
+
expect(tableElement!.getAttribute('data-layout')).toBe('wide');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('applies the initial data-layout attribute on the table DOM element', () => {
|
|
94
|
+
const { editorView } = editor(
|
|
95
|
+
doc(table({ layout: 'full-width' })(tr(tdCursor, tdEmpty, tdEmpty))),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const tables = editorView.dom.getElementsByTagName('table');
|
|
99
|
+
expect(tables.length).toBe(1);
|
|
100
|
+
const tableElement = tables[0];
|
|
101
|
+
|
|
102
|
+
expect(tableElement.getAttribute('data-layout')).toBe('full-width');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
['default', 'wide', 'full-width'].forEach((currentLayout) => {
|
|
106
|
+
describe(`#toggleTableLayout`, () => {
|
|
107
|
+
it('should toggle table layout attribute', () => {
|
|
108
|
+
const { editorView } = editor(
|
|
109
|
+
doc(
|
|
110
|
+
table({ layout: currentLayout as TableLayout })(
|
|
111
|
+
tr(tdCursor, tdEmpty, tdEmpty),
|
|
112
|
+
),
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
toggleTableLayout(editorView.state, editorView.dispatch);
|
|
116
|
+
const { tableNode } = getPluginState(editorView.state);
|
|
117
|
+
let nextLayout;
|
|
118
|
+
switch (currentLayout) {
|
|
119
|
+
case 'default':
|
|
120
|
+
nextLayout = 'wide';
|
|
121
|
+
break;
|
|
122
|
+
case 'wide':
|
|
123
|
+
nextLayout = 'full-width';
|
|
124
|
+
break;
|
|
125
|
+
case 'full-width':
|
|
126
|
+
nextLayout = 'default';
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
expect(tableNode).toBeDefined();
|
|
130
|
+
expect(tableNode!.attrs.layout).toBe(nextLayout);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('applies the initial data-layout attribute on the table DOM element', () => {
|
|
136
|
+
const { editorView } = editor(
|
|
137
|
+
doc(table({ layout: 'full-width' })(tr(tdCursor, tdEmpty, tdEmpty))),
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
const tables = editorView.dom.getElementsByTagName('table');
|
|
141
|
+
expect(tables.length).toBe(1);
|
|
142
|
+
const tableElement = tables[0];
|
|
143
|
+
|
|
144
|
+
expect(tableElement.getAttribute('data-layout')).toBe('full-width');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('#isLayoutSupported', () => {
|
|
149
|
+
(['default', 'wide', 'full-width'] as TableLayout[]).forEach((layout) => {
|
|
150
|
+
describe(`when called with "${layout}"`, () => {
|
|
151
|
+
it('returns true if permittedLayouts="all"', () => {
|
|
152
|
+
const { editorView } = editor(
|
|
153
|
+
doc(
|
|
154
|
+
table()(
|
|
155
|
+
tr(th()(p('{<>}1')), th()(p('2'))),
|
|
156
|
+
tr(td()(p('3')), td()(p('4'))),
|
|
157
|
+
),
|
|
158
|
+
),
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
expect(isLayoutSupported(editorView.state)).toBe(true);
|
|
162
|
+
});
|
|
163
|
+
it('returns false if table is nested in bodiedExtension', () => {
|
|
164
|
+
const { editorView } = editor(
|
|
165
|
+
doc(
|
|
166
|
+
bodiedExtension(bodiedExtensionData[0].attrs)(
|
|
167
|
+
table()(
|
|
168
|
+
tr(th()(p('{<>}1')), th()(p('2'))),
|
|
169
|
+
tr(td()(p('3')), td()(p('4'))),
|
|
170
|
+
),
|
|
171
|
+
),
|
|
172
|
+
),
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
expect(isLayoutSupported(editorView.state)).toBe(false);
|
|
176
|
+
});
|
|
177
|
+
it('returns false if table is nested in Columns', () => {
|
|
178
|
+
const { editorView } = editor(
|
|
179
|
+
doc(
|
|
180
|
+
layoutSection(
|
|
181
|
+
layoutColumn({ width: 50 })(
|
|
182
|
+
table()(
|
|
183
|
+
tr(th()(p('{<>}1')), th()(p('2'))),
|
|
184
|
+
tr(td()(p('3')), td()(p('4'))),
|
|
185
|
+
),
|
|
186
|
+
),
|
|
187
|
+
layoutColumn({ width: 50 })(p('text')),
|
|
188
|
+
),
|
|
189
|
+
),
|
|
190
|
+
);
|
|
191
|
+
expect(isLayoutSupported(editorView.state)).toBe(false);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
});
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import {
|
|
2
|
+
setCellAttrs,
|
|
3
|
+
findCellClosestToPos,
|
|
4
|
+
} from '@atlaskit/editor-tables/utils';
|
|
5
|
+
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
6
|
+
import {
|
|
7
|
+
doc,
|
|
8
|
+
p,
|
|
9
|
+
table,
|
|
10
|
+
tr,
|
|
11
|
+
td,
|
|
12
|
+
tdEmpty,
|
|
13
|
+
DocBuilder,
|
|
14
|
+
thEmpty,
|
|
15
|
+
th,
|
|
16
|
+
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
17
|
+
import {
|
|
18
|
+
tableBackgroundColorNames,
|
|
19
|
+
rgbToHex,
|
|
20
|
+
uuid,
|
|
21
|
+
} from '@atlaskit/adf-schema';
|
|
22
|
+
import { TablePluginState, PluginConfig } from '../../../plugins/table/types';
|
|
23
|
+
import { mergeCells } from '../../../plugins/table/transforms';
|
|
24
|
+
import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
|
|
25
|
+
import TableCellViews from '../../../plugins/table/nodeviews/tableCell';
|
|
26
|
+
import sendKeyToPm from '@atlaskit/editor-test-helpers/send-key-to-pm';
|
|
27
|
+
import * as domHelpers from '../../../plugins/table/pm-plugins/sticky-headers/nodeviews/dom';
|
|
28
|
+
import tablePlugin from '../../../plugins/table-plugin';
|
|
29
|
+
|
|
30
|
+
jest.mock('@atlaskit/editor-common/utils', () => ({
|
|
31
|
+
...jest.requireActual<Object>('@atlaskit/editor-common/utils'),
|
|
32
|
+
browser: {
|
|
33
|
+
chrome: false,
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
describe('table -> nodeviews -> tableCell.tsx', () => {
|
|
38
|
+
const TABLE_LOCAL_ID = 'test-table-local-id';
|
|
39
|
+
const createEditor = createEditorFactory<TablePluginState>();
|
|
40
|
+
|
|
41
|
+
const editor = (doc: DocBuilder, props?: PluginConfig) =>
|
|
42
|
+
createEditor({
|
|
43
|
+
doc,
|
|
44
|
+
editorProps: {
|
|
45
|
+
dangerouslyAppendPlugins: {
|
|
46
|
+
__plugins: [
|
|
47
|
+
tablePlugin({ tableOptions: { advanced: true, ...props } }),
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
pluginKey,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('when background color is set to "red"', () => {
|
|
55
|
+
beforeAll(() => {
|
|
56
|
+
uuid.setStatic(TABLE_LOCAL_ID);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
beforeEach(() => {
|
|
60
|
+
jest.clearAllMocks();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should update cell DOM node style attribute with the new color', () => {
|
|
64
|
+
const {
|
|
65
|
+
editorView,
|
|
66
|
+
refs: { pos },
|
|
67
|
+
} = editor(
|
|
68
|
+
doc(p('text'), table()(tr(td()(p('{pos}text')), tdEmpty, tdEmpty))),
|
|
69
|
+
);
|
|
70
|
+
const { state, dispatch } = editorView;
|
|
71
|
+
const cell = findCellClosestToPos(state.doc.resolve(pos))!;
|
|
72
|
+
const background = tableBackgroundColorNames.get('red');
|
|
73
|
+
dispatch(setCellAttrs(cell, { background })(state.tr));
|
|
74
|
+
const cellDomNode = document.querySelector('td')!;
|
|
75
|
+
expect(rgbToHex(cellDomNode.style.backgroundColor!)).toEqual(background);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('when background color is set to "white"', () => {
|
|
80
|
+
it('should remove backgroundColor style attribute from cell DOM node ', () => {
|
|
81
|
+
const {
|
|
82
|
+
editorView,
|
|
83
|
+
refs: { pos },
|
|
84
|
+
} = editor(
|
|
85
|
+
doc(
|
|
86
|
+
p('text'),
|
|
87
|
+
table()(
|
|
88
|
+
tr(td({ background: 'red' })(p('{pos}text')), tdEmpty, tdEmpty),
|
|
89
|
+
),
|
|
90
|
+
),
|
|
91
|
+
);
|
|
92
|
+
const { state, dispatch } = editorView;
|
|
93
|
+
const cell = findCellClosestToPos(state.doc.resolve(pos))!;
|
|
94
|
+
const background = tableBackgroundColorNames.get('white');
|
|
95
|
+
dispatch(setCellAttrs(cell, { background })(state.tr));
|
|
96
|
+
const cellDomNode = document.querySelector('td')!;
|
|
97
|
+
expect(cellDomNode.style.backgroundColor).toEqual('');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('with tableCellOptimization on', () => {
|
|
102
|
+
describe('nodeview update', () => {
|
|
103
|
+
it('should not recreate nodeviews on attrs update', () => {
|
|
104
|
+
const {
|
|
105
|
+
editorView,
|
|
106
|
+
refs: { pos },
|
|
107
|
+
} = editor(
|
|
108
|
+
doc(p('text'), table()(tr(td()(p('{pos}text')), tdEmpty, tdEmpty))),
|
|
109
|
+
{
|
|
110
|
+
tableCellOptimization: true,
|
|
111
|
+
},
|
|
112
|
+
);
|
|
113
|
+
const { state, dispatch } = editorView;
|
|
114
|
+
const cell = findCellClosestToPos(state.doc.resolve(pos))!;
|
|
115
|
+
const background = tableBackgroundColorNames.get('red');
|
|
116
|
+
const updateSpy = jest.spyOn(TableCellViews.prototype, 'update');
|
|
117
|
+
dispatch(setCellAttrs(cell, { background })(state.tr));
|
|
118
|
+
expect(updateSpy).toHaveReturnedWith(true);
|
|
119
|
+
const cellDomNode = document.querySelector('td')!;
|
|
120
|
+
expect(rgbToHex(cellDomNode.style.backgroundColor!)).toEqual(
|
|
121
|
+
background,
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('preserves correct rowspan and colspan after merge cells and undo', () => {
|
|
126
|
+
jest.spyOn(domHelpers, 'getTop').mockImplementation(() => 0);
|
|
127
|
+
|
|
128
|
+
const originalDoc = doc(
|
|
129
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
130
|
+
tr(th()(p('{<cell}')), thEmpty, thEmpty),
|
|
131
|
+
tr(td()(p('{cell>}')), tdEmpty, tdEmpty),
|
|
132
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
133
|
+
),
|
|
134
|
+
);
|
|
135
|
+
const { editorView } = editor(originalDoc, {
|
|
136
|
+
stickyHeaders: true,
|
|
137
|
+
tableCellOptimization: true,
|
|
138
|
+
});
|
|
139
|
+
const { state, dispatch } = editorView;
|
|
140
|
+
|
|
141
|
+
dispatch(mergeCells(state.tr));
|
|
142
|
+
expect(editorView.state.doc).toEqualDocument(
|
|
143
|
+
doc(
|
|
144
|
+
table({ localId: TABLE_LOCAL_ID })(
|
|
145
|
+
tr(th({ rowspan: 2 })(p('')), thEmpty, thEmpty),
|
|
146
|
+
tr(tdEmpty, tdEmpty),
|
|
147
|
+
tr(tdEmpty, tdEmpty, tdEmpty),
|
|
148
|
+
),
|
|
149
|
+
),
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
sendKeyToPm(editorView, 'Mod-z');
|
|
153
|
+
validateUnmergedDomCells();
|
|
154
|
+
expect(editorView.state.doc).toEqualDocument(originalDoc);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// make sure all colspan/rowspan attributes are removed from cells
|
|
158
|
+
function validateUnmergedDomCells() {
|
|
159
|
+
const cells = document.querySelectorAll('table td, table th');
|
|
160
|
+
Array.from(cells).forEach((cell) => {
|
|
161
|
+
expect(cell.getAttribute('rowspan')).toBeFalsy();
|
|
162
|
+
expect(cell.getAttribute('colspan')).toBeFalsy();
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { updateColgroup } from '../../../../../plugins/table/pm-plugins/table-resizing/utils/resize-state';
|
|
2
|
+
import { ResizeState } from '../../../../../plugins/table/pm-plugins/table-resizing/utils/types';
|
|
3
|
+
|
|
4
|
+
describe('table-resizing/utils/resize-state', () => {
|
|
5
|
+
describe('#updateColgroup', () => {
|
|
6
|
+
it('should not throw exception when the dom cols does not exist', () => {
|
|
7
|
+
const state = {
|
|
8
|
+
cols: [{ width: 100 }],
|
|
9
|
+
};
|
|
10
|
+
const tableRef = document.createElement('div');
|
|
11
|
+
|
|
12
|
+
const func = () => {
|
|
13
|
+
updateColgroup(state as ResizeState, tableRef);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
expect(func).not.toThrow();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should not throw exception when the column is null', () => {
|
|
20
|
+
const state = {
|
|
21
|
+
cols: [null],
|
|
22
|
+
};
|
|
23
|
+
const tableRef = document.createElement('div');
|
|
24
|
+
|
|
25
|
+
const func = () => {
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
updateColgroup(state, tableRef);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
expect(func).not.toThrow();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|