diff options
Diffstat (limited to 'src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/filter.pipe.spec.ts')
-rw-r--r-- | src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/filter.pipe.spec.ts | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/filter.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/filter.pipe.spec.ts new file mode 100644 index 000000000..58d7ff95f --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/filter.pipe.spec.ts @@ -0,0 +1,54 @@ +import { FilterPipe } from './filter.pipe'; + +describe('FilterPipe', () => { + const pipe = new FilterPipe(); + + it('create an instance', () => { + expect(pipe).toBeTruthy(); + }); + + it('filter words with "foo"', () => { + const value = ['foo', 'bar', 'foobar']; + const filters = [ + { + value: 'foo', + applyFilter: (row: any[], val: any) => { + return row.indexOf(val) !== -1; + } + } + ]; + expect(pipe.transform(value, filters)).toEqual(['foo', 'foobar']); + }); + + it('filter words with "foo" and "bar"', () => { + const value = ['foo', 'bar', 'foobar']; + const filters = [ + { + value: 'foo', + applyFilter: (row: any[], val: any) => { + return row.indexOf(val) !== -1; + } + }, + { + value: 'bar', + applyFilter: (row: any[], val: any) => { + return row.indexOf(val) !== -1; + } + } + ]; + expect(pipe.transform(value, filters)).toEqual(['foobar']); + }); + + it('filter with no value', () => { + const value = ['foo', 'bar', 'foobar']; + const filters = [ + { + value: '', + applyFilter: () => { + return false; + } + } + ]; + expect(pipe.transform(value, filters)).toEqual(['foo', 'bar', 'foobar']); + }); +}); |