Skip to content

Commit 4080b45

Browse files
qunit
1 parent 96975e1 commit 4080b45

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

packages/devextreme/testing/tests/DevExpress.ui.widgets.dataGrid/focus.integration.tests.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4980,4 +4980,86 @@ QUnit.module('Column Resizing', baseModuleConfig, () => {
49804980
// assert
49814981
assert.equal(dataGrid.getScrollable().scrollTop(), 10, 'scroll top is not changed');
49824982
});
4983+
4984+
// T1310557
4985+
QUnit.testInActiveWindow('Browser should not scroll back to the grid when a focused cell is updated or rerendered', function(assert) {
4986+
// arrange
4987+
const dataGrid = createDataGrid({
4988+
dataSource: {
4989+
store: new ArrayStore({
4990+
key: 'id',
4991+
data: [{ id: 1, name: 'test1' }],
4992+
}),
4993+
pushAggregationTimeout: 0,
4994+
},
4995+
});
4996+
$('body').css('height', 2000);
4997+
window.scrollTo(0, 0);
4998+
this.clock.tick(10);
4999+
5000+
const keyboardController = dataGrid.getController('keyboardNavigation');
5001+
const $firstCell = $(dataGrid.getCellElement(0, 0));
5002+
const scrollPosition = 300;
5003+
5004+
// assert
5005+
assert.strictEqual(window.pageYOffset, 0, 'document scroll is at the top');
5006+
5007+
// act
5008+
$firstCell.trigger(CLICK_EVENT);
5009+
this.clock.tick(10);
5010+
5011+
keyboardController.keyDownHandler({
5012+
key: 'Tab',
5013+
keyName: 'tab',
5014+
originalEvent: $.Event('keydown', { target: $firstCell.get(0) }),
5015+
});
5016+
this.clock.tick(10);
5017+
5018+
// assert
5019+
assert.ok($(dataGrid.getCellElement(0, 1)).hasClass('dx-focused'), 'second cell is focused');
5020+
5021+
// act
5022+
window.scrollTo(0, scrollPosition);
5023+
5024+
// assert
5025+
assert.strictEqual(window.pageYOffset, scrollPosition, 'document scroll is changed');
5026+
5027+
// act
5028+
dataGrid.getDataSource().store().push([{ type: 'update', key: 1, data: { name: 'updated' } }]);
5029+
this.clock.tick(10);
5030+
5031+
// assert
5032+
assert.strictEqual($(dataGrid.getCellElement(0, 1)).text(), 'updated', 'second cell text is updated');
5033+
assert.strictEqual(window.pageYOffset, scrollPosition, 'document scroll is preserved after push update');
5034+
5035+
// act
5036+
dataGrid.refresh();
5037+
this.clock.tick(10);
5038+
5039+
// assert
5040+
assert.strictEqual(window.pageYOffset, scrollPosition, 'document scroll is preserved after refresh');
5041+
5042+
// act
5043+
dataGrid.repaint();
5044+
this.clock.tick(10);
5045+
5046+
// assert
5047+
assert.strictEqual(window.pageYOffset, scrollPosition, 'document scroll is preserved after repaint');
5048+
5049+
// act
5050+
keyboardController.keyDownHandler({
5051+
key: 'ArrowLeft',
5052+
keyName: 'leftArrow',
5053+
originalEvent: $.Event('keydown', { target: $(dataGrid.getCellElement(0, 1)).get(0) }),
5054+
});
5055+
this.clock.tick(10);
5056+
5057+
// assert
5058+
assert.ok($(dataGrid.getCellElement(0, 0)).hasClass('dx-focused'), 'first cell is focused');
5059+
assert.strictEqual(window.pageYOffset, 0, 'document scroll is changed after keyboard navigation');
5060+
5061+
// cleanup
5062+
$('body').css('height', '');
5063+
window.scrollTo(0, 0);
5064+
});
49835065
});

0 commit comments

Comments
 (0)