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=fe7fa22de90faf21b338c705db778e5933e46e96;hb=3ee775c98e03fb575e58ef0fed4e6aa00bb8d80a;hp=44fcb6ae93567db2ce37bfac9cf9a05b0dfcabc0;hpb=5e248c6923681f9a3990aa57da3a0403c100bb57;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 44fcb6a..fe7fa22 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 @@ -41,56 +41,43 @@ 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 { ConsumerStatus, JobInfo } from "@interfaces/consumer.types"; import { UiService } from "@services/ui/ui.service"; import { Job, JobsListComponent } from "./jobs-list.component"; import { Subscription } from "rxjs"; +import { ConsumerService } from "@services/ei/consumer.service"; let component: JobsListComponent; let fixture: ComponentFixture; -const eijob1 = { - ei_job_identity: "job1", - ei_type_identity: "type1", - owner: "owner1", - target_uri: "http://one", -} as EIJob; -const eijob2 = { - ei_job_identity: "job2", - ei_type_identity: "type2", - owner: "owner2", - target_uri: "http://two", -} as EIJob; +const jobInfo1 = { + info_type_id: "type1", + job_owner: "owner1", + job_result_uri: "http://one", + job_definition: {}, +} as JobInfo; + +const jobStatus1 = { + info_job_status: "ENABLED", + producers: ["producer1"], +} as ConsumerStatus; const job1 = { jobId: "job1", typeId: "type1", owner: "owner1", targetUri: "http://one", - prodId: "producer1", + prodIds: ["producer1"], + status: "ENABLED" } as Job; const job2 = { jobId: "job2", - typeId: "type2", - owner: "owner2", - targetUri: "http://two", - prodId: "producer1", -} as Job; -const job3 = { - jobId: "job1", typeId: "type1", owner: "owner1", targetUri: "http://one", - prodId: "producer2", -} as Job; -const job4 = { - jobId: "job2", - typeId: "type2", - owner: "owner2", - targetUri: "http://two", - prodId: "producer2", + prodIds: ["producer1"], + status: "ENABLED" } as Job; describe("JobsListComponent", () => { @@ -98,8 +85,9 @@ describe("JobsListComponent", () => { beforeEach(async(() => { const spy = jasmine.createSpyObj("EIService", [ - "getProducerIds", - "getJobsForProducer", + "getJobIds", + "getJobInfo", + "getConsumerStatus", ]); TestBed.configureTestingModule({ @@ -115,7 +103,7 @@ describe("JobsListComponent", () => { ], schemas: [CUSTOM_ELEMENTS_SCHEMA], declarations: [JobsListComponent], - providers: [{ provide: EIService, useValue: spy }, UiService], + providers: [{ provide: ConsumerService, useValue: spy }, UiService], }) .compileComponents() .then(() => { @@ -127,10 +115,11 @@ describe("JobsListComponent", () => { const expectedJob1Row = { jobId: "job1", - prodId: "producer1", + prodIds: "producer1", typeId: "type1", owner: "owner1", targetUri: "http://one", + status: "ENABLED" }; it("should create", () => { @@ -144,8 +133,8 @@ describe("JobsListComponent", () => { tick(0); const actualJobs: Job[] = component.jobs(); - expect(actualJobs.length).toEqual(4); - expect(actualJobs).toEqual([job1, job2, job3, job4]); + expect(actualJobs.length).toEqual(2); + expect(actualJobs).toEqual([job1, job2]); newSub.unsubscribe(); })); @@ -161,10 +150,11 @@ describe("JobsListComponent", () => { headerRow[0].getCellTextByColumnName().then((header) => { expect(header).toEqual({ jobId: "Job ID", - prodId: "Producer ID", + prodIds: "Producers", typeId: "Type ID", owner: "Owner", targetUri: "Target URI", + status: "Status" }); }); }); @@ -198,24 +188,11 @@ describe("JobsListComponent", () => { expectedJob1Row, { jobId: "job2", - prodId: "producer1", - typeId: "type2", - owner: "owner2", - targetUri: "http://two", - }, - { - jobId: "job1", - prodId: "producer2", + prodIds: "producer1", typeId: "type1", owner: "owner1", targetUri: "http://one", - }, - { - jobId: "job2", - prodId: "producer2", - typeId: "type2", - owner: "owner2", - targetUri: "http://two", + status: "ENABLED" }, ]; @@ -223,7 +200,7 @@ describe("JobsListComponent", () => { .getHarness(MatTableHarness.with({ selector: "#jobsTable" })) .then((loadTable) => { loadTable.getRows().then((jobRows) => { - expect(jobRows.length).toEqual(4); + expect(jobRows.length).toEqual(2); jobRows.forEach((row) => { row.getCellTextByColumnName().then((values) => { expect(expectedJobRows).toContain( @@ -238,29 +215,36 @@ describe("JobsListComponent", () => { it("should display default values for non required properties ", fakeAsync(() => { const jobMissingProperties = { - ei_job_identity: "job1", - ei_job_data: { + job_definition: { jobparam2: "value2_job2", jobparam3: "value3_job2", jobparam1: "value1_job2", }, - target_uri: "http://one", - } as EIJob; - - let eiServiceSpy = TestBed.inject(EIService) as jasmine.SpyObj; - eiServiceSpy.getProducerIds.and.returnValue(of(["producer1"])); - eiServiceSpy.getJobsForProducer.and.returnValue( - of([jobMissingProperties]) + job_result_uri: "http://one", + } as JobInfo; + const jobMissingPropertiesStatus = { + info_job_status: "ENABLED", + producers: ["producer1"], + } as ConsumerStatus; + + let consumerServiceSpy = TestBed.inject( + ConsumerService + ) as jasmine.SpyObj; + consumerServiceSpy.getJobIds.and.returnValue(of(["job1"])); + consumerServiceSpy.getJobInfo.and.returnValue(of(jobMissingProperties)); + consumerServiceSpy.getConsumerStatus.and.returnValue( + of(jobMissingPropertiesStatus) ); component.ngOnInit(); tick(0); const expectedJobRow = { jobId: "job1", - prodId: "producer1", + prodIds: "producer1", typeId: "< No type >", owner: "< No owner >", targetUri: "http://one", + status: "ENABLED", }; loader @@ -290,7 +274,7 @@ describe("JobsListComponent", () => { idFilter.setValue("1").then((_) => { tick(10); loadTable.getRows().then((jobRows) => { - expect(jobRows.length).toEqual(2); + expect(jobRows.length).toEqual(1); jobRows[0].getCellTextByColumnName().then((value) => { expect(expectedJob1Row).toEqual( jasmine.objectContaining(value) @@ -357,6 +341,26 @@ describe("JobsListComponent", () => { }); }); }); + + loader + .getHarness( + MatInputHarness.with({ selector: "#jobStatusFilter" }) + ) + .then((statusFilter) => { + tick(10); + statusFilter.setValue("ENA").then((_) => { + loadTable.getRows().then((jobRows) => { + expect(jobRows.length).toEqual(2); + jobRows[0].getCellTextByColumnName().then((value) => { + expect(expectedJob1Row).toEqual( + jasmine.objectContaining(value) + ); + statusFilter.setValue(""); + flushMicrotasks(); + }); + }); + }); + }); }); discardPeriodicTasks(); })); @@ -366,22 +370,26 @@ describe("JobsListComponent", () => { setServiceSpy(); tick(0); - loader.getHarness(MatSortHarness).then((sort) => { - sort.getSortHeaders({ sortDirection: "" }).then((headers) => { - expect(headers.length).toBe(5); + let sort = loader.getHarness(MatSortHarness); + tick(10); - headers[0].click().then((_) => { - headers[0].isActive().then((active) => { - expect(active).toBe(true); - }); - headers[0].getSortDirection().then((direction) => { - expect(direction).toBe("asc"); - }); + sort.then((value) => { + value.getSortHeaders({ sortDirection: "" }).then((headers) => { + expect(headers.length).toBe(6); + + 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"); }); }); }); @@ -392,38 +400,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) ); }); @@ -436,11 +444,12 @@ describe("JobsListComponent", () => { it("should not sort when clicking on filtering box", fakeAsync(() => { const expectedJobRow = { - jobId: "job1", - prodId: "producer2", + jobId: "job2", + prodIds: "producer1", typeId: "type1", owner: "owner1", targetUri: "http://one", + status: "ENABLED" }; setServiceSpy(); @@ -456,8 +465,8 @@ describe("JobsListComponent", () => { tick(10); idFilter.setValue("").then((_) => { loadTable.getRows().then((jobRows) => { - expect(jobRows.length).toEqual(4); - jobRows[2].getCellTextByColumnName().then((value) => { + expect(jobRows.length).toEqual(2); + jobRows[1].getCellTextByColumnName().then((value) => { expect(expectedJobRow).toEqual( jasmine.objectContaining(value) ); @@ -473,8 +482,8 @@ describe("JobsListComponent", () => { tick(10); typeIdFilter.setValue("").then((_) => { loadTable.getRows().then((jobRows) => { - expect(jobRows.length).toEqual(4); - jobRows[2].getCellTextByColumnName().then((value) => { + expect(jobRows.length).toEqual(2); + jobRows[1].getCellTextByColumnName().then((value) => { expect(expectedJobRow).toEqual( jasmine.objectContaining(value) ); @@ -488,8 +497,8 @@ describe("JobsListComponent", () => { tick(10); ownerFilter.setValue("").then((_) => { loadTable.getRows().then((jobRows) => { - expect(jobRows.length).toEqual(4); - jobRows[2].getCellTextByColumnName().then((value) => { + expect(jobRows.length).toEqual(2); + jobRows[1].getCellTextByColumnName().then((value) => { expect(expectedJobRow).toEqual( jasmine.objectContaining(value) ); @@ -505,8 +514,25 @@ describe("JobsListComponent", () => { tick(10); targetUriFilter.setValue("").then((_) => { loadTable.getRows().then((jobRows) => { - expect(jobRows.length).toEqual(4); - jobRows[2].getCellTextByColumnName().then((value) => { + expect(jobRows.length).toEqual(2); + jobRows[1].getCellTextByColumnName().then((value) => { + expect(expectedJobRow).toEqual( + jasmine.objectContaining(value) + ); + }); + }); + }); + }); + loader + .getHarness( + MatInputHarness.with({ selector: "#jobStatusFilter" }) + ) + .then((statusFilter) => { + tick(10); + statusFilter.setValue("").then((_) => { + loadTable.getRows().then((jobRows) => { + expect(jobRows.length).toEqual(2); + jobRows[1].getCellTextByColumnName().then((value) => { expect(expectedJobRow).toEqual( jasmine.objectContaining(value) ); @@ -521,52 +547,57 @@ describe("JobsListComponent", () => { describe("#paging", () => { it("should work properly on the table", fakeAsync(() => { - let eiServiceSpy = TestBed.inject( - EIService - ) as jasmine.SpyObj; - eiServiceSpy.getProducerIds.and.returnValue( - of(["producer1", "producer2"]) - ); - eiServiceSpy.getJobsForProducer.and.returnValue( - of([eijob1, eijob2, eijob1]) + let consumerServiceSpy = TestBed.inject( + ConsumerService + ) as jasmine.SpyObj; + consumerServiceSpy.getJobIds.and.returnValue( + of(["job1", "job2", "job3", "job4", "job5", "job6", "job7"]) ); - tick(0); + consumerServiceSpy.getJobInfo.and.returnValue(of(jobInfo1)); + consumerServiceSpy.getConsumerStatus.and.returnValue(of(jobStatus1)); + component.ngOnInit(); + tick(); loader.getHarness(MatPaginatorHarness).then((paging) => { paging.setPageSize(5); - + tick(1000); loader .getHarness(MatTableHarness.with({ selector: "#jobsTable" })) .then((loadTable) => { loadTable.getRows().then((jobRows) => { expect(jobRows.length).toEqual(5); }); + paging.goToNextPage(); + tick(1000); + loadTable.getRows().then((jobRows) => { - expect(jobRows.length).toEqual(1); + expect(jobRows.length).toEqual(2); jobRows[0].getCellTextByColumnName().then((value) => { const expectedRow = { - jobId: "job1", - prodId: "producer2", + jobId: "job6", + prodIds: "producer1", typeId: "type1", owner: "owner1", targetUri: "http://one", + status: "ENABLED", }; - expect(expectedRow).toContain( - jasmine.objectContaining(value) - ); + discardPeriodicTasks(); + expect(expectedRow).toEqual(jasmine.objectContaining(value)); }); }); }); }); - discardPeriodicTasks(); })); }); }); }); 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 consumerServiceSpy = TestBed.inject( + ConsumerService + ) as jasmine.SpyObj; + consumerServiceSpy.getJobIds.and.returnValue(of(["job1", "job2"])); + consumerServiceSpy.getJobInfo.and.returnValue(of(jobInfo1)); + consumerServiceSpy.getConsumerStatus.and.returnValue(of(jobStatus1)); }