@@ -4,38 +4,45 @@ import '../../mock-wizard.js';
4
4
import { MockWizard } from '../../mock-wizard.js' ;
5
5
6
6
import { WizardTextField } from '../../../src/wizard-textfield.js' ;
7
- import { WizardInputElement } from '../../../src/foundation.js' ;
7
+ import {
8
+ Create ,
9
+ isCreate ,
10
+ isReplace ,
11
+ Replace ,
12
+ Wizard ,
13
+ WizardInputElement ,
14
+ } from '../../../src/foundation.js' ;
8
15
9
16
import {
10
- executeWizardCreateAction ,
11
- executeWizardReplaceAction ,
12
- expectWizardNoUpdateAction ,
17
+ executeWizardComplexAction ,
13
18
fetchDoc ,
14
19
setWizardTextFieldValue ,
15
20
} from '../wizards/test-support.js' ;
16
21
import {
17
22
editCompasSCLWizard ,
18
- updateSCL
19
- } from " ../../../src/compas-wizards/scl.js" ;
23
+ updateSCL ,
24
+ } from ' ../../../src/compas-wizards/scl.js' ;
20
25
21
26
describe ( 'Wizards for SCL element (CoMPAS)' , ( ) => {
22
27
let doc : XMLDocument ;
23
28
let scl : Element ;
24
29
let element : MockWizard ;
30
+ let wizard : Wizard ;
25
31
let inputs : WizardInputElement [ ] ;
26
32
27
33
async function createWizard ( scl : Element ) : Promise < void > {
28
- element = await fixture ( html `
29
- < mock-wizard > </ mock-wizard > ` ) ;
30
- const wizard = editCompasSCLWizard ( scl ) ;
34
+ element = await fixture ( html ` < mock-wizard > </ mock-wizard > ` ) ;
35
+ wizard = editCompasSCLWizard ( scl ) ;
31
36
element . workflow . push ( ( ) => wizard ) ;
32
37
await element . requestUpdate ( ) ;
33
38
inputs = Array . from ( element . wizardUI . inputs ) ;
34
39
}
35
40
36
41
describe ( 'edit scl' , ( ) => {
37
42
beforeEach ( async ( ) => {
38
- doc = await fetchDoc ( '/test/testfiles/compas/compas-scl-private-update-existing.scd' ) ;
43
+ doc = await fetchDoc (
44
+ '/test/testfiles/compas/compas-scl-private-update-existing.scd'
45
+ ) ;
39
46
scl = doc . querySelector ( 'SCL' ) ! ;
40
47
41
48
await createWizard ( scl ) ;
@@ -48,7 +55,9 @@ describe('Wizards for SCL element (CoMPAS)', () => {
48
55
49
56
describe ( 'edit scl with existing SCL Name Element' , ( ) => {
50
57
beforeEach ( async ( ) => {
51
- doc = await fetchDoc ( '/test/testfiles/compas/compas-scl-private-update-existing.scd' ) ;
58
+ doc = await fetchDoc (
59
+ '/test/testfiles/compas/compas-scl-private-update-existing.scd'
60
+ ) ;
52
61
scl = doc . querySelector ( 'SCL' ) ! ;
53
62
54
63
await createWizard ( scl ) ;
@@ -57,21 +66,38 @@ describe('Wizards for SCL element (CoMPAS)', () => {
57
66
it ( 'update SCL Name should be updated in document' , async function ( ) {
58
67
await setWizardTextFieldValue ( < WizardTextField > inputs [ 0 ] , 'updated' ) ;
59
68
60
- const replaceAction = executeWizardReplaceAction ( updateSCL ( scl ) , inputs ) ;
69
+ const complexAction = executeWizardComplexAction (
70
+ updateSCL ( scl ) ,
71
+ element . wizardUI ,
72
+ inputs
73
+ ) ;
74
+
75
+ expect ( complexAction . actions . length ) . to . be . equal ( 2 ) ;
76
+ expect ( complexAction . actions [ 0 ] ) . to . satisfy ( isReplace ) ;
77
+
78
+ const replaceAction = < Replace > complexAction . actions [ 0 ] ;
61
79
expect ( replaceAction . old . element . tagName ) . to . be . equal ( 'compas:SclName' ) ;
62
- expect ( replaceAction . old . element ) . to . have . text ( 'existing' ) ;
63
- expect ( replaceAction . new . element . tagName ) . to . be . equal ( 'compas:SclName' ) ;
64
- expect ( replaceAction . new . element ) . to . have . text ( 'updated' ) ;
80
+ expect ( replaceAction . old . element . textContent ) . to . be . equal ( 'existing' ) ;
81
+ expect ( replaceAction . new . element . textContent ) . to . be . equal ( 'updated' ) ;
65
82
} ) ;
66
83
67
- it ( 'when no fields changed there will be no update action' , async function ( ) {
68
- expectWizardNoUpdateAction ( updateSCL ( scl ) , inputs ) ;
84
+ it ( 'when no fields changed there will only be a Labels change' , async function ( ) {
85
+ const complexAction = executeWizardComplexAction (
86
+ updateSCL ( scl ) ,
87
+ element . wizardUI ,
88
+ inputs
89
+ ) ;
90
+
91
+ expect ( complexAction . actions . length ) . to . be . equal ( 1 ) ;
92
+ expect ( complexAction . actions [ 0 ] ) . to . satisfy ( isCreate ) ;
69
93
} ) ;
70
94
} ) ;
71
95
72
96
describe ( 'edit scl with missing SCL Name Element' , ( ) => {
73
97
beforeEach ( async ( ) => {
74
- doc = await fetchDoc ( '/test/testfiles/compas/compas-scl-private-missing-scl-name.scd' ) ;
98
+ doc = await fetchDoc (
99
+ '/test/testfiles/compas/compas-scl-private-missing-scl-name.scd'
100
+ ) ;
75
101
scl = doc . querySelector ( 'SCL' ) ! ;
76
102
77
103
await createWizard ( scl ) ;
@@ -80,16 +106,29 @@ describe('Wizards for SCL element (CoMPAS)', () => {
80
106
it ( 'update SCL Name should be updated in document' , async function ( ) {
81
107
await setWizardTextFieldValue ( < WizardTextField > inputs [ 0 ] , 'updated' ) ;
82
108
83
- const createAction = executeWizardCreateAction ( updateSCL ( scl ) , inputs ) ;
109
+ const complexAction = executeWizardComplexAction (
110
+ updateSCL ( scl ) ,
111
+ element . wizardUI ,
112
+ inputs
113
+ ) ;
114
+
115
+ expect ( complexAction . actions . length ) . to . be . equal ( 2 ) ;
116
+ expect ( complexAction . actions [ 0 ] ) . to . satisfy ( isCreate ) ;
117
+
118
+ const createAction = < Create > complexAction . actions [ 0 ] ;
84
119
expect ( ( < Element > createAction . new . parent ) . tagName ) . to . be . equal ( 'Private' ) ;
85
- expect ( ( < Element > createAction . new . element ) . tagName ) . to . be . equal ( 'compas:SclName' ) ;
120
+ expect ( ( < Element > createAction . new . element ) . tagName ) . to . be . equal (
121
+ 'compas:SclName'
122
+ ) ;
86
123
expect ( createAction . new . element ) . to . have . text ( 'updated' ) ;
87
124
} ) ;
88
125
} ) ;
89
126
90
127
describe ( 'edit scl with missing Private Element' , ( ) => {
91
128
beforeEach ( async ( ) => {
92
- doc = await fetchDoc ( '/test/testfiles/compas/compas-scl-private-missing-private.scd' ) ;
129
+ doc = await fetchDoc (
130
+ '/test/testfiles/compas/compas-scl-private-missing-private.scd'
131
+ ) ;
93
132
scl = doc . querySelector ( 'SCL' ) ! ;
94
133
95
134
await createWizard ( scl ) ;
@@ -98,14 +137,23 @@ describe('Wizards for SCL element (CoMPAS)', () => {
98
137
it ( 'update SCL Name should be updated in document' , async function ( ) {
99
138
await setWizardTextFieldValue ( < WizardTextField > inputs [ 0 ] , 'updated' ) ;
100
139
101
- const createAction = executeWizardCreateAction ( updateSCL ( scl ) , inputs ) ;
102
- expect ( ( < Element > createAction . new . parent ) . tagName ) . to . be . equal ( 'SCL' ) ;
103
- expect ( ( < Element > createAction . new . element ) . tagName ) . to . be . equal ( 'Private' ) ;
140
+ const complexAction = executeWizardComplexAction (
141
+ updateSCL ( scl ) ,
142
+ element . wizardUI ,
143
+ inputs
144
+ ) ;
145
+
146
+ expect ( complexAction . actions . length ) . to . be . equal ( 2 ) ;
147
+ expect ( complexAction . actions [ 0 ] ) . to . satisfy ( isCreate ) ;
104
148
105
- const newSclNameElement = ( < Element > createAction . new . element ) . querySelector ( 'SclName' ) ;
106
- expect ( newSclNameElement ) . to . not . be . null ;
107
- expect ( newSclNameElement ! . tagName ) . to . be . equal ( 'compas:SclName' ) ;
108
- expect ( newSclNameElement ) . to . have . text ( 'updated' ) ;
149
+ // Because the private is created for the Labels outside the Actions it will be the same
150
+ // Create Action being returned, but the Private Element is added directly to the SCL Element.
151
+ const createAction = < Create > complexAction . actions [ 0 ] ;
152
+ expect ( ( < Element > createAction . new . parent ) . tagName ) . to . be . equal ( 'Private' ) ;
153
+ expect ( ( < Element > createAction . new . element ) . tagName ) . to . be . equal (
154
+ 'compas:SclName'
155
+ ) ;
156
+ expect ( createAction . new . element ) . to . have . text ( 'updated' ) ;
109
157
} ) ;
110
158
} ) ;
111
159
} ) ;
0 commit comments