1import { FieldType } from '../../types/dataFrame'; 2import { fieldMatchers } from '../matchers'; 3import { simpleSeriesWithTypes } from './fieldTypeMatcher.test'; 4import { FieldMatcherID, MatcherID } from './ids'; 5import { MatcherConfig } from '../../types/transformations'; 6 7const matchesNumberConfig: MatcherConfig = { 8 id: FieldMatcherID.byType, 9 options: FieldType.number, 10}; 11const matchesTimeConfig: MatcherConfig = { 12 id: FieldMatcherID.byType, 13 options: FieldType.time, 14}; 15const both = [matchesNumberConfig, matchesTimeConfig]; 16const allFrames = [simpleSeriesWithTypes]; 17 18describe('Check Predicates', () => { 19 it('can not match both', () => { 20 const matches = fieldMatchers.get(MatcherID.allMatch).get(both); 21 for (const field of simpleSeriesWithTypes.fields) { 22 expect(matches(field, simpleSeriesWithTypes, allFrames)).toBe(false); 23 } 24 }); 25 26 it('match either time or number', () => { 27 const matches = fieldMatchers.get(MatcherID.anyMatch).get(both); 28 for (const field of simpleSeriesWithTypes.fields) { 29 expect(matches(field, simpleSeriesWithTypes, allFrames)).toBe( 30 field.type === FieldType.number || field.type === FieldType.time 31 ); 32 } 33 }); 34 35 it('match not time', () => { 36 const matches = fieldMatchers.get(MatcherID.invertMatch).get(matchesTimeConfig); 37 for (const field of simpleSeriesWithTypes.fields) { 38 expect(matches(field, simpleSeriesWithTypes, allFrames)).toBe(field.type !== FieldType.time); 39 } 40 }); 41}); 42