Skip to content

Commit

Permalink
Merge a214ca0 into 43338f3
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbell committed Oct 20, 2023
2 parents 43338f3 + a214ca0 commit e4bad32
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 23 deletions.
35 changes: 18 additions & 17 deletions src/plugins/telemetryTable/collections/TableRowCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,40 +153,41 @@ define(['lodash', 'EventEmitter'], function (_, EventEmitter) {
});
}

mergeSortedRows(rows) {
mergeSortedRows(incomingRows) {
const mergedRows = [];
let i = 0;
let j = 0;
let existingRowIndex = 0;
let incomingRowIndex = 0;

while (i < this.rows.length && j < rows.length) {
const existingRow = this.rows[i];
const incomingRow = rows[j];
while (existingRowIndex < this.rows.length && incomingRowIndex < incomingRows.length) {
const existingRow = this.rows[existingRowIndex];
const incomingRow = incomingRows[incomingRowIndex];

const index = this.getInPlaceUpdateIndex(incomingRow);
if (index > -1) {
this.updateRowInPlace(incomingRow, index);
const inPlaceIndex = this.getInPlaceUpdateIndex(incomingRow);
if (inPlaceIndex > -1) {
this.updateRowInPlace(incomingRow, inPlaceIndex);
incomingRowIndex++;
} else {
if (this.firstRowInSortOrder(existingRow, incomingRow) === existingRow) {
mergedRows.push(existingRow);
i++;
existingRowIndex++;
} else {
mergedRows.push(incomingRow);
j++;
incomingRowIndex++;
}
}
}

// tail of existing rows is all that is left to merge
if (i < this.rows.length) {
for (i; i < this.rows.length; i++) {
mergedRows.push(this.rows[i]);
if (existingRowIndex < this.rows.length) {
for (existingRowIndex; existingRowIndex < this.rows.length; existingRowIndex++) {
mergedRows.push(this.rows[existingRowIndex]);
}
}

// tail of incoming rows is all that is left to merge
if (j < rows.length) {
for (j; j < rows.length; j++) {
mergedRows.push(rows[j]);
if (incomingRowIndex < incomingRows.length) {
for (incomingRowIndex; incomingRowIndex < incomingRows.length; incomingRowIndex++) {
mergedRows.push(incomingRows[incomingRowIndex]);
}
}

Expand Down
44 changes: 38 additions & 6 deletions src/plugins/telemetryTable/pluginSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('the plugin', () => {
let tablePlugin;
let element;
let child;
let historicalProvider;
let historicalTelemetryProvider;
let originalRouterPath;
let unlistenConfigMutation;

Expand All @@ -61,12 +61,12 @@ describe('the plugin', () => {
tablePlugin = new TablePlugin();
openmct.install(tablePlugin);

historicalProvider = {
historicalTelemetryProvider = {
request: () => {
return Promise.resolve([]);
}
};
spyOn(openmct.telemetry, 'findRequestProvider').and.returnValue(historicalProvider);
spyOn(openmct.telemetry, 'findRequestProvider').and.returnValue(historicalTelemetryProvider);

element = document.createElement('div');
child = document.createElement('div');
Expand Down Expand Up @@ -137,11 +137,12 @@ describe('the plugin', () => {
let tableView;
let tableInstance;
let mockClock;
let telemetryCallback;

beforeEach(async () => {
openmct.time.timeSystem('utc', {
start: 0,
end: 4
end: 10
});

mockClock = jasmine.createSpyObj('clock', ['on', 'off', 'currentValue']);
Expand All @@ -151,7 +152,7 @@ describe('the plugin', () => {
openmct.time.addClock(mockClock);
openmct.time.clock('mockClock', {
start: 0,
end: 4
end: 10
});

testTelemetryObject = {
Expand Down Expand Up @@ -214,7 +215,21 @@ describe('the plugin', () => {
}
];

historicalProvider.request = () => Promise.resolve(testTelemetry);
historicalTelemetryProvider.request = () => {
return Promise.resolve(testTelemetry);
};

const realtimeTelemetryProvider = {
supportsSubscribe: () => true,
subscribe: (domainObject, passedCallback) => {
telemetryCallback = passedCallback;
return Promise.resolve(() => {});
}
};

spyOn(openmct.telemetry, 'findSubscriptionProvider').and.returnValue(
realtimeTelemetryProvider
);

openmct.router.path = [testTelemetryObject];

Expand Down Expand Up @@ -256,6 +271,23 @@ describe('the plugin', () => {
expect(rows.length).toBe(3);
});

it('Adds a row in place when updating with existing telemetry', async () => {
let rows = element.querySelectorAll('table.c-telemetry-table__body tr');
await nextTick();
expect(rows.length).toBe(3);
// fire some telemetry
const newTelemetry = {
utc: 2,
'some-key': 'some-value 2',
'some-other-key': 'spacecraft'
};
spyOn(tableInstance.tableRows, 'getInPlaceUpdateIndex').and.returnValue(1);
spyOn(tableInstance.tableRows, 'updateRowInPlace').and.callThrough();
telemetryCallback(newTelemetry);

expect(tableInstance.tableRows.updateRowInPlace.calls.count()).toBeGreaterThan(0);
});

it('Renders a column for every item in telemetry metadata', () => {
let headers = element.querySelectorAll('span.c-telemetry-table__headers__label');
expect(headers.length).toBe(4);
Expand Down

0 comments on commit e4bad32

Please sign in to comment.