1- import toolsList from "components/ToolsView/testData/toolsList" ;
2- import toolsListInPanel from "components/ToolsView/testData/toolsListInPanel" ;
1+ // eslint-disable-next-line simple-import-sort/imports
2+ import toolsListUntyped from "@/components/ToolsView/testData/toolsList.json" ;
3+ import toolsListInPanelUntyped from "@/components/ToolsView/testData/toolsListInPanel.json" ;
34
45import {
5- createSortedResultObject ,
6+ createSortedResultPanel ,
67 createWhooshQuery ,
78 determineWidth ,
89 filterTools ,
9- searchToolsByKeys ,
10+ searchObjectsByKeys ,
11+ type SearchCommonKeys ,
1012} from "./utilities" ;
13+ import type { Tool , ToolSection } from "@/stores/toolStore" ;
1114
1215describe ( "test helpers in tool searching utilities and panel handling" , ( ) => {
1316 it ( "panel width determination" , ( ) => {
@@ -18,6 +21,9 @@ describe("test helpers in tool searching utilities and panel handling", () => {
1821 } ) ;
1922} ) ;
2023
24+ const toolsList = toolsListUntyped as unknown as Tool [ ] ;
25+ const toolsListInPanel = toolsListInPanelUntyped as unknown as Record < string , Tool | ToolSection > ;
26+
2127const tempToolPanel = {
2228 default : {
2329 "fasta/fastq" : {
@@ -45,18 +51,35 @@ const tempToolsList = {
4551 id : "umi_tools_reduplicate" ,
4652 name : "UMI-tools reduplicate" ,
4753 } ,
48- } ,
54+ } as unknown as Record < string , Tool > ,
4955} ;
5056
5157describe ( "test helpers in tool searching utilities" , ( ) => {
58+ // Intentionally did not import the `searchTools` function from the util file
59+ // to be able to test different key sort orders here.
60+ function searchToolsByKeys (
61+ tools : Tool [ ] ,
62+ keys : SearchCommonKeys ,
63+ query : string ,
64+ currentPanel : Record < string , Tool | ToolSection > ,
65+ ) : {
66+ results : string [ ] ;
67+ resultPanel : Record < string , Tool | ToolSection > ;
68+ closestTerm : string | null ;
69+ } {
70+ const { matchedResults, closestTerm } = searchObjectsByKeys < Tool > ( tools , keys , query , [ "name" , "description" ] ) ;
71+ const { idResults, resultPanel } = createSortedResultPanel ( matchedResults , currentPanel ) ;
72+ return { results : idResults , resultPanel : resultPanel , closestTerm : closestTerm } ;
73+ }
74+
5275 it ( "test parsing helper that converts settings to whoosh query" , async ( ) => {
5376 const settings = {
5477 name : "Filter" ,
5578 id : "__FILTER_FAILED_DATASETS__" ,
5679 help : "downstream" ,
5780 owner : "devteam" ,
5881 } ;
59- const q = createWhooshQuery ( settings , "default" , [ ] ) ;
82+ const q = createWhooshQuery ( settings ) ;
6083
6184 // OrGroup (at backend) on name, name_exact, description
6285 expect ( q ) . toContain ( "name:(Filter) name_exact:(Filter) description:(Filter)" ) ;
@@ -69,7 +92,13 @@ describe("test helpers in tool searching utilities", () => {
6992 } ) ;
7093
7194 it ( "test tool search helper that searches for tools given keys" , async ( ) => {
72- const searches = [
95+ const searches : {
96+ q : string ;
97+ expectedResults : string [ ] ;
98+ keys : SearchCommonKeys ;
99+ tools : Tool [ ] ;
100+ panel : Record < string , Tool | ToolSection > ;
101+ } [ ] = [
73102 {
74103 // description prioritized
75104 q : "collection" ,
@@ -165,7 +194,7 @@ describe("test helpers in tool searching utilities", () => {
165194 } ,
166195 ] ;
167196 searches . forEach ( ( search ) => {
168- const { results } = searchToolsByKeys ( search . tools , search . keys , search . q , "default" , search . panel ) ;
197+ const { results } = searchToolsByKeys ( search . tools , search . keys , search . q , search . panel ) ;
169198 expect ( results ) . toEqual ( search . expectedResults ) ;
170199 } ) ;
171200 } ) ;
@@ -176,37 +205,38 @@ describe("test helpers in tool searching utilities", () => {
176205 // Testing if just names work with DL search
177206 const filterQueries = [ "Fillter" , "FILYER" , " Fitler" , " filtr" ] ;
178207 filterQueries . forEach ( ( q ) => {
179- const { results, closestTerm } = searchToolsByKeys ( toolsList , keys , q , "default" , toolsListInPanel ) ;
208+ const { results, closestTerm } = searchToolsByKeys ( toolsList , keys , q , toolsListInPanel ) ;
180209 expect ( results ) . toEqual ( expectedResults ) ;
181210 expect ( closestTerm ) . toEqual ( "filter" ) ;
182211 } ) ;
183212 // Testing if names and description function with DL search
184213 let queries = [ "datases from a collection" , "from a colleection" , "from a colleection" ] ;
185214 queries . forEach ( ( q ) => {
186- const { results } = searchToolsByKeys ( toolsList , keys , q , "default" , toolsListInPanel ) ;
215+ const { results } = searchToolsByKeys ( toolsList , keys , q , toolsListInPanel ) ;
187216 expect ( results ) . toEqual ( expectedResults ) ;
188217 } ) ;
189218 // Testing if different length queries correctly trigger changes in max DL distance
190219 queries = [ "datae" , "ppasetsfrom" , "datass from a cppollection" ] ;
191220 queries . forEach ( ( q ) => {
192- const { results } = searchToolsByKeys ( toolsList , keys , q , "default" , toolsListInPanel ) ;
221+ const { results } = searchToolsByKeys ( toolsList , keys , q , toolsListInPanel ) ;
193222 expect ( results ) . toEqual ( expectedResults ) ;
194223 } ) ;
195224 } ) ;
196225
197226 it ( "test tool filtering helpers on toolsList given list of ids" , async ( ) => {
198227 const ids = [ "__FILTER_FAILED_DATASETS__" , "liftOver1" ] ;
199228 // check length of first section from imported const toolsList
200- expect ( toolsListInPanel [ "collection_operations" ] . tools ) . toHaveLength ( 4 ) ;
229+ const collectionOperationsSection = toolsListInPanel [ "collection_operations" ] as ToolSection ;
230+ expect ( collectionOperationsSection . tools ) . toHaveLength ( 4 ) ;
201231 // check length of same section from filtered toolsList
202232 const matchedTools = ids . map ( ( id ) => {
203233 return { id : id , sections : [ ] , order : 0 } ;
204234 } ) ;
205- const toolResultsPanel = createSortedResultObject ( matchedTools , toolsListInPanel ) ;
206- const toolResultsSection = toolResultsPanel . resultPanel [ "collection_operations" ] ;
235+ const toolResultsPanel = createSortedResultPanel ( matchedTools , toolsListInPanel ) ;
236+ const toolResultsSection = toolResultsPanel . resultPanel [ "collection_operations" ] as ToolSection ;
207237 expect ( toolResultsSection . tools ) . toHaveLength ( 1 ) ;
208238 // check length of filtered tools (regardless of sections)
209- const toolsById = toolsList . reduce ( ( acc , item ) => {
239+ const toolsById = toolsList . reduce < Record < string , Tool > > ( ( acc , item ) => {
210240 acc [ item . id ] = item ;
211241 return acc ;
212242 } , { } ) ;
0 commit comments