+ describe("#jobsTable", () => {
+ it("should contain data after initialization", fakeAsync(() => {
+ setServiceSpy();
+ component.ngOnInit();
+ tick(0);
+
+ const expectedJobRows = [
+ expectedJob1Row,
+ {
+ jobId: "job2",
+ prodId: "producer1",
+ typeId: "type2",
+ owner: "owner2",
+ targetUri: "http://two",
+ },
+ {
+ jobId: "job1",
+ prodId: "producer2",
+ typeId: "type1",
+ owner: "owner1",
+ targetUri: "http://one",
+ },
+ {
+ jobId: "job2",
+ prodId: "producer2",
+ typeId: "type2",
+ owner: "owner2",
+ targetUri: "http://two",
+ },
+ ];
+
+ loader
+ .getHarness(MatTableHarness.with({ selector: "#jobsTable" }))
+ .then((loadTable) => {
+ loadTable.getRows().then((jobRows) => {
+ expect(jobRows.length).toEqual(4);
+ jobRows.forEach((row) => {
+ row.getCellTextByColumnName().then((values) => {
+ expect(expectedJobRows).toContain(
+ jasmine.objectContaining(values)
+ );
+ });
+ });
+ });
+ });
+ discardPeriodicTasks();
+ }));
+
+ it("should display default values for non required properties ", fakeAsync(() => {
+ const jobMissingProperties = {
+ ei_job_identity: "job1",
+ ei_job_data: {
+ jobparam2: "value2_job2",
+ jobparam3: "value3_job2",
+ jobparam1: "value1_job2",
+ },
+ target_uri: "http://one",
+ } as EIJob;
+
+ let eiServiceSpy = TestBed.inject(EIService) as jasmine.SpyObj<EIService>;
+ eiServiceSpy.getProducerIds.and.returnValue(of(["producer1"]));
+ eiServiceSpy.getJobsForProducer.and.returnValue(
+ of([jobMissingProperties])
+ );
+
+ component.ngOnInit();
+ tick(0);
+ const expectedJobRow = {
+ jobId: "job1",
+ prodId: "producer1",
+ typeId: "< No type >",
+ owner: "< No owner >",
+ targetUri: "http://one",
+ };
+
+ loader
+ .getHarness(MatTableHarness.with({ selector: "#jobsTable" }))
+ .then((loadTable) => {
+ loadTable.getRows().then((jobRows) => {
+ jobRows[0].getCellTextByColumnName().then((value) => {
+ expect(expectedJobRow).toContain(jasmine.objectContaining(value));
+ });
+ });
+ });
+ discardPeriodicTasks();
+ }));
+
+ it("filtering", fakeAsync(() => {
+ setServiceSpy();
+ component.ngOnInit();
+ tick(0);
+
+ loader
+ .getHarness(MatTableHarness.with({ selector: "#jobsTable" }))
+ .then((loadTable) => {
+ 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)
+ );
+ });
+ });
+ 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)
+ );
+ });
+ });
+ 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)
+ );
+ });
+ });
+ 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)
+ );
+ });
+ });
+ targetUriFilter.setValue("");
+ });
+ });
+
+ discardPeriodicTasks();
+ }));
+
+ describe("#sorting", () => {
+ it("should verify sort functionality on the table", fakeAsync(() => {
+ setServiceSpy();
+ tick(0);
+
+ loader.getHarness(MatSortHarness).then((sort) => {
+ sort.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().then((_) => {
+ headers[0].getSortDirection().then((direction) => {
+ expect(direction).toBe("desc");
+ });
+ });
+ });
+ });
+ discardPeriodicTasks();
+ }));
+
+ it("should sort table asc and desc by first header", fakeAsync(() => {
+ setServiceSpy();
+ tick(0);
+
+ loader.getHarness(MatSortHarness).then((sort) => {
+ 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");
+ });
+ });
+ loadTable.getRows().then((jobRows) => {
+ jobRows[0].getCellTextByColumnName().then((value) => {
+ expect(expectedJob1Row).toContain(
+ jasmine.objectContaining(value)
+ );
+ });
+ });
+ headers[0].click().then((_) => {
+ headers[0].getSortDirection().then((direction) => {
+ expect(direction).toBe("desc");
+ });
+ });
+ loadTable.getRows().then((jobRows) => {
+ jobRows[jobRows.length - 1]
+ .getCellTextByColumnName()
+ .then((value) => {
+ expect(expectedJob1Row).toContain(
+ jasmine.objectContaining(value)
+ );
+ });
+ });
+ });
+ });
+ });
+ discardPeriodicTasks();
+ }));
+
+ it("should not sort when clicking on filtering box", fakeAsync(() => {
+ setServiceSpy();
+ component.ngOnInit();
+ tick(0);
+
+ loader
+ .getHarness(MatTableHarness.with({ selector: "#jobsTable" }))
+ .then((loadTable) => {
+ loadTable.getRows().then((jobRows) => {
+ let jobIds, jobTypeIds, jobOwner, jobTargetUri: String[];
+ for (let i = 0; i < jobRows.length; i++) {
+ jobRows[i].getCellTextByColumnName().then((value) => {
+ jobIds.push(value[0]);
+ jobTypeIds.push(value[2]);
+ jobOwner.push(value[3]);
+ jobTargetUri.push(value[4]);
+ });
+ };
+ loader
+ .getHarness(MatInputHarness.with({ selector: "#jobIdFilter"}))
+ .then((idFilter) => {
+ let unfilteredJobIds: String[];
+ idFilter.setValue("");
+ for (let i = 0; i < jobRows.length; i++) {
+ jobRows[i].getCellTextByColumnName().then((value) => {
+ unfilteredJobIds.push(value[0]);
+ });
+ };
+ expect(unfilteredJobIds).toBe(jobIds);
+ });
+ loader
+ .getHarness(MatInputHarness.with({ selector: "#jobTypeIdFilter"}))
+ .then((idFilter) => {
+ let unfilteredJobTypeIds: String[];
+ idFilter.setValue("");
+ for (let i = 0; i < jobRows.length; i++) {
+ jobRows[i].getCellTextByColumnName().then((value) => {
+ unfilteredJobTypeIds.push(value[2]);
+ });
+ };
+ expect(unfilteredJobTypeIds).toBe(jobTypeIds);
+ });
+ loader
+ .getHarness(MatInputHarness.with({ selector: "#jobOwnerFilter"}))
+ .then((idFilter) => {
+ let unfilteredJobOwner: String[];
+ idFilter.setValue("");
+ for (let i = 0; i < jobRows.length; i++) {
+ jobRows[i].getCellTextByColumnName().then((value) => {
+ unfilteredJobOwner.push(value[3]);
+ });
+ };
+ expect(unfilteredJobOwner).toBe(jobOwner);
+ });
+ loader
+ .getHarness(MatInputHarness.with({ selector: "#jobTargetUriFilter"}))
+ .then((idFilter) => {
+ let unfilteredJobTargetUri: String[];
+ idFilter.setValue("");
+ for (let i = 0; i < jobRows.length; i++) {
+ jobRows[i].getCellTextByColumnName().then((value) => {
+ unfilteredJobTargetUri.push(value[4]);
+ });
+ };
+ expect(unfilteredJobTargetUri).toBe(jobTargetUri);
+ });
+ });
+ });
+ discardPeriodicTasks();
+ }));