Skip to content

Commit

Permalink
xlsx tests refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
programmer4web authored and megheaiulian committed Aug 14, 2018
1 parent a90b133 commit 7b49a79
Showing 1 changed file with 34 additions and 66 deletions.
100 changes: 34 additions & 66 deletions test/xlsx-export.html
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@
});
});

test('prepares number values', function (done) {
const numbers = xlsx.map(row => row[0]),
values = ['numbers', 432, 7001, 2405, 108, 857, 73, 5774, 0, 59, -340, -22];

for (let i = 1; i <= data.length; i++) {
assert.equal(numbers[i], values[i]);
}
test('prepares number values', done => {
xlsx
.map(row => row[0])
.slice(1)
.forEach((value, index) => {
assert.equal(value, data[index].number);
});
done();
});

Expand All @@ -268,73 +268,41 @@
});

test('prepares date values', function (done) {
const dates = xlsx.map(row => row[2]);
let day = (new Date(dates[1])).getDate();
assert.equal(new Date(dates[1]).getTime(), new Date(2020, 2, day).getTime());
day = (new Date(dates[2])).getDate();
assert.equal(new Date(dates[2]).getTime(), new Date(2029, 7, day).getTime());
day = (new Date(dates[3])).getDate();
assert.equal(new Date(dates[3]).getTime(), new Date(2018, 4, day).getTime());
day = (new Date(dates[4])).getDate();
assert.equal(new Date(dates[4]).getTime(), new Date(2017, 0, day).getTime());
day = (new Date(dates[5])).getDate();
assert.equal(new Date(dates[5]).getTime(), new Date(2016, 1, day).getTime());
day = (new Date(dates[6])).getDate();
assert.equal(new Date(dates[6]).getTime(), new Date(2013, 9, day).getTime());
day = (new Date(dates[7])).getDate();
assert.equal(new Date(dates[7]).getTime(), new Date(2024, 2, day).getTime());
day = (new Date(dates[8])).getDate();
assert.equal(new Date(dates[8]).getTime(), new Date(2009, 2, day).getTime());
day = (new Date(dates[9])).getDate();
assert.equal(new Date(dates[9]).getTime(), new Date(2012, 9, day).getTime());
day = (new Date(dates[10])).getDate();
assert.equal(new Date(dates[10]).getTime(), new Date(2018, 0, day).getTime());
day = (new Date(dates[11])).getDate();
assert.equal(new Date(dates[11]).getTime(), new Date(2018, 0, day).getTime());
const column = omnitable.columns[2];
xlsx
.map(row => row[2])
.slice(1)
.forEach((value, index) => {
const date = column.toValue(data[index].date);
date.setHours(0, 0, 0);
assert.equal(column.toValue(value).getTime(), date.getTime());
});
done();
});

test('prepares time values', function (done) {
const times = xlsx.map(row => row[3]);

assert.equal(times[1], '1:48:13 PM'); // +2h
assert.equal(times[2], '4:27:13 AM'); // +3h Daylight Saving Time
assert.equal(times[3], '5:31:29 AM'); // +3h
assert.equal(times[4], '9:25:11 AM'); // +2h
assert.equal(times[5], '7:30:51 PM'); // +2h
assert.equal(times[6], '8:07:29 AM'); // +3h
assert.equal(times[7], '1:05:07 PM'); // +2h
assert.equal(times[8], '6:25:52 AM'); // +2h
assert.equal(times[9], '10:22:46 AM'); // +3h
assert.equal(times[10], '3:47:40 PM'); // -8h
assert.equal(times[11], '3:06:29 PM'); // +1h
const column = omnitable.columns[3];
xlsx
.map(row => row[3])
.slice(1)
.forEach((value, index) => {
const time = column.toXlsxValue(data[index]);
assert.equal(value, time);
});
done();

});

test('prepares datetime values', function (done) {
const datetimes = xlsx.map(row => row[4]);
let day = (new Date(datetimes[1])).getDate();
assert.equal(new Date(datetimes[1]).getTime(), new Date(Date.UTC(2020, 2, day, 11, 48, 13)).getTime());
day = (new Date(datetimes[2])).getDate();
assert.equal(new Date(datetimes[2]).getTime(), new Date(Date.UTC(2029, 7, day, 1, 27, 13)).getTime());
day = (new Date(datetimes[3])).getDate();
assert.equal(new Date(datetimes[3]).getTime(), new Date(Date.UTC(2018, 4, day, 2, 31, 29)).getTime());
day = (new Date(datetimes[4])).getDate();
assert.equal(new Date(datetimes[4]).getTime(), new Date(Date.UTC(2017, 0, day, 7, 25, 11)).getTime());
day = (new Date(datetimes[5])).getDate();
assert.equal(new Date(datetimes[5]).getTime(), new Date(Date.UTC(2016, 1, day, 17, 30, 51)).getTime());
day = (new Date(datetimes[6])).getDate();
assert.equal(new Date(datetimes[6]).getTime(), new Date(Date.UTC(2013, 9, day, 5, 7, 29)).getTime());
day = (new Date(datetimes[7])).getDate();
assert.equal(new Date(datetimes[7]).getTime(), new Date(Date.UTC(2024, 2, day, 11, 5, 7)).getTime());
day = (new Date(datetimes[8])).getDate();
assert.equal(new Date(datetimes[8]).getTime(), new Date(Date.UTC(2009, 2, day, 4, 25, 52)).getTime());
day = (new Date(datetimes[9])).getDate();
assert.equal(new Date(datetimes[9]).getTime(), new Date(Date.UTC(2012, 9, day, 7, 22, 46)).getTime());
day = (new Date(datetimes[10])).getDate();
assert.equal(new Date(datetimes[10]).getTime(), new Date(Date.UTC(2018, 0, day, 13, 47, 40)).getTime());
day = (new Date(datetimes[2])).getDate();
assert.equal(new Date(datetimes[11]).getTime(), new Date(Date.UTC(2018, 0, day, 13, 6, 29)).getTime());
const column = omnitable.columns[4];
xlsx
.map(row => row[4])
.slice(1)
.forEach((value, index) => {
const time = column.toXlsxValue(data[index]);
assert.equal(value, time);
assert.equal(column.toValue(value).getTime(), column.toValue(data[index].datetime).getTime());
});
done();
});

Expand Down

0 comments on commit 7b49a79

Please sign in to comment.