[CSV Export] Test with headers specified

This commit is contained in:
Victor Woeltjen 2016-02-05 14:06:40 -08:00
parent 300d71ddc2
commit c4d5643ea7

View File

@ -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);
});
});
});
}