@@ -3,18 +3,30 @@ import { html, fixture, expect } from '@open-wc/testing';
3
3
import '../../../mock-wizard-editor.js' ;
4
4
import { MockWizardEditor } from '../../../mock-wizard-editor.js' ;
5
5
6
+ import TemplatesPlugin from '../../../../src/editors/Templates.js' ;
6
7
import { Editing , EditingElement } from '../../../../src/Editing.js' ;
7
8
import { Wizarding , WizardingElement } from '../../../../src/Wizarding.js' ;
8
- import TemplatesPlugin from '../../../../src/editors/Templates .js' ;
9
+ import { newWizardEvent } from '../../../../src/foundation .js' ;
9
10
10
11
describe ( 'Templates Plugin' , ( ) => {
11
12
customElements . define (
12
13
'templates-plugin' ,
13
14
Wizarding ( Editing ( TemplatesPlugin ) )
14
15
) ;
16
+
15
17
let element : TemplatesPlugin ;
18
+ let parent : MockWizardEditor ;
19
+
16
20
beforeEach ( async ( ) => {
17
- element = await fixture ( html `< templates-plugin > </ templates-plugin > ` ) ;
21
+ parent = < MockWizardEditor > (
22
+ await fixture (
23
+ html `< mock-wizard-editor
24
+ > < templates-plugin > </ templates-plugin
25
+ > </ mock-wizard-editor > `
26
+ )
27
+ ) ;
28
+
29
+ element = parent . querySelector < TemplatesPlugin > ( 'templates-plugin' ) ! ;
18
30
} ) ;
19
31
20
32
describe ( 'without a doc loaded' , ( ) => {
@@ -29,12 +41,150 @@ describe('Templates Plugin', () => {
29
41
doc = await fetch ( '/test/testfiles/templates/datypes.scd' )
30
42
. then ( response => response . text ( ) )
31
43
. then ( str => new DOMParser ( ) . parseFromString ( str , 'application/xml' ) ) ;
44
+
32
45
element . doc = doc ;
33
- await element . updateComplete ;
46
+ await element . requestUpdate ( ) ;
34
47
} ) ;
48
+
35
49
it ( 'looks like the latest snapshot' , async ( ) => {
36
50
await expect ( element ) . shadowDom . to . equalSnapshot ( ) ;
37
51
} ) ;
52
+
53
+ describe ( 'having a LNodeType element list that' , ( ) => {
54
+ beforeEach ( async ( ) => {
55
+ parent . workflow . length = 0 ;
56
+ ( < HTMLElement > (
57
+ element ?. shadowRoot
58
+ ?. querySelectorAll ( 'filtered-list' ) [ 0 ]
59
+ . querySelector ( 'mwc-list-item' )
60
+ ) ) . click ( ) ;
61
+
62
+ await parent . requestUpdate ( ) ;
63
+ } ) ;
64
+
65
+ it ( 'opens a LNodeType edit wizard on list element click' , ( ) =>
66
+ expect (
67
+ parent . wizardUI . dialog ?. querySelector (
68
+ 'wizard-textfield[label="lnClass"]'
69
+ )
70
+ ) . to . exist ) ;
71
+
72
+ it ( 'allows to reopen the LNodeType edit wizard for the same element' , async ( ) => {
73
+ parent . dispatchEvent ( newWizardEvent ( ) ) ;
74
+
75
+ await parent . requestUpdate ( ) ;
76
+
77
+ ( < HTMLElement > (
78
+ element ?. shadowRoot ?. querySelector (
79
+ 'filtered-list:nth-of-type(1) > mwc-list-item'
80
+ )
81
+ ) ) . click ( ) ;
82
+ await parent . requestUpdate ( ) ;
83
+
84
+ expect (
85
+ parent . wizardUI . dialog ?. querySelector (
86
+ 'wizard-textfield[label="lnClass"]'
87
+ )
88
+ ) . to . exist ;
89
+ } ) ;
90
+ } ) ;
91
+
92
+ describe ( 'having a DOType element list that' , ( ) => {
93
+ beforeEach ( async ( ) => {
94
+ parent . workflow . length = 0 ;
95
+ ( < HTMLElement > (
96
+ element ?. shadowRoot
97
+ ?. querySelectorAll ( 'filtered-list' ) [ 1 ]
98
+ . querySelector ( 'mwc-list-item' )
99
+ ) ) . click ( ) ;
100
+
101
+ await parent . requestUpdate ( ) ;
102
+ } ) ;
103
+
104
+ it ( 'opens a DOType edit wizard on list element click' , ( ) =>
105
+ expect (
106
+ parent . wizardUI . dialog ?. querySelector ( 'wizard-textfield[label="CDC"]' )
107
+ ) . to . exist ) ;
108
+
109
+ it ( 'allows to reopen the DOType edit wizard for the same element' , async ( ) => {
110
+ parent . dispatchEvent ( newWizardEvent ( ) ) ;
111
+
112
+ await parent . requestUpdate ( ) ;
113
+
114
+ ( < HTMLElement > (
115
+ element ?. shadowRoot
116
+ ?. querySelectorAll ( 'filtered-list' ) [ 1 ]
117
+ . querySelector ( 'mwc-list-item' )
118
+ ) ) . click ( ) ;
119
+ await parent . requestUpdate ( ) ;
120
+
121
+ expect (
122
+ parent . wizardUI . dialog ?. querySelector ( 'wizard-textfield[label="CDC"]' )
123
+ ) . to . exist ;
124
+ } ) ;
125
+ } ) ;
126
+
127
+ describe ( 'having a DAType element list that' , ( ) => {
128
+ beforeEach ( async ( ) => {
129
+ parent . workflow . length = 0 ;
130
+ ( < HTMLElement > (
131
+ element ?. shadowRoot
132
+ ?. querySelectorAll ( 'filtered-list' ) [ 2 ]
133
+ . querySelector ( 'mwc-list-item' )
134
+ ) ) . click ( ) ;
135
+
136
+ await parent . requestUpdate ( ) ;
137
+ } ) ;
138
+
139
+ it ( 'opens a DAType edit wizard on list element click' , ( ) =>
140
+ expect ( parent . wizardUI . dialog ) . to . exist ) ;
141
+
142
+ it ( 'allows to reopen the DAType edit wizard for the same element' , async ( ) => {
143
+ parent . dispatchEvent ( newWizardEvent ( ) ) ;
144
+
145
+ await parent . requestUpdate ( ) ;
146
+
147
+ ( < HTMLElement > (
148
+ element ?. shadowRoot
149
+ ?. querySelectorAll ( 'filtered-list' ) [ 3 ]
150
+ . querySelector ( 'mwc-list-item' )
151
+ ) ) . click ( ) ;
152
+ await parent . requestUpdate ( ) ;
153
+
154
+ expect ( parent . wizardUI . dialog ) . to . exist ;
155
+ } ) ;
156
+ } ) ;
157
+
158
+ describe ( 'having a EnumType element list that' , ( ) => {
159
+ beforeEach ( async ( ) => {
160
+ parent . workflow . length = 0 ;
161
+ ( < HTMLElement > (
162
+ element ?. shadowRoot
163
+ ?. querySelectorAll ( 'filtered-list' ) [ 3 ]
164
+ . querySelector ( 'mwc-list-item' )
165
+ ) ) . click ( ) ;
166
+
167
+ await parent . requestUpdate ( ) ;
168
+ } ) ;
169
+
170
+ it ( 'opens a EnumType edit wizard on list element click' , ( ) =>
171
+ expect ( parent . wizardUI . dialog ) . to . exist ) ;
172
+
173
+ it ( 'allows to reopen the EnumType edit wizard for the same element' , async ( ) => {
174
+ parent . dispatchEvent ( newWizardEvent ( ) ) ;
175
+
176
+ await parent . requestUpdate ( ) ;
177
+
178
+ ( < HTMLElement > (
179
+ element ?. shadowRoot
180
+ ?. querySelectorAll ( 'filtered-list' ) [ 3 ]
181
+ . querySelector ( 'mwc-list-item' )
182
+ ) ) . click ( ) ;
183
+ await parent . requestUpdate ( ) ;
184
+
185
+ expect ( parent . wizardUI . dialog ) . to . exist ;
186
+ } ) ;
187
+ } ) ;
38
188
} ) ;
39
189
40
190
describe ( 'with a doc loaded missing a datatypetemplates section' , ( ) => {
@@ -55,9 +205,11 @@ describe('Templates Plugin', () => {
55
205
) ;
56
206
await element . updateComplete ;
57
207
} ) ;
208
+
58
209
it ( 'has a mwc-fab' , ( ) => {
59
210
expect ( element . shadowRoot ?. querySelector ( 'mwc-fab' ) ) . to . exist ;
60
211
} ) ;
212
+
61
213
it ( 'adds a DataTypeTemplates on floating action button click' , async ( ) => {
62
214
expect ( doc . querySelector ( 'DataTypeTemplates' ) ) . to . not . exist ;
63
215
( < HTMLElement > (
@@ -73,6 +225,7 @@ describe('Templates Plugin', () => {
73
225
) . to . exist ;
74
226
} ) ;
75
227
} ) ;
228
+
76
229
describe ( 'with a doc loaded having a datatypetemplates section' , ( ) => {
77
230
let doc : XMLDocument ;
78
231
let parent : WizardingElement & EditingElement ;
@@ -90,6 +243,7 @@ describe('Templates Plugin', () => {
90
243
) ;
91
244
await element . updateComplete ;
92
245
} ) ;
246
+
93
247
it ( 'opens an add enumtype wizard' , async ( ) => {
94
248
expect ( parent . wizardUI . dialogs . length ) . to . equal ( 0 ) ;
95
249
( < HTMLElement > (
@@ -103,6 +257,7 @@ describe('Templates Plugin', () => {
103
257
await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ; // await animation
104
258
expect ( parent . wizardUI . dialogs . length ) . to . equal ( 1 ) ;
105
259
} ) ;
260
+
106
261
it ( 'adding an EnumType with the enumtype wizard' , async ( ) => {
107
262
expect ( doc . querySelectorAll ( 'EnumType' ) . length ) . to . equal ( 4 ) ;
108
263
( < HTMLElement > (
0 commit comments