Skip to content

Commit

Permalink
fix data not being filtered for entity
Browse files Browse the repository at this point in the history
  • Loading branch information
sleidig committed Oct 13, 2023
1 parent 4a5ec73 commit ea71024
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { Subject } from "rxjs";
import { UpdatedEntity } from "../../entity/model/entity-update";

describe("RelatedEntitiesWithSummaryComponent", () => {
let component: RelatedEntitiesWithSummary;
let fixture: ComponentFixture<RelatedEntitiesWithSummary>;
let component: RelatedEntitiesWithSummaryComponent;
let fixture: ComponentFixture<RelatedEntitiesWithSummaryComponent>;
const updates = new Subject<UpdatedEntity<EducationalMaterial>>();
const child = new Child("22");
const PENCIL: ConfigurableEnumValue = {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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() });
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ export class RelatedEntitiesComponent<E extends Entity> implements OnInit {
this.entityCtr = this.entities.get(this.entityType) as EntityConstructor<E>;
this.isArray = isArrayProperty(this.entityCtr, this.property);

this.data = await this.entityMapper.loadType(this.entityType);
this.data = (await this.entityMapper.loadType<E>(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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit ea71024

Please sign in to comment.