Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky admin stock items spec #5701

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: '[email protected]') }

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
Loading