@@ -3,6 +3,7 @@ import { FilterDefinition, filterExperiment, Operator } from '.'
33import rowsFixture from '../../../test/fixtures/expShow/base/rows'
44import { buildDepPath , buildMetricOrParamPath } from '../../columns/paths'
55import { Experiment , ColumnType } from '../../webview/contract'
6+ import { tagsColumnLike } from '../../columns/like'
67
78describe ( 'filterExperiment' , ( ) => {
89 const paramsFile = 'params.yaml'
@@ -292,4 +293,70 @@ describe('filterExperiment', () => {
292293 )
293294 ) . toBeUndefined ( )
294295 } )
296+
297+ it ( 'should correctly filter by tags using the equal operator' , ( ) => {
298+ const main = { ...rowsFixture [ 1 ] }
299+ ; ( main . commit as { tags : string [ ] } ) . tags = [ '0.9.3' , 'model@v1' ]
300+ const tagFilter = [
301+ {
302+ operator : Operator . EQUAL ,
303+ path : tagsColumnLike . path ,
304+ value : '0.9.3'
305+ }
306+ ]
307+ const unfiltered = filterExperiment ( tagFilter , main )
308+ expect ( unfiltered ) . toStrictEqual ( main )
309+
310+ expect ( ( main ?. subRows || [ ] ) . length > 0 ) . toBe ( true )
311+
312+ for ( const experiment of main . subRows || [ ] ) {
313+ expect ( filterExperiment ( tagFilter , experiment ) ) . toBeUndefined ( )
314+ }
315+
316+ expect (
317+ filterExperiment (
318+ [
319+ {
320+ operator : Operator . EQUAL ,
321+ path : tagsColumnLike . path ,
322+ value : '0.9'
323+ }
324+ ] ,
325+ main
326+ )
327+ ) . toBeUndefined ( )
328+ } )
329+
330+ it ( 'should correctly filter by tags using the contains operator' , ( ) => {
331+ const main = { ...rowsFixture [ 1 ] }
332+ ; ( main . commit as { tags : string [ ] } ) . tags = [ '0.9.3' , 'model@v1' , 'a-tag' ]
333+ const tagFilter = [
334+ {
335+ operator : Operator . CONTAINS ,
336+ path : tagsColumnLike . path ,
337+ value : '0.9'
338+ }
339+ ]
340+ const unfiltered = filterExperiment ( tagFilter , main )
341+ expect ( unfiltered ) . toStrictEqual ( main )
342+
343+ expect ( ( main ?. subRows || [ ] ) . length > 0 ) . toBe ( true )
344+
345+ for ( const experiment of main . subRows || [ ] ) {
346+ expect ( filterExperiment ( tagFilter , experiment ) ) . toBeUndefined ( )
347+ }
348+
349+ expect (
350+ filterExperiment (
351+ [
352+ {
353+ operator : Operator . CONTAINS ,
354+ path : tagsColumnLike . path ,
355+ value : '0.9.4'
356+ }
357+ ] ,
358+ main
359+ )
360+ ) . toBeUndefined ( )
361+ } )
295362} )
0 commit comments