diff --git a/Rakefile b/Rakefile index dd14cff..5783822 100644 --- a/Rakefile +++ b/Rakefile @@ -9,7 +9,7 @@ def install_module(path) # Temporary fix to overcome the issue with sass-embedded, see: # https://github.com/decidim/decidim/pull/11074 - system("npm i sass-embedded@~1.62.0") + # system("npm i sass-embedded@~1.62.0") end end diff --git a/app/packs/src/decidim/term_customizer/admin/translations_admin.js b/app/packs/src/decidim/term_customizer/admin/translations_admin.js index 27ceb15..258f352 100644 --- a/app/packs/src/decidim/term_customizer/admin/translations_admin.js +++ b/app/packs/src/decidim/term_customizer/admin/translations_admin.js @@ -37,7 +37,7 @@ $(() => { modifyResult: (item, valueItem) => { const sanitizedSearch = currentSearch.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); const re = new RegExp(`(${sanitizedSearch})`, "gi"); - const replacedText = item.textContent.replace(re, '$1'); + const replacedText = valueItem.label.replace(re, '$1'); item.innerHTML = replacedText; item.dataset.value = valueItem.value; }, diff --git a/lib/decidim/term_customizer/test/rspec_support/capybara.rb b/lib/decidim/term_customizer/test/rspec_support/capybara.rb new file mode 100644 index 0000000..ba81607 --- /dev/null +++ b/lib/decidim/term_customizer/test/rspec_support/capybara.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require "selenium-webdriver" + +module Decidim + # This is being added because of the issues with the chrome-driver + # in version 120 or later, and this can be removed after this pr#12160 + # being merged(more info https://github.com/decidim/decidim/pull/12159). + Capybara.register_driver :headless_chrome do |app| + options = ::Selenium::WebDriver::Chrome::Options.new + options.args << "--headless=new" + options.args << "--no-sandbox" + options.args << if ENV["BIG_SCREEN_SIZE"].present? + "--window-size=1920,3000" + else + "--window-size=1920,1080" + end + options.args << "--ignore-certificate-errors" if ENV["TEST_SSL"] + Capybara::Selenium::Driver.new( + app, + browser: :chrome, + capabilities: [options] + ) + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0b80de0..6e46fd4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,6 +8,10 @@ File.expand_path(File.join(__dir__, "decidim_dummy_app")) require "decidim/dev/test/base_spec_helper" +# This is being added because of the issues with the chrome-driver +# in version 120 or later, and this can be removed after this pr#12160 +# being merged(more info https://github.com/decidim/decidim/pull/12159). +require "#{Dir.pwd}/lib/decidim/term_customizer/test/rspec_support/capybara.rb" RSpec.configure do |config| # Add extra traslation load path for the tests diff --git a/spec/system/expolre_adding_translation_spec.rb b/spec/system/expolre_adding_translation_spec.rb new file mode 100644 index 0000000..4e3419a --- /dev/null +++ b/spec/system/expolre_adding_translation_spec.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe "explore adding translation", type: :system do + let(:organization) { create(:organization) } + let(:user) { create(:user, :admin, :confirmed, organization: organization) } + let!(:translation_set) { create(:translation_set, organization: organization, name: { en: "Dummy set" }) } + + context "when the translation value is the list" do + # let!(:translation1) { create(:translation, key: "dummy.translation.one", value: "") } + # let!(:translation2) { create(:translation, key: "dummy.translation.two", value: "dummy translation string") } + let(:translation_hash) do + { + "dummy.translation.one" => "", + "dummy.translation.two" => "dummy translation string" + } + end + + before do + switch_to_host(organization.host) + sign_in user + visit decidim_admin_term_customizer.translation_sets_path + click_link "Dummy set" + click_link "Add multiple", match: :first + end + + it "Adds the lists properly" do + # rubocop:disable RSpec/AnyInstance + allow_any_instance_of(Decidim::TermCustomizer::TranslationDirectory).to receive(:translations_search).with("dummy tran").and_return(translation_hash) + # rubocop:enable RSpec/AnyInstance + + fill_in "Search", with: "dummy tran" + li_element = page.find("li", text: "") + within "ul#autoComplete_list_1" do + expect(li_element).not_to have_css(".hide") + expect(page).to have_css("li", text: "") + expect(page).to have_css("li", text: "dummy translation string") + li_element.click + expect(li_element).not_to have_css("li", text: "") + end + within "table.table-list" do + expect(page).to have_css("th", text: "Translation key") + expect(page).to have_css("td", text: "dummy.translation.one") + expect(page).to have_css("td", text: "") + end + end + end +end