|
| 1 | +require "application_system_test_case" |
| 2 | + |
| 3 | +class LineItemSystemTest < ApplicationSystemTestCase |
| 4 | + include ActionView::Helpers::NumberHelper |
| 5 | + |
| 6 | + setup do |
| 7 | + login_as users(:accountant) |
| 8 | + |
| 9 | + @quote = quotes(:one) |
| 10 | + @line_item_date = line_item_dates(:today) |
| 11 | + @line_item = line_items(:room_today) |
| 12 | + |
| 13 | + visit quote_path(@quote) |
| 14 | + end |
| 15 | + |
| 16 | + test "Creating a new line item" do |
| 17 | + assert_selector "h1", text: "First quote" |
| 18 | + |
| 19 | + within "##{dom_id(@line_item_date)}" do |
| 20 | + click_on "Add item", match: :first |
| 21 | + end |
| 22 | + assert_selector "h1", text: "First quote" |
| 23 | + |
| 24 | + fill_in "Name", with: "Animation" |
| 25 | + fill_in "Quantity", with: 1 |
| 26 | + fill_in "Unit price", with: 1234 |
| 27 | + click_on "Create item" |
| 28 | + |
| 29 | + assert_selector "h1", text: "First quote" |
| 30 | + assert_text "Animation" |
| 31 | + assert_text number_to_currency(1234) |
| 32 | + end |
| 33 | + |
| 34 | + test "Updating a line item" do |
| 35 | + assert_selector "h1", text: "First quote" |
| 36 | + |
| 37 | + within "##{dom_id(@line_item)}" do |
| 38 | + click_on "Edit" |
| 39 | + end |
| 40 | + assert_selector "h1", text: "First quote" |
| 41 | + |
| 42 | + fill_in "Name", with: "Capybara article" |
| 43 | + fill_in "Unit price", with: 1234 |
| 44 | + click_on "Update item" |
| 45 | + |
| 46 | + assert_text "Capybara article" |
| 47 | + assert_text number_to_currency(1234) |
| 48 | + end |
| 49 | + |
| 50 | + test "Destroying a line item" do |
| 51 | + within "##{dom_id(@line_item_date)}" do |
| 52 | + assert_text @line_item.name |
| 53 | + end |
| 54 | + |
| 55 | + within "##{dom_id(@line_item)}" do |
| 56 | + click_on "Delete" |
| 57 | + end |
| 58 | + |
| 59 | + within "##{dom_id(@line_item_date)}" do |
| 60 | + assert_no_text @line_item.name |
| 61 | + end |
| 62 | + end |
| 63 | +end |
0 commit comments