Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ export class ColumnsResizerViewController extends modules.ViewController {

public _targetPoint?: ColumnPoint | null;

private _resizingInfo: any;
protected _resizingInfo: any;

protected _columnsController!: ColumnsController;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import {
afterEach, describe, expect, it, jest,
} from '@jest/globals';
import type { dxElementWrapper } from '@js/core/renderer';

import { GridCoreStickyColumnsDom } from '../dom';
import { stickyColumnsModule } from '../m_sticky_columns';

const SUPER_OFFSET = 540;
const CELL_LEFT = 419;
const NEXT_CELL_LEFT = 399;
const NEXT_COLUMN_INDEX = 4;

const { columnsResizer } = stickyColumnsModule.extenders.controllers;

const $nextCell = {
length: 1,
offset: () => ({ left: NEXT_CELL_LEFT }),
} as unknown as dxElementWrapper;

const $cell = {
offset: () => ({ left: CELL_LEFT }),
} as unknown as dxElementWrapper;

const columnElements = {
eq: (index: number) => (index === NEXT_COLUMN_INDEX ? $nextCell : { length: 0 }),
};

describe('sticky columns resizer separator offset', () => {
let superGetSeparatorOffsetX: ReturnType<typeof jest.fn>;

const createController = ({
hasStickyColumns = true,
columnResizingMode = 'nextColumn',
}: {
hasStickyColumns?: boolean;
columnResizingMode?: string;
} = {}): any => {
superGetSeparatorOffsetX = jest.fn(() => SUPER_OFFSET);

class Base {
// eslint-disable-next-line class-methods-use-this
public getSeparatorOffsetX(...args: unknown[]): number {
return superGetSeparatorOffsetX(...args) as number;
}
}

const Controller = columnsResizer(Base as any);
const controller = new Controller() as any;

controller._columnHeadersView = {
hasStickyColumns: (): boolean => hasStickyColumns,
getContent: (): undefined => undefined,
getColumnElements: () => columnElements,
};
controller._resizingInfo = { nextColumnIndex: NEXT_COLUMN_INDEX };
controller.option = (): string => columnResizingMode;
controller.addWidgetPrefix = (name: string): string => name;

return controller;
};

afterEach(() => {
jest.restoreAllMocks();
});

it('returns the next column left edge when the next column is pinned to the right in nextColumn mode (T1335911)', () => {
jest.spyOn(GridCoreStickyColumnsDom, 'isFixedCellPinnedToRight')
.mockImplementation((cell) => cell === $nextCell);

const controller = createController({ columnResizingMode: 'nextColumn' });

expect(controller.getSeparatorOffsetX($cell)).toBe(NEXT_CELL_LEFT);
expect(superGetSeparatorOffsetX).not.toHaveBeenCalled();
});

it('returns the cell left edge when the resized column itself is pinned to the right in nextColumn mode (T1335911)', () => {
jest.spyOn(GridCoreStickyColumnsDom, 'isFixedCellPinnedToRight')
.mockImplementation((cell) => cell === $cell);

const controller = createController({ columnResizingMode: 'nextColumn' });

expect(controller.getSeparatorOffsetX($cell)).toBe(CELL_LEFT);
expect(superGetSeparatorOffsetX).not.toHaveBeenCalled();
});

it('returns the cell left edge when the resized column itself is pinned to the right in widget mode (T1335911)', () => {
jest.spyOn(GridCoreStickyColumnsDom, 'isFixedCellPinnedToRight')
.mockImplementation((cell) => cell === $cell);

const controller = createController({ columnResizingMode: 'widget' });

expect(controller.getSeparatorOffsetX($cell)).toBe(CELL_LEFT);
expect(superGetSeparatorOffsetX).not.toHaveBeenCalled();
});

it('falls back to the base offset when only the next column is pinned to the right in widget mode (T1335911)', () => {
jest.spyOn(GridCoreStickyColumnsDom, 'isFixedCellPinnedToRight')
.mockImplementation((cell) => cell === $nextCell);

const controller = createController({ columnResizingMode: 'widget' });

expect(controller.getSeparatorOffsetX($cell)).toBe(SUPER_OFFSET);
expect(superGetSeparatorOffsetX).toHaveBeenCalledWith($cell);
});

it('falls back to the base offset when neither the cell nor its next column is pinned to the right (T1335911)', () => {
jest.spyOn(GridCoreStickyColumnsDom, 'isFixedCellPinnedToRight').mockReturnValue(false);

const controller = createController({ columnResizingMode: 'nextColumn' });

expect(controller.getSeparatorOffsetX($cell)).toBe(SUPER_OFFSET);
expect(superGetSeparatorOffsetX).toHaveBeenCalledWith($cell);
});

it('falls back to the base offset when there are no sticky columns (T1335911)', () => {
const spy = jest.spyOn(GridCoreStickyColumnsDom, 'isFixedCellPinnedToRight');

const controller = createController({ hasStickyColumns: false });

expect(controller.getSeparatorOffsetX($cell)).toBe(SUPER_OFFSET);
expect(spy).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -537,15 +537,23 @@ const columnsResizer = (Base: ModuleType<ColumnsResizerViewController>) => class

if (hasStickyColumns) {
const $container = $(this._columnHeadersView.getContent());
const addWidgetPrefix = this.addWidgetPrefix.bind(this);
const isFixedCellPinnedToRight = GridCoreStickyColumnsDom.isFixedCellPinnedToRight(
$cell,
$container,
this.addWidgetPrefix.bind(this),
addWidgetPrefix,
);
if (isFixedCellPinnedToRight) {
return $cell.offset()?.left ?? 0;
}

const isWidgetResizingMode = this.option('columnResizingMode') === 'widget';
const nextColumnIndex = this._resizingInfo?.nextColumnIndex;
const $nextCell = this._columnHeadersView.getColumnElements()?.eq(nextColumnIndex);

if (isWidgetResizingMode && isFixedCellPinnedToRight) {
return $cell.offset()?.left ?? 0;
if (!isWidgetResizingMode && $nextCell?.length
&& GridCoreStickyColumnsDom.isFixedCellPinnedToRight($nextCell, $container, addWidgetPrefix)) {
return $nextCell.offset()?.left ?? 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RTL mode is not taken into account. Also, just in case, please check the resizing behavior with the following functionality:

  • columnResizingMode: 'widget'
  • Band columns
  • Adaptability

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked RTL, widget mode, band columns and adaptivity in the browser - the separator tracks the column edge in each, so RTL needs no special handling here

}
}

Expand Down
Loading