Skip to content

Commit

Permalink
Fix: update select_language_label helper to select f no english found…
Browse files Browse the repository at this point in the history
… any language remaining over the not tagged (#795)

* update select_language_label  helper to select f no english found any language remaining over the not tagged

* fix tests by fixing a dependency change

* fix login system tests after securing the user delete action in the API
  • Loading branch information
syphax-bouazzouni authored Oct 30, 2024
1 parent 70f0e4d commit 1e4b809
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ GEM
ed25519 (1.3.0)
erubi (1.13.0)
erubis (2.7.0)
excon (1.0.0)
excon (0.112.0)
execjs (2.10.0)
faraday (2.0.1)
faraday-net_http (~> 2.0)
Expand Down
46 changes: 30 additions & 16 deletions app/components/tree_link_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,19 @@

class TreeLinkComponent < ViewComponent::Base
include MultiLanguagesHelper, ModalHelper, ApplicationHelper
def initialize(child:, href:, children_href: , selected: false , data: {}, muted: false, target_frame: nil, open_in_modal: false, is_reused: nil)

def initialize(child:, href:, children_href:, selected: false, data: {}, muted: false, target_frame: nil, open_in_modal: false, is_reused: nil)
super

@child = child
@active_style = selected ? 'active' : ''
#@icons = child.relation_icon(node)
@muted_style = muted ? 'text-muted' : ''
@href = href
@children_link = children_href
label = (@child.prefLabel || @child.label) rescue @child.id
if label.nil?
@pref_label_html = link_last_part(child.id)
else
pref_label_lang, @pref_label_html = select_language_label(label)
pref_label_lang = pref_label_lang.to_s.upcase
@tooltip = pref_label_lang.eql?("@NONE") ? "" : pref_label_lang

if child.obsolete?
@pref_label_html = "<span class='obsolete_class'>#{@pref_label_html}</span>".html_safe
end
end
@data ||= { controller: 'tooltip', 'tooltip-position-value': 'right', turbo: true, 'turbo-frame': target_frame, action: 'click->simple-tree#select'}
@pref_label_html, @tooltip = node_label(child)

@data ||= { controller: 'tooltip', 'tooltip-position-value': 'right', turbo: true, 'turbo-frame': target_frame, action: 'click->simple-tree#select' }

@data.merge!(data) do |_, old, new|
"#{old} #{new}"
Expand All @@ -32,7 +25,6 @@ def initialize(child:, href:, children_href: , selected: false , data: {}, muted
@is_reused = is_reused
end


# This gives a very hacky short code to use to uniquely represent a class
# based on its parent in a tree. Used for unique ids in HTML for the tree view
def short_uuid
Expand All @@ -49,7 +41,7 @@ def open?
end

def border_left
!@child.hasChildren ? 'pl-3 tree-border-left' : ''
!@child.hasChildren ? 'pl-3 tree-border-left' : ''
end

def li_id
Expand All @@ -75,4 +67,26 @@ def open_children_link

end

private

def node_label(child)
label = begin
child.prefLabel || child.label
rescue
child.id
end

if label.nil?
pref_label_html = link_last_part(child.id)
else
pref_label_lang, pref_label_html = select_language_label(label)
pref_label_lang = pref_label_lang.to_s.upcase
tooltip = pref_label_lang.eql?("@NONE") ? "" : pref_label_lang

pref_label_html = "<span class='obsolete_class'>#{pref_label_html}</span>".html_safe if child.obsolete?
end

[pref_label_html, tooltip]
end

end
2 changes: 1 addition & 1 deletion app/helpers/multi_languages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def select_language_label(concept_label, platform_languages = %i[en fr])
end
end

concept_value || concept.to_a.first
concept_value || concept.reject { |k| k.to_s.eql?('@none') }.first || concept.first
end

def main_language_label(label)
Expand Down
50 changes: 32 additions & 18 deletions test/helpers/application_test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,34 @@ module Users
def sign_in_as(username)
user = fixtures(:users)[username]
logged_in_user = LinkedData::Client::Models::User.authenticate(user.username, user.password)
if logged_in_user && !logged_in_user.errors
logged_in_user = create_user(user)
end
logged_in_user = create_user(user) if logged_in_user && !logged_in_user.errors
logged_in_user
end

def create_user(user, admin: false)
admin_user = LinkedData::Client::Models::User.authenticate('admin', 'password') if admin
admin_user = LinkedData::Client::Models::User.authenticate('admin', 'password')
existent_user = LinkedData::Client::Models::User.find_by_username(user.username).first

existent_user.delete if existent_user
conn = Faraday.new(url: LinkedData::Client.settings.rest_url) do |faraday|
faraday.request :url_encoded
faraday.response :logger
faraday.adapter Faraday.default_adapter
faraday.headers = {
"Accept" => "application/json",
"Authorization" => "apikey token=#{admin_user.apikey}",
"User-Agent" => "NCBO API Ruby Client v0.1.0"
}

end

conn.delete("/users/#{user.username}") if existent_user

values = user.to_h
values[:role] = ["ADMINISTRATOR"] if admin
existent_user = LinkedData::Client::Models::User.new(values: values)

if admin
# Overwrite the normal ".save" to accept creating admin user
conn = Faraday.new(url: LinkedData::Client.settings.rest_url) do |faraday|
faraday.request :url_encoded
faraday.response :logger
faraday.adapter Faraday.default_adapter
faraday.headers = {
"Accept" => "application/json",
"Authorization" => "apikey token=#{admin_user.apikey}",
"User-Agent" => "NCBO API Ruby Client v0.1.0"
}

end
conn.post(existent_user.class.collection_path, existent_user.to_hash.to_json, 'Content-Type' => 'application/json')
else
existent_user.save
Expand All @@ -61,7 +60,22 @@ def delete_users(users = LinkedData::Client::Models::User.all)
end

def delete_user(user)
LinkedData::Client::Models::User.find_by_username(user.username).first&.delete
admin_user = LinkedData::Client::Models::User.authenticate('admin', 'password')
existent_user = LinkedData::Client::Models::User.find_by_username(user.username).first

conn = Faraday.new(url: LinkedData::Client.settings.rest_url) do |faraday|
faraday.request :url_encoded
faraday.response :logger
faraday.adapter Faraday.default_adapter
faraday.headers = {
"Accept" => "application/json",
"Authorization" => "apikey token=#{admin_user.apikey}",
"User-Agent" => "NCBO API Ruby Client v0.1.0"
}

end

conn.delete("/users/#{user.username}") if existent_user
end
end

Expand Down Expand Up @@ -133,4 +147,4 @@ def delete_agents(agents = LinkedData::Client::Models::Agent.all)
Array(agents).each { |g| g.delete }
end
end
end
end
2 changes: 0 additions & 2 deletions test/system/login_flows_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class LoginFlowsTest < ApplicationSystemTestCase
new_user = @user_john
delete_user(new_user)

LinkedData::Client::Models::User.find_by_username(new_user.username).first&.delete

fill_in 'user_firstName', with: new_user.firstName
fill_in 'user_lastName', with: new_user.lastName
fill_in 'user_username', with: new_user.username
Expand Down
16 changes: 5 additions & 11 deletions test/system/submission_flows_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class SubmissionFlowsTest < ApplicationSystemTestCase
assert_text cat.acronym.titleize
end


assert_text @new_submission.URI
assert_text @new_submission.description
assert_text @new_submission.pullLocation
Expand Down Expand Up @@ -103,7 +102,6 @@ class SubmissionFlowsTest < ApplicationSystemTestCase
click_on "Licensing"
submission_licensing_edit_fill(ontology_2, submission_2)


# Persons and organizations tab
click_on "Persons and organizations"
submission_agent_edit_fill(submission_2)
Expand Down Expand Up @@ -148,7 +146,10 @@ class SubmissionFlowsTest < ApplicationSystemTestCase

assert_text submission_2.URI
assert_text submission_2.versionIRI

wait_for '.submission-status'
assert_selector '.submission-status', text: submission_2.version

assert_selector ".flag-icon-fr" # todo fix this
submission_2.identifier.each do |id|
assert_text id
Expand Down Expand Up @@ -258,7 +259,6 @@ class SubmissionFlowsTest < ApplicationSystemTestCase
assert_text "rdfs"
assert_text "dct"


open_dropdown "#configuration"

submission_2.keyClasses.each do |key|
Expand Down Expand Up @@ -341,10 +341,8 @@ class SubmissionFlowsTest < ApplicationSystemTestCase
sleep 0.5
click_button 'Back'


fill_ontology(ontology_2, submission_2, add_submission: true)


assert_selector 'h2', text: 'Ontology submitted successfully!'
click_on current_url.gsub("/ontologies/success/#{existent_ontology.acronym}", '') + ontology_path(existent_ontology.acronym)

Expand All @@ -362,7 +360,6 @@ class SubmissionFlowsTest < ApplicationSystemTestCase
assert_text submission_2.description
assert_text submission_2.pullLocation


# check
assert_selector '.fas.fa-key' if submission_2.status.eql?('private')

Expand All @@ -380,7 +377,6 @@ class SubmissionFlowsTest < ApplicationSystemTestCase
assert_text group.name
end


open_dropdown "#dates"
assert_date submission_2.modificationDate
assert_date existent_submission.released
Expand Down Expand Up @@ -483,7 +479,6 @@ def submission_agent_edit_fill(submission)

list_inputs "#submissioncontact_from_group_input", "submission[contact]", submission.contact


agent1 = fixtures(:agents)[:agent1]
agent2 = fixtures(:agents)[:agent2]

Expand Down Expand Up @@ -624,7 +619,6 @@ def fill_ontology(new_ontology, new_submission, add_submission: false)
list_checks new_ontology.hasDomain.map(&:acronym), @categories.map(&:acronym)
list_checks new_ontology.group.map(&:acronym), @groups.map(&:acronym)


click_button 'Next'

# Page 2
Expand All @@ -644,9 +638,9 @@ def fill_ontology(new_ontology, new_submission, add_submission: false)

# Page 3
if add_submission
date_picker_fill_in 'submission[modificationDate]', new_submission.modificationDate
date_picker_fill_in 'submission[modificationDate]', new_submission.modificationDate
else
date_picker_fill_in 'submission[released]', new_submission.released
date_picker_fill_in 'submission[released]', new_submission.released
end

list_inputs "#submissioncontact_from_group_input", "submission[contact]", new_submission.contact
Expand Down

0 comments on commit 1e4b809

Please sign in to comment.