1
1
import { html , fixture , expect } from '@open-wc/testing' ;
2
2
3
- import '../../../mock-wizard.js' ;
4
- import { MockWizard } from '../../../mock-wizard.js' ;
3
+ import '../../../mock-wizard-editor .js' ;
4
+ import { MockWizardEditor } from '../../../mock-wizard-editor .js' ;
5
5
6
- import Communication from '../../../../src/editors/Communication.js' ;
7
- import { Editing } from '../../../../src/Editing.js ' ;
8
- import { Wizarding } from '../../../../src/Wizarding .js' ;
6
+ import Communication from '../../../../src/editors/Communication.js' ;
7
+ import { Dialog } from '@material/mwc-dialog ' ;
8
+ import { WizardTextField } from '../../../../src/wizard-textfield .js' ;
9
9
10
10
describe ( 'Communication Plugin' , ( ) => {
11
11
customElements . define (
12
12
'communication-plugin' ,
13
- Wizarding ( Editing ( Communication ) )
13
+ Communication
14
14
) ;
15
15
let element : Communication ;
16
16
beforeEach ( async ( ) => {
@@ -43,18 +43,23 @@ describe('Communication Plugin', () => {
43
43
44
44
describe ( 'with a doc loaded missing a communication section' , ( ) => {
45
45
let doc : XMLDocument ;
46
- let parent : MockWizard ;
46
+ let parent : MockWizardEditor ;
47
47
let fab : HTMLElement ;
48
+ let element : Communication ;
48
49
49
50
beforeEach ( async ( ) => {
50
51
doc = await fetch ( '/test/testfiles/missingCommunication.scd' )
51
52
. then ( response => response . text ( ) )
52
53
. then ( str => new DOMParser ( ) . parseFromString ( str , 'application/xml' ) ) ;
53
- parent = < MockWizard > (
54
+
55
+ element = await fixture (
56
+ html `< communication-plugin .doc ="${ doc } "> </ communication-plugin > `
57
+ ) ;
58
+
59
+ parent = < MockWizardEditor > (
54
60
await fixture (
55
- html `< mock-wizard
56
- > < communication-plugin .doc =${ doc } > </ communication-plugin
57
- > </ mock-wizard > `
61
+ html `< mock-wizard-editor
62
+ > ${ element } /mock-wizard-editor> `
58
63
)
59
64
) ;
60
65
await element . updateComplete ;
@@ -73,5 +78,28 @@ describe('Communication Plugin', () => {
73
78
await parent . updateComplete ;
74
79
expect ( parent . wizardUI . dialogs . length ) . to . equal ( 1 ) ;
75
80
} ) ;
81
+
82
+ it ( 'Should create a Communication Element' , async ( ) => {
83
+ expect ( parent . wizardUI . dialogs . length ) . to . equal ( 0 ) ;
84
+ expect ( element . doc . querySelector ( 'Communication' ) ) . is . null ;
85
+
86
+ await fab . click ( ) ;
87
+ await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ; // await animation
88
+ await parent . updateComplete ;
89
+
90
+ const dialog : Dialog = parent . wizardUI . dialog ! ;
91
+ expect ( dialog ) . to . not . be . undefined ;
92
+
93
+ const nameInput : WizardTextField = dialog . querySelector < WizardTextField > ( 'wizard-textfield[label="name"]' ) ! ;
94
+ nameInput . value = 'Test' ;
95
+ await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ; // await animation
96
+
97
+ const saveButton : HTMLElement = dialog . querySelector ( 'mwc-button[slot="primaryAction"]' ) ! ;
98
+ await saveButton . click ( ) ;
99
+ await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ; // await animation
100
+
101
+ expect ( element . doc . querySelector ( 'Communication' ) ) . not . is . null ;
102
+ expect ( element . doc . querySelector ( 'Communication > SubNetwork[name="Test"]' ) ) . to . exist ;
103
+ } ) ;
76
104
} ) ;
77
105
} ) ;
0 commit comments