Skip to content

Commit

Permalink
Fix/Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adomi committed Nov 11, 2020
1 parent 954ecb5 commit 46d0179
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe('ProcessFiltersCloudComponent', () => {
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);

component.filterClick.subscribe((res) => {
component.filterSelected.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeRunningProcesses');
Expand All @@ -217,7 +217,7 @@ describe('ProcessFiltersCloudComponent', () => {

fixture.detectChanges();

component.filterClick.subscribe((res) => {
component.filterSelected.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeCompletedProcesses');
Expand All @@ -236,7 +236,7 @@ describe('ProcessFiltersCloudComponent', () => {
const change = new SimpleChange(null, appName, true);
fixture.detectChanges();

component.filterClick.subscribe((res) => {
component.filterSelected.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeCompletedProcesses');
Expand All @@ -255,7 +255,7 @@ describe('ProcessFiltersCloudComponent', () => {
const change = new SimpleChange(null, appName, true);
fixture.detectChanges();

component.filterClick.subscribe((res) => {
component.filterSelected.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeCompletedProcesses');
Expand All @@ -275,7 +275,7 @@ describe('ProcessFiltersCloudComponent', () => {
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();

component.filterClick.subscribe((res) => {
component.filterClicked.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeAllProcesses');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,22 +254,35 @@ describe('ServiceTaskFiltersCloudComponent', () => {

}));

it('should emit an event when a filter is selected', async(() => {
it('should emit the selected filter based on the filterParam input', async () => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
spyOn(component.filterSelected, 'emit');

component.filterParam = { id: '12' };
const filterParam = { id: '10' };
const change = new SimpleChange(null, filterParam, true);
component.filterParam = filterParam;

const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({ 'appName': change });
component.ngOnChanges({ 'filterParam': change });
fixture.detectChanges();

expect(component.filterSelected.emit).toHaveBeenCalledWith(fakeGlobalServiceFilters[0]);
});

it('should emit the clicked filter', async () => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
spyOn(component.filterClicked, 'emit');

fixture.detectChanges();
spyOn(component, 'selectFilterAndEmit').and.stub();
const filterButton = fixture.debugElement.nativeElement.querySelector(`[data-automation-id="${fakeGlobalServiceFilters[1].key}_filter"]`);
await fixture.whenStable();

const filterButton = fixture.debugElement.nativeElement.querySelector(`[data-automation-id="${fakeGlobalServiceFilters[0].key}_filter"]`);
filterButton.click();
expect(component.selectFilterAndEmit).toHaveBeenCalledWith(fakeGlobalServiceFilters[1]);
}));

fixture.detectChanges();
await fixture.whenStable();

expect(component.filterClicked.emit).toHaveBeenCalledWith(fakeGlobalServiceFilters[0]);
});

it('should reset the filter when the param is undefined', async(() => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class ServiceTaskFiltersCloudComponent extends BaseTaskFiltersCloudCompon
}

/**
* Selects and emits the filter selected by the user
* Selects and emits the clicked filter.
*/
public onFilterClick(filter: FilterParamsModel) {
if (filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,22 +254,35 @@ describe('TaskFiltersCloudComponent', () => {

}));

it('should emit an event when a filter is selected', async(() => {
it('should emit the selected filter based on the filterParam input', async(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
spyOn(component.filterSelected, 'emit');

component.filterParam = { id: '12' };
const filterParam = { id: '10' };
const change = new SimpleChange(null, filterParam, true);
component.filterParam = filterParam;

const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({ 'appName': change });
component.ngOnChanges({ 'filterParam': change });
fixture.detectChanges();

expect(component.filterSelected.emit).toHaveBeenCalledWith(fakeGlobalFilter[0]);
}));

it('should emit the clicked filter', async () => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
spyOn(component.filterClicked, 'emit');

fixture.detectChanges();
spyOn(component, 'selectFilterAndEmit').and.stub();
const filterButton = fixture.debugElement.nativeElement.querySelector(`[data-automation-id="${fakeGlobalFilter[1].key}_filter"]`);
await fixture.whenStable();

const filterButton = fixture.debugElement.nativeElement.querySelector(`[data-automation-id="${fakeGlobalFilter[0].key}_filter"]`);
filterButton.click();
expect(component.selectFilterAndEmit).toHaveBeenCalledWith(fakeGlobalFilter[1]);
}));

fixture.detectChanges();
await fixture.whenStable();

expect(component.filterClicked.emit).toHaveBeenCalledWith(fakeGlobalFilter[0]);
});

it('should reset the filter when the param is undefined', async(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
}

/**
* Selects and emits the filter selected by the user
* Selects and emits the clicked filter.
*/
public onFilterClick(filter: FilterParamsModel) {
if (filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ export const fakeGlobalFilter = [
name: 'FakeInvolvedTasks',
key: 'fake-involved-tasks',
icon: 'adjust',
id: 10,
id: '10',
status: 'open',
assignee: 'fake-involved'
}),
new TaskFilterCloudModel({
name: 'FakeMyTasks1',
key: 'fake-my-tast1',
icon: 'done',
id: 11,
id: '11',
status: 'open',
assignee: 'fake-assignee'
}),
new TaskFilterCloudModel({
name: 'FakeMyTasks2',
key: 'fake-my-tast2',
icon: 'inbox',
id: 12,
id: '12',
status: 'open',
assignee: 'fake-assignee'
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe('ProcessFiltersComponent', () => {
filter: { state: 'open', assignment: 'fake-involved' }
});

filterList.filterClick.subscribe((filter: FilterProcessRepresentationModel) => {
filterList.filterClicked.subscribe((filter: FilterProcessRepresentationModel) => {
expect(filter).toBeDefined();
expect(filter).toEqual(currentFilter);
expect(filterList.currentFilter).toEqual(currentFilter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ describe('TaskFiltersComponent', () => {
it('should emit an event when a filter is selected', (done) => {
const currentFilter = fakeGlobalFilter[0];
component.filters = fakeGlobalFilter;
component.filterClick.subscribe((filter: FilterRepresentationModel) => {
component.filterClicked.subscribe((filter: FilterRepresentationModel) => {
expect(filter).toBeDefined();
expect(filter).toEqual(currentFilter);
expect(component.currentFilter).toEqual(currentFilter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ export class TaskFiltersComponent implements OnInit, OnChanges {
this.filterSelected.emit(this.currentFilter);
}

/**
* Selects and emits the clicked filter.
*/
onFilterClick(filter: FilterParamsModel) {
this.selectFilter(filter);
this.filterClicked.emit(this.currentFilter);
Expand Down

0 comments on commit 46d0179

Please sign in to comment.