mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Adds tests around using the page
- with no products - column display dropdown - listing products with several variants
This commit is contained in:
committed by
zanetagebka
parent
44a296691a
commit
20fb38da96
@@ -18,9 +18,128 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi
|
||||
let(:categories_search_selector) { 'input[placeholder="Search for categories"]' }
|
||||
let(:tax_categories_search_selector) { 'input[placeholder="Search for tax categories"]' }
|
||||
|
||||
it "can see the new product page" do
|
||||
visit admin_products_url
|
||||
expect(page).to have_content "Bulk Edit Products"
|
||||
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/products/import")
|
||||
end
|
||||
end
|
||||
|
||||
describe "using the page" do
|
||||
describe "using column display dropdown" do
|
||||
let(:product) { create(:simple_product) }
|
||||
|
||||
before do
|
||||
pending "Pending implementation, issue #11055"
|
||||
login_as_admin
|
||||
visit spree.admin_products_path
|
||||
end
|
||||
|
||||
it "shows a column display dropdown, which shows a list of columns when clicked" do
|
||||
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).not_to have_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
|
||||
end
|
||||
|
||||
describe "listing" do
|
||||
let!(:p1) { create(:product) }
|
||||
let!(:p2) { create(:product) }
|
||||
|
||||
before do
|
||||
visit admin_products_url
|
||||
end
|
||||
|
||||
it "displays a list of products" do
|
||||
within ".products" do
|
||||
# displays table header
|
||||
expect(page).to have_selector "th", text: "Name"
|
||||
expect(page).to have_selector "th", text: "SKU"
|
||||
expect(page).to have_selector "th", text: "Unit scale"
|
||||
expect(page).to have_selector "th", text: "Unit"
|
||||
expect(page).to have_selector "th", text: "Price"
|
||||
expect(page).to have_selector "th", text: "On Hand"
|
||||
expect(page).to have_selector "th", text: "Producer"
|
||||
expect(page).to have_selector "th", text: "Category"
|
||||
expect(page).to have_selector "th", text: "Tax Category"
|
||||
expect(page).to have_selector "th", text: "Inherits Properties?"
|
||||
expect(page).to have_selector "th", text: "Actions"
|
||||
|
||||
# displays product list
|
||||
expect(page).to have_field("_products_0_name", with: p1.name.to_s)
|
||||
expect(page).to have_field("_products_1_name", with: p2.name.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
it "displays a select box for suppliers, with the appropriate supplier selected" do
|
||||
pending( "[BUU] Change producer, unit type, category and tax category #11060" )
|
||||
s1 = FactoryBot.create(:supplier_enterprise)
|
||||
s2 = FactoryBot.create(:supplier_enterprise)
|
||||
s3 = FactoryBot.create(:supplier_enterprise)
|
||||
p1 = FactoryBot.create(:product, supplier: s2)
|
||||
p2 = FactoryBot.create(:product, supplier: s3)
|
||||
|
||||
visit spree.admin_products_path
|
||||
|
||||
expect(page).to have_select "producer_id", with_options: [s1.name, s2.name, s3.name],
|
||||
selected: s2.name
|
||||
expect(page).to have_select "producer_id", with_options: [s1.name, s2.name, s3.name],
|
||||
selected: s3.name
|
||||
end
|
||||
|
||||
context "with several variants" do
|
||||
let!(:variant1) { p1.variants.first }
|
||||
let!(:variant2) { p2.variants.first }
|
||||
let!(:variant3) { create(:variant, product: p2, on_demand: false, on_hand: 4) }
|
||||
|
||||
before do
|
||||
variant1.update!(on_hand: 0, on_demand: true)
|
||||
variant2.update!(on_hand: 16, on_demand: false)
|
||||
visit spree.admin_products_path
|
||||
end
|
||||
|
||||
it "displays an on hand count in a span for each product" do
|
||||
expect(page).to have_content "On demand"
|
||||
expect(page).not_to have_content "20" # does not display the total stock
|
||||
expect(page).to have_content "16" # displays the stock for variant_2
|
||||
expect(page).to have_content "4" # displays the stock for variant_3
|
||||
end
|
||||
end
|
||||
|
||||
it "displays a select box for the unit of measure for the product's variants" do
|
||||
pending( "[BUU] Change producer, unit type and tax category #11060" )
|
||||
p = FactoryBot.create(:product, variant_unit: 'weight', variant_unit_scale: 1,
|
||||
variant_unit_name: '')
|
||||
|
||||
visit spree.admin_products_path
|
||||
|
||||
expect(page).to have_select "variant_unit_with_scale", selected: "Weight (g)"
|
||||
end
|
||||
|
||||
it "displays a text field for the item name when unit is set to 'Items'" do
|
||||
pending( "[BUU] Change producer, unit type and tax category #11060" )
|
||||
p = FactoryBot.create(:product, variant_unit: 'items', variant_unit_scale: nil,
|
||||
variant_unit_name: 'packet')
|
||||
|
||||
visit spree.admin_products_path
|
||||
|
||||
expect(page).to have_select "variant_unit_with_scale", selected: "Items"
|
||||
expect(page).to have_field "variant_unit_name", with: "packet"
|
||||
end
|
||||
end
|
||||
|
||||
describe "sorting" do
|
||||
|
||||
Reference in New Issue
Block a user