mirror of
https://github.com/nasa/openmct.git
synced 2025-06-04 16:40:53 +00:00
[Table] Test CSV Export behavior
This commit is contained in:
parent
3eb960cf5a
commit
438511c5f7
@ -47,7 +47,7 @@ define(
|
|||||||
setDefaults($scope);
|
setDefaults($scope);
|
||||||
|
|
||||||
$scope.exportAsCSV = function () {
|
$scope.exportAsCSV = function () {
|
||||||
var headers = $scope.headers;
|
var headers = $scope.displayHeaders;
|
||||||
exportService.exportCSV($scope.displayRows.map(function (row) {
|
exportService.exportCSV($scope.displayRows.map(function (row) {
|
||||||
return headers.reduce(function (r, header) {
|
return headers.reduce(function (r, header) {
|
||||||
r[header] = row[header].text;
|
r[header] = row[header].text;
|
||||||
|
@ -32,7 +32,8 @@ define(
|
|||||||
mockScope,
|
mockScope,
|
||||||
watches,
|
watches,
|
||||||
mockTimeout,
|
mockTimeout,
|
||||||
mockElement;
|
mockElement,
|
||||||
|
mockExportService;
|
||||||
|
|
||||||
function promise(value) {
|
function promise(value) {
|
||||||
return {
|
return {
|
||||||
@ -67,11 +68,20 @@ define(
|
|||||||
offsetHeight: 1000
|
offsetHeight: 1000
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mockExportService = jasmine.createSpyObj('exportService', [
|
||||||
|
'exportCSV'
|
||||||
|
]);
|
||||||
|
|
||||||
mockScope.displayHeaders = true;
|
mockScope.displayHeaders = true;
|
||||||
mockTimeout = jasmine.createSpy('$timeout');
|
mockTimeout = jasmine.createSpy('$timeout');
|
||||||
mockTimeout.andReturn(promise(undefined));
|
mockTimeout.andReturn(promise(undefined));
|
||||||
|
|
||||||
controller = new MCTTableController(mockScope, mockTimeout, mockElement);
|
controller = new MCTTableController(
|
||||||
|
mockScope,
|
||||||
|
mockTimeout,
|
||||||
|
mockElement,
|
||||||
|
mockExportService
|
||||||
|
);
|
||||||
spyOn(controller, 'setVisibleRows').andCallThrough();
|
spyOn(controller, 'setVisibleRows').andCallThrough();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -149,6 +159,22 @@ define(
|
|||||||
expect(controller.setVisibleRows).toHaveBeenCalled();
|
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 () {
|
describe('sorting', function () {
|
||||||
var sortedRows;
|
var sortedRows;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user