|
| 1 | +import { describe, it, expect } from 'vitest' |
| 2 | +import { FilterFn } from '../src' |
| 3 | +import { shouldAutoRemoveFilter } from '../src/features/ColumnFiltering' |
| 4 | + |
| 5 | +const customAutoRemove: FilterFn<any> = (row, columnId, filterValue) => { |
| 6 | + return filterValue === row.getValue(columnId) |
| 7 | +} |
| 8 | +customAutoRemove.autoRemove = (val) => val === undefined |
| 9 | + |
| 10 | +const noAutoRemove: FilterFn<any> = (row, columnId, filterValue) => { |
| 11 | + return filterValue === row.getValue(columnId) |
| 12 | +} |
| 13 | + |
| 14 | +describe('shouldAutoRemoveFilter', () => { |
| 15 | + describe('with custom autoRemove defined', () => { |
| 16 | + it('should use custom autoRemove result for empty string', () => { |
| 17 | + expect(shouldAutoRemoveFilter(customAutoRemove, '')).toBe(false) |
| 18 | + }) |
| 19 | + |
| 20 | + it('should use custom autoRemove result for undefined', () => { |
| 21 | + expect(shouldAutoRemoveFilter(customAutoRemove, undefined)).toBe(true) |
| 22 | + }) |
| 23 | + |
| 24 | + it('should use custom autoRemove result for null', () => { |
| 25 | + expect(shouldAutoRemoveFilter(customAutoRemove, null)).toBe(false) |
| 26 | + }) |
| 27 | + |
| 28 | + it('should use custom autoRemove result for zero', () => { |
| 29 | + expect(shouldAutoRemoveFilter(customAutoRemove, 0)).toBe(false) |
| 30 | + }) |
| 31 | + |
| 32 | + it('should use custom autoRemove result for false', () => { |
| 33 | + expect(shouldAutoRemoveFilter(customAutoRemove, false)).toBe(false) |
| 34 | + }) |
| 35 | + }) |
| 36 | + |
| 37 | + describe('without autoRemove defined', () => { |
| 38 | + it('should remove undefined filter', () => { |
| 39 | + expect(shouldAutoRemoveFilter(noAutoRemove, undefined)).toBe(true) |
| 40 | + }) |
| 41 | + |
| 42 | + it('should remove empty string filter', () => { |
| 43 | + expect(shouldAutoRemoveFilter(noAutoRemove, '')).toBe(true) |
| 44 | + }) |
| 45 | + |
| 46 | + it('should keep null filter', () => { |
| 47 | + expect(shouldAutoRemoveFilter(noAutoRemove, null)).toBe(false) |
| 48 | + }) |
| 49 | + }) |
| 50 | + |
| 51 | + describe('without filterFn', () => { |
| 52 | + it('should remove undefined filter', () => { |
| 53 | + expect(shouldAutoRemoveFilter(undefined, undefined)).toBe(true) |
| 54 | + }) |
| 55 | + |
| 56 | + it('should remove empty string filter', () => { |
| 57 | + expect(shouldAutoRemoveFilter(undefined, '')).toBe(true) |
| 58 | + }) |
| 59 | + }) |
| 60 | +}) |
0 commit comments