|
| 1 | +import { expect, fixture, html } from '@open-wc/testing'; |
| 2 | +import { SinonSpy, spy } from 'sinon'; |
| 3 | +import { AddLnDialog } from '../../../../src/editors/ied/add-ln-dialog'; |
| 4 | +import '../../../../src/editors/ied/add-ln-dialog.js'; |
| 5 | + |
| 6 | +describe('add-ln-dialog', () => { |
| 7 | + let element: AddLnDialog; |
| 8 | + let doc: XMLDocument; |
| 9 | + let onConfirmSpy: SinonSpy; |
| 10 | + |
| 11 | + beforeEach(async () => { |
| 12 | + doc = await fetch('/test/testfiles/editors/minimalVirtualIED.scd') |
| 13 | + .then(response => response.text()) |
| 14 | + .then(str => new DOMParser().parseFromString(str, 'application/xml')); |
| 15 | + onConfirmSpy = spy(); |
| 16 | + element = await fixture( |
| 17 | + html`<add-ln-dialog |
| 18 | + .doc=${doc} |
| 19 | + .onConfirm=${onConfirmSpy} |
| 20 | + ></add-ln-dialog>` |
| 21 | + ); |
| 22 | + }); |
| 23 | + |
| 24 | + it('looks like the latest snapshot', async () => { |
| 25 | + element.show(); |
| 26 | + await element.updateComplete; |
| 27 | + expect(element).shadowDom.to.equalSnapshot(); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should show and hide dialog', async () => { |
| 31 | + element.show(); |
| 32 | + await element.updateComplete; |
| 33 | + expect(element.dialog.open).to.be.true; |
| 34 | + |
| 35 | + element['close'](); |
| 36 | + await element.updateComplete; |
| 37 | + expect(element.dialog.open).to.be.false; |
| 38 | + }); |
| 39 | + |
| 40 | + it('displays filtered LN types', async () => { |
| 41 | + element.show(); |
| 42 | + await element.updateComplete; |
| 43 | + expect(element.filterText).to.equal(''); |
| 44 | + expect(element['filteredLNodeTypes'].length).to.equal(1); |
| 45 | + |
| 46 | + element.filterText = 'NonExistingFilter'; |
| 47 | + await element.updateComplete; |
| 48 | + expect(element['filteredLNodeTypes'].length).to.equal(0); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should create LN data on confirm', async () => { |
| 52 | + element.show(); |
| 53 | + await element.updateComplete; |
| 54 | + const listItems = element.shadowRoot?.querySelectorAll('mwc-list-item'); |
| 55 | + const targetItem = listItems |
| 56 | + ? Array.from(listItems).find(item => item.value === 'PlaceholderLLN0') |
| 57 | + : undefined; |
| 58 | + if (targetItem) { |
| 59 | + targetItem.click(); |
| 60 | + await element.updateComplete; |
| 61 | + } |
| 62 | + |
| 63 | + const amountInput = element.shadowRoot?.querySelector( |
| 64 | + '[data-testid="amount"]' |
| 65 | + ); |
| 66 | + (amountInput as HTMLInputElement).value = '3'; |
| 67 | + (amountInput as HTMLInputElement).dispatchEvent( |
| 68 | + new Event('input', { bubbles: true, composed: true }) |
| 69 | + ); |
| 70 | + await element.updateComplete; |
| 71 | + const addButton = element.shadowRoot?.querySelector( |
| 72 | + '[data-testid="add-ln-button"]' |
| 73 | + ); |
| 74 | + (addButton as HTMLElement)?.click(); |
| 75 | + await element.updateComplete; |
| 76 | + |
| 77 | + expect(onConfirmSpy.calledOnce).to.be.true; |
| 78 | + expect(onConfirmSpy.firstCall.args[0]).to.deep.include({ |
| 79 | + lnType: 'PlaceholderLLN0', |
| 80 | + lnClass: 'LLN0', |
| 81 | + amount: 3, |
| 82 | + }); |
| 83 | + }); |
| 84 | +}); |
0 commit comments