Skip to content

Commit a328446

Browse files
author
Dennis Labordus
committed
Fixed issue with existing DAI Elements and updated test.
Signed-off-by: Dennis Labordus <[email protected]>
1 parent 04a0fc2 commit a328446

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

src/editors/protocol104/foundation/cdc.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,17 @@ function findOrCreateDaiElements(
713713
const foundDaiElements = lnClonedElement.querySelectorAll(filter);
714714
if (foundDaiElements.length > 0) {
715715
// Existing DAI Element found, so use that Element.
716-
daiElements.push(...Array.from(foundDaiElements));
716+
foundDaiElements.forEach(clonedDaiElement => {
717+
const daiElement = findElementInOriginalLNStructure(
718+
lnElement,
719+
clonedDaiElement
720+
);
721+
if (daiElement) {
722+
daiElements.push(daiElement);
723+
} else {
724+
daiElements.push(clonedDaiElement);
725+
}
726+
});
717727
} else {
718728
// DAI Element doesn't exist yet, so create the structure using the DA Path.
719729
const templateStructure = createTemplateStructure(doElement, daPath);

test/testfiles/104/valid-empty-addresses.scd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@
492492
<SDI name="Oper">
493493
<DAI name="ctlVal">
494494
</DAI>
495+
<DAI name="Check">
496+
</DAI>
495497
</SDI>
496498
<DAI name="ctlModel">
497499
<Val>direct-with-normal-security</Val>

test/unit/editors/protocol104/wizards/createAddresses.test.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from '../../../../../src/editors/protocol104/wizards/createAddresses.js';
1919

2020
import { fetchDoc } from '../../../wizards/test-support.js';
21+
import { Switch } from '@material/mwc-switch';
2122

2223
describe('Wizards for preparing 104 Address Creation', () => {
2324
let doc: XMLDocument;
@@ -27,7 +28,7 @@ describe('Wizards for preparing 104 Address Creation', () => {
2728
let inputs: WizardInputElement[];
2829

2930
beforeEach(async () => {
30-
doc = await fetchDoc('/test/testfiles/104/valid-addresses.scd');
31+
doc = await fetchDoc('/test/testfiles/104/valid-empty-addresses.scd');
3132
element = await fixture(html`<mock-wizard></mock-wizard>`);
3233
});
3334

@@ -76,7 +77,7 @@ describe('Wizards for preparing 104 Address Creation', () => {
7677
lnElement,
7778
doElement,
7879
false
79-
)(inputs, element);
80+
)(inputs, element.wizardUI);
8081

8182
expectCreateActions(actions, 1);
8283
});
@@ -98,7 +99,7 @@ describe('Wizards for preparing 104 Address Creation', () => {
9899
lnElement,
99100
doElement,
100101
false
101-
)(inputs, element);
102+
)(inputs, element.wizardUI);
102103

103104
expectCreateActions(actions, 1);
104105
});
@@ -121,7 +122,7 @@ describe('Wizards for preparing 104 Address Creation', () => {
121122
lnElement,
122123
doElement,
123124
false
124-
)(inputs, element);
125+
)(inputs, element.wizardUI);
125126

126127
expectCreateActions(actions, 1);
127128
});
@@ -139,14 +140,30 @@ describe('Wizards for preparing 104 Address Creation', () => {
139140
);
140141
});
141142

142-
it('when processing the request, the expected Create Actions are returned', () => {
143+
it('when processing the request without Check Selected, the expected Create Actions are returned', () => {
143144
const actions = createAddressesAction(
144145
lnElement,
145146
doElement,
146-
false
147-
)(inputs, element);
147+
true
148+
)(inputs, element.wizardUI);
148149

149-
expectCreateActions(actions, 1);
150+
expectCreateActions(actions, 2);
151+
});
152+
153+
it('when processing the request with Check Selected, the expected Create Actions are returned', async () => {
154+
const switchElement = element.wizardUI.dialog!.querySelector<Switch>(
155+
`mwc-switch[id="controlCheck"]`
156+
)!;
157+
switchElement.checked = true;
158+
await element.requestUpdate();
159+
160+
const actions = createAddressesAction(
161+
lnElement,
162+
doElement,
163+
true
164+
)(inputs, element.wizardUI);
165+
166+
expectCreateActions(actions, 3);
150167
});
151168

152169
it('looks like the latest snapshot', async () => {

0 commit comments

Comments
 (0)