Skip to content

Commit

Permalink
4407- Showing All Item Fields In Item View (rubyforgood#4431)
Browse files Browse the repository at this point in the history
  • Loading branch information
Naraveni authored Jun 26, 2024
1 parent da7e2f5 commit 39ad8ed
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 8 deletions.
47 changes: 39 additions & 8 deletions app/views/items/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,51 @@
<div class="card">
<div class="card-body p-0">
<table class="table">
<thead>
<tbody>
<tr>
<th>Base Item</th>
<td><%= @item.base_item.name %></td>
</tr>
<tr>
<th>Name</th>
<td><%= @item.name %></td>
</tr>
<tr>
<th>Category</th>
<td><%= @item&.item_category&.name %></td>
</tr>
<tr>
<th>Value Per Item</th>
<th>Distribution Quantity</th>
<td><%= @item.value_in_cents || 0 %></td>
</tr>
<tr>
<th>Quantity Per Indivudual</th>
<td><%= @item.distribution_quantity || 0 %></td>
</tr>
<tr>
<th>On hand minimum quantity</th>
<td><%= @item.on_hand_minimum_quantity || 0 %></td>
</tr>
<tr>
<th>On hand recommended quantity</th>
<td><%= @item.on_hand_recommended_quantity || 0 %></td>
</tr>
<tr>
<th>Package Size</th>
<td><%= @item.package_size || 0 %></td>
</tr>
<tr>
<% if Flipper.enabled?(:enable_packs) %>
<th>Custom Units</th>
<% item_units = @item.request_units&.pluck("item_units.name") %>
<td><%= item_units&.join("; ") %></td>
<% end %>
</tr>
</thead>
<tbody>
<tr>
<td><%= @item.value_in_cents ? @item.value_in_cents : 0 %></td>
<td><%= @item.distribution_quantity ? @item.distribution_quantity : 0 %></td>
<td><%= @item.package_size ? @item.package_size : 0 %></td>
<th>Item is visible to partners</th>
<td><%= @item.visible_to_partners ? 'Yes' : 'No' %></td>
</tr>
</tbody>
</tbody>
</table>
</div>
<!-- /.card-body -->
Expand Down
39 changes: 39 additions & 0 deletions spec/requests/items_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,44 @@
end
end
end

describe 'GET #show' do
let!(:base_item) { create(:base_item, name: 'BASEITEM') }
let!(:item_category) { create(:item_category, name: 'CURRENTCATEGORY') }
let!(:item) { create(:item, organization: organization, name: "ACTIVEITEM", item_category_id: item_category.id, distribution_quantity: 2000, on_hand_recommended_quantity: 2348, package_size: 100, value_in_cents: 20000, on_hand_minimum_quantity: 1200, visible_to_partners: true) }
let!(:item_unit_1) { create(:item_unit, item: item, name: 'ITEM1') }
let!(:item_unit_2) { create(:item_unit, item: item, name: 'ITEM2') }
it 'shows complete item details except custom request' do
get item_path(id: item.id)
expect(response.body).to include('Base Item')
expect(response.body).to include('BASEITEM')
expect(response.body).to include('Name')
expect(response.body).to include("ACTIVEITEM")
expect(response.body).to include('Category')
expect(response.body).to include('CURRENTCATEGORY')
expect(response.body).to include('Value Per Item')
expect(response.body).to include('20000')
expect(response.body).to include('Quantity Per Indivudual')
expect(response.body).to include('2000')
expect(response.body).to include('On hand minimum quantity')
expect(response.body).to include('1200')
expect(response.body).to include('On hand recommended quantity')
expect(response.body).to include('2348')
expect(response.body).to include('Package Size')
expect(response.body).to include('100')
expect(response.body).not_to include('Custom Units')
expect(response.body).not_to include("#ITEM1; ITEM2")
expect(response.body).to include('Item is visible to partners')
expect(response.body).to include('Yes')
end

it 'shows custom request units when flipper enabled' do
Flipper.enable(:enable_packs)
get item_path(id: item.id)
print(response.body)
expect(response.body).to include('Custom Units')
expect(response.body).to include("ITEM1; ITEM2")
end
end
end
end

0 comments on commit 39ad8ed

Please sign in to comment.