|
| 1 | +require "rails_helper" |
| 2 | + |
| 3 | +RSpec.describe "BarcodeItems", type: :system do |
| 4 | + let(:organization) { create(:organization) } |
| 5 | + let(:organization_admin) { create(:organization_admin, organization: organization) } |
| 6 | + let!(:barcode_items) { create_list(:barcode_item, 6, organization: organization) } |
| 7 | + let(:items) { barcode_items.map(&:barcodeable) } |
| 8 | + let(:barcode_item) { barcode_items.first } |
| 9 | + |
| 10 | + context "when organizational admin is signed in" do |
| 11 | + before do |
| 12 | + sign_in(organization_admin) |
| 13 | + end |
| 14 | + describe "Creating a Barcode Item" do |
| 15 | + before { visit new_barcode_item_path } |
| 16 | + |
| 17 | + it "retains item dropdown options after an unsuccessful form submission" do |
| 18 | + select items.first.name, from: "Item" |
| 19 | + click_button "Save" |
| 20 | + expect(page).to have_content("Something didn't work quite right -- try again?") |
| 21 | + items.each do |item| |
| 22 | + expect(page).to have_select("Item", with_options: [item.name]) |
| 23 | + end |
| 24 | + end |
| 25 | + end |
| 26 | + |
| 27 | + describe "Editing a Barcode Item" do |
| 28 | + before { visit edit_barcode_item_path(barcode_item) } |
| 29 | + it "retains item dropdown options after an unsuccessful form submission" do |
| 30 | + fill_in "Barcode", with: "" |
| 31 | + click_button "Save" |
| 32 | + expect(page).to have_content("Something didn't work quite right -- try again?") |
| 33 | + items.each do |item| |
| 34 | + expect(page).to have_select("Item", with_options: [item.name]) |
| 35 | + end |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + describe "when admin visits index page" do |
| 40 | + before { visit barcode_items_path } |
| 41 | + |
| 42 | + it "displays all barcode items" do |
| 43 | + barcode_items.each do |barcode_item| |
| 44 | + expect(page).to have_content(barcode_item.value) |
| 45 | + expect(page).to have_content(barcode_item.quantity) |
| 46 | + expect(page).to have_content(barcode_item.barcodeable_type) |
| 47 | + end |
| 48 | + end |
| 49 | + end |
| 50 | + end |
| 51 | +end |
0 commit comments