Skip to content

Commit

Permalink
add system spec
Browse files Browse the repository at this point in the history
  • Loading branch information
vjain98 committed Oct 20, 2022
1 parent 776b84f commit 6c3517f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions spec/system/admin/enterprise_fees_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,34 @@
expect(page).to have_selector "#sets_enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_flat_percent[value='12.34']"
end

it "creating an enterprise fee with invalid amount shows error flash message" do
# Given an enterprise
e = create(:supplier_enterprise, name: 'Feedme')

# When I go to the enterprise fees page
login_as_admin_and_visit admin_enterprise_fees_path

# And I fill in the fields for a new enterprise fee and click update
select 'Feedme', 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: 'Hello!'
select 'GST', 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'

# Then I should see my fee and fields for the calculator
expect(page).to have_content "Your enterprise fees have been updated."
expect(page).to have_selector "input[value='Hello!']"

# When I fill in the calculator fields and click update
fill_in 'sets_enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_flat_percent',
with: "\'20.0'"
click_button 'Update'

# Then I should see the flash error message
expect(flash_message).to eq('Invalid input. Please use only numbers. For example: 10, 5.5, -20')
end

context "editing an enterprise fee" do
# Given an enterprise fee
let!(:fee) { create(:enterprise_fee) }
Expand Down Expand Up @@ -106,6 +134,16 @@

expect(fee.reload.calculator_type).to eq("Calculator::PerItem")
end

it 'shows error flash when updating fee amount with invalid values' do
# When I fill in the calculator fields and click update
fill_in 'sets_enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_flat_percent',
with: "\'20.0'"
click_button 'Update'

# Then I should see the flash error message
expect(flash_message).to eq('Invalid input. Please use only numbers. For example: 10, 5.5, -20')
end
end

it "deleting an enterprise fee" do
Expand Down

0 comments on commit 6c3517f

Please sign in to comment.