Skip to content

Commit 7ca9df9

Browse files
committed
Refactor ganttDb tests
1 parent f912f85 commit 7ca9df9

File tree

1 file changed

+40
-143
lines changed

1 file changed

+40
-143
lines changed

src/diagrams/gantt/ganttDb.spec.js

Lines changed: 40 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -6,151 +6,48 @@ describe('when using the ganttDb', function () {
66
ganttDb.clear()
77
})
88

9-
it('should handle an fixed dates', function () {
10-
ganttDb.setDateFormat('YYYY-MM-DD')
11-
ganttDb.addSection('testa1')
12-
ganttDb.addTask('test1', 'id1,2013-01-01,2013-01-12')
13-
const tasks = ganttDb.getTasks()
14-
expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1))
15-
expect(tasks[0].endTime).toEqual(new Date(2013, 0, 12))
16-
expect(tasks[0].id).toEqual('id1')
17-
expect(tasks[0].task).toEqual('test1')
18-
})
19-
it('should handle duration (days) instead of fixed date to determine end date', function () {
20-
ganttDb.setDateFormat('YYYY-MM-DD')
21-
ganttDb.addSection('testa1')
22-
ganttDb.addTask('test1', 'id1,2013-01-01,2d')
23-
const tasks = ganttDb.getTasks()
24-
expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1))
25-
expect(tasks[0].endTime).toEqual(new Date(2013, 0, 3))
26-
expect(tasks[0].id).toEqual('id1')
27-
expect(tasks[0].task).toEqual('test1')
28-
})
29-
it('should handle duration (hours) instead of fixed date to determine end date', function () {
30-
ganttDb.setDateFormat('YYYY-MM-DD')
31-
ganttDb.addSection('testa1')
32-
ganttDb.addTask('test1', 'id1,2013-01-01,2h')
33-
const tasks = ganttDb.getTasks()
34-
expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1))
35-
expect(tasks[0].endTime).toEqual(new Date(2013, 0, 1, 2))
36-
expect(tasks[0].id).toEqual('id1')
37-
expect(tasks[0].task).toEqual('test1')
38-
})
39-
it('should handle duration (minutes) instead of fixed date to determine end date', function () {
40-
ganttDb.setDateFormat('YYYY-MM-DD')
41-
ganttDb.addSection('testa1')
42-
ganttDb.addTask('test1', 'id1,2013-01-01,2m')
43-
const tasks = ganttDb.getTasks()
44-
expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1))
45-
expect(tasks[0].endTime).toEqual(new Date(2013, 0, 1, 0, 2))
46-
expect(tasks[0].id).toEqual('id1')
47-
expect(tasks[0].task).toEqual('test1')
48-
})
49-
it('should handle duration (seconds) instead of fixed date to determine end date', function () {
50-
ganttDb.setDateFormat('YYYY-MM-DD')
51-
ganttDb.addSection('testa1')
52-
ganttDb.addTask('test1', 'id1,2013-01-01,2s')
53-
const tasks = ganttDb.getTasks()
54-
expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1))
55-
expect(tasks[0].endTime).toEqual(new Date(2013, 0, 1, 0, 0, 2))
56-
expect(tasks[0].id).toEqual('id1')
57-
expect(tasks[0].task).toEqual('test1')
58-
})
59-
it('should handle duration (weeks) instead of fixed date to determine end date', function () {
60-
ganttDb.setDateFormat('YYYY-MM-DD')
61-
ganttDb.addSection('testa1')
62-
ganttDb.addTask('test1', 'id1,2013-01-01,2w')
63-
const tasks = ganttDb.getTasks()
64-
expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1))
65-
expect(tasks[0].endTime).toEqual(new Date(2013, 0, 15))
66-
expect(tasks[0].id).toEqual('id1')
67-
expect(tasks[0].task).toEqual('test1')
68-
})
69-
70-
it('should handle relative start date based on id', function () {
71-
ganttDb.setDateFormat('YYYY-MM-DD')
72-
ganttDb.addSection('testa1')
73-
ganttDb.addTask('test1', 'id1,2013-01-01,2w')
74-
ganttDb.addTask('test2', 'id2,after id1,1d')
75-
76-
const tasks = ganttDb.getTasks()
77-
78-
expect(tasks[1].startTime).toEqual(new Date(2013, 0, 15))
79-
expect(tasks[1].id).toEqual('id2')
80-
expect(tasks[1].task).toEqual('test2')
81-
})
82-
83-
it('should handle relative start date based on id when id is invalid', function () {
84-
ganttDb.setDateFormat('YYYY-MM-DD')
85-
ganttDb.addSection('testa1')
86-
ganttDb.addTask('test1', 'id1,2013-01-01,2w')
87-
ganttDb.addTask('test2', 'id2,after id3,1d')
88-
const tasks = ganttDb.getTasks()
89-
expect(tasks[1].startTime).toEqual(new Date((new Date()).setHours(0, 0, 0, 0)))
90-
expect(tasks[1].id).toEqual('id2')
91-
expect(tasks[1].task).toEqual('test2')
92-
})
93-
94-
it('should handle fixed dates without id', function () {
95-
ganttDb.setDateFormat('YYYY-MM-DD')
96-
ganttDb.addSection('testa1')
97-
ganttDb.addTask('test1', '2013-01-01,2013-01-12')
98-
const tasks = ganttDb.getTasks()
99-
expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1))
100-
expect(tasks[0].endTime).toEqual(new Date(2013, 0, 12))
101-
expect(tasks[0].id).toEqual('task1')
102-
expect(tasks[0].task).toEqual('test1')
103-
})
104-
105-
it('should handle duration instead of a fixed date to determine end date without id', function () {
106-
ganttDb.setDateFormat('YYYY-MM-DD')
107-
ganttDb.addSection('testa1')
108-
ganttDb.addTask('test1', '2013-01-01,4d')
109-
const tasks = ganttDb.getTasks()
110-
expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1))
111-
expect(tasks[0].endTime).toEqual(new Date(2013, 0, 5))
112-
expect(tasks[0].id).toEqual('task1')
113-
expect(tasks[0].task).toEqual('test1')
114-
})
115-
116-
it('should handle relative start date of a fixed date to determine end date without id', function () {
117-
ganttDb.setDateFormat('YYYY-MM-DD')
118-
ganttDb.addSection('testa1')
119-
ganttDb.addTask('test1', 'id1,2013-01-01,2w')
120-
ganttDb.addTask('test2', 'after id1,1d')
121-
122-
const tasks = ganttDb.getTasks()
123-
124-
expect(tasks[1].startTime).toEqual(new Date(2013, 0, 15))
125-
expect(tasks[1].id).toEqual('task1')
126-
expect(tasks[1].task).toEqual('test2')
127-
})
128-
it('should handle a new task with only an end date as definition', function () {
129-
ganttDb.setDateFormat('YYYY-MM-DD')
130-
ganttDb.addSection('testa1')
131-
ganttDb.addTask('test1', 'id1,2013-01-01,2w')
132-
ganttDb.addTask('test2', '2013-01-26')
133-
134-
const tasks = ganttDb.getTasks()
135-
136-
expect(tasks[1].startTime).toEqual(new Date(2013, 0, 15))
137-
expect(tasks[1].endTime).toEqual(new Date(2013, 0, 26))
138-
expect(tasks[1].id).toEqual('task1')
139-
expect(tasks[1].task).toEqual('test2')
140-
})
141-
it('should handle a new task with only an end date as definition', function () {
142-
ganttDb.setDateFormat('YYYY-MM-DD')
143-
ganttDb.addSection('testa1')
144-
ganttDb.addTask('test1', 'id1,2013-01-01,2w')
145-
ganttDb.addTask('test2', '2d')
9+
it.each`
10+
testName | section | taskName | taskData | expStartDate | expEndDate | expId | expTask
11+
${'should handle fixed dates'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2013-01-12'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 12)} | ${'id1'} | ${'test1'}
12+
${'should handle duration (days) instead of fixed date to determine end date'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2d'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 3)} | ${'id1'} | ${'test1'}
13+
${'should handle duration (hours) instead of fixed date to determine end date'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2h'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 1, 2)} | ${'id1'} | ${'test1'}
14+
${'should handle duration (minutes) instead of fixed date to determine end date'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2m'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 1, 0, 2)} | ${'id1'} | ${'test1'}
15+
${'should handle duration (seconds) instead of fixed date to determine end date'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2s'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 1, 0, 0, 2)} | ${'id1'} | ${'test1'}
16+
${'should handle duration (weeks) instead of fixed date to determine end date'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2w'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 15)} | ${'id1'} | ${'test1'}
17+
${'should handle fixed dates without id'} | ${'testa1'} | ${'test1'} | ${'2013-01-01,2013-01-12'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 12)} | ${'task1'} | ${'test1'}
18+
${'should handle duration instead of a fixed date to determine end date without id'} | ${'testa1'} | ${'test1'} | ${'2013-01-01,4d'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 5)} | ${'task1'} | ${'test1'}
19+
`('$testName', ({ section, taskName, taskData, expStartDate, expEndDate, expId, expTask }) => {
20+
ganttDb.setDateFormat('YYYY-MM-DD')
21+
ganttDb.addSection(section)
22+
ganttDb.addTask(taskName, taskData)
23+
const tasks = ganttDb.getTasks()
24+
expect(tasks[0].startTime).toEqual(expStartDate)
25+
expect(tasks[0].endTime).toEqual(expEndDate)
26+
expect(tasks[0].id).toEqual(expId)
27+
expect(tasks[0].task).toEqual(expTask)
28+
})
14629

147-
const tasks = ganttDb.getTasks()
30+
it.each`
31+
section | taskName1 | taskName2 | taskData1 | taskData2 | expStartDate2 | expEndDate2 | expId2 | expTask2
32+
${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'id2,after id1,1d'} | ${new Date(2013, 0, 15)} | ${undefined} | ${'id2'} | ${'test2'}
33+
${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'id2,after id3,1d'} | ${new Date((new Date()).setHours(0, 0, 0, 0))} | ${undefined} | ${'id2'} | ${'test2'}
34+
${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'after id1,1d'} | ${new Date(2013, 0, 15)} | ${undefined} | ${'task1'} | ${'test2'}
35+
${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'2013-01-26'} | ${new Date(2013, 0, 15)} | ${new Date(2013, 0, 26)} | ${'task1'} | ${'test2'}
36+
${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'2d'} | ${new Date(2013, 0, 15)} | ${new Date(2013, 0, 17)} | ${'task1'} | ${'test2'}
37+
`('$testName', ({ section, taskName1, taskName2, taskData1, taskData2, expStartDate2, expEndDate2, expId2, expTask2 }) => {
38+
ganttDb.setDateFormat('YYYY-MM-DD')
39+
ganttDb.addSection(section)
40+
ganttDb.addTask(taskName1, taskData1)
41+
ganttDb.addTask(taskName2, taskData2)
42+
const tasks = ganttDb.getTasks()
43+
expect(tasks[1].startTime).toEqual(expStartDate2)
44+
if (!expEndDate2 === undefined) {
45+
expect(tasks[1].endTime).toEqual(expEndDate2)
46+
}
47+
expect(tasks[1].id).toEqual(expId2)
48+
expect(tasks[1].task).toEqual(expTask2)
49+
})
14850

149-
expect(tasks[1].startTime).toEqual(new Date(2013, 0, 15))
150-
expect(tasks[1].endTime).toEqual(new Date(2013, 0, 17))
151-
expect(tasks[1].id).toEqual('task1')
152-
expect(tasks[1].task).toEqual('test2')
153-
})
15451
it('should handle relative start date based on id regardless of sections', function () {
15552
ganttDb.setDateFormat('YYYY-MM-DD')
15653
ganttDb.addSection('testa1')

0 commit comments

Comments
 (0)