Skip to content

Commit

Permalink
Add static limit values to LAD tables (#7193)
Browse files Browse the repository at this point in the history
* limits shown

* use more verbose way for uniqueness

* when adding items, check for what columns we need

* make header logic much simpler

* add test coverage

* fix test and lint

* Update e2e/tests/functional/plugins/lad/lad.e2e.spec.js

Co-authored-by: Jesse Mazzella <[email protected]>

* Update e2e/tests/functional/plugins/lad/lad.e2e.spec.js

Co-authored-by: Jesse Mazzella <[email protected]>

* change to getByTitle

* lint and change to getByLabel

---------

Co-authored-by: Jesse Mazzella <[email protected]>
  • Loading branch information
scottbell and ozyx authored Nov 8, 2023
1 parent 09b7873 commit 51eb2a4
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 102 deletions.
116 changes: 105 additions & 11 deletions e2e/tests/functional/plugins/lad/lad.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,24 @@ const {
createDomainObjectWithDefaults,
setStartOffset,
setFixedTimeMode,
setRealTimeMode
setRealTimeMode,
openObjectTreeContextMenu
} = require('../../../../appActions');

test.describe('Testing LAD table configuration', () => {
let ladTable;
let sineWaveObject;
test.beforeEach(async ({ page }) => {
await page.goto('./', { waitUntil: 'domcontentloaded' });

// Create LAD table
const ladTable = await createDomainObjectWithDefaults(page, {
ladTable = await createDomainObjectWithDefaults(page, {
type: 'LAD Table',
name: 'Test LAD Table'
});

// Create Sine Wave Generator
await createDomainObjectWithDefaults(page, {
sineWaveObject = await createDomainObjectWithDefaults(page, {
type: 'Sine Wave Generator',
name: 'Test Sine Wave Generator',
parent: ladTable.uuid
Expand All @@ -50,31 +53,51 @@ test.describe('Testing LAD table configuration', () => {
test('in edit mode, LAD Tables provide ability to hide columns', async ({ page }) => {
// Edit LAD table
await page.locator('[title="Edit"]').click();

// // Expand the 'My Items' folder in the left tree
// await page.locator('.c-tree__item__view-control.c-disclosure-triangle').click();
// // Add the Sine Wave Generator to the LAD table and save changes
// await page.dragAndDrop('role=treeitem[name=/Test Sine Wave Generator/]', '.c-lad-table-wrapper');
// select configuration tab in inspector
await page.getByRole('tab', { name: 'LAD Table Configuration' }).click();

// make sure headers are visible initially
await expect(page.getByRole('cell', { name: 'Timestamp' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'Units' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'Type' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'WATCH' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'WARNING' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'DISTRESS' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'CRITICAL' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'SEVERE' })).toBeVisible();

// hide timestamp column
await page.getByLabel('Timestamp').uncheck();
await expect(page.getByRole('cell', { name: 'Timestamp' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'Units' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'Type' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'WATCH' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'WARNING' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'DISTRESS' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'CRITICAL' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'SEVERE' })).toBeVisible();

// hide units & type column
await page.getByLabel('Units').uncheck();
await page.getByLabel('Type').uncheck();
await expect(page.getByRole('cell', { name: 'Timestamp' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'Units' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'Type' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'WATCH' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'WARNING' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'DISTRESS' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'CRITICAL' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'SEVERE' })).toBeVisible();

// hide WATCH column
await page.getByLabel('WATCH').uncheck();
await expect(page.getByRole('cell', { name: 'Timestamp' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'Units' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'Type' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'WATCH' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'WARNING' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'DISTRESS' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'CRITICAL' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'SEVERE' })).toBeVisible();

// save and reload and verify they columns are still hidden
await page.locator('button[title="Save"]').click();
Expand All @@ -83,6 +106,11 @@ test.describe('Testing LAD table configuration', () => {
await expect(page.getByRole('cell', { name: 'Timestamp' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'Units' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'Type' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'WATCH' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'WARNING' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'DISTRESS' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'CRITICAL' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'SEVERE' })).toBeVisible();

// Edit LAD table
await page.locator('[title="Edit"]').click();
Expand All @@ -93,25 +121,41 @@ test.describe('Testing LAD table configuration', () => {
await expect(page.getByRole('cell', { name: 'Units' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'Type' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'Timestamp' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'WATCH' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'WARNING' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'DISTRESS' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'CRITICAL' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'SEVERE' })).toBeVisible();

// save and reload and make sure only timestamp is still visible
// save and reload and make sure timestamp is still visible
await page.locator('button[title="Save"]').click();
await page.locator('text=Save and Finish Editing').click();
await page.reload();
await expect(page.getByRole('cell', { name: 'Units' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'Type' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'Timestamp' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'WATCH' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'WARNING' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'DISTRESS' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'CRITICAL' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'SEVERE' })).toBeVisible();

// Edit LAD table
await page.locator('[title="Edit"]').click();
await page.getByRole('tab', { name: 'LAD Table Configuration' }).click();

// show units and type columns
// show units, type, and WATCH columns
await page.getByLabel('Units').check();
await page.getByLabel('Type').check();
await page.getByLabel('WATCH').check();
await expect(page.getByRole('cell', { name: 'Timestamp' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'Units' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'Type' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'WATCH' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'WARNING' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'DISTRESS' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'CRITICAL' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'SEVERE' })).toBeVisible();

// save and reload and make sure all columns are still visible
await page.locator('button[title="Save"]').click();
Expand All @@ -120,6 +164,56 @@ test.describe('Testing LAD table configuration', () => {
await expect(page.getByRole('cell', { name: 'Timestamp' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'Units' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'Type' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'WATCH' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'WARNING' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'DISTRESS' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'CRITICAL' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'SEVERE' })).toBeVisible();
});

test('When adding something without Units, do not show Units column', async ({ page }) => {
// Create Sine Wave Generator
await createDomainObjectWithDefaults(page, {
type: 'Event Message Generator',
parent: ladTable.uuid
});

await page.goto(ladTable.url);

// Edit LAD table
await page.getByLabel('Edit').click();
await page.getByRole('tab', { name: 'LAD Table Configuration' }).click();

// make sure Sine Wave headers are visible initially too
await expect(page.getByRole('cell', { name: 'Timestamp' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'Units' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'Type' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'WATCH' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'WARNING' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'DISTRESS' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'CRITICAL' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'SEVERE' })).toBeVisible();

// save and reload and verify they columns are still hidden
await page.getByLabel('Save').click();
await page.getByRole('listitem', { name: 'Save and Finish Editing' }).click();

// Remove Sin Wave Generator
openObjectTreeContextMenu(page, sineWaveObject.url);
await page.getByRole('menuitem', { name: /Remove/ }).click();
await page.getByRole('button', { name: 'OK' }).click();

// Ensure Units & Limit columns are gone
// as Event Generator don't have them
await page.goto(ladTable.url);
await expect(page.getByRole('cell', { name: 'Timestamp' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'Type' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'Units' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'WATCH' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'WARNING' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'DISTRESS' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'CRITICAL' })).toBeHidden();
await expect(page.getByRole('cell', { name: 'SEVERE' })).toBeHidden();
});

test("LAD Tables don't allow selection of rows but does show context click menus", async ({
Expand Down
37 changes: 37 additions & 0 deletions src/plugins/LADTable/components/LadRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
{{ unit }}
</td>
<td v-if="showType" class="js-type-data">{{ typeLabel }}</td>
<td v-for="limit in formattedLimitValues" :key="limit.key" class="js-limit-data">
{{ limit.value }}
</td>
</tr>
</template>

Expand Down Expand Up @@ -77,6 +80,19 @@ export default {
configuration: {
type: Object,
required: true
},
limitDefinition: {
type: Object,
default() {
return {};
}
},
limitColumnNames: {
// for ordering
type: Array,
default() {
return [];
}
}
},
emits: ['row-context-click'],
Expand All @@ -85,6 +101,7 @@ export default {
datum: undefined,
timestamp: undefined,
timestampKey: undefined,
valueKey: null,
composition: [],
unit: ''
};
Expand All @@ -97,6 +114,26 @@ export default {
return this.formats[this.valueKey].format(this.datum);
},
formattedLimitValues() {
if (!this.valueKey) {
return [];
}
return this.limitColumnNames.map((column) => {
if (this.limitDefinition?.[column.key]) {
const highValue = this.limitDefinition[column.key].high[this.valueKey];
const lowValue = this.limitDefinition[column.key].low[this.valueKey];
return {
key: column.key,
value: `${lowValue}${highValue}`
};
} else {
return {
key: column.key,
value: BLANK_VALUE
};
}
});
},
typeLabel() {
if (this.isAggregate) {
return 'Aggregate';
Expand Down
25 changes: 24 additions & 1 deletion src/plugins/LADTable/components/LadTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@
<th>Value</th>
<th v-if="hasUnits">Units</th>
<th v-if="showType">Type</th>
<th v-for="limitColumn in limitColumnNames" :key="limitColumn.key">
{{ limitColumn.label }}
</th>
</tr>
</thead>
<tbody>
<lad-row
v-for="ladRow in items"
:key="ladRow.key"
:domain-object="ladRow.domainObject"
:limit-definition="ladRow.limitDefinition"
:limit-column-names="limitColumnNames"
:path-to-table="objectPath"
:has-units="hasUnits"
:is-stale="staleObjects.includes(ladRow.key)"
Expand Down Expand Up @@ -89,6 +94,23 @@ export default {
return itemsWithUnits.length !== 0 && !this.configuration?.hiddenColumns?.units;
},
limitColumnNames() {
const limitDefinitions = [];
this.items.forEach((item) => {
if (item.limitDefinition) {
const limits = Object.keys(item.limitDefinition);
limits.forEach((limit) => {
const limitAlreadyAdded = limitDefinitions.some((limitDef) => limitDef.key === limit);
const limitHidden = this.configuration?.hiddenColumns?.[limit];
if (!limitAlreadyAdded && !limitHidden) {
limitDefinitions.push({ label: `Limit ${limit}`, key: limit });
}
});
}
});
return limitDefinitions;
},
showTimestamp() {
return !this.configuration?.hiddenColumns?.timestamp;
},
Expand Down Expand Up @@ -149,10 +171,11 @@ export default {
this.composition.off('reorder', this.reorder);
},
methods: {
addItem(domainObject) {
async addItem(domainObject) {
let item = {};
item.domainObject = domainObject;
item.key = this.openmct.objects.makeKeyString(domainObject.identifier);
item.limitDefinition = await this.openmct.telemetry.limitDefinition(domainObject).limits();
this.items.push(item);
this.subscribeToStaleness(domainObject);
Expand Down
Loading

0 comments on commit 51eb2a4

Please sign in to comment.