UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

121 lines (120 loc) 4.25 kB
/** * DevExtreme (esm/__internal/grids/grid_core/focus/m_focus.integration.test.js) * Version: 25.2.3 * Build date: Fri Dec 12 2025 * * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import { afterEach, describe, expect, it, jest } from "@jest/globals"; import $ from "../../../../core/renderer"; import DataGrid from "../../../../ui/data_grid"; const SELECTORS = { gridContainer: "#gridContainer" }; const GRID_CONTAINER_ID = "gridContainer"; const createDataGrid = async function() { let options = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}; return new Promise((resolve => { const $container = $("<div>").attr("id", "gridContainer").appendTo(document.body); const instance = new DataGrid($container.get(0), Object.assign({ loadingTimeout: null }, options)); resolve({ $container: $container, instance: instance }) })) }; describe("GridCore focus", (() => { afterEach((() => { const $container = $(SELECTORS.gridContainer); const dataGrid = $container.dxDataGrid("instance"); dataGrid.dispose(); $container.remove() })); describe.each([ [true, "insert", 2], [true, "remove", 0], [true, "update", 2], [false, "insert", 2], [false, "remove", 0], [false, "update", 2] ])("when repaintChangesOnly=%s and performing %s operation", ((repaintChangesOnly, operation, expectedFocusedRowIndex) => { it("should updates the focused row index correctly", (async () => { const onFocusedRowChanged = jest.fn(); const { instance: instance } = await createDataGrid({ dataSource: { store: { type: "array", data: [{ id: 1, name: "Item 1" }, { id: 2, name: "Item 2" }, { id: 3, name: "Item 3" }], key: "id" }, reshapeOnPush: true, pushAggregationTimeout: 0 }, showBorders: true, focusedRowEnabled: true, focusedRowKey: 2, onFocusedRowChanged: onFocusedRowChanged, repaintChangesOnly: repaintChangesOnly, columns: [{ dataField: "id", width: 80 }, { dataField: "name", caption: "Name", sortOrder: "asc" }] }); const store = instance.getDataSource().store(); onFocusedRowChanged.mockClear(); switch (operation) { case "insert": store.push([{ type: "insert", index: 0, data: { name: "Item 0" } }]); break; case "remove": store.push([{ type: "remove", key: 1 }]); break; case "update": store.push([{ type: "update", key: 3, data: { id: 3, name: "A Item 3" } }]) } expect(onFocusedRowChanged.mock.calls.length).toBe(1); expect(instance.option("focusedRowKey")).toEqual(2); expect(instance.option("focusedRowIndex")).toEqual(expectedFocusedRowIndex) })) })) }));