X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fei-coordinator%2Fjobs-list%2Fjobs-list.component.spec.ts;h=f5021dff428602d0253b7683ca2280e7946ac15a;hb=1b0075b7dba448dc6ea494649e0141bee615b8f5;hp=927ab9d7252dd43c343e1723c8ae07abfba2891e;hpb=18a21c8796772fab295df182763f59700333e9ab;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/ei-coordinator/jobs-list/jobs-list.component.spec.ts b/webapp-frontend/src/app/ei-coordinator/jobs-list/jobs-list.component.spec.ts index 927ab9d..f5021df 100644 --- a/webapp-frontend/src/app/ei-coordinator/jobs-list/jobs-list.component.spec.ts +++ b/webapp-frontend/src/app/ei-coordinator/jobs-list/jobs-list.component.spec.ts @@ -27,6 +27,7 @@ import { fakeAsync, TestBed, tick, + flushMicrotasks, } from "@angular/core/testing"; import { FormsModule, ReactiveFormsModule } from "@angular/forms"; import { MatFormFieldModule } from "@angular/material/form-field"; @@ -40,8 +41,8 @@ import { MatTableModule } from "@angular/material/table"; import { MatTableHarness } from "@angular/material/table/testing"; import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; import { of } from "rxjs/observable/of"; -import { EIJob } from "@interfaces/ei.types"; -import { EIService } from "@services/ei/ei.service"; +import { JobInfo } from "@interfaces/producer.types"; +import { ProducerService } from "@services/ei/producer.service"; import { UiService } from "@services/ui/ui.service"; import { Job, JobsListComponent } from "./jobs-list.component"; @@ -50,18 +51,18 @@ import { Subscription } from "rxjs"; let component: JobsListComponent; let fixture: ComponentFixture; -const eijob1 = { - ei_job_identity: "job1", - ei_type_identity: "type1", +const jobInfo1 = { + info_job_identity: "job1", + info_type_identity: "type1", owner: "owner1", target_uri: "http://one", -} as EIJob; -const eijob2 = { - ei_job_identity: "job2", - ei_type_identity: "type2", +} as JobInfo; +const jobInfo2 = { + info_job_identity: "job2", + info_type_identity: "type2", owner: "owner2", target_uri: "http://two", -} as EIJob; +} as JobInfo; const job1 = { jobId: "job1", @@ -114,7 +115,7 @@ describe("JobsListComponent", () => { ], schemas: [CUSTOM_ELEMENTS_SCHEMA], declarations: [JobsListComponent], - providers: [{ provide: EIService, useValue: spy }, UiService], + providers: [{ provide: ProducerService, useValue: spy }, UiService], }) .compileComponents() .then(() => { @@ -237,18 +238,18 @@ describe("JobsListComponent", () => { it("should display default values for non required properties ", fakeAsync(() => { const jobMissingProperties = { - ei_job_identity: "job1", - ei_job_data: { + info_job_identity: "job1", + info_job_data: { jobparam2: "value2_job2", jobparam3: "value3_job2", jobparam1: "value1_job2", }, target_uri: "http://one", - } as EIJob; + } as JobInfo; - let eiServiceSpy = TestBed.inject(EIService) as jasmine.SpyObj; - eiServiceSpy.getProducerIds.and.returnValue(of(["producer1"])); - eiServiceSpy.getJobsForProducer.and.returnValue( + let producerServiceSpy = TestBed.inject(ProducerService) as jasmine.SpyObj; + producerServiceSpy.getProducerIds.and.returnValue(of(["producer1"])); + producerServiceSpy.getJobsForProducer.and.returnValue( of([jobMissingProperties]) ); @@ -267,7 +268,7 @@ describe("JobsListComponent", () => { .then((loadTable) => { loadTable.getRows().then((jobRows) => { jobRows[0].getCellTextByColumnName().then((value) => { - expect(expectedJobRow).toContain(jasmine.objectContaining(value)); + expect(expectedJobRow).toEqual(jasmine.objectContaining(value)); }); }); }); @@ -285,63 +286,78 @@ describe("JobsListComponent", () => { loader .getHarness(MatInputHarness.with({ selector: "#jobIdFilter" })) .then((idFilter) => { - idFilter.setValue("1"); - loadTable.getRows().then((jobRows) => { - expect(jobRows.length).toEqual(2); - jobRows[0].getCellTextByColumnName().then((value) => { - expect(expectedJob1Row).toContain( - jasmine.objectContaining(value) - ); + tick(10); + idFilter.setValue("1").then((_) => { + tick(10); + loadTable.getRows().then((jobRows) => { + expect(jobRows.length).toEqual(2); + jobRows[0].getCellTextByColumnName().then((value) => { + expect(expectedJob1Row).toEqual( + jasmine.objectContaining(value) + ); + idFilter.setValue(""); + flushMicrotasks(); + }); }); }); - idFilter.setValue(""); }); + loader .getHarness(MatInputHarness.with({ selector: "#jobTypeIdFilter" })) .then((typeIdFilter) => { - typeIdFilter.setValue("1"); - loadTable.getRows().then((jobRows) => { - expect(jobRows.length).toEqual(2); - jobRows[0].getCellTextByColumnName().then((value) => { - expect(expectedJob1Row).toContain( - jasmine.objectContaining(value) - ); + tick(10); + typeIdFilter.setValue("1").then((_) => { + loadTable.getRows().then((jobRows) => { + expect(jobRows.length).toEqual(2); + jobRows[0].getCellTextByColumnName().then((value) => { + expect(expectedJob1Row).toEqual( + jasmine.objectContaining(value) + ); + typeIdFilter.setValue(""); + flushMicrotasks(); + }); }); }); - typeIdFilter.setValue(""); }); + loader .getHarness(MatInputHarness.with({ selector: "#jobOwnerFilter" })) .then((ownerFilter) => { - ownerFilter.setValue("1"); - loadTable.getRows().then((jobRows) => { - expect(jobRows.length).toEqual(2); - jobRows[0].getCellTextByColumnName().then((value) => { - expect(expectedJob1Row).toContain( - jasmine.objectContaining(value) - ); + tick(10); + ownerFilter.setValue("1").then((_) => { + loadTable.getRows().then((jobRows) => { + expect(jobRows.length).toEqual(2); + jobRows[0].getCellTextByColumnName().then((value) => { + expect(expectedJob1Row).toEqual( + jasmine.objectContaining(value) + ); + ownerFilter.setValue(""); + flushMicrotasks(); + }); }); }); - ownerFilter.setValue(""); }); + loader .getHarness( MatInputHarness.with({ selector: "#jobTargetUriFilter" }) ) .then((targetUriFilter) => { - targetUriFilter.setValue("1"); - loadTable.getRows().then((jobRows) => { - expect(jobRows.length).toEqual(2); - jobRows[0].getCellTextByColumnName().then((value) => { - expect(expectedJob1Row).toContain( - jasmine.objectContaining(value) - ); + tick(10); + targetUriFilter.setValue("one").then((_) => { + loadTable.getRows().then((jobRows) => { + expect(jobRows.length).toEqual(2); + jobRows[0].getCellTextByColumnName().then((value) => { + expect(expectedJob1Row).toEqual( + jasmine.objectContaining(value) + ); + targetUriFilter.setValue(""); + flushMicrotasks(); + }); }); }); - targetUriFilter.setValue(""); }); }); - discardPeriodicTasks(); })); @@ -350,22 +366,26 @@ describe("JobsListComponent", () => { setServiceSpy(); tick(0); - loader.getHarness(MatSortHarness).then((sort) => { - sort.getSortHeaders({ sortDirection: "" }).then((headers) => { + let sort = loader.getHarness(MatSortHarness); + tick(10); + + sort.then((value) => { + value.getSortHeaders({ sortDirection: "" }).then((headers) => { expect(headers.length).toBe(5); - headers[0].click().then((_) => { - headers[0].isActive().then((active) => { - expect(active).toBe(true); - }); - headers[0].getSortDirection().then((direction) => { - expect(direction).toBe("asc"); - }); + headers[0].click(); + tick(10); + headers[0].isActive().then((value) => { + expect(value).toBe(true); }); - headers[0].click().then((_) => { - headers[0].getSortDirection().then((direction) => { - expect(direction).toBe("desc"); - }); + headers[0].getSortDirection().then((value) => { + expect(value).toBe("asc"); + }); + + headers[0].click(); + tick(10); + headers[0].getSortDirection().then((value) => { + expect(value).toBe("desc"); }); }); }); @@ -376,38 +396,38 @@ describe("JobsListComponent", () => { setServiceSpy(); tick(0); - loader.getHarness(MatSortHarness).then((sort) => { + let sort = loader.getHarness(MatSortHarness); + tick(10); + + sort.then((value) => { loader .getHarness(MatTableHarness.with({ selector: "#jobsTable" })) .then((loadTable) => { - sort.getSortHeaders().then((headers) => { - headers[0].click().then((_) => { - headers[0].getSortDirection().then((direction) => { - expect(direction).toBe(""); - }); - }); - headers[0].click().then((_) => { - headers[0].getSortDirection().then((direction) => { - expect(direction).toBe("asc"); - }); + tick(10); + value.getSortHeaders().then((headers) => { + headers[0].click(); + tick(10); + headers[0].getSortDirection().then((direction) => { + expect(direction).toBe("asc"); }); loadTable.getRows().then((jobRows) => { jobRows[0].getCellTextByColumnName().then((value) => { - expect(expectedJob1Row).toContain( + expect(expectedJob1Row).toEqual( jasmine.objectContaining(value) ); }); }); - headers[0].click().then((_) => { - headers[0].getSortDirection().then((direction) => { - expect(direction).toBe("desc"); - }); + + headers[0].click(); + tick(10); + headers[0].getSortDirection().then((direction) => { + expect(direction).toBe("desc"); }); loadTable.getRows().then((jobRows) => { jobRows[jobRows.length - 1] .getCellTextByColumnName() .then((value) => { - expect(expectedJob1Row).toContain( + expect(expectedJob1Row).toEqual( jasmine.objectContaining(value) ); }); @@ -417,18 +437,102 @@ describe("JobsListComponent", () => { }); discardPeriodicTasks(); })); + + it("should not sort when clicking on filtering box", fakeAsync(() => { + const expectedJobRow = { + jobId: "job1", + prodId: "producer2", + typeId: "type1", + owner: "owner1", + targetUri: "http://one", + }; + + setServiceSpy(); + component.ngOnInit(); + tick(0); + + loader + .getHarness(MatTableHarness.with({ selector: "#jobsTable" })) + .then((loadTable) => { + loader + .getHarness(MatInputHarness.with({ selector: "#jobIdFilter" })) + .then((idFilter) => { + tick(10); + idFilter.setValue("").then((_) => { + loadTable.getRows().then((jobRows) => { + expect(jobRows.length).toEqual(4); + jobRows[2].getCellTextByColumnName().then((value) => { + expect(expectedJobRow).toEqual( + jasmine.objectContaining(value) + ); + }); + }); + }); + }); + loader + .getHarness( + MatInputHarness.with({ selector: "#jobTypeIdFilter" }) + ) + .then((typeIdFilter) => { + tick(10); + typeIdFilter.setValue("").then((_) => { + loadTable.getRows().then((jobRows) => { + expect(jobRows.length).toEqual(4); + jobRows[2].getCellTextByColumnName().then((value) => { + expect(expectedJobRow).toEqual( + jasmine.objectContaining(value) + ); + }); + }); + }); + }); + loader + .getHarness(MatInputHarness.with({ selector: "#jobOwnerFilter" })) + .then((ownerFilter) => { + tick(10); + ownerFilter.setValue("").then((_) => { + loadTable.getRows().then((jobRows) => { + expect(jobRows.length).toEqual(4); + jobRows[2].getCellTextByColumnName().then((value) => { + expect(expectedJobRow).toEqual( + jasmine.objectContaining(value) + ); + }); + }); + }); + }); + loader + .getHarness( + MatInputHarness.with({ selector: "#jobTargetUriFilter" }) + ) + .then((targetUriFilter) => { + tick(10); + targetUriFilter.setValue("").then((_) => { + loadTable.getRows().then((jobRows) => { + expect(jobRows.length).toEqual(4); + jobRows[2].getCellTextByColumnName().then((value) => { + expect(expectedJobRow).toEqual( + jasmine.objectContaining(value) + ); + }); + }); + }); + }); + }); + discardPeriodicTasks(); + })); }); describe("#paging", () => { it("should work properly on the table", fakeAsync(() => { - let eiServiceSpy = TestBed.inject( - EIService - ) as jasmine.SpyObj; - eiServiceSpy.getProducerIds.and.returnValue( + let producerServiceSpy = TestBed.inject( + ProducerService + ) as jasmine.SpyObj; + producerServiceSpy.getProducerIds.and.returnValue( of(["producer1", "producer2"]) ); - eiServiceSpy.getJobsForProducer.and.returnValue( - of([eijob1, eijob2, eijob1]) + producerServiceSpy.getJobsForProducer.and.returnValue( + of([jobInfo1, jobInfo2, jobInfo1]) ); tick(0); @@ -459,7 +563,6 @@ describe("JobsListComponent", () => { }); }); }); - discardPeriodicTasks(); })); }); @@ -467,7 +570,7 @@ describe("JobsListComponent", () => { }); function setServiceSpy() { - let eiServiceSpy = TestBed.inject(EIService) as jasmine.SpyObj; - eiServiceSpy.getProducerIds.and.returnValue(of(["producer1", "producer2"])); - eiServiceSpy.getJobsForProducer.and.returnValue(of([eijob1, eijob2])); + let producerServiceSpy = TestBed.inject(ProducerService) as jasmine.SpyObj; + producerServiceSpy.getProducerIds.and.returnValue(of(["producer1", "producer2"])); + producerServiceSpy.getJobsForProducer.and.returnValue(of([jobInfo1, jobInfo2])); }