Skip to content

Commit

Permalink
fix(Tests): Date() usage failing on Safari 5
Browse files Browse the repository at this point in the history
Safari is bailing on things like `new Date('2009-12-12'). According to SO it looks its date parsers doesn't like the hashes. This change uses the standard
argument-based method of date creation.

Additionally, Safari 5 appears to offset the timezone inappropriately.
This change also uses .toISOString() for date string comparisons, rather
than using the explicit typed-out date string.
  • Loading branch information
c0bra committed Oct 8, 2014
1 parent 4bb2d69 commit 6440d81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions src/features/exporter/test/exporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,17 @@ describe('ui.grid.exporter uiGridExporterService', function () {
{name: 'col3', displayName: 'Col3', width: 100, align: 'left'},
{name: 'x', displayName: '12345234', width: 200, align: 'left'}
];

var date = new Date(2014, 11, 12, 0, 0, 0, 0);

var data = [
[ 'a string', 'a string', 'A string', 'a string' ],
[ '', '45', 'A string', false ],
[ new Date('2014-12-12'), 45, 'A string', true ]
[ date, 45, 'A string', true ]
];

expect(uiGridExporterService.formatAsCsv(columnHeaders, data)).toEqual(
'"Col1","Col2","Col3","12345234"\n"a string","a string","A string","a string"\n"","45","A string",FALSE\n"2014-12-12T00:00:00.000Z",45,"A string",TRUE'
'"Col1","Col2","Col3","12345234"\n"a string","a string","A string","a string"\n"","45","A string",FALSE\n"' + date.toISOString() + '",45,"A string",TRUE'
);
});
});
Expand Down Expand Up @@ -233,10 +236,13 @@ describe('ui.grid.exporter uiGridExporterService', function () {
{name: 'col3', displayName: 'Col3', width: 100, align: 'left'},
{name: 'x', displayName: '12345234', width: 200, align: 'left'}
];

var date = new Date(2014, 11, 12, 0, 0, 0, 0);

var data = [
[ 'a string', 'a string', 'A string', 'a string' ],
[ '', '45', 'A string', false ],
[ new Date('2014-12-12'), 45, 'A string', true ]
[ date, 45, 'A string', true ]
];

var result = uiGridExporterService.prepareAsPdf(grid, columnHeaders, data);
Expand All @@ -256,7 +262,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
],
[ 'a string', 'a string', 'A string', 'a string' ],
[ '', '45', 'A string', 'FALSE' ],
[ "2014-12-12T00:00:00.000Z", '45', 'A string', 'TRUE' ]
[ date.toISOString(), '45', 'A string', 'TRUE' ]
]
}
}],
Expand Down Expand Up @@ -295,10 +301,13 @@ describe('ui.grid.exporter uiGridExporterService', function () {
{name: 'col3', displayName: 'Col3', width: 100, align: 'left'},
{name: 'x', displayName: '12345234', width: 200, align: 'left'}
];

var date = new Date(2014, 12, 12, 0, 0, 0, 0);

var data = [
[ 'a string', 'a string', 'A string', 'a string' ],
[ '', '45', 'A string', false ],
[ new Date('2014-12-12'), 45, 'A string', true ]
[ date, 45, 'A string', true ]
];

var result = uiGridExporterService.prepareAsPdf(grid, columnHeaders, data);
Expand All @@ -318,7 +327,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
],
[ 'a string', 'a string', 'A string', 'a string' ],
[ '', '45', 'A string', 'FALSE' ],
[ '2014-12-12T00:00:00.000Z', '45', 'A string', 'TRUE' ]
[ date.toISOString(), '45', 'A string', 'TRUE' ]
]
}
} ],
Expand Down
2 changes: 1 addition & 1 deletion test/unit/core/row-sorting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe('rowSorter', function() {
sortNumber: [ undefined, null, 1, 2 ],
sortNumberStr: [ undefined, null, '3.a5', '5.b7' ],
sortAlpha: [ undefined, null, 'a', 'b' ],
sortDate: [ undefined, null, new Date('2009-12-12'), new Date('2010-11-11') ],
sortDate: [ undefined, null, new Date(2009, 12, 12), new Date(2010, 11, 11) ],
sortBool: [ undefined, null, false, true ]
};

Expand Down

0 comments on commit 6440d81

Please sign in to comment.