Move specs to relevant file

These tests are about browsing products, not performing actions.

Well, ok there's one about updating, which should probably go in the update file. But hey this is better than before.
And admittedly the "Actions" file covers three different things, not just the actions menu. shrug.
This commit is contained in:
David Cook
2026-02-03 15:14:53 +11:00
parent dff9d7ede6
commit 1332051a6e
2 changed files with 99 additions and 101 deletions

View File

@@ -2,7 +2,7 @@
require "system_helper"
RSpec.describe 'As an enterprise user, I can manage my products' do
RSpec.describe 'As an enterprise user, I can perform actions on the products screen' do
include AdminHelper
include WebHelper
include AuthenticationHelper
@@ -19,18 +19,6 @@ RSpec.describe 'As an enterprise user, I can manage my products' do
let(:categories_search_selector) { 'input[placeholder="Select category"]' }
let(:tax_categories_search_selector) { 'input[placeholder="Search for tax categories"]' }
describe "with no products" do
before { visit admin_products_url }
it "can see the new product page" do
expect(page).to have_content "Bulk Edit Products"
expect(page).to have_text "No products found"
# displays buttons to add products with the correct links
expect(page).to have_link(class: "button", text: "New Product", href: "/admin/products/new")
expect(page).to have_link(class: "button", text: "Import multiple products",
href: admin_product_import_path)
end
end
describe "column selector" do
let!(:product) { create(:simple_product) }
@@ -105,8 +93,6 @@ RSpec.describe 'As an enterprise user, I can manage my products' do
end
end
describe "columns"
describe "Changing producers, category and tax category" do
let!(:variant_a1) {
product_a.variants.first.tap{ |v|
@@ -527,90 +513,6 @@ RSpec.describe 'As an enterprise user, I can manage my products' do
end
end
context "as an enterprise manager" do
let(:supplier_managed1) { create(:supplier_enterprise, name: 'Supplier Managed 1') }
let(:supplier_managed2) { create(:supplier_enterprise, name: 'Supplier Managed 2') }
let(:supplier_unmanaged) { create(:supplier_enterprise, name: 'Supplier Unmanaged') }
let(:supplier_permitted) { create(:supplier_enterprise, name: 'Supplier Permitted') }
let(:distributor_managed) { create(:distributor_enterprise, name: 'Distributor Managed') }
let(:distributor_unmanaged) { create(:distributor_enterprise, name: 'Distributor Unmanaged') }
let!(:product_supplied) { create(:product, supplier_id: supplier_managed1.id, price: 10.0) }
let!(:product_not_supplied) { create(:product, supplier_id: supplier_unmanaged.id) }
let!(:product_supplied_permitted) {
create(:product, name: 'Product Permitted', supplier_id: supplier_permitted.id, price: 10.0)
}
let(:product_supplied_inactive) {
create(:product, supplier_id: supplier_managed1.id, price: 10.0)
}
let!(:supplier_permitted_relationship) do
create(:enterprise_relationship, parent: supplier_permitted, child: supplier_managed1,
permissions_list: [:manage_products])
end
before do
enterprise_user = create(:user)
enterprise_user.enterprise_roles.build(enterprise: supplier_managed1).save
enterprise_user.enterprise_roles.build(enterprise: supplier_managed2).save
enterprise_user.enterprise_roles.build(enterprise: distributor_managed).save
login_as enterprise_user
end
it "shows only products that I supply" do
visit spree.admin_products_path
# displays permitted product list only
expect(page).to have_selector row_containing_name(product_supplied.name)
expect(page).to have_selector row_containing_name(product_supplied_permitted.name)
expect(page).not_to have_selector row_containing_name(product_not_supplied.name)
end
it "shows only suppliers that I manage or have permission to" do
visit spree.admin_products_path
within row_containing_placeholder(product_supplied.name) do
expect(page).to have_select(
'_products_0_variants_attributes_0_supplier_id',
options: [
'Select producer',
supplier_managed1.name, supplier_managed2.name, supplier_permitted.name
], selected: supplier_managed1.name
)
end
within row_containing_placeholder(product_supplied_permitted.name) do
expect(page).to have_select(
'_products_1_variants_attributes_0_supplier_id',
options: [
'Select producer',
supplier_managed1.name, supplier_managed2.name, supplier_permitted.name
], selected: supplier_permitted.name
)
end
end
it "shows inactive products that I supply" do
product_supplied_inactive
visit spree.admin_products_path
expect(page).to have_selector row_containing_name(product_supplied_inactive.name)
end
it "allows me to update a product" do
visit spree.admin_products_path
within row_containing_name(product_supplied.name) do
fill_in "Name", with: "Pommes"
end
click_button "Save changes"
expect(page).to have_content "Changes saved"
expect(page).to have_selector row_containing_name("Pommes")
end
end
def open_action_menu
page.find(".vertical-ellipsis-menu").click
end
@@ -618,4 +520,4 @@ RSpec.describe 'As an enterprise user, I can manage my products' do
def close_action_menu
page.find("div#content").click
end
end
end

View File

@@ -2,7 +2,7 @@
require "system_helper"
RSpec.describe 'As an enterprise user, I can manage my products' do
RSpec.describe 'As an enterprise user, I can browse my products' do
include AdminHelper
include WebHelper
include AuthenticationHelper
@@ -19,6 +19,18 @@ RSpec.describe 'As an enterprise user, I can manage my products' do
let(:categories_search_selector) { 'input[placeholder="Search for categories"]' }
let(:tax_categories_search_selector) { 'input[placeholder="Search for tax categories"]' }
describe "with no products" do
before { visit admin_products_url }
it "can see the new product page" do
expect(page).to have_content "Bulk Edit Products"
expect(page).to have_text "No products found"
# displays buttons to add products with the correct links
expect(page).to have_link(class: "button", text: "New Product", href: "/admin/products/new")
expect(page).to have_link(class: "button", text: "Import multiple products",
href: admin_product_import_path)
end
end
describe "listing" do
let!(:p1) { create(:product, name: "Product1") }
let!(:p2) { create(:product, name: "Product2") }
@@ -463,4 +475,88 @@ RSpec.describe 'As an enterprise user, I can manage my products' do
end
end
end
context "as an enterprise manager" do
let(:supplier_managed1) { create(:supplier_enterprise, name: 'Supplier Managed 1') }
let(:supplier_managed2) { create(:supplier_enterprise, name: 'Supplier Managed 2') }
let(:supplier_unmanaged) { create(:supplier_enterprise, name: 'Supplier Unmanaged') }
let(:supplier_permitted) { create(:supplier_enterprise, name: 'Supplier Permitted') }
let(:distributor_managed) { create(:distributor_enterprise, name: 'Distributor Managed') }
let(:distributor_unmanaged) { create(:distributor_enterprise, name: 'Distributor Unmanaged') }
let!(:product_supplied) { create(:product, supplier_id: supplier_managed1.id, price: 10.0) }
let!(:product_not_supplied) { create(:product, supplier_id: supplier_unmanaged.id) }
let!(:product_supplied_permitted) {
create(:product, name: 'Product Permitted', supplier_id: supplier_permitted.id, price: 10.0)
}
let(:product_supplied_inactive) {
create(:product, supplier_id: supplier_managed1.id, price: 10.0)
}
let!(:supplier_permitted_relationship) do
create(:enterprise_relationship, parent: supplier_permitted, child: supplier_managed1,
permissions_list: [:manage_products])
end
before do
enterprise_user = create(:user)
enterprise_user.enterprise_roles.build(enterprise: supplier_managed1).save
enterprise_user.enterprise_roles.build(enterprise: supplier_managed2).save
enterprise_user.enterprise_roles.build(enterprise: distributor_managed).save
login_as enterprise_user
end
it "shows only products that I supply" do
visit spree.admin_products_path
# displays permitted product list only
expect(page).to have_selector row_containing_name(product_supplied.name)
expect(page).to have_selector row_containing_name(product_supplied_permitted.name)
expect(page).not_to have_selector row_containing_name(product_not_supplied.name)
end
it "shows only suppliers that I manage or have permission to" do
visit spree.admin_products_path
within row_containing_placeholder(product_supplied.name) do
expect(page).to have_select(
'_products_0_variants_attributes_0_supplier_id',
options: [
'Select producer',
supplier_managed1.name, supplier_managed2.name, supplier_permitted.name
], selected: supplier_managed1.name
)
end
within row_containing_placeholder(product_supplied_permitted.name) do
expect(page).to have_select(
'_products_1_variants_attributes_0_supplier_id',
options: [
'Select producer',
supplier_managed1.name, supplier_managed2.name, supplier_permitted.name
], selected: supplier_permitted.name
)
end
end
it "shows inactive products that I supply" do
product_supplied_inactive
visit spree.admin_products_path
expect(page).to have_selector row_containing_name(product_supplied_inactive.name)
end
it "allows me to update a product" do
visit spree.admin_products_path
within row_containing_name(product_supplied.name) do
fill_in "Name", with: "Pommes"
end
click_button "Save changes"
expect(page).to have_content "Changes saved"
expect(page).to have_selector row_containing_name("Pommes")
end
end
end