Refactors order_selector

Moves the information about the current order to the selector, not to
the container
This commit is contained in:
kikito
2015-09-12 16:48:31 +02:00
parent a2163c068a
commit d300bb6bcb
5 changed files with 33 additions and 17 deletions

View File

@@ -1,7 +1,7 @@
<section role="main"> <section role="main">
<div class="wrap row"> <div class="wrap row">
<div id="debates" class="debates-list small-12 medium-9 column js-order-<%= @current_order.dasherize %>"> <div id="debates" class="debates-list small-12 medium-9 column">
<div class="filters"> <div class="filters">
<div class="small-12 medium-7 column"> <div class="small-12 medium-7 column">
<% if @search_terms %> <% if @search_terms %>
@@ -27,7 +27,7 @@
<%= t("debates.index.select_order_long") %> <%= t("debates.index.select_order_long") %>
</h2> </h2>
<% end %> <% end %>
<%= render 'shared/order_select', i18n_namespace: "debates.index" %> <%= render 'shared/order_selector', i18n_namespace: "debates.index" %>
</div> </div>
<div class="show-for-small-only"> <div class="show-for-small-only">
<%= link_to t("debates.index.start_debate"), new_debate_path, class: 'button radius expand' %> <%= link_to t("debates.index.start_debate"), new_debate_path, class: 'button radius expand' %>

View File

@@ -1,7 +1,7 @@
<section role="main"> <section role="main">
<div class="wrap row"> <div class="wrap row">
<div id="proposals" class="Proposals-list small-12 medium-9 column js-order-<%= @current_order.dasherize %>"> <div id="proposals" class="Proposals-list small-12 medium-9 column">
<div class="filters"> <div class="filters">
<div class="small-12 medium-7 column"> <div class="small-12 medium-7 column">
<% if @search_terms %> <% if @search_terms %>
@@ -27,7 +27,7 @@
<%= t("proposals.index.select_order_long") %> <%= t("proposals.index.select_order_long") %>
</h2> </h2>
<% end %> <% end %>
<%= render 'shared/order_select', i18n_namespace: "proposals.index" %> <%= render 'shared/order_selector', i18n_namespace: "proposals.index" %>
</div> </div>
<div class="show-for-small-only"> <div class="show-for-small-only">
<%= link_to t("proposals.index.start_proposal"), new_proposal_path, class: 'button radius expand' %> <%= link_to t("proposals.index.start_proposal"), new_proposal_path, class: 'button radius expand' %>

View File

@@ -4,7 +4,7 @@
%> %>
<form class="inline-block"> <form class="inline-block">
<select class="js-location-changer" name="order-selector"> <select class="js-location-changer js-order-selector" data-order="<%= @current_order %>" name="order-selector">
<% @valid_orders.each do |order| %> <% @valid_orders.each do |order| %>
<option <%= 'selected' if order == @current_order %> <option <%= 'selected' if order == @current_order %>
value='<%= current_path_with_query_params(order: order, page: 1) %>'> value='<%= current_path_with_query_params(order: order, page: 1) %>'>

View File

@@ -378,7 +378,9 @@ feature 'Debates' do
visit debates_path visit debates_path
select 'most active', from: 'order-selector' select 'most active', from: 'order-selector'
within '#debates.js-order-hot-score' do expect(page).to have_selector('.js-order-selector[data-order="hot_score"]')
within '#debates' do
expect('Best').to appear_before('Medium') expect('Best').to appear_before('Medium')
expect('Medium').to appear_before('Worst') expect('Medium').to appear_before('Worst')
end end
@@ -395,7 +397,9 @@ feature 'Debates' do
visit debates_path visit debates_path
select 'most commented', from: 'order-selector' select 'most commented', from: 'order-selector'
within '#debates.js-order-most-commented' do expect(page).to have_selector('.js-order-selector[data-order="most_commented"]')
within '#debates' do
expect('Best').to appear_before('Medium') expect('Best').to appear_before('Medium')
expect('Medium').to appear_before('Worst') expect('Medium').to appear_before('Worst')
end end
@@ -412,7 +416,9 @@ feature 'Debates' do
visit debates_path visit debates_path
select 'newest', from: 'order-selector' select 'newest', from: 'order-selector'
within '#debates.js-order-created-at' do expect(page).to have_selector('.js-order-selector[data-order="created_at"]')
within '#debates' do
expect('Best').to appear_before('Medium') expect('Best').to appear_before('Medium')
expect('Medium').to appear_before('Worst') expect('Medium').to appear_before('Worst')
end end
@@ -426,13 +432,15 @@ feature 'Debates' do
visit debates_path visit debates_path
select 'random', from: 'order-selector' select 'random', from: 'order-selector'
debates_first_time = find("#debates.js-order-random").text expect(page).to have_selector('.js-order-selector[data-order="random"]')
debates_first_time = find("#debates").text
select 'most commented', from: 'order-selector' select 'most commented', from: 'order-selector'
expect(page).to have_selector('#debates.js-order-most-commented') expect(page).to have_selector('.js-order-selector[data-order="most_commented"]')
select 'random', from: 'order-selector' select 'random', from: 'order-selector'
debates_second_time = find("#debates.js-order-random").text expect(page).to have_selector('.js-order-selector[data-order="random"]')
debates_second_time = find("#debates").text
expect(debates_first_time).to_not eq(debates_second_time) expect(debates_first_time).to_not eq(debates_second_time)
expect(current_url).to include('page=1') expect(current_url).to include('page=1')

View File

@@ -71,7 +71,9 @@ feature 'Proposals' do
visit proposals_path visit proposals_path
select 'most active', from: 'order-selector' select 'most active', from: 'order-selector'
within '#proposals.js-order-hot-score' do expect(page).to have_selector('.js-order-selector[data-order="hot_score"]')
within '#proposals' do
expect('Best Proposal').to appear_before('Medium Proposal') expect('Best Proposal').to appear_before('Medium Proposal')
expect('Medium Proposal').to appear_before('Worst Proposal') expect('Medium Proposal').to appear_before('Worst Proposal')
end end
@@ -88,7 +90,9 @@ feature 'Proposals' do
visit proposals_path visit proposals_path
select 'most commented', from: 'order-selector' select 'most commented', from: 'order-selector'
within '#proposals.js-order-most-commented' do expect(page).to have_selector('.js-order-selector[data-order="most_commented"]')
within '#proposals' do
expect('Best Proposal').to appear_before('Medium Proposal') expect('Best Proposal').to appear_before('Medium Proposal')
expect('Medium Proposal').to appear_before('Worst Proposal') expect('Medium Proposal').to appear_before('Worst Proposal')
end end
@@ -105,7 +109,9 @@ feature 'Proposals' do
visit proposals_path visit proposals_path
select 'newest', from: 'order-selector' select 'newest', from: 'order-selector'
within '#proposals.js-order-created-at' do expect(page).to have_selector('.js-order-selector[data-order="created_at"]')
within '#proposals' do
expect('Best Proposal').to appear_before('Medium Proposal') expect('Best Proposal').to appear_before('Medium Proposal')
expect('Medium Proposal').to appear_before('Worst Proposal') expect('Medium Proposal').to appear_before('Worst Proposal')
end end
@@ -119,13 +125,15 @@ feature 'Proposals' do
visit proposals_path visit proposals_path
select 'random', from: 'order-selector' select 'random', from: 'order-selector'
proposals_first_time = find("#proposals.js-order-random").text expect(page).to have_selector('.js-order-selector[data-order="random"]')
proposals_first_time = find("#proposals").text
select 'most commented', from: 'order-selector' select 'most commented', from: 'order-selector'
expect(page).to have_selector('#proposals.js-order-most-commented') expect(page).to have_selector('.js-order-selector[data-order="most_commented"]')
select 'random', from: 'order-selector' select 'random', from: 'order-selector'
proposals_second_time = find("#proposals.js-order-random").text expect(page).to have_selector('.js-order-selector[data-order="random"]')
proposals_second_time = find("#proposals").text
expect(proposals_first_time).to_not eq(proposals_second_time) expect(proposals_first_time).to_not eq(proposals_second_time)
expect(current_url).to include('page=1') expect(current_url).to include('page=1')