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