fakeAsync,
TestBed,
tick,
+ flushMicrotasks,
} from "@angular/core/testing";
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { MatFormFieldModule } from "@angular/material/form-field";
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<JobsListComponent>;
-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"],
} 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"],
} as Job;
describe("JobsListComponent", () => {
beforeEach(async(() => {
const spy = jasmine.createSpyObj("EIService", [
- "getProducerIds",
- "getJobsForProducer",
+ "getJobIds",
+ "getJobInfo",
+ "getConsumerStatus",
]);
TestBed.configureTestingModule({
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
declarations: [JobsListComponent],
- providers: [{ provide: EIService, useValue: spy }, UiService],
+ providers: [{ provide: ConsumerService, useValue: spy }, UiService],
})
.compileComponents()
.then(() => {
const expectedJob1Row = {
jobId: "job1",
- prodId: "producer1",
+ prodIds: "producer1",
typeId: "type1",
owner: "owner1",
targetUri: "http://one",
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();
}));
headerRow[0].getCellTextByColumnName().then((header) => {
expect(header).toEqual({
jobId: "Job ID",
- prodId: "Producer ID",
+ prodIds: "Producers",
typeId: "Type ID",
owner: "Owner",
targetUri: "Target URI",
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",
- },
];
loader
.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(
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<EIService>;
- 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<ConsumerService>;
+ 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",
.then((loadTable) => {
loadTable.getRows().then((jobRows) => {
jobRows[0].getCellTextByColumnName().then((value) => {
- expect(expectedJobRow).toContain(jasmine.objectContaining(value));
+ expect(expectedJobRow).toEqual(jasmine.objectContaining(value));
});
});
});
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(1);
+ 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();
}));
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");
});
});
});
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)
);
});
});
discardPeriodicTasks();
}));
+
+ it("should not sort when clicking on filtering box", fakeAsync(() => {
+ const expectedJobRow = {
+ jobId: "job2",
+ prodIds: "producer1",
+ 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(2);
+ jobRows[1].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(2);
+ jobRows[1].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(2);
+ jobRows[1].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(2);
+ jobRows[1].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<EIService>;
- eiServiceSpy.getProducerIds.and.returnValue(
- of(["producer1", "producer2"])
- );
- eiServiceSpy.getJobsForProducer.and.returnValue(
- of([eijob1, eijob2, eijob1])
+ let consumerServiceSpy = TestBed.inject(
+ ConsumerService
+ ) as jasmine.SpyObj<ConsumerService>;
+ 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",
};
- expect(expectedRow).toContain(
- jasmine.objectContaining(value)
- );
+ discardPeriodicTasks();
+ expect(expectedRow).toEqual(jasmine.objectContaining(value));
});
});
});
});
-
- discardPeriodicTasks();
}));
});
});
});
function setServiceSpy() {
- let eiServiceSpy = TestBed.inject(EIService) as jasmine.SpyObj<EIService>;
- eiServiceSpy.getProducerIds.and.returnValue(of(["producer1", "producer2"]));
- eiServiceSpy.getJobsForProducer.and.returnValue(of([eijob1, eijob2]));
+ let consumerServiceSpy = TestBed.inject(
+ ConsumerService
+ ) as jasmine.SpyObj<ConsumerService>;
+ consumerServiceSpy.getJobIds.and.returnValue(of(["job1", "job2"]));
+ consumerServiceSpy.getJobInfo.and.returnValue(of(jobInfo1));
+ consumerServiceSpy.getConsumerStatus.and.returnValue(of(jobStatus1));
}