@@ -43,6 +43,19 @@ class SearchFacetTest < ActiveSupport::TestCase
4343 { id : 'NCBITaxon_9606' , name : 'Homo sapiens' } ,
4444 { id : 'NCBITaxon_10090' , name : 'Mus musculus' }
4545 ]
46+
47+ SearchFacet . create ( name : 'Cell type' , identifier : 'cell_type' , is_mongo_based : true ,
48+ ontology_urls : [
49+ {
50+ name : 'Cell Ontology' ,
51+ url : 'https://www.ebi.ac.uk/ols/api/ontologies/cl' ,
52+ browser_url : 'https://www.ebi.ac.uk/ols/ontologies/cl'
53+ }
54+ ] ,
55+ data_type : 'string' , is_ontology_based : true , is_array_based : false ,
56+ big_query_id_column : 'cell_type' ,
57+ big_query_name_column : 'cell_type__ontology_label' ,
58+ convention_name : 'Alexandria Metadata Convention' , convention_version : '2.2.0' )
4659 end
4760
4861 after ( :all ) do
@@ -158,6 +171,7 @@ class SearchFacetTest < ActiveSupport::TestCase
158171 test 'should find all filter matches' do
159172 azul_diseases = AzulSearchService . get_all_facet_filters [ 'disease' ]
160173 disease_keyword = 'cancer'
174+ skip 'Azul search service not available' unless azul_diseases
161175 cancers = azul_diseases [ :filters ] . select { |d | d . match? ( disease_keyword ) }
162176 disease_facet = SearchFacet . find_by ( identifier : 'disease' )
163177 disease_facet . update_filter_values! ( azul_diseases )
@@ -215,18 +229,7 @@ class SearchFacetTest < ActiveSupport::TestCase
215229 ]
216230 }
217231 ] )
218- facet = SearchFacet . create ( name : 'Cell type' , identifier : 'cell_type' , is_mongo_based : true ,
219- ontology_urls : [
220- {
221- name : 'Cell Ontology' ,
222- url : 'https://www.ebi.ac.uk/ols/api/ontologies/cl' ,
223- browser_url : 'https://www.ebi.ac.uk/ols/ontologies/cl'
224- }
225- ] ,
226- data_type : 'string' , is_ontology_based : true , is_array_based : false ,
227- big_query_id_column : 'cell_type' ,
228- big_query_name_column : 'cell_type__ontology_label' ,
229- convention_name : 'Alexandria Metadata Convention' , convention_version : '2.2.0' )
232+ facet = SearchFacet . find_by ( identifier : 'cell_type' )
230233 expected_filters = [
231234 { id : 'CL_0000236' , name : 'B cell' } ,
232235 { id : 'CL_0000561' , name : 'amacrine cell' } ,
@@ -255,4 +258,16 @@ class SearchFacetTest < ActiveSupport::TestCase
255258 facet . reload
256259 assert_equal expected_filter , facet . filter_for_presence
257260 end
261+
262+ test 'should sort and uniquify filters properly' do
263+ facet = SearchFacet . find_by ( identifier : 'cell_type' )
264+ facet . update_filter_values!
265+ assert facet . filters . first [ :name ] == 'amacrine cell'
266+ external_filters = { filters : [ 'b cell' , 'B cell' , 'amacrine cell' , 'Amacrine Cell' , 'T cell' ] }
267+ facet . update_filter_values! ( external_filters )
268+ facet . reload
269+ assert_equal 1 , facet . filters_with_external . select { |f | f [ :name ] == 'amacrine cell' } . count
270+ assert_equal 1 , facet . filters_with_external . select { |f | f [ :name ] == 'T cell' } . count
271+ assert_equal 'T cell' , facet . filters_with_external . last [ :name ]
272+ end
258273end
0 commit comments