human-essentials icon indicating copy to clipboard operation
human-essentials copied to clipboard

[BUG]: Incorrect Item Request no preserving values

Open elasticspoon opened this issue 1 year ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

When an incorrect individuals request is submitted all values in the form are cleared

Expected Behavior

The values should be retained

Steps To Reproduce

Sign in as a partner. Click on "Create request" under "# of individuals. Fill in a valid item and an invalid item Click submit request. You get a fresh form, instead of values being preserved

Environment

No response

Criteria for Completion

No response

Anything else?

Here is a test for it managing_requests_system_spec.rb:171:

      context 'WHEN they create a request partly improperly' do
        let(:items_to_select) { partner_user.partner.organization.valid_items.sample(3) }
        let(:item_details) do
          items_to_select.map do |item|
            {
              name: item[:name],
              quantity: Faker::Number.within(range: 5..25)
            }
          end
        end

        before do
          fill_in 'Comments', with: Faker::Lorem.paragraph

          # Select items
          item_details.each_with_index do |item, idx|
            if idx != 0
              click_link 'Add Another Item'
            end

            last_row = find_all('tr').last
            last_row.find('option', text: item[:name], exact_text: true).select_option
            last_row.find_all('.form-control').last.fill_in(with: item[:quantity])
          end

          last_row = find_all('tr').last
          last_row.find_all('.form-control').last.fill_in(with: -1)
          click_button 'Submit Essentials Request'
        end

        it 'should will retain inputs' do
          rows = find_all('tr')
          expect(rows.size).to eq(4)
          expect(rows.last.find('input').value).to eq('-1')
        end

        context 'THEN remove improper item' do
          before do
            # delete an item
            find_all('td').last.click

            # Trigger another row but keep it empty. It should still be valid!
            click_link 'Add Another Item'
          end
          context 'THEN a request records will be created and the partner will be notified via flash message on the dashboard' do
            before do
              expect { click_button 'Submit Essentials Request' }.to change { Request.count }.by(1)

              expect(current_path).to eq(partners_request_path(Request.last.id))
              expect(page).to have_content('Request has been successfully created!')
              expect(page).to have_content("#{partner.organization.name} should have received the request.")
            end

            it 'AND the partner_user can view the details of the created request in a seperate page' do
              visit partners_request_path(id: Request.last.id)

              deleted_item = item_details.pop
              item_details.each do |item|
                expect(page).to have_content("#{item[:quantity]} of #{item[:name]}")
              end

              # Should not have the last item: it was deleted.
              expect(page).not_to have_content("#{deleted_item[:quantity]} of #{deleted_item[:name]}")
            end
          end
        end
      end

Code of Conduct

  • [X] I've read the Code of Conduct and understand my responsibilities as a member of the Ruby for Good community

elasticspoon avatar Feb 22 '24 21:02 elasticspoon