diff options
Diffstat (limited to 'spec/frontend/analytics/shared/utils_spec.js')
-rw-r--r-- | spec/frontend/analytics/shared/utils_spec.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/frontend/analytics/shared/utils_spec.js b/spec/frontend/analytics/shared/utils_spec.js new file mode 100644 index 00000000000..e3293f2d8bd --- /dev/null +++ b/spec/frontend/analytics/shared/utils_spec.js @@ -0,0 +1,24 @@ +import { filterBySearchTerm } from '~/analytics/shared/utils'; + +describe('filterBySearchTerm', () => { + const data = [ + { name: 'eins', title: 'one' }, + { name: 'zwei', title: 'two' }, + { name: 'drei', title: 'three' }, + ]; + const searchTerm = 'rei'; + + it('filters data by `name` for the provided search term', () => { + expect(filterBySearchTerm(data, searchTerm)).toEqual([data[2]]); + }); + + it('with no search term returns the data', () => { + ['', null].forEach((search) => { + expect(filterBySearchTerm(data, search)).toEqual(data); + }); + }); + + it('with a key, filters by the provided key', () => { + expect(filterBySearchTerm(data, 'ne', 'title')).toEqual([data[0]]); + }); +}); |