@@ -2,26 +2,28 @@ import { getVisualizationsByCommand } from 'uiSrc/utils'
2
2
import { IPluginVisualization } from 'uiSrc/slices/interfaces'
3
3
4
4
describe ( 'getVisualizationsByCommand' , ( ) => {
5
- it ( 'should return proper visualizations by query' , ( ) => {
6
- const visualizations = [
7
- { matchCommands : [ 'ft.search' , 'ft.get' ] } ,
8
- { matchCommands : [ 'ft._list' ] } ,
9
- { matchCommands : [ 'ft.*' ] } ,
10
- { matchCommands : [ 'get' ] }
11
- ] as IPluginVisualization [ ]
5
+ const getVisualizationsByCommandTests : [ string , number ] [ ] = [
6
+ [ 'ft.search sa' , 2 ] ,
7
+ [ 'ft.get zxc' , 2 ] ,
8
+ [ 'command ft. zxc zxcz ft' , 0 ] ,
9
+ [ 'command ft' , 0 ] ,
10
+ [ 'any command' , 0 ] ,
11
+ [ 'get key' , 1 ] ,
12
+ ]
12
13
13
- const query1 = 'ft.search sa'
14
- const query2 = 'ft.get zxc'
15
- const query3 = 'command ft. zxc zxcz ft'
16
- const query4 = 'command ft'
17
- const query5 = 'any command'
18
- const query6 = 'get key'
14
+ const visualizations = [
15
+ { matchCommands : [ 'ft.search' , 'ft.get' ] } ,
16
+ { matchCommands : [ ' ft._list' ] } ,
17
+ { matchCommands : [ 'ft.*' ] } ,
18
+ { matchCommands : [ 'get' ] }
19
+ ] as IPluginVisualization [ ]
19
20
20
- expect ( getVisualizationsByCommand ( query1 , visualizations ) ) . toHaveLength ( 2 )
21
- expect ( getVisualizationsByCommand ( query2 , visualizations ) ) . toHaveLength ( 2 )
22
- expect ( getVisualizationsByCommand ( query3 , visualizations ) ) . toHaveLength ( 0 )
23
- expect ( getVisualizationsByCommand ( query4 , visualizations ) ) . toHaveLength ( 0 )
24
- expect ( getVisualizationsByCommand ( query5 , visualizations ) ) . toHaveLength ( 0 )
25
- expect ( getVisualizationsByCommand ( query6 , visualizations ) ) . toHaveLength ( 1 )
26
- } )
21
+ test . each ( getVisualizationsByCommandTests ) (
22
+ 'for %j, should be %i' ,
23
+ ( input , expected ) => {
24
+ // @ts -ignore
25
+ const result = getVisualizationsByCommand ( input , visualizations )
26
+ expect ( result ) . toHaveLength ( expected )
27
+ }
28
+ )
27
29
} )
0 commit comments