Fix HTML markup

We cannot use 'id' html attributes on nested answers
because there will be many answers form each question so
this would have generated invalid HTML.
This commit is contained in:
Senén Rodero Rodríguez
2019-03-21 10:48:25 +01:00
parent bc2d020d7e
commit 5e98c23be5
4 changed files with 22 additions and 28 deletions

View File

@@ -25,18 +25,15 @@
</div>
</div>
<div id="questions">
<div class="js-questions">
<%= f.fields_for :questions do |question| %>
<%= render 'question_fields', f: question %>
<% end %>
<div id="question-links" class="links row expanded">
<div class="links row expanded">
<div class="small-12 column">
<%= link_to_add_association t("dashboard.polls.form.add_question"),
f, :questions, class: "button",
data: {
association_insertion_node: "#question-links"
} %>
f, :questions, class: "button" %>
</div>
</div>
</div>

View File

@@ -1,4 +1,4 @@
<div class="nested-fields small-12 medium-6 column">
<div class="nested-fields nested-answers small-12 medium-6 column">
<div class="answer-fields">
<%= f.hidden_field :given_order %>
<div class="row expanded">

View File

@@ -12,18 +12,15 @@
</div>
</div>
<div id="answers">
<div class="js-answers">
<%= f.fields_for :question_answers do |answer| %>
<%= render 'question_answer_fields', f: answer %>
<% end %>
<div id="answer-links" class="links row expanded">
<div class="answer-links links row expanded">
<div class="small-12 column">
<%= link_to_add_association t("dashboard.polls.question_fields.add_answer"),
f, :question_answers, class: "button hollow",
data: {
association_insertion_node: "#answer-links"
} %>
f, :question_answers, class: "button hollow" %>
</div>
</div>
</div>

View File

@@ -104,51 +104,51 @@ feature 'Polls' do
end
end
scenario 'Edit poll should allow to remove questions', :js do
scenario "Edit poll should allow to remove questions", :js do
poll = create(:poll, :incoming, related: proposal)
question1 = create(:poll_question, poll: poll)
question2 = create(:poll_question, poll: poll)
create(:poll_question, poll: poll)
create(:poll_question, poll: poll)
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
click_link 'Edit survey'
click_link "Edit survey"
end
within "#questions" do
within ".js-questions" do
expect(page).to have_css ".nested-fields", count: 2
within first(".nested-fields") do
find('a.delete').click
find("a.delete").click
end
expect(page).to have_css ".nested-fields", count: 1
end
click_button 'Update poll'
click_button "Update poll"
visit edit_proposal_dashboard_poll_path(proposal, poll)
expect(page).to have_css ".nested-fields", count: 1
end
scenario 'Edit poll should allow to remove answers', :js do
scenario "Edit poll should allow to remove answers", :js do
poll = create(:poll, :incoming, related: proposal)
question = create(:poll_question, poll: poll)
answer1 = create(:poll_question_answer, question: question)
answer2 = create(:poll_question_answer, question: question)
create(:poll_question_answer, question: question)
create(:poll_question_answer, question: question)
visit proposal_dashboard_polls_path(proposal)
within "div#poll_#{poll.id}" do
click_link 'Edit survey'
click_link "Edit survey"
end
within "#questions #answers" do
within ".js-questions .js-answers" do
expect(page).to have_css ".nested-fields", count: 2
within first(".nested-fields") do
find('a.delete').click
find("a.delete").click
end
expect(page).to have_css ".nested-fields", count: 1
end
click_button 'Update poll'
click_button "Update poll"
visit edit_proposal_dashboard_poll_path(proposal, poll)
within "#questions #answers" do
within ".js-questions .js-answers" do
expect(page).to have_css ".nested-fields", count: 1
end
end