Skip to content

Commit 0573357

Browse files
committed
test: Add tests
1 parent 912b866 commit 0573357

3 files changed

Lines changed: 77 additions & 2 deletions

File tree

__snapshots__/scl-bay-template.spec.snap.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ snapshots['SclBayTemplate Plugin looks like the latest snapshot'] = `<main>
3939
type="file"
4040
>
4141
<span title="Create New Function/EqFunction">
42-
<mwc-icon-button icon="functions">
42+
<mwc-icon-button
43+
disabled=""
44+
icon="functions"
45+
>
4346
</mwc-icon-button>
4447
</span>
4548
</nav>

foundation/scl.spec.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { expect } from '@open-wc/testing';
2+
3+
import { testScl } from '../scl-bay-template.testfiles';
4+
import { createElementNS, getProcessPath } from './scl.js';
5+
6+
describe('scl', () => {
7+
let doc: XMLDocument;
8+
9+
beforeEach(() => {
10+
doc = new DOMParser().parseFromString(testScl, 'application/xml');
11+
});
12+
13+
describe('getProcessPath', () => {
14+
const testCases = [
15+
{
16+
title: 'ConductingEquipment',
17+
selector: 'ConductingEquipment[name="QCE1"]',
18+
expectedPath: 'TEMPLATE/TEMPLATE/TEMPLATE/QCE1',
19+
},
20+
{
21+
title: 'Bay',
22+
selector: 'Bay[name="TEMPLATE"]',
23+
expectedPath: 'TEMPLATE/TEMPLATE/TEMPLATE',
24+
},
25+
];
26+
27+
testCases.forEach(tc => {
28+
it(`should calculate correct process path for ${tc.title}`, () => {
29+
const element = doc.querySelector(tc.selector)!;
30+
const processPath = getProcessPath(element);
31+
32+
expect(processPath).to.equal(tc.expectedPath);
33+
});
34+
});
35+
});
36+
37+
describe('createElementNS', () => {
38+
const testNameSpaceURI = 'http://test.de/2000';
39+
const testNameSpacePrefix = 'test_2000';
40+
41+
it('should create element include namespace and prefix', () => {
42+
const tagname = 'TestElement';
43+
44+
const element = createElementNS(
45+
doc,
46+
tagname,
47+
{
48+
name: 'test1',
49+
height: '200',
50+
},
51+
{
52+
namespaceURI: testNameSpaceURI,
53+
elementPrefix: testNameSpacePrefix,
54+
}
55+
);
56+
57+
expect(element.tagName).to.equal(`${testNameSpacePrefix}:${tagname}`);
58+
expect(element.getAttribute('name')).to.equal('test1');
59+
expect(element.getAttribute('height')).to.equal('200');
60+
expect(element.namespaceURI).to.equal(testNameSpaceURI);
61+
});
62+
63+
it('should use default namespace if non is provided', () => {
64+
const tagname = 'TestElement';
65+
66+
const element = createElementNS(doc, tagname, {}, {});
67+
68+
expect(element.namespaceURI).to.equal(doc.documentElement.namespaceURI);
69+
expect(element.tagName).to.equal(tagname);
70+
});
71+
});
72+
});

scl-bay-template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export default class SclBayTemplate extends LitElement {
234234
addFunction(): void {
235235
const hasNotSelectedElement = this.parent === undefined;
236236
if (hasNotSelectedElement) {
237-
return;
237+
throw new Error('No element selected in SLD');
238238
}
239239

240240
const tagName = this.parent?.tagName;

0 commit comments

Comments
 (0)