Fixing sorting test
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / ei-coordinator / jobs-list / jobs-list.component.spec.ts
index 927ab9d..e76f20b 100644 (file)
@@ -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";
@@ -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,6 +437,90 @@ 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", () => {
@@ -459,7 +563,6 @@ describe("JobsListComponent", () => {
               });
             });
         });
-
         discardPeriodicTasks();
       }));
     });