diff --git a/frontend/src/framework/EnsembleParameters.ts b/frontend/src/framework/EnsembleParameters.ts index 6d868f905..6cd5c41e3 100644 --- a/frontend/src/framework/EnsembleParameters.ts +++ b/frontend/src/framework/EnsembleParameters.ts @@ -59,6 +59,17 @@ export class ParameterIdent { return this.name; } } + + equals(otherIdent: ParameterIdent | null): boolean { + if (!otherIdent) { + return false; + } + if (otherIdent === this) { + return true; + } + + return this.name === otherIdent.name && this.groupName === otherIdent.groupName; + } } export class EnsembleParameters { @@ -72,7 +83,7 @@ export class EnsembleParameters { const identArr: ParameterIdent[] = []; for (const par of this._parameterArr) { if (requiredParamType == null || par.type === requiredParamType) { - identArr.push({ name: par.name, groupName: par.groupName }); + identArr.push(new ParameterIdent(par.name, par.groupName)); } } diff --git a/frontend/tests/unit-tests/EnsembleParameters.test.ts b/frontend/tests/unit-tests/EnsembleParameters.test.ts index 0e16fd033..fb4c89b4d 100644 --- a/frontend/tests/unit-tests/EnsembleParameters.test.ts +++ b/frontend/tests/unit-tests/EnsembleParameters.test.ts @@ -97,3 +97,22 @@ describe("EnsembleParameters tests", () => { } }); }); + + +describe("ParameterIdent tests", () => { + test("Conversion to/from string", () => { + const ident = ParameterIdent.fromNameAndGroup("aName", "aGroup"); + const identStr = ident.toString(); + expect(ParameterIdent.fromString(identStr)).toEqual(ident); + }); + + test("Check for equality", () => { + const identA = new ParameterIdent("aName", "aGroup"); + const identB = new ParameterIdent("aName", "aGroup"); + const identC = new ParameterIdent("anotherName", "anotherGroup"); + expect(identA.equals(identA)).toBe(true); + expect(identA.equals(identB)).toBe(true); + expect(identA.equals(identC)).toBe(false); + expect(identA.equals(null)).toBe(false); + }); +});