|
233 | 233 | expect(response).to have_error |
234 | 234 | end |
235 | 235 |
|
| 236 | + it "renders #new on failure with only active items in dropdown" do |
| 237 | + create(:item, organization: organization, name: 'Active Item') |
| 238 | + create(:item, :inactive, organization: organization, name: 'Inactive Item') |
| 239 | + |
| 240 | + post distributions_path(distribution: { comment: nil, partner_id: nil, storage_location_id: nil }, format: :turbo_stream) |
| 241 | + expect(response).to have_http_status(400) |
| 242 | + |
| 243 | + page = Nokogiri::HTML(response.body) |
| 244 | + selectable_items = page.at_css("select.line_item_name").text.split("\n") |
| 245 | + |
| 246 | + expect(selectable_items).to include("Active Item") |
| 247 | + expect(selectable_items).not_to include("Inactive Item") |
| 248 | + end |
| 249 | + |
236 | 250 | context "Deactivated partners should not be displayed in partner dropdown" do |
237 | 251 | before do |
238 | 252 | create(:partner, name: 'Active Partner', organization: organization, status: "approved") |
|
275 | 289 | expect(page.css('#distribution_storage_location_id option[selected]')).to be_empty |
276 | 290 | end |
277 | 291 |
|
| 292 | + it "should only show active items in item dropdown" do |
| 293 | + create(:item, :inactive, organization: organization, name: 'Inactive Item') |
| 294 | + |
| 295 | + get new_distribution_path(default_params) |
| 296 | + |
| 297 | + page = Nokogiri::HTML(response.body) |
| 298 | + selectable_items = page.at_css("select#barcode_item_barcodeable_id").text.split("\n") |
| 299 | + |
| 300 | + expect(selectable_items).to include("Item 1", "Item 2") |
| 301 | + expect(selectable_items).not_to include("Inactive Item") |
| 302 | + end |
| 303 | + |
278 | 304 | context "with org default but no partner default" do |
279 | 305 | it "selects org default" do |
280 | 306 | organization.update!(default_storage_location: storage_location.id) |
|
572 | 598 | expect(response.body).to include("Active Partner") |
573 | 599 | end |
574 | 600 |
|
| 601 | + it "should only show active items in item dropdown" do |
| 602 | + create(:item, organization: organization, name: 'Active Item') |
| 603 | + create(:item, :inactive, organization: organization, name: 'Inactive Item') |
| 604 | + |
| 605 | + get edit_distribution_path(id: distribution.id) |
| 606 | + |
| 607 | + page = Nokogiri::HTML(response.body) |
| 608 | + selectable_items = page.at_css("select#barcode_item_barcodeable_id").text.split("\n") |
| 609 | + |
| 610 | + expect(selectable_items).to include("Active Item") |
| 611 | + expect(selectable_items).not_to include("Inactive Item") |
| 612 | + end |
| 613 | + |
575 | 614 | context 'with units' do |
576 | 615 | let!(:request) { |
577 | 616 | create(:request, |
|
0 commit comments