From 347d20c3fb0f0160dbaa64a79778878f637c79f5 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Mon, 5 May 2025 14:38:09 +1000 Subject: [PATCH] Add system test for tags --- .../tag_list_input_component.html.haml | 2 +- spec/support/products_helper.rb | 5 +++++ spec/system/admin/products_v3/index_spec.rb | 17 +++++++++++++++++ spec/system/admin/products_v3/update_spec.rb | 6 +++++- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/components/tag_list_input_component/tag_list_input_component.html.haml b/app/components/tag_list_input_component/tag_list_input_component.html.haml index ef4b02d199..7298271b2a 100644 --- a/app/components/tag_list_input_component/tag_list_input_component.html.haml +++ b/app/components/tag_list_input_component/tag_list_input_component.html.haml @@ -16,4 +16,4 @@ %span=tag %a.remove-button{ "data-action": "click->tag-list-input-component--tag-list-input#removeTag" } × - = text_field_tag "variant_add_tag_#{f.object.id}".to_sym, nil, class: "input", placeholder: placeholder, "data-action": "keydown.enter->tag-list-input-component--tag-list-input#addTag keyup->tag-list-input-component--tag-list-input#filterInput", "data-tag-list-input-component--tag-list-input-target": "newTag" + = text_field_tag "variant_add_tag_#{f.object.id}".to_sym, nil, "aria-label": "Tags", class: "input", placeholder: placeholder, "data-action": "keydown.enter->tag-list-input-component--tag-list-input#addTag keyup->tag-list-input-component--tag-list-input#filterInput", "data-tag-list-input-component--tag-list-input-target": "newTag" diff --git a/spec/support/products_helper.rb b/spec/support/products_helper.rb index 518aa45257..42de042eb3 100644 --- a/spec/support/products_helper.rb +++ b/spec/support/products_helper.rb @@ -34,6 +34,11 @@ module ProductsHelper click_button "Search" end + def search_by_tag(tag) + tomselect_multiselect tag, from: "tags_name_in" + click_button "Search" + end + # Selector for table row that has an input with this value. # Because there are no visible labels, the user has to assume which product it is, based on the # visible name. diff --git a/spec/system/admin/products_v3/index_spec.rb b/spec/system/admin/products_v3/index_spec.rb index d88bc2451e..9c9adfdf61 100644 --- a/spec/system/admin/products_v3/index_spec.rb +++ b/spec/system/admin/products_v3/index_spec.rb @@ -377,5 +377,22 @@ RSpec.describe 'As an enterprise user, I can manage my products' do expect(page).to have_field "Name", with: product_by_category.name end end + + context "with variant tag", feature: :variant_tag do + before do + create(:variant, tag_list: "organic") + create_products 1 + end + + it "can search by tag" do + visit admin_products_url + pause + search_by_tag "organic" + + expect(page).to have_select "tags_name_in", selected: "organic" + expect(page).to have_content "1 product found for your search criteria. Showing 1 to 1." + expect_products_count_to_be 1 + end + end end end diff --git a/spec/system/admin/products_v3/update_spec.rb b/spec/system/admin/products_v3/update_spec.rb index d82fa77400..58e81aa5a5 100644 --- a/spec/system/admin/products_v3/update_spec.rb +++ b/spec/system/admin/products_v3/update_spec.rb @@ -20,7 +20,7 @@ RSpec.describe 'As an enterprise user, I can update my products' do let(:categories_search_selector) { 'input[placeholder="Search for categories"]' } let(:tax_categories_search_selector) { 'input[placeholder="Search for tax categories"]' } - describe "updating" do + describe "updating", feature: :variant_tag do let!(:taxon) { create(:taxon) } let!(:variant_a1) { product_a.variants.first.tap{ |v| @@ -65,6 +65,9 @@ RSpec.describe 'As an enterprise user, I can update my products' do fill_in "Unit value", with: "500.1" fill_in "Price", with: "10.25" + fill_in "Tags", with: "tag one" + find_field("Tags").send_keys(:enter) # add the tag + # Stock popout click_on "On Hand" # activate popout fill_in "On Hand", with: "-1" @@ -89,6 +92,7 @@ RSpec.describe 'As an enterprise user, I can update my products' do .and change{ variant_a1.on_hand }.to(6) .and change{ variant_a1.variant_unit }.to("volume") .and change{ variant_a1.variant_unit_scale }.to(0.001) + .and change{ variant_a1.tag_list }.to(["tag one"]) within row_containing_name("Pommes") do expect(page).to have_field "Name", with: "Pommes"