From 41dbad629b96c82bb7e1e07919b59f88e3f95f07 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Tue, 8 Aug 2023 14:53:54 +1000 Subject: [PATCH] Add system spec to cover deleting data when filtering covers tag scenario and code scenario --- spec/system/admin/customers_spec.rb | 74 ++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/spec/system/admin/customers_spec.rb b/spec/system/admin/customers_spec.rb index fc7172697b..e50c0c71db 100644 --- a/spec/system/admin/customers_spec.rb +++ b/spec/system/admin/customers_spec.rb @@ -37,8 +37,7 @@ describe 'Customers' do # Prompts for a hub for a list of my managed enterprises expect(page) .to have_select2 "shop_id", with_options: [managed_distributor1.name, - managed_distributor2.name], - without_options: [unmanaged_distributor.name] + managed_distributor2.name], without_options: [unmanaged_distributor.name] select2_select managed_distributor2.name, from: "shop_id" @@ -185,6 +184,77 @@ describe 'Customers' do end end + describe "filtering" do + before do + customer4.update enterprise: managed_distributor1 + end + + context "when filtering by code" do + before do + customer4.update code: 12345 + + select2_select managed_distributor1.name, from: "shop_id" + + fill_in "quick_search", with: customer4.code + end + + it "displays only customer matching the code" do + expect(page).to have_content(customer4.email) + expect(page).not_to have_content(customer1.email) + expect(page).not_to have_content(customer2.email) + end + + context "when updating code" do + pending "allows user to save changes" do + fill_in "code", with: "" + + expect(page).not_to have_content("12345") + expect(page).to have_content 'You have unsaved changes' + + click_button "Save Changes" + + # changes are saved in the database + expect(customer4.reload.code).to eq(nil) + end + end + end + + context "when filtering by tag" do + before do + # Add test_tag to customer4 + select2_select managed_distributor1.name, from: "shop_id" + within "tr#c_#{customer4.id}" do + find(:css, "tags-input .tags input").set "test_tag\n" + end + click_button "Save Changes" + + # Reload the page + visit admin_customers_path + select2_select managed_distributor1.name, from: "shop_id" + fill_in "quick_search", with: "test_tag" + end + + it "displays only customer matching the tag" do + expect(page).to have_content(customer4.email) + expect(page).not_to have_content(customer1.email) + expect(page).not_to have_content(customer2.email) + end + + context "when removing tag" do + it "allows user to save changes" do + find("tags-input li.tag-item a.remove-button").click + + expect(page).to have_content("No customers found") + expect(page).to have_content 'You have unsaved changes' + + click_button "Save Changes" + + expect(customer4.reload.tag_list).to be_empty + end + end + end + end + it "allows updating of attributes" do select2_select managed_distributor1.name, from: "shop_id"