mirror of
https://github.com/nasa/openmct.git
synced 2025-02-20 17:33:23 +00:00
[Table] Test CSV Export behavior
This commit is contained in:
parent
3eb960cf5a
commit
438511c5f7
@ -47,7 +47,7 @@ define(
|
||||
setDefaults($scope);
|
||||
|
||||
$scope.exportAsCSV = function () {
|
||||
var headers = $scope.headers;
|
||||
var headers = $scope.displayHeaders;
|
||||
exportService.exportCSV($scope.displayRows.map(function (row) {
|
||||
return headers.reduce(function (r, header) {
|
||||
r[header] = row[header].text;
|
||||
|
@ -32,7 +32,8 @@ define(
|
||||
mockScope,
|
||||
watches,
|
||||
mockTimeout,
|
||||
mockElement;
|
||||
mockElement,
|
||||
mockExportService;
|
||||
|
||||
function promise(value) {
|
||||
return {
|
||||
@ -67,11 +68,20 @@ define(
|
||||
offsetHeight: 1000
|
||||
};
|
||||
|
||||
mockExportService = jasmine.createSpyObj('exportService', [
|
||||
'exportCSV'
|
||||
]);
|
||||
|
||||
mockScope.displayHeaders = true;
|
||||
mockTimeout = jasmine.createSpy('$timeout');
|
||||
mockTimeout.andReturn(promise(undefined));
|
||||
|
||||
controller = new MCTTableController(mockScope, mockTimeout, mockElement);
|
||||
controller = new MCTTableController(
|
||||
mockScope,
|
||||
mockTimeout,
|
||||
mockElement,
|
||||
mockExportService
|
||||
);
|
||||
spyOn(controller, 'setVisibleRows').andCallThrough();
|
||||
});
|
||||
|
||||
@ -149,6 +159,22 @@ define(
|
||||
expect(controller.setVisibleRows).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("can be exported as CSV", function () {
|
||||
controller.setRows(testRows);
|
||||
controller.setHeaders(Object.keys(testRows[0]));
|
||||
mockScope.exportAsCSV();
|
||||
expect(mockExportService.exportCSV)
|
||||
.toHaveBeenCalled();
|
||||
mockExportService.exportCSV.mostRecentCall.args[0]
|
||||
.forEach(function (row, i) {
|
||||
Object.keys(row).forEach(function (k) {
|
||||
expect(row[k]).toEqual(
|
||||
mockScope.displayRows[i][k].text
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('sorting', function () {
|
||||
var sortedRows;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user