updated filter tests
This commit is contained in:
parent
c21c91ee12
commit
daf9e4f788
|
@ -1,22 +1,26 @@
|
|||
import { filterByCat, filterByRating } from '$helpers';
|
||||
import { filterProductsBy } from '$helpers';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { testProducts, testTags } from './data';
|
||||
|
||||
describe('filterByCat', () => {
|
||||
describe('filterProducts', () => {
|
||||
test('filters products by passed category tag', () => {
|
||||
expect(filterByCat(testProducts, 'Exercise', testTags)).toHaveLength(1);
|
||||
expect(filterByCat(testProducts, 'Electronics', testTags)).toHaveLength(1);
|
||||
expect(
|
||||
filterProductsBy('tag', testProducts, { value: 'Exercise', $tags: testTags })
|
||||
).toHaveLength(1);
|
||||
expect(
|
||||
filterProductsBy('tag', testProducts, { value: 'Electronics', $tags: testTags })
|
||||
).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('returns unchanged products if tag does not exist', () => {
|
||||
expect(filterByCat(testProducts, 'grapes', testTags)).toEqual(testProducts);
|
||||
});
|
||||
});
|
||||
|
||||
describe('filterByRating', () => {
|
||||
test('filterByRating returns products only greater than # passed in', () => {
|
||||
expect(filterByRating(testProducts, 3)).toHaveLength(3);
|
||||
|
||||
expect(filterByRating(testProducts, 5)).toHaveLength(0);
|
||||
test('filter by tag returns unchanged products if tag does not exist', () => {
|
||||
expect(filterProductsBy('tag', testProducts, { value: 'grapes', $tags: testTags })).toEqual(
|
||||
testProducts
|
||||
);
|
||||
});
|
||||
|
||||
test('filters ratings only greater than # passed in', () => {
|
||||
expect(filterProductsBy('rating', testProducts, { value: 3 })).toHaveLength(3);
|
||||
|
||||
expect(filterProductsBy('rating', testProducts, { value: 5 })).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue