From 6440d81c6d2ca2604aff5e0f8904a6e66093b8a9 Mon Sep 17 00:00:00 2001 From: c0bra Date: Wed, 8 Oct 2014 11:39:52 -0500 Subject: [PATCH] fix(Tests): Date() usage failing on Safari 5 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. --- src/features/exporter/test/exporter.spec.js | 21 +++++++++++++++------ test/unit/core/row-sorting.spec.js | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/features/exporter/test/exporter.spec.js b/src/features/exporter/test/exporter.spec.js index 378a7c279b..8a1e1b9550 100644 --- a/src/features/exporter/test/exporter.spec.js +++ b/src/features/exporter/test/exporter.spec.js @@ -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' ); }); }); @@ -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); @@ -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' ] ] } }], @@ -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); @@ -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' ] ] } } ], diff --git a/test/unit/core/row-sorting.spec.js b/test/unit/core/row-sorting.spec.js index fd0f09e742..ce97e7a7c8 100644 --- a/test/unit/core/row-sorting.spec.js +++ b/test/unit/core/row-sorting.spec.js @@ -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 ] };