Skip to content

Commit

Permalink
Brings the tests back to green, after rebasing
Browse files Browse the repository at this point in the history
This is a WIP branch, and each time we rebase we'll have some specs breaking. The changes in this commit mostly relate to the change in /admin/products URL, which points to the new BUU prodcts page; disabling the feature around related tests brings the branch back to green.
  • Loading branch information
filipefurtad0 committed Nov 21, 2023
1 parent 7d8f038 commit d8313b8
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 64 deletions.
30 changes: 17 additions & 13 deletions spec/system/admin/bulk_product_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
include AuthenticationHelper
include WebHelper

around do |example|
Flipper.disable(:admin_style_v3)
example.run
end

describe "listing products" do
before do
login_as_admin
Expand All @@ -18,7 +23,6 @@
it "displays a list of products" do
p1 = FactoryBot.create(:product)
p2 = FactoryBot.create(:product)

visit spree.admin_products_path

expect(page).to have_field "product_name", with: p1.name
Expand Down Expand Up @@ -201,8 +205,8 @@
login_as_admin
visit spree.admin_products_path

find("a", text: "New Product").click
expect(page).to have_content 'New Product'
find("a", text: "NEW PRODUCT").click
expect(page).to have_content "NEW PRODUCT"

fill_in 'product_name', with: 'Big Bag Of Apples'
select supplier.name, from: 'product_supplier_id'
Expand Down Expand Up @@ -703,17 +707,17 @@
login_as_admin
visit spree.admin_products_path

expect(page).to have_selector "th", text: "Name"
expect(page).to have_selector "th", text: "Producer"
expect(page).to have_selector "th", text: "Price"
expect(page).to have_selector "th", text: "On Hand"
expect(page).to have_selector "th", text: "NAME"
expect(page).to have_selector "th", text: "PRODUCER"
expect(page).to have_selector "th", text: "PRICE"
expect(page).to have_selector "th", text: "ON HAND"

toggle_columns /^.{0,1}Producer$/i

expect(page).to have_no_selector "th", text: "Producer"
expect(page).to have_selector "th", text: "Name"
expect(page).to have_selector "th", text: "Price"
expect(page).to have_selector "th", text: "On Hand"
expect(page).to have_no_selector "th", text: "PRODUCER"
expect(page).to have_selector "th", text: "NAME"
expect(page).to have_selector "th", text: "PRICE"
expect(page).to have_selector "th", text: "ON HAND"
end
end

Expand Down Expand Up @@ -818,8 +822,8 @@

visit spree.admin_products_path

find("a", text: "New Product").click
expect(page).to have_content 'New Product'
find("a", text: "NEW PRODUCT").click
expect(page).to have_content 'NEW PRODUCT'
expect(page).to have_select 'product_supplier_id',
with_options: [supplier_managed1.name, supplier_managed2.name,
supplier_permitted.name]
Expand Down
9 changes: 7 additions & 2 deletions spec/system/admin/product_import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
include AuthenticationHelper
include WebHelper

around do |example|
Flipper.disable(:admin_style_v3)
example.run
end

let!(:admin) { create(:admin_user) }
let!(:user) { create(:user) }
let!(:user2) { create(:user) }
Expand Down Expand Up @@ -707,8 +712,8 @@

expect(page).to have_selector '.created-count', text: '1'
expect(page).to have_no_selector '.updated-count'
expect(page).to have_content "Go To Products Page"
expect(page).to have_content "Upload Another File"
expect(page).to have_content "Go To Products Page".upcase
expect(page).to have_content "Upload Another File".upcase

visit spree.admin_products_path

Expand Down
106 changes: 58 additions & 48 deletions spec/system/admin/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,76 +204,86 @@
end
end

describe "deleting" do
let!(:product1) { create(:simple_product, name: 'a product to keep', supplier: @supplier) }

context 'a simple product' do
let!(:product2) { create(:simple_product, name: 'a product to delete', supplier: @supplier) }

before do
login_as_admin
visit spree.admin_products_path

within "#p_#{product2.id}" do
accept_alert { page.find("[data-powertip=Remove]").click }
end
visit current_path
end

it 'removes it from the product list' do
expect(page).not_to have_selector "#p_#{product2.id}"
expect(page).to have_selector "#p_#{product1.id}"
end
describe "legacy products page" do
around do |example|
Flipper.disable(:admin_style_v3)
example.run
end

context 'a shipped product' do
let!(:order) { create(:shipped_order, line_items_count: 1) }
let!(:line_item) { order.reload.line_items.first }
describe "deleting" do
let!(:product1) { create(:simple_product, name: 'a product to keep', supplier: @supplier) }

context 'a simple product' do
let!(:product2) {
create(:simple_product, name: 'a product to delete', supplier: @supplier)
}

context "a deleted line item from a shipped order" do
before do
login_as_admin
visit spree.admin_products_path

within "#p_#{order.variants.first.product_id}" do
within "#p_#{product2.id}" do
accept_alert { page.find("[data-powertip=Remove]").click }
end
visit current_path
end

it 'removes it from the product list' do
visit spree.admin_products_path

expect(page).not_to have_selector "#p_#{product2.id}"
expect(page).to have_selector "#p_#{product1.id}"
expect(page).not_to have_selector "#p_#{order.variants.first.product_id}"
end
end

context 'a shipped product' do
let!(:order) { create(:shipped_order, line_items_count: 1) }
let!(:line_item) { order.reload.line_items.first }

context "a deleted line item from a shipped order" do
before do
login_as_admin
visit spree.admin_products_path

within "#p_#{order.variants.first.product_id}" do
accept_alert { page.find("[data-powertip=Remove]").click }
end
end

it 'removes it from the product list' do
visit spree.admin_products_path

expect(page).to have_selector "#p_#{product1.id}"
expect(page).not_to have_selector "#p_#{order.variants.first.product_id}"
end

it 'keeps the line item on the order (admin)' do
visit spree.edit_admin_order_path(order)
it 'keeps the line item on the order (admin)' do
visit spree.edit_admin_order_path(order)

expect(page).to have_content(line_item.product.name.to_s)
expect(page).to have_content(line_item.product.name.to_s)
end
end
end
end
end

describe 'cloning' do
let!(:product1) {
create(:simple_product, name: 'a weight product', supplier: @supplier, variant_unit: "weight")
}
describe 'cloning' do
let!(:product1) {
create(:simple_product, name: 'a weight product', supplier: @supplier,
variant_unit: "weight")
}

context 'products' do
before do
login_as_admin
visit spree.admin_products_path
end

it 'creates a copy of the product' do
within "#p_#{product1.id}" do
page.find("[data-powertip=Clone]").click
context 'products' do
before do
login_as_admin
visit spree.admin_products_path
end
visit current_path
within "#p_#{product1.id + 1}" do
expect(page).to have_input "product_name", with: 'COPY OF a weight product'

it 'creates a copy of the product' do
within "#p_#{product1.id}" do
page.find("[data-powertip=Clone]").click
end
visit current_path
within "#p_#{product1.id + 1}" do
expect(page).to have_input "product_name", with: 'COPY OF a weight product'
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/system/admin/subscriptions/crud_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
accept_alert 'Are you sure?' do
find("a.cancel-order").click
end
expect(page).to have_content 'CANCELLED'.upcase
expect(page).to have_content 'CANCELLED'
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now

# Resuming an order
Expand Down
2 changes: 2 additions & 0 deletions spec/system/admin/subscriptions/smoke_tests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,14 @@
expect(page).to have_selector "#subscription-line-items .item", count: 4

# Delete an existing product
Flipper.disable(:admin_style_v3) # disabling BUU for legacy products page
login_as_admin
visit spree.admin_products_path
within "#p_#{shop_product2.id}" do
accept_alert { page.find("[data-powertip=Remove]").click }
end

Flipper.enable(:admin_style_v3) # re-enabling it for the rest of the spec
visit edit_admin_subscription_path(subscription)

# Remove deleted shop_variant from the subscription
Expand Down

0 comments on commit d8313b8

Please sign in to comment.