Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

[1643] Hide Unavailable Equipment Items #1668

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/views/catalog/_catalog_listing.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</h2>
<div class="thumbnails row">
<% (equipment_models[0, 3]).each do |equipment_model| %>
<div class="col-md-4">
<div class="col-md-4 eq-item">
<%= render partial: 'catalog/equipment_model_div', locals: {
equipment_model: equipment_model,
availability_hash: availability_hash,
Expand All @@ -15,4 +15,4 @@
<% end %>
</div>
<% end %>
<% end %>
<% end %>
32 changes: 30 additions & 2 deletions app/views/catalog/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<%= render partial: 'no_equipment' %>
<% else %>
<div class="row">
<div id="pagination_line" class="col-md-12">
<div id="pagination_line" class="col-md-10">
<%# for kaminari pagination %>
<%= paginate @page_eq_models_by_category,
params: { controller: 'catalog', action: 'index' } %>
Expand All @@ -16,7 +16,10 @@
<%= select_tag :items_per_page,
options_for_select(@per_page_opts, session[:items_per_page]),
class: 'autosubmitme form-control' %>
<% end %>
<% end %>
</div>
<div id="etc" class="col-md-2" style="margin-top: 17.6px;">
<%= button_tag 'Hide unavailable', id: 'toggle_unavailable', class: 'btn btn-default'%>
</div>
</div>

Expand All @@ -31,3 +34,28 @@
<%= paginate @page_eq_models_by_category %>
<% end %>
</div>

<script>
$(document).ready(function() {
$('#toggle_unavailable').width(
Math.max.apply(
Math,
$('#toggle_unavailable').map(function(){
return $(this).width();
}).get()
)
);
$("#toggle_unavailable").click(function() {
if ($("#toggle_unavailable").text() == "Hide unavailable") {
$("#toggle_unavailable").text("Show unavailable");
} else {
$("#toggle_unavailable").text("Hide unavailable");
}
$(".eq-item").each(function() {
if ($(this).find(".availability-num").text() <= 0) {
$(this).toggle();
}
});
});
});
</script>
38 changes: 38 additions & 0 deletions spec/features/reservations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -836,4 +836,42 @@
expect(page).to have_content('Description')
end
end

context 'when hide unavailable button is clicked' do
before(:each) do
empty_cart
Capybara.ignore_hidden_elements = false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this necessary?

@eq_model1 = FactoryGirl.create(:equipment_model, category: @category)
FactoryGirl.create(:equipment_item, equipment_model: @eq_model1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have an equipment_model_with_item factory

@eq_model1[:overdue_count] = 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should actually create an overdue reservation for this because it's a feature spec

@eq_model1.save!
@eq_model1.reload
page.reset!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this necessary? you haven't visited a page yet

visit root_path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this belongs in the individual it blocks

end

after(:each) do
Capybara.ignore_hidden_elements = true
@eq_model1.destroy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't necessary

page.reset!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also shouldn't be necessary

end

it 'shows all items by default' do
expect(page).to have_css('.availability-num', text: 1, visible: true)
expect(page).to have_css('.availability-num', text: 0, visible: true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these checks are nice!

end

it 'hides only unavailable items when clicked' do
click_button 'toggle_unavailable'
expect(page).to have_css('.availability-num', text: 1, visible: true)
expect(page).to have_css('.availability-num', text: 0, visible: false)
end

it 'reshows all items when clicked again' do
click_button 'toggle_unavailable'
click_button 'toggle_unavailable'
expect(page).to have_css('.availability-num', text: 1, visible: :true)
expect(page).to have_css('.availability-num', text: 0, visible: :true)
end
end
end