From ba60db3dd65393b3ef40d9e860867bd67b152b88 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 3 Jan 2024 11:30:53 +0100 Subject: [PATCH 1/6] Merge the coverage command and job Avoid env variables that seem to not work properly and bump the ruby version. --- .circleci/config.yml | 56 +++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5e0062d9a89..8c23e674112 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -114,30 +114,6 @@ commands: - store_test_results: path: /tmp/test-results - test_with_coverage: - # This command creates a dir to hold coverage data, run test suites with coverage enabled and - # generate the coverage report. - description: Run Tests With Coverage Enabled - steps: - - run: - name: Setup Coverage Env Vars - command: | - echo 'export COVERAGE_FILE=$COVERAGE_DIR/coverage.xml' >> $BASH_ENV - source $BASH_ENV - - run: - name: Verify Coverage Env Vars - command: | - echo $COVERAGE - echo $COVERAGE_DIR - echo $COVERAGE_FILE - - run: - name: Setup Coverage Directory - command: mkdir -p $COVERAGE_DIR - - test - - run: - name: Report Coverage - command: bundle exec rake solidus:coverage[cobertura] - libvips: steps: - run: @@ -315,6 +291,8 @@ jobs: - setup - test + # This job creates a dir to hold coverage data, run test suites with coverage enabled and + # generate the coverage report. test_solidus_with_coverage: parameters: database: @@ -322,7 +300,7 @@ jobs: default: postgres ruby: type: string - default: '3.1' + default: '3.2' executor: name: << parameters.database >> ruby: << parameters.ruby >> @@ -333,19 +311,33 @@ jobs: DISABLE_ACTIVE_STORAGE: false steps: - setup - - test_with_coverage + - run: + name: Setup Coverage Env Vars + command: | + echo 'export COVERAGE_FILE=/tmp/coverage/coverage.xml' >> $BASH_ENV + source $BASH_ENV + - run: + name: Verify Coverage Env Vars + command: | + echo $COVERAGE + echo /tmp/coverage + echo /tmp/coverage/coverage.xml + - run: + name: Setup Coverage Directory + command: mkdir -p /tmp/coverage + - test + - run: + name: Report Coverage + command: bundle exec rake solidus:coverage[cobertura] + - codecov/upload: + file: /tmp/coverage/coverage.xml workflows: build: jobs: - lint_code - solidus_installer - - # Only test with coverage support with the default versions - - test_solidus_with_coverage: - post-steps: - - codecov/upload: - file: $COVERAGE_FILE + - test_solidus_with_coverage # Only test with coverage support with the default versions # Based on supported versions for the current Solidus release and recommended versions from # https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html. From 6948a97cdf475834fb70a2c60752373645cab7b3 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 3 Jan 2024 13:27:34 +0100 Subject: [PATCH 2/6] Fix the admin/properties spec filename --- admin/spec/features/{properties.rb => properties_spec.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename admin/spec/features/{properties.rb => properties_spec.rb} (100%) diff --git a/admin/spec/features/properties.rb b/admin/spec/features/properties_spec.rb similarity index 100% rename from admin/spec/features/properties.rb rename to admin/spec/features/properties_spec.rb From 811d3baeaa22d8aac678b1ac9e31bc77c46963b1 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 3 Jan 2024 13:27:54 +0100 Subject: [PATCH 3/6] Add coverage for editing stock items in the admin --- admin/spec/features/stock_items_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/admin/spec/features/stock_items_spec.rb b/admin/spec/features/stock_items_spec.rb index 85c1607d6c3..eac6abea459 100644 --- a/admin/spec/features/stock_items_spec.rb +++ b/admin/spec/features/stock_items_spec.rb @@ -7,6 +7,7 @@ it "lists stock items and allows navigating through scopes" do non_backorderable = create(:stock_item, backorderable: false) + non_backorderable.variant.update!(sku: 'MY-SKU-1234567890') backorderable = create(:stock_item, backorderable: true) out_of_stock = begin item = create(:stock_item, backorderable: false) @@ -27,6 +28,13 @@ expect(page).to have_content(out_of_stock.variant.sku) expect(page).to have_content(low_stock.variant.sku) + # Edit stock item + find('td', text: 'MY-SKU-1234567890').click + fill_in :quantity_adjustment, with: 1 + click_on "Save" + expect(find('tr', text: 'MY-SKU-1234567890')).to have_content('11') + expect(find('tr', text: 'MY-SKU-1234567890')).to have_content('1 stock movement') + click_on 'Back Orderable' expect(page).to_not have_content(non_backorderable.variant.sku) expect(page).to have_content(backorderable.variant.sku) From dcab63a20a263061d17df718c998098e3b259490 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 3 Jan 2024 13:28:12 +0100 Subject: [PATCH 4/6] Add a missing spec for the admin/tax_rates section --- admin/spec/features/tax_rates_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 admin/spec/features/tax_rates_spec.rb diff --git a/admin/spec/features/tax_rates_spec.rb b/admin/spec/features/tax_rates_spec.rb new file mode 100644 index 00000000000..c0e1809c7a9 --- /dev/null +++ b/admin/spec/features/tax_rates_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe "Tax rates", :js, type: :feature do + before { sign_in create(:admin_user, email: 'admin@example.com') } + + it "lists tax rates and allows deleting them" do + create(:tax_rate, name: "Clothing") + create(:tax_rate, name: "Food") + + visit "/admin/tax_rates" + expect(page).to have_content("Clothing") + expect(page).to have_content("Food") + expect(page).to be_axe_clean + + select_row("Clothing") + click_on "Delete" + expect(page).to have_content("Tax rates were successfully removed.") + expect(page).not_to have_content("Clothing") + expect(Spree::TaxRate.count).to eq(1) + expect(page).to be_axe_clean + end +end From 0025c047646c3ace7853593f8d589b8a442f1cf6 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 3 Jan 2024 13:28:37 +0100 Subject: [PATCH 5/6] Add spec coverage for missing translations handling --- .../components/solidus_admin/base_component.rb | 2 +- admin/config/initializers/view_component.rb | 2 +- .../solidus_admin/base_component_spec.rb | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/admin/app/components/solidus_admin/base_component.rb b/admin/app/components/solidus_admin/base_component.rb index 97de174fa9b..1da4c637c45 100644 --- a/admin/app/components/solidus_admin/base_component.rb +++ b/admin/app/components/solidus_admin/base_component.rb @@ -43,7 +43,7 @@ def missing_translation(key, options) logger.debug " [#{self.class}] Missing translation: #{keys.join('.')}" - if options[:locale] != :en + if (options[:locale] || I18n.default_locale) != :en t(key, **options, locale: :en) else "translation missing: #{keys.join('.')}" diff --git a/admin/config/initializers/view_component.rb b/admin/config/initializers/view_component.rb index 5222819a7db..beb9345c26a 100644 --- a/admin/config/initializers/view_component.rb +++ b/admin/config/initializers/view_component.rb @@ -10,7 +10,7 @@ clear = "\e[0m" ActiveSupport::Notifications.subscribe("render.view_component") do |*args| - next unless args.last[:name].starts_with?("SolidusAdmin::") + next unless args.last[:name]&.starts_with?("SolidusAdmin::") event = ActiveSupport::Notifications::Event.new(*args) SolidusAdmin::BaseComponent.logger.debug \ diff --git a/admin/spec/components/solidus_admin/base_component_spec.rb b/admin/spec/components/solidus_admin/base_component_spec.rb index dc2ab173aa9..2c95f2c9fd3 100644 --- a/admin/spec/components/solidus_admin/base_component_spec.rb +++ b/admin/spec/components/solidus_admin/base_component_spec.rb @@ -48,4 +48,20 @@ def call expect(SolidusAdmin::Foo::Bar::Component.new.stimulus_id).to eq("foo--bar") end end + + describe "missing translations" do + it "logs and shows the full chain of keys" do + debug_logs = [] + + allow(Rails.logger).to receive(:debug) { debug_logs << _1 } + + component_class = stub_const("Foo::Component", Class.new(described_class){ erb_template "" }) + component = component_class.new + render_inline(component) + translation = component.translate("foo.bar.baz") + + expect(translation).to eq("translation missing: en.foo.bar.baz") + expect(debug_logs).to include(%{ [Foo::Component] Missing translation: en.foo.bar.baz}) + end + end end From 4465f025dec03441d8e51a12abdeffb3c607a491 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 3 Jan 2024 14:28:30 +0100 Subject: [PATCH 6/6] Add coverage for importing backend menu items into the admin --- .../spec/solidus_admin/configuration_spec.rb | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/admin/spec/solidus_admin/configuration_spec.rb b/admin/spec/solidus_admin/configuration_spec.rb index 61322c69469..98da3b2cbf9 100644 --- a/admin/spec/solidus_admin/configuration_spec.rb +++ b/admin/spec/solidus_admin/configuration_spec.rb @@ -39,4 +39,95 @@ expect(config.storefront_product_path(product)).to eq("/foo/bar/foo-bar-123") end end + + describe "#import_menu_items_from_backend!" do + it "imports the menu items from the backend" do + allow(Spree::Backend::Config).to receive(:menu_items).and_return([ + Spree::BackendConfiguration::MenuItem.new( + label: :item1, + icon: 'ri-inbox-line', + condition: -> {}, + match_path: %r{/foo}, + url: :foo, + ), + Spree::BackendConfiguration::MenuItem.new( + label: :item2, + icon: 'shopping-cart', + condition: -> {}, + match_path: -> {}, + url: "/bar" + ), + Spree::BackendConfiguration::MenuItem.new( + label: :item3, + icon: 'shopping-cart', + condition: -> {}, + match_path: "foo", + url: -> {}, + ), + Spree::BackendConfiguration::MenuItem.new( + label: :item4, + icon: 'shopping-cart', + condition: -> {}, + match_path: nil, + url: nil, + children: [ + Spree::BackendConfiguration::MenuItem.new( + label: :item4_1, + icon: 'shopping-cart', + condition: -> {}, + match_path: nil, + url: nil, + ), + ], + ), + ]) + + config = described_class.new + config.import_menu_items_from_backend! + + expect(config.menu_items).to match([ + { + key: :item1, + icon: 'inbox-line', + route: a_kind_of(Proc), + children: [], + match_path: a_kind_of(Proc), + position: 0, + }, + { + key: :item2, + icon: 'record-circle-line', + route: a_kind_of(Proc), + children: [], + match_path: a_kind_of(Proc), + position: 1, + }, + { + key: :item3, + icon: 'record-circle-line', + route: a_kind_of(Proc), + children: [], + match_path: a_kind_of(Proc), + position: 2, + }, + { + key: :item4, + icon: 'record-circle-line', + route: a_kind_of(Proc), + children: [ + { + key: :item4_1, + icon: 'record-circle-line', + route: a_kind_of(Proc), + children: [], + match_path: a_kind_of(Proc), + position: 0, + }, + ], + match_path: a_kind_of(Proc), + position: 3, + }, + ]) + end + end end