Skip to content

Commit e7c8aee

Browse files
committed
update: add fcid to unit
1 parent 21646e7 commit e7c8aee

File tree

3 files changed

+36
-34
lines changed

3 files changed

+36
-34
lines changed

dist/js/subworkflows/subworkflow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class Subworkflow extends BaseSubworkflow {
294294
*/
295295
addSuffixToFlowchartID(suffix) {
296296
this._units.forEach(unit => {
297-
unit._flowchartId = `${unit._flowchartId}-${suffix}`;
297+
unit.setProp("flowchartId", `${unit.flowchartId}-${suffix}`);
298298
});
299299
return this;
300300
}

src/js/subworkflows/subworkflow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export class Subworkflow extends BaseSubworkflow {
354354
*/
355355
addSuffixToFlowchartID(suffix) {
356356
this._units.forEach((unit) => {
357-
unit._flowchartId = `${unit._flowchartId}-${suffix}`;
357+
unit.setProp("flowchartId", `${unit.flowchartId}-${suffix}`);
358358
});
359359
return this;
360360
}

tests/js/subworkflow.test.js

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -138,60 +138,62 @@ describe("subworkflow addSuffixToFlowchartID", () => {
138138
});
139139
});
140140

141-
it("should create a new subworkflow instance with unique flowchart IDs", () => {
141+
it("should append suffix to flowchart IDs", () => {
142+
const originalFlowchartId = subworkflow.units[0].flowchartId;
142143
const uniqueSubworkflow = subworkflow.addSuffixToFlowchartID(1);
143144

144-
// Should be a different instance
145-
expect(uniqueSubworkflow).to.not.equal(subworkflow);
145+
// Should return the same instance (mutates in place)
146+
expect(uniqueSubworkflow).to.equal(subworkflow);
146147

147-
// Original subworkflow should be unchanged
148-
expect(subworkflow.units[0].flowchartId).to.not.include("-1");
148+
// Original subworkflow should be changed (mutated)
149+
expect(subworkflow.units[0].flowchartId).to.include("-1");
150+
expect(subworkflow.units[0].flowchartId).to.equal(`${originalFlowchartId}-1`);
149151

150-
// New subworkflow should have suffixed IDs
151-
uniqueSubworkflow.units.forEach((unit) => {
152+
// All units should have suffixed IDs
153+
subworkflow.units.forEach((unit) => {
152154
expect(unit.flowchartId).to.match(/-1$/);
153155
});
154156
});
155157

156-
it("should update next references correctly", () => {
157-
const uniqueSubworkflow = subworkflow.addSuffixToFlowchartID(2);
158+
it("should append suffix to flowchart IDs when called multiple times", () => {
159+
subworkflow.addSuffixToFlowchartID(2);
158160

159-
uniqueSubworkflow.units.forEach((unit) => {
160-
if (unit.next) {
161-
// next should also have the suffix
162-
expect(unit.next).to.match(/-2$/);
161+
subworkflow.units.forEach((unit) => {
162+
expect(unit.flowchartId).to.match(/-2$/);
163+
});
163164

164-
// next should point to an existing unit
165-
const nextUnit = uniqueSubworkflow.units.find((u) => u.flowchartId === unit.next);
166-
expect(nextUnit).to.not.be.undefined;
167-
}
165+
// Calling again should append another suffix
166+
subworkflow.addSuffixToFlowchartID(3);
167+
subworkflow.units.forEach((unit) => {
168+
expect(unit.flowchartId).to.match(/-2-3$/);
168169
});
169170
});
170171

171172
it("should handle custom suffix values", () => {
172-
const uniqueSubworkflow1 = subworkflow.addSuffixToFlowchartID("custom");
173-
const uniqueSubworkflow2 = subworkflow.addSuffixToFlowchartID(42);
173+
subworkflow.addSuffixToFlowchartID("custom");
174174

175-
uniqueSubworkflow1.units.forEach((unit) => {
175+
subworkflow.units.forEach((unit) => {
176176
expect(unit.flowchartId).to.match(/-custom$/);
177177
});
178-
179-
uniqueSubworkflow2.units.forEach((unit) => {
180-
expect(unit.flowchartId).to.match(/-42$/);
181-
});
182178
});
183179

184180
it("should preserve all unit properties except flowchart IDs", () => {
185-
const uniqueSubworkflow = subworkflow.addSuffixToFlowchartID(1);
181+
const originalUnitCount = subworkflow.units.length;
182+
const originalName = subworkflow.name;
183+
const originalAppName = subworkflow.application.name;
184+
const originalUnitTypes = subworkflow.units.map((u) => u.type);
185+
const originalUnitNames = subworkflow.units.map((u) => u.name);
186+
187+
subworkflow.addSuffixToFlowchartID(1);
186188

187-
expect(uniqueSubworkflow.units.length).to.equal(subworkflow.units.length);
188-
expect(uniqueSubworkflow.name).to.equal(subworkflow.name);
189-
expect(uniqueSubworkflow.application.name).to.equal(subworkflow.application.name);
189+
expect(subworkflow.units.length).to.equal(originalUnitCount);
190+
expect(subworkflow.name).to.equal(originalName);
191+
expect(subworkflow.application.name).to.equal(originalAppName);
190192

191-
uniqueSubworkflow.units.forEach((unit, index) => {
192-
const originalUnit = subworkflow.units[index];
193-
expect(unit.type).to.equal(originalUnit.type);
194-
expect(unit.name).to.equal(originalUnit.name);
193+
subworkflow.units.forEach((unit, index) => {
194+
expect(unit.type).to.equal(originalUnitTypes[index]);
195+
expect(unit.name).to.equal(originalUnitNames[index]);
196+
expect(unit.flowchartId).to.match(/-1$/);
195197
});
196198
});
197199
});

0 commit comments

Comments
 (0)