Skip to content

Commit

Permalink
fix: state leaks in matching component (#1746)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSlimvReal authored Mar 2, 2023
1 parent d7c5159 commit a0a6180
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { BehaviorSubject, of } from "rxjs";
import { FormFieldConfig } from "../../../core/entity-components/entity-form/entity-form/FormConfig";
import { Coordinates } from "../../location/coordinates";
import { MockedTestingModule } from "../../../utils/mocked-testing.module";
import { School } from "../../../child-dev-project/schools/model/school";

describe("MatchingEntitiesComponent", () => {
let component: MatchingEntitiesComponent;
Expand Down Expand Up @@ -390,6 +391,29 @@ describe("MatchingEntitiesComponent", () => {

Child.schema.delete("address");
});

it("should not alter the config object", async () => {
const config: MatchingEntitiesConfig = {
columns: [
["name", "name"],
["projectNumber", "distance"],
],
rightSide: { entityType: "School", columns: ["name", "distance"] },
leftSide: { entityType: "Child", columns: ["name", "distance"] },
};
Child.schema.set("address", { dataType: "location" });
School.schema.set("address", { dataType: "location" });

const configCopy = JSON.parse(JSON.stringify(config));
mockActivatedRoute.data = of({ config: configCopy });

await component.ngOnInit();

expect(configCopy).toEqual(config);

Child.schema.delete("address");
School.schema.delete("address");
});
});

function expectConfigToMatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,15 @@ export class MatchingEntitiesComponent
* @private
*/
private initConfig(config: MatchingEntitiesConfig, entity?: Entity) {
const defaultConfig = this.configService.getConfig<MatchingEntitiesConfig>(
MatchingEntitiesComponent.DEFAULT_CONFIG_KEY
const defaultConfig =
this.configService.getConfig<MatchingEntitiesConfig>(
MatchingEntitiesComponent.DEFAULT_CONFIG_KEY
) ?? {};
config = Object.assign(
{},
JSON.parse(JSON.stringify(defaultConfig)),
JSON.parse(JSON.stringify(config))
);
config = Object.assign({}, defaultConfig, config);

this.columns = config.columns ?? this.columns;
this.matchActionLabel = config.matchActionLabel ?? this.matchActionLabel;
Expand Down

0 comments on commit a0a6180

Please sign in to comment.