|
| 1 | +/* eslint-disable no-unused-expressions */ |
| 2 | +import { fixture, expect, html } from '@open-wc/testing'; |
| 3 | +import { SinonSpy, spy } from 'sinon'; |
| 4 | +import { DeleteDialog } from './delete-lnodetype-dialog.js'; |
| 5 | + |
| 6 | +customElements.define('delete-dialog', DeleteDialog); |
| 7 | + |
| 8 | +describe('DeleteDialog', () => { |
| 9 | + let deleteDialog: DeleteDialog; |
| 10 | + let confirmSpy: SinonSpy; |
| 11 | + |
| 12 | + beforeEach(async () => { |
| 13 | + confirmSpy = spy(); |
| 14 | + |
| 15 | + deleteDialog = await fixture( |
| 16 | + html`<delete-dialog |
| 17 | + .lnodeTypeId=${'MMXU$oscd$_c53e78191fabefa3'} |
| 18 | + .onConfirm=${confirmSpy} |
| 19 | + ></delete-dialog>` |
| 20 | + ); |
| 21 | + }); |
| 22 | + |
| 23 | + afterEach(async () => { |
| 24 | + deleteDialog.remove(); |
| 25 | + }); |
| 26 | + |
| 27 | + it('displays the correct LNodeType ID in the message', () => { |
| 28 | + deleteDialog.show(); |
| 29 | + expect(deleteDialog.shadowRoot?.textContent).to.include( |
| 30 | + 'MMXU$oscd$_c53e78191fabefa3' |
| 31 | + ); |
| 32 | + expect(deleteDialog.shadowRoot?.textContent).to.include('Confirm delete'); |
| 33 | + expect(deleteDialog.shadowRoot?.textContent).to.include( |
| 34 | + 'This action may have severe consequences' |
| 35 | + ); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should call onConfirm and close when Delete button is clicked', async () => { |
| 39 | + deleteDialog.show(); |
| 40 | + await deleteDialog.updateComplete; |
| 41 | + await deleteDialog.dialog.updateComplete; |
| 42 | + |
| 43 | + const buttons = |
| 44 | + deleteDialog.shadowRoot?.querySelectorAll('md-outlined-button'); |
| 45 | + const deleteButton = Array.from(buttons || []).find( |
| 46 | + btn => btn.textContent?.trim() === 'Delete' |
| 47 | + ) as HTMLElement; |
| 48 | + |
| 49 | + expect(deleteButton).to.exist; |
| 50 | + deleteButton.click(); |
| 51 | + await deleteDialog.updateComplete; |
| 52 | + await deleteDialog.dialog.updateComplete; |
| 53 | + |
| 54 | + expect(confirmSpy.callCount).to.equal(1); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should update displayed ID when lnodeTypeId property changes', async () => { |
| 58 | + deleteDialog.show(); |
| 59 | + await deleteDialog.updateComplete; |
| 60 | + expect(deleteDialog.shadowRoot?.textContent).to.include( |
| 61 | + 'MMXU$oscd$_c53e78191fabefa3' |
| 62 | + ); |
| 63 | + |
| 64 | + deleteDialog.lnodeTypeId = 'LLN0$oscd$_85c7ffbe25d80e63'; |
| 65 | + await deleteDialog.updateComplete; |
| 66 | + expect(deleteDialog.shadowRoot?.textContent).to.include( |
| 67 | + 'LLN0$oscd$_85c7ffbe25d80e63' |
| 68 | + ); |
| 69 | + expect(deleteDialog.shadowRoot?.textContent).to.not.include( |
| 70 | + 'MMXU$oscd$_c53e78191fabefa3' |
| 71 | + ); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should not call onConfirm when dialog is cancelled', async () => { |
| 75 | + deleteDialog.show(); |
| 76 | + await deleteDialog.updateComplete; |
| 77 | + |
| 78 | + const buttons = |
| 79 | + deleteDialog.shadowRoot?.querySelectorAll('md-outlined-button'); |
| 80 | + const cancelButton = Array.from(buttons || []).find( |
| 81 | + btn => btn.textContent?.trim() === 'Cancel' |
| 82 | + ) as HTMLElement; |
| 83 | + |
| 84 | + cancelButton.click(); |
| 85 | + await deleteDialog.updateComplete; |
| 86 | + |
| 87 | + expect(confirmSpy.callCount).to.equal(0); |
| 88 | + }); |
| 89 | +}); |
0 commit comments