From 8dbfe1b001510504e0085d44c5395c9293f07bde Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Thu, 4 Aug 2022 13:58:06 +0200 Subject: [PATCH 1/3] Use Compas Open Component to select Template and make Compas Versions uses compare from foundation. Signed-off-by: Dennis Labordus --- public/js/plugins.js | 16 +- src/compas-editors/CompasVersions.ts | 50 +- src/compas/CompasCompareDialog.ts | 204 --- src/compas/foundation.ts | 41 + src/menu/CompasCompareIED.ts | 24 + src/translations/de.ts | 24 +- src/translations/en.ts | 52 +- .../__snapshots__/open-scd.test.snap.js | 1535 ----------------- test/unit/compas/CompasCompareDialog.test.ts | 69 - test/unit/compas/foundation.test.ts | 38 + test/unit/menu/CompasCompareIED.test.ts | 43 + .../CompasCompareIED.test.snap.js | 18 + 12 files changed, 262 insertions(+), 1852 deletions(-) delete mode 100644 src/compas/CompasCompareDialog.ts create mode 100644 src/menu/CompasCompareIED.ts delete mode 100644 test/integration/__snapshots__/open-scd.test.snap.js delete mode 100644 test/unit/compas/CompasCompareDialog.test.ts create mode 100644 test/unit/menu/CompasCompareIED.test.ts create mode 100644 test/unit/menu/__snapshots__/CompasCompareIED.test.snap.js diff --git a/public/js/plugins.js b/public/js/plugins.js index 8389dd853..d38a3fac3 100644 --- a/public/js/plugins.js +++ b/public/js/plugins.js @@ -101,7 +101,7 @@ export const officialPlugins = [ default: true, kind: 'menu', requireDoc: false, - position: 'top' + position: 'top', }, { name: 'Import from API', @@ -110,7 +110,7 @@ export const officialPlugins = [ default: false, kind: 'menu', requireDoc: false, - position: 'top' + position: 'top', }, { name: 'Save project', @@ -119,7 +119,7 @@ export const officialPlugins = [ default: true, kind: 'menu', requireDoc: true, - position: 'top' + position: 'top', }, { name: 'Save project as', @@ -213,9 +213,9 @@ export const officialPlugins = [ }, { name: 'Compare IED', - src: '/src/menu/CompareIED.js', + src: '/src/menu/CompasCompareIED.js', icon: 'compare_arrows', - default: false, + default: true, kind: 'menu', requireDoc: true, position: 'middle', @@ -227,7 +227,7 @@ export const officialPlugins = [ default: true, kind: 'menu', requireDoc: true, - position: 'middle' + position: 'middle', }, { name: 'Locamation VMU', @@ -236,7 +236,7 @@ export const officialPlugins = [ default: false, kind: 'menu', requireDoc: true, - position: 'middle' + position: 'middle', }, { name: 'CoMPAS Settings', @@ -245,7 +245,7 @@ export const officialPlugins = [ default: true, kind: 'menu', requireDoc: false, - position: 'bottom' + position: 'bottom', }, { name: 'Help', diff --git a/src/compas-editors/CompasVersions.ts b/src/compas-editors/CompasVersions.ts index c163885aa..82363c937 100644 --- a/src/compas-editors/CompasVersions.ts +++ b/src/compas-editors/CompasVersions.ts @@ -15,13 +15,15 @@ import '@material/mwc-list'; import '@material/mwc-list/mwc-list-item'; import '@material/mwc-list/mwc-check-list-item'; +import { MultiSelectedEvent } from '@material/mwc-list/mwc-list-foundation'; + import { newLogEvent, newOpenDocEvent, newWizardEvent, Wizard, } from '../foundation.js'; -import { MultiSelectedEvent } from '@material/mwc-list/mwc-list-foundation'; +import { renderDiff } from '../foundation/compare.js'; import { CompasSclDataService, @@ -29,14 +31,49 @@ import { } from '../compas-services/CompasSclDataService.js'; import { createLogEvent } from '../compas-services/foundation.js'; import { + compareVersions, getTypeFromDocName, updateDocumentInOpenSCD, } from '../compas/foundation.js'; import { addVersionToCompasWizard } from '../compas/CompasUploadVersion.js'; -import { compareWizard } from '../compas/CompasCompareDialog.js'; import { getElementByName, styles } from './foundation.js'; import { wizards } from '../wizards/wizard-library.js'; +interface CompareOptions { + title: string; +} + +function compareWizard( + plugin: Element, + oldElement: Element, + newElement: Element, + options: CompareOptions +): Wizard { + function renderDialogContent(): TemplateResult { + return html` ${renderDiff(newElement, oldElement) ?? + html`${translate('compas.compare.noDiff')}`}`; + } + + function close() { + return function () { + plugin.dispatchEvent(newWizardEvent()); + return []; + }; + } + + return [ + { + title: options.title, + secondary: { + icon: '', + label: get('close'), + action: close(), + }, + content: [renderDialogContent()], + }, + ]; +} + /** An editor [[`plugin`]] for selecting the `Substation` section. */ export default class CompasVersionsPlugin extends LitElement { @property() @@ -244,15 +281,15 @@ export default class CompasVersionsPlugin extends LitElement { const selectedVersions = this.getSelectedVersions(); if (selectedVersions.length === 1) { const oldVersion = selectedVersions[0]; + const oldScl = await this.getVersion(oldVersion); const newScl = this.doc.documentElement; this.dispatchEvent( newWizardEvent( compareWizard(this, oldScl, newScl, { - title: get('compas.compare.title', { + title: get('compas.compare.titleCurrent', { oldVersion: oldVersion, - newVersion: 'current', }), }) ) @@ -274,8 +311,9 @@ export default class CompasVersionsPlugin extends LitElement { async compareVersions(): Promise { const selectedVersions = this.getSelectedVersions(); if (selectedVersions.length === 2) { - const oldVersion = selectedVersions[0]; - const newVersion = selectedVersions[1]; + const sortedVersions = selectedVersions.slice().sort(compareVersions); + const oldVersion = sortedVersions[0]; + const newVersion = sortedVersions[1]; const oldScl = await this.getVersion(oldVersion); const newScl = await this.getVersion(newVersion); diff --git a/src/compas/CompasCompareDialog.ts b/src/compas/CompasCompareDialog.ts deleted file mode 100644 index 5fdaf2664..000000000 --- a/src/compas/CompasCompareDialog.ts +++ /dev/null @@ -1,204 +0,0 @@ -import { html, TemplateResult } from 'lit-element'; -import { repeat } from 'lit-html/directives/repeat'; -import { get, translate } from 'lit-translate'; - -import '@material/mwc-list'; -import '@material/mwc-list/mwc-list-item'; -import '@material/mwc-icon'; - -import { identity, isSame, newWizardEvent, Wizard } from '../foundation.js'; - -interface CompareOptions { - title: string; -} - -export type Diff = - | { oldValue: T; newValue: null } - | { oldValue: null; newValue: T } - | { oldValue: T; newValue: T }; - -function describe(element: Element): string { - const id = identity(element); - return typeof id === 'string' ? id : get('unidentifiable'); -} - -export function diffSclAttributes( - oldElement: Element, - newElement: Element -): [string, Diff][] { - const attrDiffs: [string, Diff][] = []; - - // First check if there is any text inside the element and there should be no child elements. - const oldText = oldElement.textContent ?? ''; - const newText = newElement.textContent ?? ''; - if ( - oldElement.childElementCount === 0 && - newElement.childElementCount === 0 && - newText !== oldText - ) { - attrDiffs.push(['value', { oldValue: oldText, newValue: newText }]); - } - - // Next check if there are any difference between attributes. - const attributeNames = new Set( - newElement.getAttributeNames().concat(oldElement.getAttributeNames()) - ); - for (const name of attributeNames) { - if (newElement.getAttribute(name) !== oldElement.getAttribute(name)) { - attrDiffs.push([ - name, - >{ - newValue: newElement.getAttribute(name), - oldValue: oldElement.getAttribute(name), - }, - ]); - } - } - return attrDiffs; -} - -export function diffSclChilds( - oldElement: Element, - newElement: Element -): Diff[] { - const childDiffs: Diff[] = []; - const oldChildren = Array.from(oldElement.children); - const newChildren = Array.from(newElement.children); - - newChildren.forEach(newValue => { - if (!newValue.closest('Private')) { - const twinIndex = oldChildren.findIndex(ourChild => - isSame(newValue, ourChild) - ); - const oldValue = twinIndex > -1 ? oldChildren[twinIndex] : null; - - if (oldValue) { - oldChildren.splice(twinIndex, 1); - childDiffs.push({ newValue, oldValue }); - } else { - childDiffs.push({ newValue: newValue, oldValue: null }); - } - } - }); - oldChildren.forEach(oldValue => { - if (!oldValue.closest('Private')) { - childDiffs.push({ newValue: null, oldValue }); - } - }); - return childDiffs; -} - -export function renderDiff( - oldElement: Element, - newElement: Element -): TemplateResult { - // Determine the ID from the current tag. These can be numbers or strings. - let idTitle = identity(oldElement).toString(); - if (idTitle && idTitle !== '' && idTitle !== 'NaN') { - idTitle = '(' + idTitle + ')'; - } else { - idTitle = ''; - } - - // First get all differences in attributes and text for the current 2 elements. - const attrDiffs: [string, Diff][] = diffSclAttributes( - oldElement, - newElement - ); - // Next check which elements are added, deleted or in both elements. - const childDiffs: Diff[] = diffSclChilds(oldElement, newElement); - - const childAddedOrDeleted: Diff[] = []; - const childToCompare: Diff[] = []; - childDiffs.forEach(diff => { - if (!diff.oldValue || !diff.newValue) { - childAddedOrDeleted.push(diff); - } else { - childToCompare.push(diff); - } - }); - - return html` ${attrDiffs.length || childAddedOrDeleted.length - ? html` - ${attrDiffs.length - ? html` - ${translate('compas.compare.attributes')} ${oldElement.tagName} - ${idTitle} - -
  • ` - : ''} - ${repeat( - attrDiffs, - e => e, - ([name, diff]) => - html` - ${name} - - ${diff.oldValue ?? ''} - ${diff.oldValue && diff.newValue ? html`↶` : ' '} - ${diff.newValue ?? ''} - - - ${diff.oldValue ? (diff.newValue ? 'edit' : 'delete') : 'add'} - - ` - )} - ${childAddedOrDeleted.length - ? html`${translate('compas.compare.children')} ${oldElement.tagName} - ${idTitle} -
  • ` - : ''} - ${repeat( - childAddedOrDeleted, - e => e, - diff => - html` - ${diff.oldValue?.tagName ?? diff.newValue?.tagName} - - ${diff.oldValue - ? describe(diff.oldValue) - : describe(diff.newValue)} - - - ${diff.oldValue ? 'delete' : 'add'} - - ` - )} -
    ` - : ''} - ${repeat( - childToCompare, - e => e, - diff => { - return html`${renderDiff(diff.oldValue!, diff.newValue!)}`; - } - )}`; -} - -export function compareWizard( - plugin: Element, - oldElement: Element, - newElement: Element, - options: CompareOptions -): Wizard { - function close() { - return function () { - plugin.dispatchEvent(newWizardEvent()); - return []; - }; - } - - return [ - { - title: options.title, - secondary: { - icon: '', - label: get('close'), - action: close(), - }, - content: [html`${renderDiff(oldElement, newElement)}`], - }, - ]; -} diff --git a/src/compas/foundation.ts b/src/compas/foundation.ts index e82a3ef63..7c6243410 100644 --- a/src/compas/foundation.ts +++ b/src/compas/foundation.ts @@ -65,3 +65,44 @@ export function updateDocumentInOpenSCD( newOpenDocEvent(doc, docName, { detail: { docId: id } }) ); } + +export function compareVersions( + leftVersion: string, + rightVersion: string +): number { + // Function to compare parts of the version. + function comparePart(leftPart: string, rightPart: string): number { + // First make convert them to number and check if the strings are numbers. + const leftNumber = parseInt(leftPart); + const rightNumber = parseInt(rightPart); + if (isNaN(leftNumber) || isNaN(rightNumber)) { + return 0; + } + // Now compare the two numbers. + return leftNumber < rightNumber ? -1 : leftNumber > rightNumber ? 1 : 0; + } + + // If the strings are the same, just return 0, because they are the same. + if (leftVersion.localeCompare(rightVersion) == 0) { + return 0; + } + + // Split the version into parts. + const leftParts = leftVersion.split('.'); + const rightParts = rightVersion.split('.'); + + // Version should exist out of 3 parts, major, minor, patch + if (leftParts.length != 3 && rightParts.length != 3) { + return 0; + } + + // Now first compare the major version, if they are the same repeat for minor version and patch version. + let result = comparePart(leftParts[0], rightParts[0]); + if (result === 0) { + result = comparePart(leftParts[1], rightParts[1]); + if (result === 0) { + result = comparePart(leftParts[2], rightParts[2]); + } + } + return result; +} diff --git a/src/menu/CompasCompareIED.ts b/src/menu/CompasCompareIED.ts new file mode 100644 index 000000000..8c986e58e --- /dev/null +++ b/src/menu/CompasCompareIED.ts @@ -0,0 +1,24 @@ +import { html, TemplateResult } from 'lit-element'; + +import '../compas/CompasOpen.js'; + +import { DocRetrievedEvent } from '../compas/CompasOpen.js'; + +import CompareIEDPlugin from './CompareIED.js'; + +export default class CompasCompareIEDPlugin extends CompareIEDPlugin { + /** + * Overwriting the render function for opening the template project. + * Now it will also be possible to select the template project from the CoMPAS Data Service. + * + * @override + */ + protected renderSelectTemplateFile(): TemplateResult { + return html` { + this.templateDoc = evt.detail.doc; + }} + > + ${this.renderCloseButton()}`; + } +} diff --git a/src/translations/de.ts b/src/translations/de.ts index bb591513e..4e15359cd 100644 --- a/src/translations/de.ts +++ b/src/translations/de.ts @@ -745,7 +745,7 @@ export const de: Translations = { nodataset: 'Kein verbundener Datensatz', }, userinfo: { - loggedInAs: '???' + loggedInAs: '???', }, add: 'Hinzufügen', new: 'Neu', @@ -773,7 +773,7 @@ export const de: Translations = { notExists: '???', noSclTypes: '???', noScls: '???', - noSclVersions: "???", + noSclVersions: '???', comment: '???', error: { type: '???', @@ -786,7 +786,7 @@ export const de: Translations = { patch: '???', }, import: { - title: '???' + title: '???', }, open: { title: '???', @@ -830,8 +830,8 @@ export const de: Translations = { title: '???', sclInfo: '???: {{name}}, ???: {{version}}', addVersionButton: '???', - confirmRestoreTitle: "???", - confirmRestore: "??? {{version}}?", + confirmRestoreTitle: '???', + confirmRestore: '??? {{version}}?', restoreVersionSuccess: '??? {{version}}', deleteProjectButton: '???', confirmDeleteTitle: '???', @@ -840,13 +840,13 @@ export const de: Translations = { confirmDeleteVersionTitle: '???', confirmDeleteVersion: '??? {{version}}?', deleteVersionSuccess: '??? {{version}}', - confirmButton: "???", - compareButton: "???", - selectTwoVersionsTitle: "???", - selectTwoVersionsMessage: "???", + confirmButton: '???', + compareButton: '???', + selectTwoVersionsTitle: '???', + selectTwoVersionsMessage: '???', compareCurrentButton: '???', - selectOneVersionsTitle: "???", - selectOneVersionsMessage: "???", + selectOneVersionsTitle: '???', + selectOneVersionsMessage: '???', }, scl: { wizardTitle: '???', @@ -854,6 +854,8 @@ export const de: Translations = { }, compare: { title: '???', + titleCurrent: '???', + noDiff: '???', attributes: 'Attribute', children: 'Kindelemente', }, diff --git a/src/translations/en.ts b/src/translations/en.ts index a960ce733..c6a0eb200 100644 --- a/src/translations/en.ts +++ b/src/translations/en.ts @@ -739,7 +739,7 @@ export const en = { nodataset: 'No DataSet referenced', }, userinfo: { - loggedInAs: 'Logged in as {{name}}' + loggedInAs: 'Logged in as {{name}}', }, add: 'Add', new: 'New', @@ -780,7 +780,7 @@ export const en = { patch: 'Patch change', }, import: { - title: 'Import from API' + title: 'Import from API', }, open: { title: 'Open project', @@ -803,7 +803,7 @@ export const en = { title: 'Update substation', }, importIEDS: { - title: 'Import IED\'s', + title: "Import IED's", }, merge: { title: 'Merge project', @@ -833,21 +833,26 @@ export const en = { deleteSuccess: 'Removed project from CoMPAS', confirmDeleteVersionTitle: 'Delete version?', confirmDeleteVersion: 'Are you sure to delete version {{version}}?', - deleteVersionSuccess: 'Removed version {{version}} of project from CoMPAS', + deleteVersionSuccess: + 'Removed version {{version}} of project from CoMPAS', confirmButton: 'Confirm', compareButton: 'Compare versions', selectTwoVersionsTitle: 'Select two versions?', - selectTwoVersionsMessage: 'Select maximum two versions to compare with each other. Currently selected: {{size}}.', + selectTwoVersionsMessage: + 'Select maximum two versions to compare with each other. Currently selected: {{size}}.', compareCurrentButton: 'Compare version (current)', selectOneVersionsTitle: 'Select one version?', - selectOneVersionsMessage: 'Select maximum one version to compare the current project against. Currently selected: {{size}}.', + selectOneVersionsMessage: + 'Select maximum one version to compare the current project against. Currently selected: {{size}}.', }, scl: { wizardTitle: 'Edit SCL', filenameHelper: 'Filename used by CoMPAS when saving to a filesystem', }, compare: { - title: 'Compare version {{oldVersion}} with version {{newVersion}}', + title: 'Compare version {{newVersion}} against version {{oldVersion}}', + titleCurrent: 'Compare current project against version {{oldVersion}}', + noDiff: 'No difference between versions', attributes: 'Attributes from', children: 'Child elements from', }, @@ -861,15 +866,18 @@ export const en = { }, session: { headingExpiring: 'Your session is about to expire!', - explainExpiring: 'Because of inactivity ({{expiringSessionWarning}} minutes), your session with the CoMPAS Systems is about to expire.
    ' + - 'If you want to continue working press the button \'Continue\'. Otherwise the session will expire in {{timeTillExpire}} minutes.', + explainExpiring: + 'Because of inactivity ({{expiringSessionWarning}} minutes), your session with the CoMPAS Systems is about to expire.
    ' + + "If you want to continue working press the button 'Continue'. Otherwise the session will expire in {{timeTillExpire}} minutes.", continue: 'Continue', headingExpired: 'Your session is expired!', - explainExpiredWithProject: 'Because of inactivity ({{expiredSessionMessage}} minutes), your session with the CoMPAS Systems is expired.
    ' + + explainExpiredWithProject: + 'Because of inactivity ({{expiredSessionMessage}} minutes), your session with the CoMPAS Systems is expired.
    ' + 'To continue working you need to reload the browser to login again, but modifications to the project are lost.
    ' + - 'To prevent this you can first save the project to your local filesystem using the button \'Save project\'.
    ' + - 'After loading the original project from CoMPAS you can add this file as new version using the tab \'CoMPAS Versions\'.', - explainExpiredWithoutProject: 'Because of inactivity ({{expiredSessionMessage}} minutes), your session with the CoMPAS Systems is expired.
    ' + + "To prevent this you can first save the project to your local filesystem using the button 'Save project'.
    " + + "After loading the original project from CoMPAS you can add this file as new version using the tab 'CoMPAS Versions'.", + explainExpiredWithoutProject: + 'Because of inactivity ({{expiredSessionMessage}} minutes), your session with the CoMPAS Systems is expired.
    ' + 'To continue working you need to reload the browser to login again.', saveProject: 'Save project', }, @@ -891,16 +899,22 @@ export const en = { }, version: 'Locamation VMU Version', identifier: 'Identifier', - identifierHelper: 'The address of the sensor. The address is constructed of 3 numbers, separated by dots. The range of each number is 0-255.', + identifierHelper: + 'The address of the sensor. The address is constructed of 3 numbers, separated by dots. The range of each number is 0-255.', sum: 'Sum', - sumHelper: 'The collection of three channel numbers for which the sum of currents or voltages will be calculated. The numbers are separated by commas. Values for the current sensor range from 0 - 5, for the voltage sensor 0-2.', + sumHelper: + 'The collection of three channel numbers for which the sum of currents or voltages will be calculated. The numbers are separated by commas. Values for the current sensor range from 0 - 5, for the voltage sensor 0-2.', channel: 'Channel', - channelHelper: 'The channel number on the sensor. Values for the current sensor range from 0 - 5, for the voltage sensor 0-2.', + channelHelper: + 'The channel number on the sensor. Values for the current sensor range from 0 - 5, for the voltage sensor 0-2.', transformPrimary: 'TransformPrimary', - transformPrimaryHelper: 'The nominator of the ratio of the measement transformer.', + transformPrimaryHelper: + 'The nominator of the ratio of the measement transformer.', transformSecondary: 'TransformSecondary', - transformSecondaryHelper: 'The denominator of the ratio of the measement transformer.', - updateAction: 'Locamation private fields updated for Logica Node {{lnName}}', + transformSecondaryHelper: + 'The denominator of the ratio of the measement transformer.', + updateAction: + 'Locamation private fields updated for Logica Node {{lnName}}', }, }, }; diff --git a/test/integration/__snapshots__/open-scd.test.snap.js b/test/integration/__snapshots__/open-scd.test.snap.js deleted file mode 100644 index 8dff6fff4..000000000 --- a/test/integration/__snapshots__/open-scd.test.snap.js +++ /dev/null @@ -1,1535 +0,0 @@ -/* @web/test-runner snapshot v1 */ -export const snapshots = {}; - -snapshots["open-scd looks like its snapshot"] = -` - - Menu - - -
  • -
  • - - - folder_open - - - Open project - - - - - - - create_new_folder - - - New project - - - - - - - input - - - Project from CIM - - - - - - - save - - - Save project - - - - - - - save - - - Save project as - - - - -
  • -
  • - - - undo - - - Undo - - - - - redo - - - Redo - - - - - rule_folder - - - Validate using OCL - - - - - - - rule_folder - - - Validate Schema - - - - - - - rule_folder - - - Validate Templates - - - - - - - history - - - View log - - - - - rule - - - View diagnostics - - -
  • -
  • - - - snippet_folder - - - Import IEDs - - - - - - - play_circle - - - Subscriber Update - - - - - - - merge_type - - - Merge Project - - - - - - - merge_type - - - Update Substation - - - - - - - dashboard - - - Auto Align SLD - - - - -
  • -
  • - - - settings - - - Settings - - - - - settings - - - CoMPAS Settings - - - - - - - help - - - Help - - - - -
  • -
  • - - - extension - - - Extensions - - -
    - - - -
    -
    - - - - - - - - -
    -
    -
    - -
    - Open project -
    -
    - -
    - New project -
    -
    - -
    - Project from CIM -
    -
    -
    - - - - - - - - - - - - - - - Edits, errors, and other notifications will show up here. - - - info - - - - - - - - - Close - - - - - - - Issues found during validation will show up here - - - info - - - - - Close - - - - - - - - - Show - - - - - - - Show - - - - - - - Show - - - - - - - - - Editor tab - - - tab - - -
  • -
  • - - - margin - - Substation - - - - developer_board - - IED - - - - edit - - Single Line Diagram - - - - link - - Subscriber (GOOSE) - - - - link - - Subscriber (SMV) - - - - settings_ethernet - - Communication - - - - settings_ethernet - - 104 - - - - copy_all - - Templates - - - - copy_all - - CoMPAS Versions - - - - publish - - Publisher - - - - cleaning_services - - Cleanup - - - - Menu entry - - - - play_circle - - - -
  • -
  • - - - folder_open - - Open project - - - - create_new_folder - - New project - - - - input - - Project from CIM - - - - cloud_download - - Import from API - - - - save - - Save project - - - - save - - Save project as - -
  • -
  • - - - rule_folder - - Validate using OCL - - - - rule_folder - - Validate Schema - - - - rule_folder - - Validate Templates - -
  • -
  • - - - snippet_folder - - Import IEDs - - - - developer_board - - Create Virtual IED - - - - play_circle - - Subscriber Update - - - - play_circle - - Update desc (ABB) - - - - play_circle - - Update desc (SEL) - - - - merge_type - - Merge Project - - - - merge_type - - Update Substation - - - - compare_arrows - - Compare IED - - - - dashboard - - Auto Align SLD - - - - edit_note - - Locamation VMU - -
  • -
  • - - - settings - - CoMPAS Settings - - - - help - - Help - -
    - - - - - - -
    - -
    -

    - Here you may add remote extensions directly from a custom URL. - You do this at your own risk. -

    - - - - - Editor tab - - tab - - - - Menu entry - - play_circle - - - - - Validator - - rule_folder - - - - - -
    - - - - -
    - - - - - -
    - - - English - - - German (Deutsch) - - - - - - - - - - - - - - -
    - - -
    -

    - Uploaded NSDoc files -

    -
    - - - - IEC 61850-7-2 - - - close - - - - - IEC 61850-7-3 - - - close - - - - - IEC 61850-7-4 - - - close - - - - - IEC 61850-8-1 - - - close - - - - - Cancel - - - Reset - - - Save - -
    - - - - -`; -/* end snapshot open-scd looks like its snapshot */ - diff --git a/test/unit/compas/CompasCompareDialog.test.ts b/test/unit/compas/CompasCompareDialog.test.ts deleted file mode 100644 index c3197f62d..000000000 --- a/test/unit/compas/CompasCompareDialog.test.ts +++ /dev/null @@ -1,69 +0,0 @@ -import {expect, fixtureSync, html} from '@open-wc/testing'; - -import {diffSclAttributes, diffSclChilds, renderDiff} from "../../../src/compas/CompasCompareDialog.js"; - -describe('compas-compare-dialog', () => { - let oldSclElement: Element; - let newSclElement: Element; - - beforeEach(async () => { - oldSclElement = await fetch('/test/testfiles/compas/minigrid-3.0.0.cid') - .then(response => response.text()) - .then(str => new DOMParser().parseFromString(str, 'application/xml')) - .then(document => document.documentElement); - newSclElement = await fetch('/test/testfiles/compas/minigrid-3.1.0.cid') - .then(response => response.text()) - .then(str => new DOMParser().parseFromString(str, 'application/xml')) - .then(document => document.documentElement); - }); - - describe('diff SCL childs', () => { - it('get root child diffs', () => { - const diffChilds = diffSclChilds(oldSclElement, newSclElement); - expect(diffChilds).to.have.length(5); - }); - - it('get voltage level child diffs with removed bay', () => { - const oldVoltageLevel = oldSclElement.querySelector('VoltageLevel[name="S4 110kV"]') - const newVoltageLevel = newSclElement.querySelector('VoltageLevel[name="S4 110kV"]') - - const diffChilds = diffSclChilds(oldVoltageLevel!, newVoltageLevel!); - expect(diffChilds).to.have.length(9); - - const removedBay = diffChilds.filter(diff => diff.newValue == null) - expect(removedBay).to.have.length(1); - expect(removedBay[0].oldValue?.tagName).to.be.equal('Bay') - }); - }); - - describe('diff SCL attributes', () => { - it('get root attributes diffs', () => { - const diffAttributes = diffSclAttributes(oldSclElement, newSclElement); - expect(diffAttributes).to.have.length(0); - }); - - it('get header attributes diffs with different version', () => { - const oldHeader = oldSclElement.querySelector('Header') - const newHeader = newSclElement.querySelector('Header') - - const diffAttributes = diffSclAttributes(oldHeader!, newHeader!); - expect(diffAttributes).to.have.length(1); - expect(diffAttributes[0][0]).to.be.equal('version'); - expect(diffAttributes[0][1].oldValue).to.be.equal('3.0.0'); - expect(diffAttributes[0][1].newValue).to.be.equal('3.1.0'); - }); - }); - - describe('rendering full compare dialog', () => { - let element: Element; - - beforeEach(async () => { - element = fixtureSync(html`
    ${renderDiff(oldSclElement, newSclElement)}
    `); - await element; - }); - - it('looks like the latest snapshot', async () => { - await expect(element).to.equalSnapshot(); - }); - }); -}); diff --git a/test/unit/compas/foundation.test.ts b/test/unit/compas/foundation.test.ts index 6328c55a7..b0c5867c4 100644 --- a/test/unit/compas/foundation.test.ts +++ b/test/unit/compas/foundation.test.ts @@ -1,6 +1,7 @@ import { expect } from '@open-wc/testing'; import { + compareVersions, getTypeFromDocName, stripExtensionFromName, } from '../../../src/compas/foundation.js'; @@ -38,4 +39,41 @@ describe('compas-foundation', () => { expect(stripExtensionFromName(name)).to.be.equal(name); }); }); + + describe('compareVersions', () => { + it('when comparing non version strings, nothing is changed', () => { + expect(compareVersions('bbb', 'aaa')).to.be.equal(0); + expect(compareVersions('aaa', 'bbb')).to.be.equal(0); + expect(compareVersions('a.a.a', 'b.b.b')).to.be.equal(0); + }); + + it('when comparing same versions then 0 returned', () => { + expect(compareVersions('1.2.3', '1.2.3')).to.be.equal(0); + expect(compareVersions('10.2.3', '10.2.3')).to.be.equal(0); + }); + + it('when comparing two versions with different major digits then the major versions are leading', () => { + expect(compareVersions('1.3.0', '2.0.0')).to.be.equal(-1); + expect(compareVersions('1.3.0', '10.0.0')).to.be.equal(-1); + + expect(compareVersions('2.0.0', '1.3.0')).to.be.equal(1); + expect(compareVersions('10.0.0', '1.3.0')).to.be.equal(1); + }); + + it('when comparing two versions with different minor digits then the minor versions are leading', () => { + expect(compareVersions('1.3.0', '1.4.0')).to.be.equal(-1); + expect(compareVersions('1.3.0', '1.10.0')).to.be.equal(-1); + + expect(compareVersions('1.4.0', '1.3.0')).to.be.equal(1); + expect(compareVersions('1.10.0', '1.3.0')).to.be.equal(1); + }); + + it('when comparing two versions with different patch digits then the patch versions are leading', () => { + expect(compareVersions('1.1.3', '1.1.4')).to.be.equal(-1); + expect(compareVersions('1.1.3', '1.1.10')).to.be.equal(-1); + + expect(compareVersions('1.1.4', '1.1.3')).to.be.equal(1); + expect(compareVersions('1.1.10', '1.1.3')).to.be.equal(1); + }); + }); }); diff --git a/test/unit/menu/CompasCompareIED.test.ts b/test/unit/menu/CompasCompareIED.test.ts new file mode 100644 index 000000000..505b51e8e --- /dev/null +++ b/test/unit/menu/CompasCompareIED.test.ts @@ -0,0 +1,43 @@ +import { expect, fixture, html } from '@open-wc/testing'; + +import CompasCompareIEDPlugin from '../../../src/menu/CompasCompareIED.js'; + +describe('Compas Compare IED Plugin', () => { + if (customElements.get('compas-compare-ied') === undefined) + customElements.define('compas-compare-ied', CompasCompareIEDPlugin); + + let plugin: CompasCompareIEDPlugin; + let doc: XMLDocument; + + beforeEach(async () => { + plugin = await fixture(html``); + doc = await fetch('/test/testfiles/menu/compare-ied-changed.scd') + .then(response => response.text()) + .then(str => new DOMParser().parseFromString(str, 'application/xml')); + }); + + describe('show template project selection dialog', () => { + beforeEach(async () => { + plugin.doc = doc; + plugin.run(); + await plugin.requestUpdate(); + }); + + it('after closing the dialog everything set to undefined', async () => { + expect(plugin.templateDoc).to.be.undefined; + expect(plugin.selectedProjectIed).to.be.undefined; + expect(plugin.selectedTemplateIed).to.be.undefined; + + plugin['onClosed'](); + await plugin.requestUpdate(); + + expect(plugin.templateDoc).to.be.undefined; + expect(plugin.selectedProjectIed).to.be.undefined; + expect(plugin.selectedTemplateIed).to.be.undefined; + }); + + it('looks like its latest snapshot', async () => { + await expect(plugin.dialog).to.equalSnapshot(); + }); + }); +}); diff --git a/test/unit/menu/__snapshots__/CompasCompareIED.test.snap.js b/test/unit/menu/__snapshots__/CompasCompareIED.test.snap.js new file mode 100644 index 000000000..fa8af920c --- /dev/null +++ b/test/unit/menu/__snapshots__/CompasCompareIED.test.snap.js @@ -0,0 +1,18 @@ +/* @web/test-runner snapshot v1 */ +export const snapshots = {}; + +snapshots["Compas Compare IED Plugin show template project selection dialog looks like its latest snapshot"] = +` + + + + + +`; +/* end snapshot Compas Compare IED Plugin show template project selection dialog looks like its latest snapshot */ + From 131d09d10deb639e6b4ae2ad76a3af2ef7197b09 Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Thu, 4 Aug 2022 13:58:14 +0200 Subject: [PATCH 2/3] Use Compas Open Component to select Template and make Compas Versions uses compare from foundation. Signed-off-by: Dennis Labordus --- .../__snapshots__/open-scd.test.snap.js | 1554 +++++++++++++++++ 1 file changed, 1554 insertions(+) create mode 100644 test/integration/__snapshots__/open-scd.test.snap.js diff --git a/test/integration/__snapshots__/open-scd.test.snap.js b/test/integration/__snapshots__/open-scd.test.snap.js new file mode 100644 index 000000000..080d1344c --- /dev/null +++ b/test/integration/__snapshots__/open-scd.test.snap.js @@ -0,0 +1,1554 @@ +/* @web/test-runner snapshot v1 */ +export const snapshots = {}; + +snapshots["open-scd looks like its snapshot"] = +` + + Menu + + +
  • +
  • + + + folder_open + + + Open project + + + + + + + create_new_folder + + + New project + + + + + + + input + + + Project from CIM + + + + + + + save + + + Save project + + + + + + + save + + + Save project as + + + + +
  • +
  • + + + undo + + + Undo + + + + + redo + + + Redo + + + + + rule_folder + + + Validate using OCL + + + + + + + rule_folder + + + Validate Schema + + + + + + + rule_folder + + + Validate Templates + + + + + + + history + + + View log + + + + + rule + + + View diagnostics + + +
  • +
  • + + + snippet_folder + + + Import IEDs + + + + + + + play_circle + + + Subscriber Update + + + + + + + merge_type + + + Merge Project + + + + + + + merge_type + + + Update Substation + + + + + + + compare_arrows + + + Compare IED + + + + + + + dashboard + + + Auto Align SLD + + + + +
  • +
  • + + + settings + + + Settings + + + + + settings + + + CoMPAS Settings + + + + + + + help + + + Help + + + + +
  • +
  • + + + extension + + + Extensions + + +
    + + + +
    +
    + + + + + + + + +
    +
    +
    + +
    + Open project +
    +
    + +
    + New project +
    +
    + +
    + Project from CIM +
    +
    +
    + + + + + + + + + + + + + + + Edits, errors, and other notifications will show up here. + + + info + + + + + + + + + Close + + + + + + + Issues found during validation will show up here + + + info + + + + + Close + + + + + + + + + Show + + + + + + + Show + + + + + + + Show + + + + + + + + + Editor tab + + + tab + + +
  • +
  • + + + margin + + Substation + + + + developer_board + + IED + + + + edit + + Single Line Diagram + + + + link + + Subscriber (GOOSE) + + + + link + + Subscriber (SMV) + + + + settings_ethernet + + Communication + + + + settings_ethernet + + 104 + + + + copy_all + + Templates + + + + copy_all + + CoMPAS Versions + + + + publish + + Publisher + + + + cleaning_services + + Cleanup + + + + Menu entry + + + + play_circle + + + +
  • +
  • + + + folder_open + + Open project + + + + create_new_folder + + New project + + + + input + + Project from CIM + + + + cloud_download + + Import from API + + + + save + + Save project + + + + save + + Save project as + +
  • +
  • + + + rule_folder + + Validate using OCL + + + + rule_folder + + Validate Schema + + + + rule_folder + + Validate Templates + +
  • +
  • + + + snippet_folder + + Import IEDs + + + + developer_board + + Create Virtual IED + + + + play_circle + + Subscriber Update + + + + play_circle + + Update desc (ABB) + + + + play_circle + + Update desc (SEL) + + + + merge_type + + Merge Project + + + + merge_type + + Update Substation + + + + compare_arrows + + Compare IED + + + + dashboard + + Auto Align SLD + + + + edit_note + + Locamation VMU + +
  • +
  • + + + settings + + CoMPAS Settings + + + + help + + Help + +
    + + + + + + +
    + +
    +

    + Here you may add remote extensions directly from a custom URL. + You do this at your own risk. +

    + + + + + Editor tab + + tab + + + + Menu entry + + play_circle + + + + + Validator + + rule_folder + + + + + +
    + + + + +
    + + + + + +
    + + + English + + + German (Deutsch) + + + + + + + + + + + + + + +
    + + +
    +

    + Uploaded NSDoc files +

    +
    + + + + IEC 61850-7-2 + + + close + + + + + IEC 61850-7-3 + + + close + + + + + IEC 61850-7-4 + + + close + + + + + IEC 61850-8-1 + + + close + + + + + Cancel + + + Reset + + + Save + +
    + + + + +`; +/* end snapshot open-scd looks like its snapshot */ + From d628780a41d961643112f8d1ba9d4f28246408ca Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Thu, 4 Aug 2022 15:36:23 +0200 Subject: [PATCH 3/3] Updated description of test. Signed-off-by: Dennis Labordus --- test/unit/menu/CompasCompareIED.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/menu/CompasCompareIED.test.ts b/test/unit/menu/CompasCompareIED.test.ts index 505b51e8e..eacf2bdaa 100644 --- a/test/unit/menu/CompasCompareIED.test.ts +++ b/test/unit/menu/CompasCompareIED.test.ts @@ -23,7 +23,7 @@ describe('Compas Compare IED Plugin', () => { await plugin.requestUpdate(); }); - it('after closing the dialog everything set to undefined', async () => { + it('after closing the dialog everything stays undefined', async () => { expect(plugin.templateDoc).to.be.undefined; expect(plugin.selectedProjectIed).to.be.undefined; expect(plugin.selectedTemplateIed).to.be.undefined;