Compare commits

...

10 Commits

9 changed files with 342 additions and 309 deletions

View File

@ -19,7 +19,6 @@
* this source code distribution or the Licensing information page available * this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information. * at runtime from the About dialog for additional information.
*****************************************************************************/ *****************************************************************************/
import AutoflowTabularPlugin from './AutoflowTabularPlugin';
import AutoflowTabularConstants from './AutoflowTabularConstants'; import AutoflowTabularConstants from './AutoflowTabularConstants';
import DOMObserver from './dom-observer'; import DOMObserver from './dom-observer';
import { import {
@ -29,50 +28,64 @@ import {
} from 'utils/testing'; } from 'utils/testing';
import Vue from 'vue'; import Vue from 'vue';
// TODO lots of its without expects describe("AutoflowTabularPlugin", () => {
xdescribe("AutoflowTabularPlugin", () => { let testTypeObject;
let testType; let autoflowObject;
let testObject; let otherObject;
let mockmct; let openmct;
let viewProviders;
let autoflowViewProvider;
beforeEach(() => { beforeEach(done => {
testType = "some-type"; testTypeObject = {
testObject = { type: testType }; type: 'some-type'
mockmct = createOpenMct(); };
spyOn(mockmct.composition, 'get'); autoflowObject = {
spyOn(mockmct.objectViews, 'addProvider'); identifier: {
spyOn(mockmct.telemetry, 'getMetadata'); namespace: '',
spyOn(mockmct.telemetry, 'getValueFormatter'); key: 'some-type-key'
spyOn(mockmct.telemetry, 'limitEvaluator'); },
spyOn(mockmct.telemetry, 'request'); type: 'some-type'
spyOn(mockmct.telemetry, 'subscribe'); };
otherObject = {
identifier: {
namespace: '',
key: 'other-type-key'
},
type: 'other-type'
};
const plugin = new AutoflowTabularPlugin({ type: testType }); openmct = createOpenMct();
plugin(mockmct); openmct.install(openmct.plugins.AutoflowView(testTypeObject));
spyOn(openmct.composition, 'get');
spyOn(openmct.telemetry, 'getMetadata');
spyOn(openmct.telemetry, 'getValueFormatter');
spyOn(openmct.telemetry, 'limitEvaluator');
spyOn(openmct.telemetry, 'request');
spyOn(openmct.telemetry, 'subscribe');
openmct.on('start', done);
openmct.startHeadless();
viewProviders = openmct.objectViews.get(autoflowObject, []);
autoflowViewProvider = viewProviders.filter(provider => provider?.key === 'autoflow')?.[0];
}); });
afterEach(() => { afterEach(() => {
return resetApplicationState(mockmct); return resetApplicationState(openmct);
}); });
it("installs a view provider", () => { it("installs a view provider", () => {
expect(mockmct.objectViews.addProvider).toHaveBeenCalled(); expect(autoflowViewProvider).toBeDefined();
});
describe("installs a view provider which", () => {
let provider;
beforeEach(() => {
provider =
mockmct.objectViews.addProvider.calls.mostRecent().args[0];
}); });
it("applies its view to the type from options", () => { it("applies its view to the type from options", () => {
expect(provider.canView(testObject, [])).toBe(true); expect(autoflowViewProvider.canView(autoflowObject, [])).toBeTrue();
}); });
it("does not apply to other types", () => { it("does not apply to other types", () => {
expect(provider.canView({ type: 'foo' }, [])).toBe(false); expect(autoflowViewProvider.canView(otherObject, [])).toBeFalse();
}); });
describe("provides a view which", () => { describe("provides a view which", () => {
@ -110,7 +123,6 @@ xdescribe("AutoflowTabularPlugin", () => {
callBack(); callBack();
}); });
testObject = { type: 'some-type' };
testKeys = ['abc', 'def', 'xyz']; testKeys = ['abc', 'def', 'xyz'];
testChildren = testKeys.map((key) => { testChildren = testKeys.map((key) => {
return { return {
@ -146,15 +158,15 @@ xdescribe("AutoflowTabularPlugin", () => {
return map; return map;
}, {}); }, {});
mockmct.composition.get.and.returnValue(mockComposition); openmct.composition.get.and.returnValue(mockComposition);
mockComposition.load.and.callFake(() => { mockComposition.load.and.callFake(() => {
testChildren.forEach(emitEvent.bind(null, mockComposition, 'add')); testChildren.forEach(emitEvent.bind(null, mockComposition, 'add'));
return Promise.resolve(testChildren); return Promise.resolve(testChildren);
}); });
mockmct.telemetry.getMetadata.and.returnValue(mockMetadata); openmct.telemetry.getMetadata.and.returnValue(mockMetadata);
mockmct.telemetry.getValueFormatter.and.callFake((metadatum) => { openmct.telemetry.getValueFormatter.and.callFake((metadatum) => {
const mockFormatter = jasmine.createSpyObj('formatter', ['format']); const mockFormatter = jasmine.createSpyObj('formatter', ['format']);
mockFormatter.format.and.callFake((datum) => { mockFormatter.format.and.callFake((datum) => {
return datum[metadatum.hint]; return datum[metadatum.hint];
@ -162,14 +174,14 @@ xdescribe("AutoflowTabularPlugin", () => {
return mockFormatter; return mockFormatter;
}); });
mockmct.telemetry.limitEvaluator.and.returnValue(mockEvaluator); openmct.telemetry.limitEvaluator.and.returnValue(mockEvaluator);
mockmct.telemetry.subscribe.and.callFake((obj, callback) => { openmct.telemetry.subscribe.and.callFake((obj, callback) => {
const key = obj.identifier.key; const key = obj.identifier.key;
callbacks[key] = callback; callbacks[key] = callback;
return mockUnsubscribes[key]; return mockUnsubscribes[key];
}); });
mockmct.telemetry.request.and.callFake((obj, request) => { openmct.telemetry.request.and.callFake((obj, request) => {
const key = obj.identifier.key; const key = obj.identifier.key;
return Promise.resolve([testHistories[key]]); return Promise.resolve([testHistories[key]]);
@ -178,7 +190,7 @@ xdescribe("AutoflowTabularPlugin", () => {
return [{ hint: hints[0] }]; return [{ hint: hints[0] }];
}); });
view = provider.view(testObject); view = autoflowViewProvider.view(autoflowObject);
view.show(testContainer); view.show(testContainer);
return Vue.nextTick(); return Vue.nextTick();
@ -199,29 +211,36 @@ xdescribe("AutoflowTabularPlugin", () => {
return rows === testChildren.length; return rows === testChildren.length;
} }
it("shows one row per child object", () => { it("shows one row per child object", async () => {
return domObserver.when(rowsMatch); const success = await domObserver.when(rowsMatch);
expect(success).toBeTrue();
}); });
// it("adds rows on composition change", () => { it("adds rows on composition change", async () => {
// const child = { const child = {
// identifier: { identifier: {
// namespace: "test", namespace: "test",
// key: "123" key: "123"
// }, },
// name: "Object 123" name: "Object 123"
// }; };
// testChildren.push(child); testChildren.push(child);
// emitEvent(mockComposition, 'add', child); emitEvent(mockComposition, 'add', child);
// return domObserver.when(rowsMatch); const success = await domObserver.when(rowsMatch);
// });
it("removes rows on composition change", () => { expect(success).toBeTrue();
});
it("removes rows on composition change", async () => {
const child = testChildren.pop(); const child = testChildren.pop();
emitEvent(mockComposition, 'remove', child.identifier); emitEvent(mockComposition, 'remove', child.identifier);
return domObserver.when(rowsMatch); const success = await domObserver.when(rowsMatch);
expect(success).toBeTrue();
}); });
}); });
@ -235,27 +254,27 @@ xdescribe("AutoflowTabularPlugin", () => {
}); });
}); });
it("provides a button to change column width", () => { it("provides a button to change column width", async () => {
const initialWidth = AutoflowTabularConstants.INITIAL_COLUMN_WIDTH; let buttonClicked;
const nextWidth =
initialWidth + AutoflowTabularConstants.COLUMN_WIDTH_STEP;
expect(testContainer.querySelector('.l-autoflow-col').css('width')) const initialWidth = testContainer.querySelector('.l-autoflow-col').style.width;
.toEqual(initialWidth + 'px');
testContainer.querySelector('.change-column-width').click(); expect(initialWidth.length).toBeGreaterThan(0);
function widthHasChanged() { function widthHasChanged() {
const width = testContainer.querySelector('.l-autoflow-col').css('width'); if (!buttonClicked) {
buttonClicked = true;
return width !== initialWidth + 'px'; testContainer.querySelector('.change-column-width').click();
} }
return domObserver.when(widthHasChanged) const changedWidth = testContainer.querySelector('.l-autoflow-col').style.width;
.then(() => {
expect(testContainer.querySelector('.l-autoflow-col').css('width')) return changedWidth !== initialWidth;
.toEqual(nextWidth + 'px'); }
});
const success = await domObserver.when(widthHasChanged);
expect(success).toBeTrue();
}); });
it("subscribes to all child objects", () => { it("subscribes to all child objects", () => {
@ -266,14 +285,17 @@ xdescribe("AutoflowTabularPlugin", () => {
it("displays historical telemetry", () => { it("displays historical telemetry", () => {
function rowTextDefined() { function rowTextDefined() {
return testContainer.querySelector(".l-autoflow-item").filter(".r").text() !== ""; return testContainer.querySelector(".l-autoflow-item.r").textContent !== "";
} }
return domObserver.when(rowTextDefined).then(() => { return domObserver.when(rowTextDefined).then(() => {
const rows = testContainer.querySelectorAll(".l-autoflow-row");
testKeys.forEach((key, index) => { testKeys.forEach((key, index) => {
const datum = testHistories[key]; const datum = testHistories[key];
const $cell = testContainer.querySelector(".l-autoflow-row").eq(index).find(".r"); const $cell = rows[index].querySelector(".l-autoflow-item.r");
expect($cell.text()).toEqual(String(datum.range));
expect($cell.textContent).toEqual(String(datum.range));
}); });
}); });
}); });
@ -292,16 +314,21 @@ xdescribe("AutoflowTabularPlugin", () => {
}); });
return waitsForChange().then(() => { return waitsForChange().then(() => {
const rows = testContainer.querySelectorAll(".l-autoflow-row");
testData.forEach((datum, index) => { testData.forEach((datum, index) => {
const $cell = testContainer.querySelector(".l-autoflow-row").eq(index).find(".r"); const $cell = rows[index].querySelector(".l-autoflow-item.r");
expect($cell.text()).toEqual(String(datum.range));
expect($cell.textContent).toEqual(String(datum.range));
}); });
}); });
}); });
it("updates classes for limit violations", () => { it("updates classes for limit violations", () => {
const testClass = "some-limit-violation"; const testClass = "some-limit-violation";
mockEvaluator.evaluate.and.returnValue({ cssClass: testClass }); mockEvaluator.evaluate.and.returnValue({ cssClass: testClass });
testKeys.forEach((key) => { testKeys.forEach((key) => {
callbacks[key]({ callbacks[key]({
range: 'foo', range: 'foo',
@ -310,9 +337,12 @@ xdescribe("AutoflowTabularPlugin", () => {
}); });
return waitsForChange().then(() => { return waitsForChange().then(() => {
const rows = testContainer.querySelectorAll(".l-autoflow-row");
testKeys.forEach((datum, index) => { testKeys.forEach((datum, index) => {
const $cell = testContainer.querySelector(".l-autoflow-row").eq(index).find(".r"); const $cell = rows[index].querySelector(".l-autoflow-item.r");
expect($cell.hasClass(testClass)).toBe(true);
expect($cell.classList.contains(testClass)).toBe(true);
}); });
}); });
}); });
@ -325,27 +355,27 @@ xdescribe("AutoflowTabularPlugin", () => {
let promiseChain = Promise.resolve(); let promiseChain = Promise.resolve();
function columnsHaveAutoflowed() { function columnsHaveAutoflowed() {
const itemsHeight = $container.querySelector('.l-autoflow-items').height(); const itemsHeight = $container.querySelector('.l-autoflow-items').style.height;
const availableHeight = itemsHeight - sliderHeight; const availableHeight = itemsHeight - sliderHeight;
const availableRows = Math.max(Math.floor(availableHeight / rowHeight), 1); const availableRows = Math.max(Math.floor(availableHeight / rowHeight), 1);
const columns = Math.ceil(count / availableRows); const columns = Math.ceil(count / availableRows);
return $container.querySelector('.l-autoflow-col').length === columns; return $container.querySelectorAll('.l-autoflow-col').length === columns;
} }
$container.find('.abs').css({ const absElement = $container.querySelector('.abs');
position: 'absolute', absElement.style.position = 'absolute';
left: '0px', absElement.style.left = 0;
right: '0px', absElement.style.right = 0;
top: '0px', absElement.style.top = 0;
bottom: '0px' absElement.style.bottom = 0;
});
$container.css({ position: 'absolute' });
$container.appendTo(document.body); $container.style.position = 'absolute';
document.body.append($container);
function setHeight(height) { function setHeight(height) {
$container.css('height', height + 'px'); $container.style.height = `${height}px`;
return domObserver.when(columnsHaveAutoflowed); return domObserver.when(columnsHaveAutoflowed);
} }
@ -355,7 +385,9 @@ xdescribe("AutoflowTabularPlugin", () => {
promiseChain = promiseChain.then(setHeight.bind(this, height)); promiseChain = promiseChain.then(setHeight.bind(this, height));
} }
return promiseChain.then(() => { return promiseChain.then(success => {
expect(success).toBeTrue();
$container.remove(); $container.remove();
}); });
}); });
@ -368,5 +400,4 @@ xdescribe("AutoflowTabularPlugin", () => {
expect(mockComposition.load.calls.count()).toEqual(1); expect(mockComposition.load.calls.count()).toEqual(1);
}); });
}); });
});
}); });

View File

@ -30,7 +30,7 @@ define([], function () {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
//Test latch function at least once //Test latch function at least once
if (latchFunction()) { if (latchFunction()) {
resolve(); resolve(true);
} else { } else {
//Latch condition not true yet, create observer on DOM and test again on change. //Latch condition not true yet, create observer on DOM and test again on change.
const config = { const config = {
@ -40,7 +40,7 @@ define([], function () {
}; };
const observer = new MutationObserver(function () { const observer = new MutationObserver(function () {
if (latchFunction()) { if (latchFunction()) {
resolve(); resolve(true);
} }
}); });
observer.observe(this.element, config); observer.observe(this.element, config);

View File

@ -493,6 +493,7 @@ describe("The Imagery View Layouts", () => {
}); });
}); });
}); });
//Note this is a WIP test. Coverage was added in e2e suite
xit('should change the image zoom factor when using the zoom buttons', async (done) => { xit('should change the image zoom factor when using the zoom buttons', async (done) => {
await Vue.nextTick(); await Vue.nextTick();
let imageSizeBefore; let imageSizeBefore;
@ -514,6 +515,7 @@ describe("The Imagery View Layouts", () => {
expect(imageSizeAfter.width).toBeLessThan(imageSizeBefore.width); expect(imageSizeAfter.width).toBeLessThan(imageSizeBefore.width);
done(); done();
}); });
//Note this is a WIP test. Coverage was added in e2e suite
xit('should reset the zoom factor on the image when clicking the zoom button', async (done) => { xit('should reset the zoom factor on the image when clicking the zoom button', async (done) => {
await Vue.nextTick(); await Vue.nextTick();
// test clicking the zoom reset button // test clicking the zoom reset button

View File

@ -28,7 +28,7 @@ import EventEmitter from "EventEmitter";
import PlotOptions from "./inspector/PlotOptions.vue"; import PlotOptions from "./inspector/PlotOptions.vue";
import PlotConfigurationModel from "./configuration/PlotConfigurationModel"; import PlotConfigurationModel from "./configuration/PlotConfigurationModel";
describe("the plugin", function () { xdescribe("the plugin", function () {
let element; let element;
let child; let child;
let openmct; let openmct;

View File

@ -26,7 +26,7 @@ define([
SummaryWidgetTelemetryProvider SummaryWidgetTelemetryProvider
) { ) {
xdescribe('SummaryWidgetTelemetryProvider', function () { describe('SummaryWidgetTelemetryProvider', function () {
let telemObjectA; let telemObjectA;
let telemObjectB; let telemObjectB;
let summaryWidgetObject; let summaryWidgetObject;

View File

@ -21,7 +21,7 @@
*****************************************************************************/ *****************************************************************************/
define(['../src/ConditionManager'], function (ConditionManager) { define(['../src/ConditionManager'], function (ConditionManager) {
xdescribe('A Summary Widget Condition Manager', function () { describe('A Summary Widget Condition Manager', function () {
let conditionManager; let conditionManager;
let mockDomainObject; let mockDomainObject;
let mockCompObject1; let mockCompObject1;
@ -360,7 +360,7 @@ define(['../src/ConditionManager'], function (ConditionManager) {
}); });
}); });
it('populates its LAD cache with historial data on load, if available', function (done) { xit('populates its LAD cache with historial data on load, if available', function (done) {
expect(telemetryRequests.length).toBe(2); expect(telemetryRequests.length).toBe(2);
expect(telemetryRequests[0].object).toBe(mockCompObject1); expect(telemetryRequests[0].object).toBe(mockCompObject1);
expect(telemetryRequests[1].object).toBe(mockCompObject2); expect(telemetryRequests[1].object).toBe(mockCompObject2);
@ -379,7 +379,7 @@ define(['../src/ConditionManager'], function (ConditionManager) {
telemetryRequests[1].resolve([mockTelemetryValues.mockCompObject2]); telemetryRequests[1].resolve([mockTelemetryValues.mockCompObject2]);
}); });
it('updates its LAD cache upon receiving telemetry and invokes the appropriate handlers', function () { xit('updates its LAD cache upon receiving telemetry and invokes the appropriate handlers', function () {
mockTelemetryAPI.triggerTelemetryCallback('mockCompObject1'); mockTelemetryAPI.triggerTelemetryCallback('mockCompObject1');
expect(conditionManager.subscriptionCache.mockCompObject1.property1).toEqual('Its a different string'); expect(conditionManager.subscriptionCache.mockCompObject1.property1).toEqual('Its a different string');
mockTelemetryAPI.triggerTelemetryCallback('mockCompObject2'); mockTelemetryAPI.triggerTelemetryCallback('mockCompObject2');

View File

@ -21,7 +21,7 @@
*****************************************************************************/ *****************************************************************************/
define(['../src/Condition'], function (Condition) { define(['../src/Condition'], function (Condition) {
xdescribe('A summary widget condition', function () { describe('A summary widget condition', function () {
let testCondition; let testCondition;
let mockConfig; let mockConfig;
let mockConditionManager; let mockConditionManager;

View File

@ -21,7 +21,7 @@
*****************************************************************************/ *****************************************************************************/
define(['../src/SummaryWidget'], function (SummaryWidget) { define(['../src/SummaryWidget'], function (SummaryWidget) {
xdescribe('The Summary Widget', function () { describe('The Summary Widget', function () {
let summaryWidget; let summaryWidget;
let mockDomainObject; let mockDomainObject;
let mockOldDomainObject; let mockOldDomainObject;
@ -97,7 +97,7 @@ define(['../src/SummaryWidget'], function (SummaryWidget) {
summaryWidget.show(mockContainer); summaryWidget.show(mockContainer);
}); });
it('queries with legacyId', function () { xit('queries with legacyId', function () {
expect(mockObjectService.getObjects).toHaveBeenCalledWith(['testNamespace:testKey']); expect(mockObjectService.getObjects).toHaveBeenCalledWith(['testNamespace:testKey']);
}); });
@ -154,14 +154,14 @@ define(['../src/SummaryWidget'], function (SummaryWidget) {
setTimeout(function () { setTimeout(function () {
summaryWidget.onEdit([]); summaryWidget.onEdit([]);
expect(summaryWidget.editing).toEqual(false); expect(summaryWidget.editing).toEqual(false);
expect(summaryWidget.ruleArea.css('display')).toEqual('none'); expect(summaryWidget.ruleArea.style.display).toEqual('none');
expect(summaryWidget.testDataArea.css('display')).toEqual('none'); expect(summaryWidget.testDataArea.style.display).toEqual('none');
expect(summaryWidget.addRuleButton.css('display')).toEqual('none'); expect(summaryWidget.addRuleButton.style.display).toEqual('none');
summaryWidget.onEdit(['editing']); summaryWidget.onEdit(['editing']);
expect(summaryWidget.editing).toEqual(true); expect(summaryWidget.editing).toEqual(true);
expect(summaryWidget.ruleArea.css('display')).not.toEqual('none'); expect(summaryWidget.ruleArea.style.display).not.toEqual('none');
expect(summaryWidget.testDataArea.css('display')).not.toEqual('none'); expect(summaryWidget.testDataArea.style.display).not.toEqual('none');
expect(summaryWidget.addRuleButton.css('display')).not.toEqual('none'); expect(summaryWidget.addRuleButton.style.display).not.toEqual('none');
}, 100); }, 100);
}); });

View File

@ -83,7 +83,7 @@ describe("the inspector", () => {
}); });
}); });
xit("should allow a saved style to be applied", () => { it("should allow a saved style to be applied", () => {
spyOn(openmct.editor, 'isEditing').and.returnValue(true); spyOn(openmct.editor, 'isEditing').and.returnValue(true);
selection = mockTelemetryTableSelection; selection = mockTelemetryTableSelection;