Skip to content

Commit

Permalink
improved unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SheenaMalhotra182 committed Jul 15, 2023
1 parent 37afb1d commit ff78347
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { mockError, fakeProcessFiltersResponse } from '../../mock';
import { FilterProcessRepresentationModel } from '../models/filter-process.model';
import { ProcessFilterService } from './process-filter.service';
import { CoreTestingModule } from '@alfresco/adf-core';
import { setupTestBed, CoreTestingModule } from '@alfresco/adf-core';
import { ProcessInstanceFilterRepresentation } from '@alfresco/js-api';

declare let jasmine: any;

Expand Down Expand Up @@ -236,17 +238,35 @@ describe('Process filter', () => {
});

describe('isFilterAlreadyExisting', () => {
let dummyProcessFilters;
let dummyProcessFilters : FilterProcessRepresentationModel[];
let filterRepresentationData : ProcessInstanceFilterRepresentation;

beforeEach(() => {
dummyProcessFilters = [
{ name: 'processFilter1' },
{ name: 'processiFlter2' }
];
{
appId: 0,
filter: filterRepresentationData,
icon: 'fa-random',
id: 8,
index: 0,
name: 'Running',
recent: false,
hasFilter: () => {
return true;
}
}
]

filterRepresentationData = {
name : '',
sort : 'created-desc',
state : 'running'
}

});

it('should return true if the filter already exists', () => {
const processFilterName = 'processiFlter2';
it('should return true if the process filter already exists', () => {
const processFilterName = 'Running';
const isFilterAlreadyExistingSpy = spyOn<any>(service, 'isFilterAlreadyExisting').and.callThrough();

const result = service.isFilterAlreadyExisting(dummyProcessFilters, processFilterName);
Expand All @@ -255,8 +275,8 @@ describe('Process filter', () => {
expect(result).toBe(true);
});

it('should return false if the filter does not exist', () => {
const processFilterName = 'processiFlter3';
it('should return false if the process filter does not exist', () => {
const processFilterName = 'All';
const isFilterAlreadyExistingSpy = spyOn<any>(service, 'isFilterAlreadyExisting').and.callThrough();

const result = service.isFilterAlreadyExisting(dummyProcessFilters, processFilterName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class ProcessFilterService {
});
}

isFilterAlreadyExisting(filters: any, filterName: string): boolean {
isFilterAlreadyExisting(filters: FilterProcessRepresentationModel[], filterName: string): boolean {
return filters.some((existingFilter) => existingFilter.name === filterName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { FilterRepresentationModel } from '../models/filter.model';
import { TaskFilterService } from './task-filter.service';
import { CoreModule } from '@alfresco/adf-core';
import { ProcessTestingModule } from '../../testing/process.testing.module';
import { TaskFilterRepresentation } from '@alfresco/js-api';

declare let jasmine: any;

Expand Down Expand Up @@ -253,17 +254,36 @@ describe('Activiti Task filter Service', () => {
});

describe('isFilterAlreadyExisting', () => {
let dummyTaskFilters;
let dummyTaskFilters : FilterRepresentationModel[];
let filterRepresentationData : TaskFilterRepresentation;
;


beforeEach(() => {
dummyTaskFilters = [
{ name: 'taskFilter1' },
{ name: 'taskFilter2' }
];
{
appId: 0,
filter: filterRepresentationData,
icon: 'fa-random',
id: 9,
index: 0,
name: 'My Tasks',
recent: false,
hasFilter: () => {
return true;
}
}
]

filterRepresentationData = {
name : '',
sort : 'created-desc',
state : 'running'
}
});

it('should return true if the filter already exists', () => {
const taskFilterName = 'taskFilter2';
it('should return true if the task filter already exists', () => {
const taskFilterName = 'My Tasks';
const isFilterAlreadyExistingSpy = spyOn<any>(service, 'isFilterAlreadyExisting').and.callThrough();

const result = service.isFilterAlreadyExisting(dummyTaskFilters, taskFilterName);
Expand All @@ -272,8 +292,8 @@ describe('Activiti Task filter Service', () => {
expect(result).toBe(true);
});

it('should return false if the filter does not exist', () => {
const taskFilterName = 'taskFilter3';
it('should return false if the task filter does not exist', () => {
const taskFilterName = 'Involved Tasks';
const isFilterAlreadyExistingSpy = spyOn<any>(service, 'isFilterAlreadyExisting').and.callThrough();

const result = service.isFilterAlreadyExisting(dummyTaskFilters, taskFilterName);
Expand Down

0 comments on commit ff78347

Please sign in to comment.