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 3a4e1f0
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 26 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
3 changes: 2 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ def get_class(params)
@root.children = @roots.sort{|x,y| (x.prefLabel || "").downcase <=> (y.prefLabel || "").downcase}

# get the initial concept to display
root_child = @root.children.first
root_child = @root.children&.first
not_found("Missing roots #{@roots.id}") if root_child.nil?

@concept = root_child.explore.self(full: true, lang: lang)
# Some ontologies have "too many children" at their root. These will not process and are handled here.
Expand Down
9 changes: 6 additions & 3 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 @@ -95,12 +95,15 @@ def show_tree
return
end
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
if @ontology.nil?
if @ontology.nil? || @ontology.errors
ontology_not_found(params[:ontology])
else
get_class(params) #application_controller

not_found("Missing roots") if @root.nil?

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
5 changes: 4 additions & 1 deletion app/controllers/properties_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ def show_tree
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
ontology_not_found(params[:ontology]) if @ontology.nil?
@root = OpenStruct.new({children: property_roots(params[:ontology])})
not_found(@root.children.errors.join) if @root.children.respond_to?(:errors)

if params[:propertyid]
@property = get_property(params[:propertyid])
else
@property ||= @root.children.first
end

render inline: helpers.property_tree_component(@root, @property,
@ontology.acronym, request_lang,
id: 'properties_tree_view', auto_click: true)
Expand All @@ -29,7 +32,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
32 changes: 25 additions & 7 deletions test/controllers/ontologies_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,32 @@ 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
assert_response :success, "GET #{path} returned #{response.status}"
end

test "should open the tree views of #{ont.acronym} ontology" do
paths = [
ajax_classes_treeview_path(ontology: ont.acronym),
ajax_properties_treeview_path(ontology: ont.acronym)
]
paths.each do |path|
begin
get path
assert_includes [404, 200], response.status, "GET #{path} returned #{response.status}"
rescue StandardError => e
assert_equal ActiveRecord::RecordNotFound, e.class
end
end

end
end
end

0 comments on commit 3a4e1f0

Please sign in to comment.