Skip to content

Commit 3facc85

Browse files
authored
Gantt: fix tasks selection if they have null start and end dates and taskContentTemplate is specified (T1281618) (DevExpress#29277)
1 parent a65f483 commit 3facc85

File tree

4 files changed

+175
-8
lines changed

4 files changed

+175
-8
lines changed

packages/devextreme/testing/tests/DevExpress.ui.widgets/gantt.tests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import './ganttParts/constraintViolationDialog.tests.js';
3030
import './ganttParts/undo.tests.js';
3131
import './ganttParts/treeListExpanding.tests.js';
3232
import './ganttParts/scrolling.tests.js';
33+
import './ganttParts/selection.tests.js';
3334

3435
QUnit.testStart(() => {
3536
const markup = '<div id="gantt"></div>';
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
import $ from 'jquery';
2+
import 'ui/gantt';
3+
import { Consts } from '../../../helpers/ganttHelpers.js';
4+
const { test } = QUnit;
5+
6+
const moduleConfig = {
7+
beforeEach: function() {
8+
this.createInstance = (settings) => {
9+
this.instance = this.$element.dxGantt(settings).dxGantt('instance');
10+
};
11+
12+
this.$element = $('#gantt');
13+
this.clock = sinon.useFakeTimers();
14+
},
15+
afterEach: function() {
16+
this.clock.restore();
17+
}
18+
};
19+
20+
const getTasks = (isCorrect = true) => {
21+
const tasks = [{
22+
id: 1,
23+
parentId: -1,
24+
title: 'Software Development',
25+
start: new Date('2019-02-21T05:00:00.000Z'),
26+
end: new Date('2019-07-04T12:00:00.000Z'),
27+
progress: 31
28+
},
29+
{
30+
id: 2,
31+
parentId: 1,
32+
title: 'Secure project sponsorship',
33+
start: new Date('2019-02-21T05:00:00.000Z'),
34+
end: new Date('2019-02-26T09:00:00.000Z'),
35+
progress: 60
36+
},
37+
{
38+
id: 3,
39+
parentId: 1,
40+
title: 'Determine project scope',
41+
start: new Date('2019-02-21T05:00:00.000Z'),
42+
end: new Date('2019-02-21T09:00:00.000Z'),
43+
progress: 100
44+
}];
45+
if(isCorrect) {
46+
return tasks;
47+
} else {
48+
return tasks.map((item) => {
49+
return item.id === 2 ? { ...item, start: null, end: null } : item;
50+
});
51+
}
52+
};
53+
54+
QUnit.module('Row selection', moduleConfig, () => {
55+
test('Selection should be correct after change selectedRowKey', function(assert) {
56+
const tasks = getTasks();
57+
let selectedRowKey;
58+
this.createInstance({
59+
rootValue: -1,
60+
tasks: { dataSource: tasks },
61+
columns: [
62+
{ dataField: 'title', caption: 'Subject' },
63+
{ dataField: 'start', caption: 'Start' },
64+
{ dataField: 'end', caption: 'End Date' }
65+
],
66+
onSelectionChanged: function(e) {
67+
selectedRowKey = e.selectedRowKey;
68+
}
69+
});
70+
this.clock.tick(10);
71+
72+
this.instance.option('selectedRowKey', 2);
73+
assert.equal(this.$element.find(Consts.SELECTION_SELECTOR).length, 1);
74+
assert.equal(selectedRowKey, 2);
75+
76+
this.instance.option('selectedRowKey', 3);
77+
assert.equal(this.$element.find(Consts.SELECTION_SELECTOR).length, 1);
78+
assert.equal(selectedRowKey, 3);
79+
});
80+
81+
test('Selection should be correct after change selectedRowKey, items start and end is null', function(assert) {
82+
const tasks = getTasks(false);
83+
let selectedRowKey;
84+
this.createInstance({
85+
rootValue: -1,
86+
tasks: { dataSource: tasks },
87+
columns: [
88+
{ dataField: 'title', caption: 'Subject' },
89+
{ dataField: 'start', caption: 'Start' },
90+
{ dataField: 'end', caption: 'End Date' }
91+
],
92+
onSelectionChanged: function(e) {
93+
selectedRowKey = e.selectedRowKey;
94+
}
95+
});
96+
this.clock.tick(10);
97+
98+
this.instance.option('selectedRowKey', 2);
99+
assert.equal(this.$element.find(Consts.SELECTION_SELECTOR).length, 1);
100+
assert.equal(selectedRowKey, 2);
101+
102+
this.instance.option('selectedRowKey', 3);
103+
assert.equal(this.$element.find(Consts.SELECTION_SELECTOR).length, 1);
104+
assert.equal(selectedRowKey, 3);
105+
});
106+
107+
test('Selection should be correct after change selectedRowKey, with template', function(assert) {
108+
const tasks = getTasks();
109+
let selectedRowKey;
110+
this.createInstance({
111+
rootValue: -1,
112+
tasks: { dataSource: tasks },
113+
columns: [
114+
{ dataField: 'title', caption: 'Subject' },
115+
{ dataField: 'start', caption: 'Start' },
116+
{ dataField: 'end', caption: 'End Date' }
117+
],
118+
taskContentTemplate(item, container) {
119+
container.append(item.taskHTML);
120+
return container;
121+
},
122+
onSelectionChanged: function(e) {
123+
selectedRowKey = e.selectedRowKey;
124+
}
125+
});
126+
this.clock.tick(10);
127+
128+
this.instance.option('selectedRowKey', 2);
129+
assert.equal(this.$element.find(Consts.SELECTION_SELECTOR).length, 1);
130+
assert.equal(selectedRowKey, 2);
131+
132+
this.instance.option('selectedRowKey', 3);
133+
assert.equal(this.$element.find(Consts.SELECTION_SELECTOR).length, 1);
134+
assert.equal(selectedRowKey, 3);
135+
});
136+
137+
test('Selection should be correct after change selectedRowKey, items start and end is null, with template', function(assert) {
138+
const tasks = getTasks(false);
139+
let selectedRowKey;
140+
this.createInstance({
141+
rootValue: -1,
142+
tasks: { dataSource: tasks },
143+
columns: [
144+
{ dataField: 'title', caption: 'Subject' },
145+
{ dataField: 'start', caption: 'Start' },
146+
{ dataField: 'end', caption: 'End Date' }
147+
],
148+
taskContentTemplate(item, container) {
149+
container.append(item.taskHTML);
150+
return container;
151+
},
152+
onSelectionChanged: function(e) {
153+
selectedRowKey = e.selectedRowKey;
154+
}
155+
});
156+
this.clock.tick(10);
157+
158+
this.instance.option('selectedRowKey', 2);
159+
assert.equal(this.$element.find(Consts.SELECTION_SELECTOR).length, 1);
160+
assert.equal(selectedRowKey, 2);
161+
162+
this.instance.option('selectedRowKey', 3);
163+
assert.equal(this.$element.find(Consts.SELECTION_SELECTOR).length, 1);
164+
assert.equal(selectedRowKey, 3);
165+
});
166+
});

pnpm-lock.yaml

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ packages:
66

77
catalog:
88
devexpress-diagram: 2.2.15
9-
devexpress-gantt: 4.1.59
9+
devexpress-gantt: 4.1.60
1010
eslint: 9.18.0
1111
eslint-config-airbnb-typescript: 18.0.0
1212
eslint-plugin-i18n: 2.4.0

0 commit comments

Comments
 (0)