Test pass: test_edit
This commit is contained in:
parent
8bd102f8de
commit
cb4c528908
@ -53,7 +53,8 @@ class TargetsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@targets = @goal.targets.where(effective_from: params[:effective_from])
|
@targets = @goal.targets.where(effective_from: params[:date]).to_a
|
||||||
|
@effective_from = @targets.first&.effective_from
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
15
app/views/targets/_edit_form.html.erb
Normal file
15
app/views/targets/_edit_form.html.erb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<%= labelled_form_for @targets,
|
||||||
|
url: project_targets_path(@project, @view_params),
|
||||||
|
method: :patch, remote: true,
|
||||||
|
html: {id: 'edit-target-form', name: 'edit-target-form'} do |f| %>
|
||||||
|
|
||||||
|
<%= render partial: 'targets/form', locals: {f: f} %>
|
||||||
|
|
||||||
|
<div class="tabular">
|
||||||
|
<p>
|
||||||
|
<%= submit_tag l(:button_save) %>
|
||||||
|
<%= link_to l(:button_cancel), "#",
|
||||||
|
onclick: '$(this).closest("tr").remove(); return false;' %>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
@ -57,7 +57,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<% @targets_by_date.each do |date, targets| %>
|
<% @targets_by_date.each do |date, targets| %>
|
||||||
<% row_class = "date #{cycle('odd', 'even')}" %>
|
<% row_class = "date #{cycle('odd', 'even')}" %>
|
||||||
<tr id="date-<%= date.strftime('%Y%m%d') %>" class="primary <%= row_class %>">
|
<tr id="date-<%= date %>" class="primary <%= row_class %>">
|
||||||
<td class="date unwrappable" style="cursor: pointer;"
|
<td class="date unwrappable" style="cursor: pointer;"
|
||||||
onclick="$(this).closest('tr').toggle();
|
onclick="$(this).closest('tr').toggle();
|
||||||
$(this).closest('tr').nextUntil('tr.primary', '.date').toggle();
|
$(this).closest('tr').nextUntil('tr.primary', '.date').toggle();
|
||||||
|
7
app/views/targets/edit.js.erb
Normal file
7
app/views/targets/edit.js.erb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
$('tr[id=date-<%= @effective_from %>]').nextUntil('tr.primary', ':not(.date)').remove();
|
||||||
|
var columns = $('table > thead > tr > th').length;
|
||||||
|
$('tr[id=date-<%= @effective_from %>]').nextUntil('tr.primary').addBack().last().after(
|
||||||
|
'<tr><td class="form" colspan="'+columns+'"><div id="edit-target">' +
|
||||||
|
'<%= j render partial: 'targets/edit_form' %>' +
|
||||||
|
'</div></td></tr>'
|
||||||
|
);
|
@ -12,9 +12,10 @@ resources :projects, shallow: true do
|
|||||||
post 'toggle_exposure', to: 'targets#toggle_exposure'
|
post 'toggle_exposure', to: 'targets#toggle_exposure'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :targets, except: [:show, :edit] do
|
resources :targets, except: [:show, :edit, :update] do
|
||||||
collection do
|
collection do
|
||||||
get 'edit/:date', to: 'targets#edit', as: :edit
|
get 'edit/:date', to: 'targets#edit', as: :edit
|
||||||
|
patch :update
|
||||||
post 'reapply/:date', to: 'targets#reapply', as: :reapply
|
post 'reapply/:date', to: 'targets#reapply', as: :reapply
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -101,11 +101,36 @@ class TargetsTest < BodyTrackingSystemTestCase
|
|||||||
assert_equal @project1.goals.binding, Target.last.goal
|
assert_equal @project1.goals.binding, Target.last.goal
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_create_multiple_targets
|
||||||
|
end
|
||||||
|
|
||||||
# TODO: test_create_failure(s)
|
# TODO: test_create_failure(s)
|
||||||
# * restoring user input
|
# * restoring user input
|
||||||
# * removing empty targets
|
# * removing empty targets
|
||||||
|
|
||||||
# TODO: test edit and update separately
|
def test_edit
|
||||||
|
target = Target.offset(rand(Target.count)).take
|
||||||
|
visit project_targets_path(@project1)
|
||||||
|
within find('td', text: target.effective_from.strftime).ancestor('tr') do
|
||||||
|
assert_no_selector 'form#edit-target-form'
|
||||||
|
click_link t(:button_edit)
|
||||||
|
|
||||||
|
within find(:xpath, 'following-sibling::*//form[@id="edit-target-form"]') do
|
||||||
|
assert has_select?(t(:field_goal), selected: target.goal.name)
|
||||||
|
assert has_field?(t(:field_effective_from), with: target.effective_from.strftime)
|
||||||
|
|
||||||
|
threshold = target.thresholds.first
|
||||||
|
within find('select option[selected]', exact_text: threshold.quantity.name)
|
||||||
|
.ancestor('p') do
|
||||||
|
assert has_select?(selected: target.condition)
|
||||||
|
assert has_field?(with: threshold.value)
|
||||||
|
assert has_select?(selected: threshold.unit.shortname)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert_selector 'form#edit-target-form', count: 1
|
||||||
|
end
|
||||||
|
|
||||||
def test_update
|
def test_update
|
||||||
visit project_targets_path(@project1)
|
visit project_targets_path(@project1)
|
||||||
within 'table#targets tbody tr' do
|
within 'table#targets tbody tr' do
|
||||||
|
Reference in New Issue
Block a user