Skip to content

Commit

Permalink
update export data tast tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jvigliotta committed Jun 27, 2024
1 parent 78b8844 commit 8bed57a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 82 deletions.
6 changes: 3 additions & 3 deletions src/exportDataAction/ExportDataActionSpec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*global define,describe,beforeEach,jasmine,spyOn,Promise,it,expect,waitsFor,runs,afterEach*/

define([
'../src/ExportDataAction'
], function (ExportDataAction) {
'use strict';
'./ExportDataAction'
], function (ExportDataActionModule) {
const ExportDataAction = ExportDataActionModule.default;

xdescribe("The Export Data action", function () {
var mockExportService,
Expand Down
130 changes: 52 additions & 78 deletions src/exportDataAction/ExportDataTaskSpec.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,30 @@
/*global define,describe,beforeEach,jasmine,spyOn,Promise,it,expect,waitsFor,runs,afterEach*/

define([
'../src/ExportDataTask'
], function (ExportDataTask) {
'use strict';

xdescribe("ExportDataTask", function () {
var testIds,
testTelemetryData,
mockExportService,
mockTelemetryObjects,
mockTelemetryCapabilities,
pendingPromises,
task;
'./ExportDataTask'
], function (ExportDataTaskModule) {
const ExportDataTask = ExportDataTaskModule.default;

describe("ExportDataTask", () => {
let testIds;
let testTelemetryData;
let mockTelemetryObjects;
let mockOpenMct;
let pendingPromises;
let task;

function makeMockTelemetryObject(id) {
var mockTelemetryObject = jasmine.createSpyObj(
'object-' + id,
[ 'getId', 'getModel', 'getCapability' ]
),
mockTelemetryCapability = jasmine.createSpyObj(
'telemetry-' + id,
[ 'requestData' ]
),
mockTelemetrySeries = jasmine.createSpyObj(
'series-' + id,
[ 'getData' ]
),
seriesPromise = Promise.resolve(mockTelemetrySeries);

mockTelemetryObject.getId.and.returnValue(id);
mockTelemetryObject.getModel.and.returnValue({});
mockTelemetryObject.getCapability.and.callFake(function (c) {
return c === 'telemetry' && mockTelemetryCapability;
});

mockTelemetryCapability.requestData.and.returnValue(seriesPromise);
mockTelemetrySeries.getData.and.returnValue(testTelemetryData[id]);

mockTelemetryCapabilities[id] = mockTelemetryCapability;

pendingPromises.push(seriesPromise);
const mockTelemetryObject = {
identifier: {
namespace: 'object',
key: id
}
};

return mockTelemetryObject;
}

beforeEach(function () {
beforeEach(() => {
testIds = [ 'a', 'b', 'c' ];

testTelemetryData = {
Expand All @@ -64,77 +43,72 @@ define([
]
};

mockOpenMct = {};
mockOpenMct.telemetry = jasmine.createSpyObj('telemetryApi', [
'request'
]);
mockOpenMct.telemetry.request.and.callFake(function (telemetryObject) {
return Promise.resolve(testTelemetryData[telemetryObject.identifier.key]);
});

pendingPromises = [];

mockTelemetryCapabilities = {};
spyOn(ExportDataTask.prototype, 'exportCSV').and.callThrough();

mockExportService = jasmine.createSpyObj(
'exportService',
[ 'exportCSV' ]
);
mockTelemetryObjects =
['a', 'b', 'c'].map(makeMockTelemetryObject);
mockTelemetryObjects = ['a', 'b', 'c'].map(makeMockTelemetryObject);

task = new ExportDataTask(mockExportService, mockTelemetryObjects);
task = new ExportDataTask(mockOpenMct, 'TestObject', mockTelemetryObjects);
});

describe("when performed", function () {
let taskPromise;
describe("when invoked", () => {

beforeEach(function () {
taskPromise = task.perform();
beforeEach(async (done) => {
await task.invoke();
done();
});

it("requests comprehensive telemetry for all objects", function () {
it("requests comprehensive telemetry for all objects", () => {
testIds.forEach(function (id) {
expect(mockTelemetryCapabilities[id].requestData)
.toHaveBeenCalledWith({ strategy: 'comprehensive' });
const telemetryObject = mockTelemetryObjects.find(obj => obj.identifier.key === id);
expect(mockOpenMct.telemetry.request)
.toHaveBeenCalledWith(telemetryObject, { strategy: 'comprehensive' });
});
});

describe("and data is received", function () {
beforeEach(function () {
return taskPromise;
});
describe("and data is received", () => {

it("initiates a CSV export", function () {
expect(mockExportService.exportCSV)
.toHaveBeenCalled();
it("initiates a CSV export", () => {
expect(ExportDataTask.prototype.exportCSV).toHaveBeenCalled();
});

it("includes rows for telemetry for all objects", function () {
var rows =
mockExportService.exportCSV.calls.mostRecent().args[0];
it("includes rows for telemetry for all objects", () => {
const rows = ExportDataTask.prototype.exportCSV.calls.mostRecent().args[0];
expect(rows.length).toEqual(testIds.map(function (id) {
return testTelemetryData[id].length;
}).reduce(function (a, b) { return a + b; }));
});

it("includes headers for all data properties", function () {
var options =
mockExportService.exportCSV.calls.mostRecent().args[1],
headers = options.headers;
it("includes headers for all data properties", () => {
const options = ExportDataTask.prototype.exportCSV.calls.mostRecent().args[1];
const headers = options.headers;
expect(headers.sort()).toEqual(['id', 'x', 'y', 'z']);
});

it("contains all telemetry data for all objects", function () {
var rows =
mockExportService.exportCSV.calls.mostRecent().args[0],
options =
mockExportService.exportCSV.calls.mostRecent().args[1],
headers = options.headers;
it("contains all telemetry data for all objects", () => {
const rows = ExportDataTask.prototype.exportCSV.calls.mostRecent().args[0];
const options = ExportDataTask.prototype.exportCSV.calls.mostRecent().args[1];
const headers = options.headers;

function hasValue(id, key, value) {
return rows.filter(function (row) {
return rows.some(function (row) {
return row.id === id && row[key] === value;
}).length > 0;
});
}

testIds.forEach(function (id) {
testTelemetryData[id].forEach(function (datum) {
Object.keys(datum).forEach(function (key) {
expect(hasValue(id, key, datum[key]))
.toBeTruthy();
expect(hasValue(id, key, datum[key])).toBeTruthy();
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/types/TypeCompositionPolicySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ define([
) {
var TypeCompositionPolicy = TypeCompositionPolicyModule.default; // Accessing the default export

fdescribe('TypeCompositionPolicy', () => {
describe('TypeCompositionPolicy', () => {
var policy;
var parent;
var child;
Expand Down

0 comments on commit 8bed57a

Please sign in to comment.