summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/filter.pipe.spec.ts
blob: 58d7ff95fcdbf77c44c27ee5493384081b1b8131 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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']);
  });
});