+ 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).toEqual(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) => {
+ 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();
+ });
+ });
+ });
+ });
+
+ loader
+ .getHarness(MatInputHarness.with({ selector: "#jobTypeIdFilter" }))
+ .then((typeIdFilter) => {
+ 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();
+ });
+ });
+ });
+ });
+
+ loader
+ .getHarness(MatInputHarness.with({ selector: "#jobOwnerFilter" }))
+ .then((ownerFilter) => {
+ 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();
+ });
+ });
+ });
+ });
+
+ loader
+ .getHarness(
+ MatInputHarness.with({ selector: "#jobTargetUriFilter" })
+ )
+ .then((targetUriFilter) => {
+ 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();
+ });
+ });
+ });
+ });
+ });
+ 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(() => {
+ 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();
+ }));