Skip to content

Commit

Permalink
add tree view links controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jan 3, 2024
1 parent 4ba616c commit 568d913
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 23 deletions.
5 changes: 4 additions & 1 deletion app/components/tree_link_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ def li_id
@child.id.eql?('bp_fake_root') ? 'bp_fake_root' : short_uuid
end

def self.tree_close_icon
"<i class='fas fa-chevron-down text-primary' data-action='click->simple-tree#toggleChildren'></i>".html_safe
end

def open_children_link
return unless @child.hasChildren
if @child.expanded?
tree_close_icon
self.class.tree_close_icon
else
content_tag('turbo_frame', id: "#{child_id}_open_link") do
link_to @children_link,
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/concepts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def show
@concept.children = @concept.explore.children(pagesize: 750, concept_schemes: Array(@schemes).join(','), language: request_lang, display: 'prefLabel,obsolete,hasChildren').collection || []
@concept.children.sort! { |x, y| (x.prefLabel || "").downcase <=> (y.prefLabel || "").downcase } unless @concept.children.empty?
render turbo_stream: [
replace(helpers.child_id(@concept) + '_open_link') { helpers.tree_close_icon },
replace(helpers.child_id(@concept) + '_open_link') { TreeLinkComponent.tree_close_icon },
replace(helpers.child_id(@concept) + '_childs') do
helpers.concepts_tree_component(@concept, @concept, @ontology.acronym, Array(@schemes), request_lang, sub_tree: true)
end
Expand Down Expand Up @@ -100,7 +100,7 @@ def show_tree
else
get_class(params) #application_controller
render inline: helpers.concepts_tree_component(@root, @concept,
@ontology.acronym, params[:concept_schemes]&.split(','), request_lang,
@ontology.acronym, Array(params[:concept_schemes]&.split(',')), request_lang,
id: 'concepts_tree_view', auto_click: params[:auto_click] || true)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/properties_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def show_children
@property.children = property_children(id, acronym)

render turbo_stream: [
replace(helpers.child_id(@property) + '_open_link') { helpers.tree_close_icon },
replace(helpers.child_id(@property) + '_open_link') { TreeLinkComponent.tree_close_icon },
replace(helpers.child_id(@property) + '_childs') do
helpers.property_tree_component(@property, @property, acronym, request_lang, sub_tree: true)
end
Expand Down
12 changes: 2 additions & 10 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,7 @@ def get_groups_data(groups = nil)
@groups_for_js = @groups_map.to_json
end

def metadata_for_select
get_metadata
return @metadata_for_select
end

def get_metadata
@metadata_for_select = []
submission_metadata.each do |data|
@metadata_for_select << data["attribute"]
end
end


def ontologies_to_acronyms(ontologyIDs)
Expand All @@ -324,6 +314,8 @@ def at_slice?
!@subdomain_filter.nil? && !@subdomain_filter[:active].nil? && @subdomain_filter[:active] == true
end


# TODO this helper is not used but can be usefully
def truncate_with_more(text, options = {})
length ||= options[:length] ||= 30
trailing_text ||= options[:trailing_text] ||= " ... "
Expand Down
4 changes: 1 addition & 3 deletions app/helpers/components_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def tree_component(root, selected, target_frame:, sub_tree: false, id: nil, auto
end
end

def tree_close_icon
content_tag(:i, nil, class: "fas fa-chevron-down text-primary", data:{action:'click->simple-tree#toggleChildren'})
end



def chart_component(title: '', type: , labels: , datasets: , index_axis: 'x', show_legend: false)
Expand Down
25 changes: 19 additions & 6 deletions test/controllers/ontologies_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,26 @@ class OntologiesControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end

ONTOLOGIES.flat_map { |ont| PAGES.map { |page| [ont, page] } }.each do |ont, page|
test "should get page #{page} of #{ont.acronym} ontology" do
path = "#{ontologies_path}/#{ont.acronym}?p=#{page}"
get path
if response.redirect?
follow_redirect!
ONTOLOGIES.each do |ont|
PAGES.each do |page|
test "should get page #{page} of #{ont.acronym} ontology" do
path = "#{ontologies_path}/#{ont.acronym}?p=#{page}"
get path
if response.redirect?
follow_redirect!
end
assert_response :success, "GET #{path} returned #{response.status}"
end
end

test "should open the tree views of #{ont.acronym} ontology" do
path = ajax_classes_treeview_path(ontology: ont.acronym)
get path

assert_response :success, "GET #{path} returned #{response.status}"

path = ajax_properties_treeview_path(ontology: ont.acronym)
get path
assert_response :success, "GET #{path} returned #{response.status}"
end
end
Expand Down

0 comments on commit 568d913

Please sign in to comment.