diff --git a/src/app/core/entity-details/related-entities-with-summary/related-entities-with-summary.component.spec.ts b/src/app/core/entity-details/related-entities-with-summary/related-entities-with-summary.component.spec.ts index 40c3cd6871..2c876a4bc9 100644 --- a/src/app/core/entity-details/related-entities-with-summary/related-entities-with-summary.component.spec.ts +++ b/src/app/core/entity-details/related-entities-with-summary/related-entities-with-summary.component.spec.ts @@ -16,8 +16,8 @@ import { Subject } from "rxjs"; import { UpdatedEntity } from "../../entity/model/entity-update"; describe("RelatedEntitiesWithSummaryComponent", () => { - let component: RelatedEntitiesWithSummary; - let fixture: ComponentFixture; + let component: RelatedEntitiesWithSummaryComponent; + let fixture: ComponentFixture; const updates = new Subject>(); const child = new Child("22"); const PENCIL: ConfigurableEnumValue = { @@ -31,14 +31,17 @@ describe("RelatedEntitiesWithSummaryComponent", () => { beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ - imports: [RelatedEntitiesWithSummary, MockedTestingModule.withState()], + imports: [ + RelatedEntitiesWithSummaryComponent, + MockedTestingModule.withState(), + ], }).compileComponents(); const entityMapper = TestBed.inject(EntityMapperService); spyOn(entityMapper, "receiveUpdates").and.returnValue(updates); })); beforeEach(() => { - fixture = TestBed.createComponent(RelatedEntitiesWithSummary); + fixture = TestBed.createComponent(RelatedEntitiesWithSummaryComponent); component = fixture.componentInstance; component.entity = child; component.entityType = EducationalMaterial.ENTITY_TYPE; diff --git a/src/app/core/entity-details/related-entities/related-entities.component.spec.ts b/src/app/core/entity-details/related-entities/related-entities.component.spec.ts index 44c9b0eebd..49a1a1f2f5 100644 --- a/src/app/core/entity-details/related-entities/related-entities.component.spec.ts +++ b/src/app/core/entity-details/related-entities/related-entities.component.spec.ts @@ -30,7 +30,7 @@ describe("RelatedEntitiesComponent", () => { expect(component).toBeTruthy(); }); - it("should load the entities which are linked with the passed one", async () => { + it("should load only the entities which are linked with the passed one", async () => { const c1 = new Child(); const c2 = new Child(); const r1 = new ChildSchoolRelation(); @@ -52,7 +52,7 @@ describe("RelatedEntitiesComponent", () => { await component.ngOnInit(); expect(component.columns).toBe(columns); - expect(component.data).toEqual([r1, r2, r3]); + expect(component.data).toEqual([r1, r2]); expect(component.filter).toEqual({ ...filter, childId: c1.getId() }); }); diff --git a/src/app/core/entity-details/related-entities/related-entities.component.ts b/src/app/core/entity-details/related-entities/related-entities.component.ts index b4fc010fdf..7e5a4eb93e 100644 --- a/src/app/core/entity-details/related-entities/related-entities.component.ts +++ b/src/app/core/entity-details/related-entities/related-entities.component.ts @@ -64,7 +64,12 @@ export class RelatedEntitiesComponent implements OnInit { this.entityCtr = this.entities.get(this.entityType) as EntityConstructor; this.isArray = isArrayProperty(this.entityCtr, this.property); - this.data = await this.entityMapper.loadType(this.entityType); + this.data = (await this.entityMapper.loadType(this.entityType)).filter( + (e) => + this.isArray + ? e[this.property].includes(this.entity.getId()) + : e[this.property] === this.entity.getId(), + ); this.filter = { ...this.filter, [this.property]: this.isArray diff --git a/src/app/core/entity-details/related-time-period-entities/related-time-period-entities.component.spec.ts b/src/app/core/entity-details/related-time-period-entities/related-time-period-entities.component.spec.ts index 85bcc2e268..e5ad40422f 100644 --- a/src/app/core/entity-details/related-time-period-entities/related-time-period-entities.component.spec.ts +++ b/src/app/core/entity-details/related-time-period-entities/related-time-period-entities.component.spec.ts @@ -124,13 +124,14 @@ describe("RelatedTimePeriodEntitiesComponent", () => { }); it("should create a new entity with the start date inferred from previous relations", async () => { + const child = new Child(); const existingRelation = new ChildSchoolRelation(); existingRelation.start = moment().subtract(1, "year").toDate(); existingRelation.end = moment().subtract(1, "week").toDate(); + existingRelation.childId = child.getId(false); const loadType = spyOn(entityMapper, "loadType"); loadType.and.resolveTo([existingRelation]); - const child = new Child(); component.entity = child; await component.ngOnInit();