|
35 | 35 |
|
36 | 36 | context "kit creation" do |
37 | 37 | let(:kit_traits) { attributes_for(:kit) } |
38 | | - let(:item) { Item.last } |
39 | | - let(:quantity_per_kit) { 5 } |
40 | 38 | let(:value_in_dollars) { 10.10 } |
| 39 | + let(:value_in_cents) { value_in_dollars * 100 } |
| 40 | + let!(:items) { create_list(:item, 2, value_in_cents: value_in_cents, organization: organization) } |
| 41 | + let(:quantity_per_kit) { 5 } |
| 42 | + let(:kit_value_in_dollars) { (items.count * quantity_per_kit * value_in_dollars).round(2) } |
41 | 43 |
|
42 | 44 | before do |
43 | 45 | visit new_kit_path |
44 | 46 | fill_in "Name", with: kit_traits[:name] |
45 | 47 | find(:css, '#visible_to_partners').set(false) |
46 | | - find(:css, '#kit_value_in_dollars').set(value_in_dollars) |
47 | | - select item.name, from: "kit_line_items_attributes_0_item_id" |
48 | | - find(:css, '#kit_line_items_attributes_0_quantity').set(quantity_per_kit) |
| 48 | + all(:css, '.line_item_name').first.select(items[0].name) |
| 49 | + all(:css, '.quantity').first.set(quantity_per_kit) |
| 50 | + click_link "Add Another Item" |
| 51 | + all(:css, '.line_item_name').last.select(items[1].name) |
| 52 | + all(:css, '.quantity').last.set(quantity_per_kit) |
49 | 53 | end |
50 | 54 |
|
51 | 55 | subject { click_button "Save" } |
|
55 | 59 | subject |
56 | 60 | expect(page.find(".alert")).to have_content "Kit created successfully" |
57 | 61 | expect(page).to have_content(kit_traits[:name]) |
58 | | - expect(page).to have_content("#{quantity_per_kit} #{item.name}") |
| 62 | + expect(page).to have_content("#{quantity_per_kit} #{items[0].name}") |
| 63 | + expect(page).to have_content("#{quantity_per_kit} #{items[1].name}") |
59 | 64 | expect(Kit.last.name).to eq(kit_traits[:name]) |
60 | 65 | expect(Kit.last.visible_to_partners).to eq(false) |
61 | | - expect(Kit.last.value_in_dollars).to eq(value_in_dollars) |
62 | | - expect(item.reload.visible_to_partners).to eq(false) |
63 | | - expect(item.reload.value_in_dollars).to eq(value_in_dollars) |
| 66 | + expect(Kit.last.value_in_dollars).to eq(kit_value_in_dollars) |
| 67 | + expect(items[0].reload.visible_to_partners).to eq(false) |
| 68 | + expect(items[1].reload.visible_to_partners).to eq(false) |
| 69 | + expect(items[0].reload.value_in_dollars).to eq(value_in_dollars) |
| 70 | + expect(items[1].reload.value_in_dollars).to eq(value_in_dollars) |
64 | 71 | }.to change(Kit, :count).by(1) |
65 | 72 | end |
| 73 | + |
| 74 | + context "items not selected" do |
| 75 | + before do |
| 76 | + visit new_kit_path |
| 77 | + fill_in "Name", with: kit_traits[:name] |
| 78 | + find(:css, '#visible_to_partners').set(false) |
| 79 | + end |
| 80 | + |
| 81 | + it "displays error indicating at least one item is required" do |
| 82 | + expect { |
| 83 | + subject |
| 84 | + expect(page.find(".alert")).to have_content "At least one item is required" |
| 85 | + }.not_to change(Kit, :count) |
| 86 | + end |
| 87 | + end |
66 | 88 | end |
67 | 89 |
|
68 | 90 | it "can add items correctly" do |
|
225 | 247 | visit new_kit_path |
226 | 248 | kit_traits = attributes_for(:kit) |
227 | 249 |
|
228 | | - find(:css, '#kit_value_in_dollars').set('10.10') |
229 | | - |
230 | 250 | item = Item.last |
231 | 251 | quantity_per_kit = 5 |
232 | 252 | select item.name, from: "kit_line_items_attributes_0_item_id" |
|
0 commit comments