Skip to content

Commit

Permalink
Merge branch 'P2-903-Tracking-of-outcomes-achievements-against-target…
Browse files Browse the repository at this point in the history
…s' into dev
  • Loading branch information
xKeCo committed Nov 27, 2024
2 parents 3e15f88 + 5bb4bdf commit 2685af1
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,122 @@ describe('FilterIndicatorBySearchPipe', () => {
pipe = new FilterIndicatorBySearchPipe();
});

it('should create an instance', () => {
it('should create', () => {
expect(pipe).toBeTruthy();
});

it('should return an empty array if input is not an array', () => {
const result = pipe.transform(null, 'search');
expect(result).toEqual([]);
it('should return empty array if list is not an array', () => {
expect(pipe.transform(null as any, '', false)).toEqual([]);
expect(pipe.transform(undefined as any, '', false)).toEqual([]);
});

it('should return the original list if searchFilter is empty', () => {
const list = [{ toc_result_description: 'Test', toc_results: [] }];
const result = pipe.transform(list, '');
expect(result).toBeDefined();
expect(result).toEqual(list);
});

it('should filter the list based on searchFilter', () => {
const list = [
{ toc_result_description: 'Test1', toc_results: [{ toc_result_description: 'Desc1', indicators: [] }] },
{ toc_result_description: 'Test2', toc_results: [{ toc_result_description: 'Desc2', indicators: [] }] }
];
const result = pipe.transform(list, 'Desc1');
expect(result.length).toBe(1);
expect(result[0].toc_result_description).toBe('Test1');
});

it('should handle isWPsTable flag correctly', () => {
const list = [
describe('Default filtering (non-WPsTable)', () => {
const mockList = [
{
toc_result_description: 'Test1',
toc_results: [
toc_result_description: 'Result 1',
indicators: [
{
indicator_name: 'Indicator 1',
indicator_description: 'Description 1',
is_indicator_custom: true
}
]
},
{
toc_result_description: 'Result 2',
indicators: [
{
toc_result_description: 'Desc1',
indicators: [{ indicator_description: 'Indicator1', isVisible: false }]
indicator_name: 'Indicator 2',
indicator_description: 'Description 2',
is_indicator_custom: false
}
]
}
];
const result = pipe.transform(list, 'Indicator1', true);
expect(result.length).toBe(1);
expect(result[0].toc_results[0].indicators[0].isVisible).toBe(true);

it('should return full list when no search filter', () => {
const result = pipe.transform(mockList, '', false);
expect(result.length).toBe(2);
});

it('should filter by result description', () => {
const result = pipe.transform(mockList, 'Result 1', false);
expect(result.length).toBe(1);
expect(result[0].toc_result_description).toBe('Result 1');
});

it('should be case insensitive', () => {
const result = pipe.transform(mockList, 'result 1', false);
expect(result.length).toBe(1);
expect(result[0].toc_result_description).toBe('Result 1');
});
});

it('should reset indicators if searchFilter is empty and isWPsTable is true', () => {
const list = [
describe('WPsTable filtering', () => {
const mockWPsList = [
{
toc_results: [
{
toc_result_description: 'WP Result 1',
indicators: [{ indicator_description: 'WP Indicator 1' }, { indicator_description: 'WP Indicator 2' }]
}
]
},
{
toc_result_description: 'Test1',
toc_results: [
{
toc_result_description: 'Desc1',
indicators: [{ indicator_description: 'Indicator1', isVisible: true }]
toc_result_description: 'WP Result 2',
indicators: [{ indicator_description: 'WP Indicator 3' }]
}
]
}
];
pipe.transform(list, '', true);
expect(list[0].toc_results[0].indicators[0].isVisible).toBe(true);

it('should return full list when no search filter', () => {
const result = pipe.transform(mockWPsList, '', true);
expect(result.length).toBe(2);
});

it('should filter by result description in WPsTable mode', () => {
const result = pipe.transform(mockWPsList, 'WP Result 1', true);
expect(result.length).toBe(1);
expect(result[0].toc_results[0].toc_result_description).toBe('WP Result 1');
});

it('should filter by indicator description in WPsTable mode', () => {
const result = pipe.transform(mockWPsList, 'WP Indicator 1', true);
expect(result.length).toBe(1);
expect(result[0].toc_results[0].indicators[0].indicator_description).toBe('WP Indicator 1');
});

it('should preserve original indicators when resetting', () => {
pipe.transform(mockWPsList, 'WP Indicator 1', true);
const result = pipe.transform(mockWPsList, '', true);

expect(result[0].toc_results[0].indicators.length).toBe(2);
expect(result[1].toc_results[0].indicators.length).toBe(1);
});

it('should mark indicators as visible based on search', () => {
const result = pipe.transform(mockWPsList, 'WP Indicator 1', true);
expect(result[0].toc_results[0].indicators[0].isVisible).toBe(true);
});
});

describe('Edge cases', () => {
it('should handle empty lists', () => {
expect(pipe.transform([], '', false)).toEqual([]);
expect(pipe.transform([], 'search', true)).toEqual([]);
});

it('should handle missing properties gracefully', () => {
const incompleteList = [{ toc_results: [] }, { toc_results: null }, {}];
expect(() => pipe.transform(incompleteList, 'search', false)).not.toThrow(TypeError);
});

it('should handle undefined search filter', () => {
const mockList = [{ toc_result_description: 'Test' }];
expect(() => pipe.transform(mockList, undefined as any, false)).not.toThrow();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class FilterIndicatorBySearchPipe implements PipeTransform {
}

private isIndicatorVisible(indicator: any, searchUpper: string, result: any): boolean {
// return indicator.indicator_description.toUpperCase().includes(searchUpper);
return (
!searchUpper ||
indicator.indicator_description.toUpperCase().includes(searchUpper) ||
Expand Down

0 comments on commit 2685af1

Please sign in to comment.