Skip to content

Commit

Permalink
Merge pull request #5580 from solidusio/elia/restore-coverage-uploads
Browse files Browse the repository at this point in the history
Restore coverage tracking
  • Loading branch information
elia authored Jan 3, 2024
2 parents d01b825 + 4465f02 commit 4c635fe
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 34 deletions.
56 changes: 24 additions & 32 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -323,14 +299,16 @@ 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:
type: string
default: postgres
ruby:
type: string
default: '3.1'
default: '3.2'
executor:
name: << parameters.database >>
ruby: << parameters.ruby >>
Expand All @@ -341,19 +319,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.
Expand Down
2 changes: 1 addition & 1 deletion admin/app/components/solidus_admin/base_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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('.')}"
Expand Down
2 changes: 1 addition & 1 deletion admin/config/initializers/view_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
16 changes: 16 additions & 0 deletions admin/spec/components/solidus_admin/base_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
File renamed without changes.
8 changes: 8 additions & 0 deletions admin/spec/features/stock_items_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions admin/spec/features/tax_rates_spec.rb
Original file line number Diff line number Diff line change
@@ -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: '[email protected]') }

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
91 changes: 91 additions & 0 deletions admin/spec/solidus_admin/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4c635fe

Please sign in to comment.