Skip to content

Commit

Permalink
Merge pull request solidusio#5701 from mamhoff/fix-flaky-admin-spec
Browse files Browse the repository at this point in the history
Fix flaky admin stock items spec
  • Loading branch information
tvdeyen authored Mar 18, 2024
2 parents 96baef2 + 755f381 commit 9997bce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
33 changes: 16 additions & 17 deletions admin/spec/features/stock_items_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
describe "Stock Items", :js, type: :feature do
before { sign_in create(:admin_user, email: 'admin@example.com') }

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)
item.reduce_count_on_hand_to_zero
item
end
low_stock = begin
item = create(:stock_item, backorderable: false)
item.set_count_on_hand(SolidusAdmin::Config[:low_stock_value] - 1)
item
end
# We don't want multiple stock items per variant, and stock locations are created implicitly otherwise,
# and their default is to create stock items for all variants, which in this spec we do manually.
let!(:stock_location) { create(:stock_location, name: 'default', propagate_all_variants: false) }

let(:backorderable_variant) { create(:variant, sku: 'backorderable', stock_items: []) }
let(:non_backorderable_variant) { create(:variant, sku: 'non-backorderable', stock_items: []) }
let(:out_of_stock_variant) { create(:variant, sku: 'out-of-stock', stock_items: []) }
let(:low_stock_variant) { create(:variant, sku: 'low-stock', stock_items: []) }
let!(:backorderable) { create(:stock_item, variant: backorderable_variant, backorderable: true) }
let!(:non_backorderable) { create(:stock_item, variant: non_backorderable_variant, backorderable: false) }
let!(:out_of_stock) { create(:stock_item, variant: out_of_stock_variant, backorderable: false, on_hand: 0) }
let!(:low_stock) { create(:stock_item, variant: low_stock_variant, backorderable: false, on_hand: SolidusAdmin::Config.low_stock_value - 1) }

it "lists stock items and allows navigating through scopes" do
visit "/admin/stock_items"

# `All` default scope
Expand All @@ -29,11 +28,11 @@
expect(page).to have_content(low_stock.variant.sku)

# Edit stock item
find('td', text: 'MY-SKU-1234567890').click
find('td', text: 'non-backorderable').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')
expect(find('tr', text: 'non-backorderable')).to have_content('11')
expect(find('tr', text: 'non-backorderable')).to have_content('1 stock movement')

click_on 'Back Orderable'
expect(page).to have_css('[aria-current="true"]', text: 'Back Orderable')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
association :stock_location, factory: :stock_location_without_variant_propagation
variant

after(:create) { |object| object.adjust_count_on_hand(10) }
transient do
on_hand { 10 }
end

after(:create) { |object, evaluator| object.adjust_count_on_hand(evaluator.on_hand) }
end
end

0 comments on commit 9997bce

Please sign in to comment.