Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
VasilyStrelyaev committed Oct 23, 2024
1 parent 0a3fbb6 commit 9a983fc
Showing 1 changed file with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,12 @@ describe('TableColumnReordering', () => {
{children}
</div>
);
const mountWithCellTemplates = ({
defaultOrder, onOrderChange,
}, deps = {}) => mount((

const TestComponent = ({
defaultOrder,
onOrderChange,
deps,
}) => (
<DragDropProvider>
<PluginHost>
<Template name="table">
Expand Down Expand Up @@ -207,6 +210,16 @@ describe('TableColumnReordering', () => {
/>
</PluginHost>
</DragDropProvider>
);

const mountWithCellTemplates = ({
defaultOrder, onOrderChange,
}, deps = {}) => mount((
<TestComponent
defaultOrder={defaultOrder}
onOrderChange={onOrderChange}
deps={deps}
/>
));

beforeEach(() => {
Expand Down Expand Up @@ -313,6 +326,53 @@ describe('TableColumnReordering', () => {
.toHaveBeenLastCalledWith(['c', 'a', 'b'], 1, 2);
});

it('should clear cell dimension cache when the number of columns changes', () => {
const deps = {
getter: {
tableColumns: [
...defaultDeps.getter.tableColumns,
],
},
};
let cellDimensions;

orderedColumns.mockImplementation(() => deps.getter.tableColumns);
getTableTargetColumnIndex.mockImplementation((cellDimensionsArg) => {
cellDimensions = cellDimensionsArg;
return 1;
});

const wrapper = mount(
<TestComponent
defaultOrder={['a', 'b']}
onOrderChange={() => undefined}
deps={deps}
/>
);

const onOver = wrapper.find(TableMock).prop('onOver');

onOver({ payload: [{ type: 'column', columnName: 'a' }], ...defaultClientOffset });

expect(cellDimensions.length).toEqual(2);

const newDeps = {
getter: {
tableColumns: [
...[defaultDeps.getter.tableColumns[0]],
],
},
};
cellDimensions = [];

orderedColumns.mockImplementation(() => newDeps.getter.tableColumns);
wrapper.setProps({ deps: newDeps });

onOver({ payload: [{ type: 'column', columnName: 'a' }], ...defaultClientOffset });

expect(cellDimensions.length).toEqual(1);
});

it('should reset cell dimensions after leave and drop events', () => {
const onOverArg = { payload: [{ type: 'column', columnName: 'a' }], ...defaultClientOffset };
const { onOver, onLeave, onDrop } = mountWithCellTemplates({ defaultOrder: ['a', 'b'] })
Expand Down

0 comments on commit 9a983fc

Please sign in to comment.