From 1e4b80996ec39f9f70191d9f45043ac7c6596887 Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Wed, 30 Oct 2024 15:57:12 +0100 Subject: [PATCH] Fix: update select_language_label helper to select f no english found 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 --- Gemfile.lock | 2 +- app/components/tree_link_component.rb | 46 ++++++++++++++-------- app/helpers/multi_languages_helper.rb | 2 +- test/helpers/application_test_helpers.rb | 50 +++++++++++++++--------- test/system/login_flows_test.rb | 2 - test/system/submission_flows_test.rb | 16 +++----- 6 files changed, 69 insertions(+), 49 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3bb8c6881..73328d841 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/app/components/tree_link_component.rb b/app/components/tree_link_component.rb index 73da902f2..fd23706d9 100644 --- a/app/components/tree_link_component.rb +++ b/app/components/tree_link_component.rb @@ -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 = "#{@pref_label_html}".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}" @@ -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 @@ -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 @@ -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 = "#{pref_label_html}".html_safe if child.obsolete? + end + + [pref_label_html, tooltip] + end + end diff --git a/app/helpers/multi_languages_helper.rb b/app/helpers/multi_languages_helper.rb index 9e21f2e0e..6e127b94e 100644 --- a/app/helpers/multi_languages_helper.rb +++ b/app/helpers/multi_languages_helper.rb @@ -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) diff --git a/test/helpers/application_test_helpers.rb b/test/helpers/application_test_helpers.rb index 975c220ea..28530711f 100644 --- a/test/helpers/application_test_helpers.rb +++ b/test/helpers/application_test_helpers.rb @@ -16,17 +16,27 @@ 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 @@ -34,17 +44,6 @@ def create_user(user, admin: false) 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 @@ -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 @@ -133,4 +147,4 @@ def delete_agents(agents = LinkedData::Client::Models::Agent.all) Array(agents).each { |g| g.delete } end end -end \ No newline at end of file +end diff --git a/test/system/login_flows_test.rb b/test/system/login_flows_test.rb index d6ff0deb4..8bed283d2 100644 --- a/test/system/login_flows_test.rb +++ b/test/system/login_flows_test.rb @@ -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 diff --git a/test/system/submission_flows_test.rb b/test/system/submission_flows_test.rb index 6045308d0..a0c06a4f4 100644 --- a/test/system/submission_flows_test.rb +++ b/test/system/submission_flows_test.rb @@ -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 @@ -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) @@ -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 @@ -258,7 +259,6 @@ class SubmissionFlowsTest < ApplicationSystemTestCase assert_text "rdfs" assert_text "dct" - open_dropdown "#configuration" submission_2.keyClasses.each do |key| @@ -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) @@ -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') @@ -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 @@ -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] @@ -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 @@ -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