small tweaks to test code to get it to work
[aai/sparky-fe.git] / test / utils / DateTimeChartUtil.test.js
1 import {
2   sortDataByField,
3   dateFormatLocalTimeZoneMMDDYYYY,
4   dateFormatLocalTimeZoneYYYYMMDD,
5   getTicks,
6   getTicksData
7 } from 'utils/DateTimeChartUtil.js';
8
9 describe('DateTimeChartUtil Tests', () => {
10   it('sortDataByField', () => {
11     let initialData = [
12       {word: 'plum', number: 2},
13       {word: 'apple', number: 3},
14       {word: 'banana', number: 1}
15     ];
16
17     sortDataByField(initialData, 'number');
18     expect(initialData[0]['number']).toBe(1);
19     expect(initialData[0]['word']).toBe('banana');
20     expect(initialData[1]['number']).toBe(2);
21     expect(initialData[1]['word']).toBe('plum');
22     expect(initialData[2]['number']).toBe(3);
23     expect(initialData[2]['word']).toBe('apple');
24   });
25
26   it('dateFormatLocalTimeZoneMMDDYYYY', () => {
27     const timestamp = Date.parse('Mon, 25 Dec 1995 13:30:00 GMT');
28     let formattedDate = dateFormatLocalTimeZoneMMDDYYYY(timestamp);
29     expect(formattedDate).toBe('12/25/1995');
30   });
31
32   it('dateFormatLocalTimeZoneYYYYMMDD', () => {
33     const timestamp = Date.parse('Mon, 25 Dec 1995 13:30:00 GMT');
34     let formattedDate = dateFormatLocalTimeZoneYYYYMMDD(timestamp);
35     expect(formattedDate).toBe('1995-12-25');
36   });
37
38   it('getTicks', () => {
39     const timestamps = [
40       {timestamp: 1521604800000, date: 'Thu, 21 Mar 2018 04:00:00 GMT'},
41       {timestamp: 1521777600000, date: 'Thu, 23 Mar 2018 04:00:00 GMT'},
42       {timestamp: 1521950400000, date: 'Thu, 25 Mar 2018 04:00:00 GMT'},
43       {timestamp: 1522296000000, date: 'Thu, 29 Mar 2018 04:00:00 GMT'}
44     ];
45     let ticksPerDay = getTicks(timestamps, 'timestamp');
46     // expect 1 tick (timestamp) for each day between March 22 - March 29
47     expect(ticksPerDay.length).toBe(9);
48   });
49
50   it('getTicks - empty data', () => {
51     const timestamps = [];
52     let ticksPerDay = getTicks(timestamps, 'timestamp');
53     expect(ticksPerDay.length).toBe(0);
54   });
55
56   it('getTicksData', () => {
57     const timestamps = [
58       {timestamp: 1521604800000, date: 'Thu, 21 Mar 2018 04:00:00 GMT'},
59       {timestamp: 1521777600000, date: 'Thu, 23 Mar 2018 04:00:00 GMT'},
60       {timestamp: 1521950400000, date: 'Thu, 25 Mar 2018 04:00:00 GMT'},
61       {timestamp: 1522296000000, date: 'Thu, 29 Mar 2018 04:00:00 GMT'}
62     ];
63     let ticksPerDay = getTicks(timestamps, 'timestamp');
64     let mergedData = getTicksData(timestamps, ticksPerDay, 'timestamp');
65     // expect original 4 objects plus 4 additional objects for the missing days
66     // (4 additional objects will only have timestamp attribute, no date attribute)
67     expect(mergedData.length).toBe(9);
68     expect(mergedData[0]['timestamp']).toBe(1521604800000);
69     expect(mergedData[0]['date']).toBe('Thu, 21 Mar 2018 04:00:00 GMT');
70     expect(mergedData[1]['timestamp']).toBe(1521777600000);
71     expect(mergedData[1]['date']).toBe('Thu, 23 Mar 2018 04:00:00 GMT');
72     expect(mergedData[2]['timestamp']).toBe(1521950400000);
73     expect(mergedData[2]['date']).toBe('Thu, 25 Mar 2018 04:00:00 GMT');
74     expect(mergedData[3]['timestamp']).toBe(1522296000000);
75     expect(mergedData[3]['date']).toBe('Thu, 29 Mar 2018 04:00:00 GMT');
76     expect(mergedData[4]['timestamp']).toBeTruthy();
77     expect(mergedData[4]['date']).toBeUndefined();
78     expect(mergedData[5]['timestamp']).toBeTruthy();
79     expect(mergedData[5]['date']).toBeUndefined();
80     expect(mergedData[6]['timestamp']).toBeTruthy();
81     expect(mergedData[6]['date']).toBeUndefined();
82     expect(mergedData[7]['timestamp']).toBeTruthy();
83     expect(mergedData[7]['date']).toBeUndefined();
84   });
85
86   it('getTicksData - empty data', () => {
87     const timestamps = [];
88     let ticksPerDay = getTicks(timestamps, 'timestamp');
89     let mergedData = getTicksData(timestamps, ticksPerDay, 'timestamp');
90     expect(mergedData.length).toBe(0);
91   });
92 })

© 2017 ONAP. Copyright © The Linux Foundation ®. All Rights Reserved.
The Linux Foundation has registered trademarks and uses trademarks.
For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.
Linux is a registered trademark of Linus Torvalds.
Privacy Policy and Terms of Use