From 6f5dd5ab0c65bf08212403de08d80624c6a9fef1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 10 Mar 2022 09:53:16 +0100 Subject: [PATCH] Prepare to receive another test in the same context --- spec/system/admin/enterprise_fees_spec.rb | 64 ++++++++++++----------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/spec/system/admin/enterprise_fees_spec.rb b/spec/system/admin/enterprise_fees_spec.rb index 680ff8eb50..90c88c7b2a 100644 --- a/spec/system/admin/enterprise_fees_spec.rb +++ b/spec/system/admin/enterprise_fees_spec.rb @@ -58,42 +58,46 @@ describe ' expect(page).to have_selector "#sets_enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_flat_percent[value='12.34']" end - it "editing an enterprise fee" do + context "editing an enterprise fee" do # Given an enterprise fee - fee = create(:enterprise_fee) - enterprise = create(:enterprise, name: 'Foo') + let!(:fee) { create(:enterprise_fee) } + let!(:enterprise) { create(:enterprise, name: 'Foo') } - # When I go to the enterprise fees page - login_as_admin_and_visit admin_enterprise_fees_path + before do + # When I go to the enterprise fees page + login_as_admin_and_visit admin_enterprise_fees_path + # And I update the fields for the enterprise fee and click update + select 'Foo', from: 'sets_enterprise_fee_set_collection_attributes_0_enterprise_id' + select 'Admin', from: 'sets_enterprise_fee_set_collection_attributes_0_fee_type' + fill_in 'sets_enterprise_fee_set_collection_attributes_0_name', with: 'Greetings!' + select 'Inherit From Product', from: 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id' + select 'Flat Percent', from: 'sets_enterprise_fee_set_collection_attributes_0_calculator_type' + click_button 'Update' + end - # And I update the fields for the enterprise fee and click update - select 'Foo', from: 'sets_enterprise_fee_set_collection_attributes_0_enterprise_id' - select 'Admin', from: 'sets_enterprise_fee_set_collection_attributes_0_fee_type' - fill_in 'sets_enterprise_fee_set_collection_attributes_0_name', with: 'Greetings!' - select 'Inherit From Product', - from: 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id' - select 'Flat Percent', from: 'sets_enterprise_fee_set_collection_attributes_0_calculator_type' - click_button 'Update' + it "handle the default cases" do + # Then I should see the updated fields for my fee + expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_enterprise_id", + selected: 'Foo' + expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_fee_type", + selected: 'Admin fee' + expect(page).to have_selector "input[value='Greetings!']" + expect(page).to have_select 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id', + selected: 'Inherit From Product' + expect(page).to have_selector "option[selected]", text: 'Flat Percent (per item)' - # Then I should see the updated fields for my fee - expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_enterprise_id", - selected: 'Foo' - expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_fee_type", - selected: 'Admin fee' - expect(page).to have_selector "input[value='Greetings!']" - expect(page).to have_select 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id', - selected: 'Inherit From Product' - expect(page).to have_selector "option[selected]", text: 'Flat Percent (per item)' + fee.reload + expect(fee.enterprise).to eq(enterprise) + expect(fee.name).to eq('Greetings!') + expect(fee.fee_type).to eq('admin') + expect(fee.calculator_type).to eq("Calculator::FlatPercentPerItem") + + # Sets tax_category and inherits_tax_category + expect(fee.tax_category).to eq(nil) + expect(fee.inherits_tax_category).to eq(true) + end - fee.reload - expect(fee.enterprise).to eq(enterprise) - expect(fee.name).to eq('Greetings!') - expect(fee.fee_type).to eq('admin') - expect(fee.calculator_type).to eq("Calculator::FlatPercentPerItem") - # Sets tax_category and inherits_tax_category - expect(fee.tax_category).to eq(nil) - expect(fee.inherits_tax_category).to eq(true) end it "deleting an enterprise fee" do