|
| 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 | +}); |
0 commit comments