@@ -4,10 +4,11 @@ import { SinonSpy, spy } from 'sinon';
4
4
import '../../../../mock-wizard.js' ;
5
5
6
6
import { Checkbox } from '@material/mwc-checkbox' ;
7
- import { editConnectedAp104Wizard } from '../../../../../src/editors/protocol104/wizards/connectedap.js' ;
7
+ import { createConnectedApWizard , editConnectedAp104Wizard } from '../../../../../src/editors/protocol104/wizards/connectedap.js' ;
8
8
import { ComplexAction , Create , Delete , isCreate , isDelete , WizardInputElement } from '../../../../../src/foundation.js' ;
9
9
import { MockWizard } from '../../../../mock-wizard.js' ;
10
10
import { WizardTextField } from '../../../../../src/wizard-textfield.js' ;
11
+ import { ListItemBase } from '@material/mwc-list/mwc-list-item-base' ;
11
12
12
13
describe ( 'Wizards for SCL element ConnectedAP' , ( ) => {
13
14
let doc : XMLDocument ;
@@ -19,29 +20,31 @@ describe('Wizards for SCL element ConnectedAP', () => {
19
20
let actionEvent : SinonSpy ;
20
21
21
22
beforeEach ( async ( ) => {
22
- element = < MockWizard > await fixture ( html `< mock-wizard > </ mock-wizard > ` ) ;
23
-
24
23
doc = await fetch ( '/test/testfiles/104/valid-subnetwork.scd' )
25
24
. then ( response => response . text ( ) )
26
25
. then ( str => new DOMParser ( ) . parseFromString ( str , 'application/xml' ) ) ;
27
26
28
- const wizard = editConnectedAp104Wizard ( doc . querySelector ( 'SubNetwork[type="104"] > ConnectedAP[apName="AP2"]' ) ! ) ;
29
- element . workflow . push ( ( ) => wizard ) ;
30
- await element . requestUpdate ( ) ;
31
-
32
- inputs = Array . from ( element . wizardUI . inputs ) ;
33
-
34
- primaryAction = < HTMLElement > (
35
- element . wizardUI . dialog ?. querySelector (
36
- 'mwc-button[slot="primaryAction"]'
37
- )
38
- ) ;
27
+ element = < MockWizard > await fixture ( html `< mock-wizard > </ mock-wizard > ` ) ;
39
28
40
29
actionEvent = spy ( ) ;
41
30
window . addEventListener ( 'editor-action' , actionEvent ) ;
42
31
} ) ;
43
32
44
33
describe ( 'include an edit wizard that' , ( ) => {
34
+ beforeEach ( async ( ) => {
35
+ const wizard = editConnectedAp104Wizard ( doc . querySelector ( 'SubNetwork[type="104"] > ConnectedAP[apName="AP2"]' ) ! ) ;
36
+ element . workflow . push ( ( ) => wizard ) ;
37
+ await element . requestUpdate ( ) ;
38
+
39
+ inputs = Array . from ( element . wizardUI . inputs ) ;
40
+
41
+ primaryAction = < HTMLElement > (
42
+ element . wizardUI . dialog ?. querySelector (
43
+ 'mwc-button[slot="primaryAction"]'
44
+ )
45
+ ) ;
46
+ } ) ;
47
+
45
48
it ( 'does not edit any P element with unchanged wizard inputs' , async ( ) => {
46
49
primaryAction . click ( ) ;
47
50
await element . requestUpdate ( ) ;
@@ -133,4 +136,81 @@ describe('Wizards for SCL element ConnectedAP', () => {
133
136
) . to . exist ;
134
137
} ) ;
135
138
} ) ;
139
+
140
+ describe ( 'include a create wizard that' , ( ) => {
141
+ beforeEach ( async ( ) => {
142
+ const wizard = createConnectedApWizard ( doc . querySelector ( 'SubNetwork[type="104"] > ConnectedAP[apName="AP2"]' ) ! ) ;
143
+ element . workflow . push ( ( ) => wizard ) ;
144
+ await element . requestUpdate ( ) ;
145
+
146
+ inputs = Array . from ( element . wizardUI . inputs ) ;
147
+
148
+ primaryAction = < HTMLElement > (
149
+ element . wizardUI . dialog ?. querySelector (
150
+ 'mwc-button[slot="primaryAction"]'
151
+ )
152
+ ) ;
153
+ } ) ;
154
+
155
+ it ( 'looks like the latest snapshot' , async ( ) => {
156
+ await expect ( element . wizardUI . dialog ) . dom . to . equalSnapshot ( ) ;
157
+ } ) ;
158
+
159
+ it ( 'does not allow to add connected AccessPoints' , ( ) => {
160
+ const disabledItems = Array . from (
161
+ element . wizardUI . dialog ! . querySelectorAll < ListItemBase > (
162
+ 'mwc-check-list-item'
163
+ )
164
+ ) . filter ( item => item . disabled ) ;
165
+
166
+ for ( const item of disabledItems ) {
167
+ const [ iedName , apName ] = item . value . split ( '>' ) ;
168
+ expect (
169
+ doc . querySelector (
170
+ `ConnectedAP[iedName="${ iedName } "][apName="${ apName } "]`
171
+ )
172
+ ) . to . exist ;
173
+ }
174
+ } ) ;
175
+
176
+ it ( 'allows to add unconnected AccessPoints' , ( ) => {
177
+ const enabledItems = Array . from (
178
+ element . wizardUI . dialog ! . querySelectorAll < ListItemBase > (
179
+ 'mwc-check-list-item'
180
+ )
181
+ ) . filter ( item => ! item . disabled ) ;
182
+
183
+ for ( const item of enabledItems ) {
184
+ const [ iedName , apName ] = item . value . split ( '>' ) ;
185
+ expect (
186
+ doc . querySelector (
187
+ `ConnectedAP[iedName="${ iedName } "][apName="${ apName } "]`
188
+ )
189
+ ) . to . not . exist ;
190
+ }
191
+ } ) ;
192
+
193
+ it ( 'shows all AccessPoint in the project' , async ( ) => {
194
+ expect (
195
+ element . wizardUI . dialog ?. querySelectorAll ( 'mwc-check-list-item' ) . length
196
+ ) . to . equal ( doc . querySelectorAll ( ':root > IED > AccessPoint' ) . length )
197
+ } ) ;
198
+
199
+ it ( 'triggers a create editor action on primary action' , async ( ) => {
200
+ Array . from (
201
+ element . wizardUI . dialog ! . querySelectorAll < ListItemBase > (
202
+ 'mwc-check-list-item'
203
+ )
204
+ )
205
+ . filter ( item => ! item . disabled ) [ 0 ]
206
+ . click ( ) ;
207
+ await element . requestUpdate ( ) ;
208
+
209
+ primaryAction . click ( ) ;
210
+ await element . requestUpdate ( ) ;
211
+
212
+ expect ( actionEvent ) . to . be . calledOnce ;
213
+ expect ( actionEvent . args [ 0 ] [ 0 ] . detail . action ) . to . satisfy ( isCreate ) ;
214
+ } ) ;
215
+ } ) ;
136
216
} ) ;
0 commit comments