utils.test.tsā¢1.58 kB
import { matchesAnyTag } from '../src/utils';
describe('hasMatchingTag', () => {
test('should return true when there is a common tag', () => {
const tags = ['apple š', 'banana š', 'orange š'];
const filteringTags = ['banana š', 'grape š'];
expect(matchesAnyTag(tags, filteringTags)).toBeTruthy();
});
test('should return false when there are no common tags', () => {
const tags = ['apple š', 'banana š', 'orange š'];
const filteringTags = ['grape š', 'kiwi š„'];
expect(matchesAnyTag(tags, filteringTags)).toBeFalsy();
});
test('should return false when tags array is empty (i.e. deactivated tool)', () => {
const tags: string[] = [];
const filteringTags = ['apple š', 'banana š'];
expect(matchesAnyTag(tags, filteringTags)).toBeFalsy();
});
test('should return true when no filtering tag are provided (i.e. all tools are activated)', () => {
const tags = ['apple š', 'banana š', 'orange š'];
const filteringTags: string[] = [];
expect(matchesAnyTag(tags, filteringTags)).toBeTruthy();
});
test('should match even if casing if different', () => {
const tags = ['banana š'];
const filteringTags = ['BANANA š'];
expect(matchesAnyTag(tags, filteringTags)).toBeTruthy();
});
test('should return true when multiple common tags exist', () => {
const tags = ['apple š', 'banana š', 'orange š'];
const filteringTags = ['banana š', 'orange š', 'grape š'];
expect(matchesAnyTag(tags, filteringTags)).toBeTruthy();
});
});