From fb0be1c7f36e365ab36519d391de33a755b2c96d Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Sat, 25 May 2024 15:13:59 +0100 Subject: [PATCH 1/7] Adds tests around using the page - with no products - column display dropdown - listing products with several variants --- .../system/admin/products_v3/products_spec.rb | 125 +++++++++++++++++- 1 file changed, 122 insertions(+), 3 deletions(-) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 757be44d02..fb739b2cac 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -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 From 80a682e2f505057a9cfdb5ee314e30ac56551f97 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Sat, 25 May 2024 15:59:10 +0100 Subject: [PATCH 2/7] Updates tests around product and variant search Adds test for a non-existing product Adds test for variant search Improves tests with multiple variants --- .../system/admin/products_v3/products_spec.rb | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index fb739b2cac..e025e8dcda 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -208,11 +208,13 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi end describe "search" do - # TODO: explicitly test with multiple products, to ensure incorrect products don't show. - # TODO: test with multiple variants, to ensure distinct query reponse context "product has searchable term" do # create a product with a name that can be searched let!(:product_by_name) { create(:simple_product, name: "searchable product") } + let!(:variant_a) { + create(:variant, product_id: product_by_name.id, display_name: "Medium box") + } + let!(:variant_b) { create(:variant, product_id: product_by_name.id, display_name: "Big box") } it "can search for a product" do create_products 1 @@ -221,7 +223,39 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi search_for "searchable product" expect(page).to have_field "search_term", with: "searchable product" - # expect(page).to have_content "1 product found for your search criteria." + expect(page).to have_content "1 products found for your search criteria." + expect_products_count_to_be 1 + end + + it "with multiple products" do + create_products 2 + visit admin_products_url + + # returns no results, if the product does not exist + search_for "a product which does not exist" + + expect(page).to have_field "search_term", with: "a product which does not exist" + expect(page).to have_content "No products found for your search criteria" + expect_products_count_to_be 0 + + # returns the existing product + search_for "searchable product" + + expect(page).to have_field "search_term", with: "searchable product" + expect(page).to have_content "1 products found for your search criteria." + expect_products_count_to_be 1 + end + + it "can search variant names" do + create_products 1 + visit admin_products_url + + expect_products_count_to_be 2 + + search_for "Big box" + + expect(page).to have_field "search_term", with: "Big box" + expect(page).to have_content "1 products found for your search criteria." expect_products_count_to_be 1 end @@ -238,7 +272,7 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi expect_per_page_to_be 15 expect_products_count_to_be 1 search_for "searchable product" - # expect(page).to have_content "1 product found for your search criteria." + expect(page).to have_content "1 products found for your search criteria." expect_products_count_to_be 1 end @@ -248,7 +282,7 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi search_for "searchable product" expect(page).to have_field "search_term", with: "searchable product" - # expect(page).to have_content "1 product found for your search criteria." + expect(page).to have_content "1 products found for your search criteria." expect_products_count_to_be 1 expect(page).to have_field "Name", with: product_by_name.name From c711387c5ab341e5a3f9d381a5f6b947c1092b57 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Sun, 26 May 2024 17:18:03 +0100 Subject: [PATCH 3/7] Removes pending test case - covered in: - Changing producers, category and tax category, done in 15ee4f6 - Updating Unit value, done in 49226ff Removes comment about errors for empty variant_unit_name I think this was done in commit f05d27b Would you agree @dacook? --- spec/system/admin/products_v3/products_spec.rb | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index e025e8dcda..31e4fc4e9e 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -85,22 +85,6 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi 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 } @@ -397,7 +381,6 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi end # Unit popout - # TODO: prevent empty value fill_in "Unit value", with: "" click_button "Save changes" # attempt to save or close the popout expect(page).to have_field "Unit value", with: "" # popout is still open From 2c081dc5f033f731af67588cba41a077bbcbd427 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Sun, 26 May 2024 18:24:43 +0100 Subject: [PATCH 4/7] Assures the Edit button link is always displayed for the first variant, although the delete button is not Also should work for a second (non-default variant) Removes unecessary test cases --- spec/system/admin/products_v3/products_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 31e4fc4e9e..adf8b94e3a 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -1196,6 +1196,9 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi let(:default_variant_selector) { "tr:has(input[aria-label=Price][value='#{product_a.price}'])" } + let(:link_edit_variant) { + "/admin/products/#{Spree::Product.first.id}/variants/#{Spree::Variant.first.id}/edit" + } describe "Actions columns (delete)" do before do @@ -1203,6 +1206,7 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi end it "shows an actions menu with a delete link when clicking on icon for product. " \ + "shows link to clone and edit the product;" \ "doesn't show delete link for the single variant" do within product_selector do page.find(".vertical-ellipsis-menu").click @@ -1213,6 +1217,7 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi # to select the default variant within default_variant_selector do page.find(".vertical-ellipsis-menu").click + expect(page).to have_link "Edit", href: link_edit_variant expect(page).not_to have_css(delete_option_selector) end end @@ -1224,17 +1229,21 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi display_name: "Medium box", sku: "APL-01", price: 5.25) + link_edit_variant2 = + "/admin/products/#{Spree::Product.first.id}/variants/#{Spree::Variant.second.id}/edit" visit admin_products_url # to select the default variant within default_variant_selector do page.find(".vertical-ellipsis-menu").click + expect(page).to have_link "Edit", href: link_edit_variant expect(page).to have_css(delete_option_selector) end page.find("div#content").click # to close the vertical actions menu within variant_selector do page.find(".vertical-ellipsis-menu").click + expect(page).to have_link "Edit", href: link_edit_variant2 expect(page).to have_css(delete_option_selector) end end From 3d1c94720a64ffd2ae99f3b97940e84487c26289 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 29 May 2024 15:40:30 +0100 Subject: [PATCH 5/7] Applies existing helper to assert on rows with product name --- spec/system/admin/products_v3/products_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index adf8b94e3a..57f3390b82 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -80,8 +80,8 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi 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) + expect(page).to have_selector row_containing_name(p1.name.to_s) + expect(page).to have_selector row_containing_name(p2.name.to_s) end end From ce36fb45a0d6d9a490ae51706d5c2a91d5fd1d29 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Sun, 2 Jun 2024 16:00:44 +0200 Subject: [PATCH 6/7] Removes tests on edit action, under the Delete section --- spec/system/admin/products_v3/products_spec.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 57f3390b82..823910fa64 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -1196,9 +1196,6 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi let(:default_variant_selector) { "tr:has(input[aria-label=Price][value='#{product_a.price}'])" } - let(:link_edit_variant) { - "/admin/products/#{Spree::Product.first.id}/variants/#{Spree::Variant.first.id}/edit" - } describe "Actions columns (delete)" do before do @@ -1217,7 +1214,6 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi # to select the default variant within default_variant_selector do page.find(".vertical-ellipsis-menu").click - expect(page).to have_link "Edit", href: link_edit_variant expect(page).not_to have_css(delete_option_selector) end end @@ -1236,14 +1232,12 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi # to select the default variant within default_variant_selector do page.find(".vertical-ellipsis-menu").click - expect(page).to have_link "Edit", href: link_edit_variant expect(page).to have_css(delete_option_selector) end page.find("div#content").click # to close the vertical actions menu within variant_selector do page.find(".vertical-ellipsis-menu").click - expect(page).to have_link "Edit", href: link_edit_variant2 expect(page).to have_css(delete_option_selector) end end From 999bc13fb5ed6e6b2f496baa76f30db9dc76f51a Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 3 Jun 2024 09:22:26 +1000 Subject: [PATCH 7/7] Remove redundant code --- .../system/admin/products_v3/products_spec.rb | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 823910fa64..3e1d6f007f 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -103,27 +103,6 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi 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 @@ -1203,7 +1182,6 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi end it "shows an actions menu with a delete link when clicking on icon for product. " \ - "shows link to clone and edit the product;" \ "doesn't show delete link for the single variant" do within product_selector do page.find(".vertical-ellipsis-menu").click @@ -1225,8 +1203,6 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi display_name: "Medium box", sku: "APL-01", price: 5.25) - link_edit_variant2 = - "/admin/products/#{Spree::Product.first.id}/variants/#{Spree::Variant.second.id}/edit" visit admin_products_url # to select the default variant