From c4d5643ea7557e495c6907f9c18dc0bdeda610b9 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 5 Feb 2016 14:06:40 -0800 Subject: [PATCH] [CSV Export] Test with headers specified --- platform/exporters/ExportServiceSpec.js | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/platform/exporters/ExportServiceSpec.js b/platform/exporters/ExportServiceSpec.js index 5e1c7e33bb..41a66bbffe 100644 --- a/platform/exporters/ExportServiceSpec.js +++ b/platform/exporters/ExportServiceSpec.js @@ -84,6 +84,41 @@ define( }); }); + describe("#exportCSV(rows, options.headers)", function () { + var testHeaders; + + beforeEach(function () { + testHeaders = [ 'a', 'b' ]; + exportService + .exportCSV(testRows, { headers: testHeaders }); + waitsFor(finishedReadingCSV); + }); + + it("triggers saving of a file", function () { + expect(mockSaveAs).toHaveBeenCalledWith( + jasmine.any(Blob), + jasmine.any(String) + ); + }); + + it("includes only the specified headers", function () { + expect(csvContents[0]) + .toEqual(testHeaders); + expect(csvContents[0]) + .not.toEqual(Object.keys(testRows[0]).sort()); + }); + + it("includes a subset data from the data set", function () { + var headers = testHeaders, + expectedData = testRows.map(function (row) { + return headers.map(function (key) { + return String(row[key]); + }); + }); + expect(csvContents.slice(1)).toEqual(expectedData); + }); + }); + }); }