diff --git a/spec/requests/check_errors_controller_spec.rb b/spec/requests/check_errors_controller_spec.rb
index 179897008..f0f1887aa 100644
--- a/spec/requests/check_errors_controller_spec.rb
+++ b/spec/requests/check_errors_controller_spec.rb
@@ -59,7 +59,7 @@ RSpec.describe CheckErrorsController, type: :request do
it "displays correct clear links" do
expect(page).to have_selector("input[type=submit][value='Clear']", count: 3)
- expect(page).to have_link("Clear all", href: "/lettings-logs/#{lettings_log.id}/confirm-clear-all-answers")
+ expect(page).to have_button("Clear all")
end
end
@@ -83,9 +83,10 @@ RSpec.describe CheckErrorsController, type: :request do
post "/sales-logs/#{sales_log.id}/buyer-1-income", params: params
end
- it "displays correct clear links" do
- expect(page).to have_button("Clear", count: 3)
- expect(page).to have_link("Clear all", href: "/sales-logs/#{sales_log.id}/confirm-clear-all-answers")
+ it "displays correct clear and change links" do
+ expect(page.all(:button, value: "Clear").count).to eq(2)
+ expect(page).to have_link("Change", count: 1)
+ expect(page).to have_button("Clear all")
end
end
end
@@ -179,6 +180,66 @@ RSpec.describe CheckErrorsController, type: :request do
end
end
+ describe "confirm clear all answers" do
+ context "when user is signed in" do
+ context "and clearing all lettings questions" do
+ let(:params) do
+ {
+ id: lettings_log.id,
+ clear_all: "Clear all",
+ lettings_log: {
+ earnings: "100000",
+ incfreq: "1",
+ hhmemb: "2",
+ page_id: "income_amount",
+ },
+ }
+ end
+
+ before do
+ sign_in user
+ post "/lettings-logs/#{lettings_log.id}/confirm-clear-answer", params:
+ end
+
+ it "displays correct clear links" do
+ expect(page).to have_content("Are you sure you want to clear all")
+ expect(page).to have_content("You've selected 5 answers to clear")
+ expect(page).to have_content("You will not be able to undo this action")
+ expect(page).to have_link("Cancel")
+ expect(page).to have_button("Confirm and continue")
+ end
+ end
+
+ context "and clearing all sales question" do
+ let(:params) do
+ {
+ id: sales_log.id,
+ clear_all: "Clear all",
+ sales_log: {
+ income1: "100000",
+ la: "E09000001",
+ ownershipsch: "1",
+ page_id: "buyer_1_income",
+ },
+ }
+ end
+
+ before do
+ sign_in user
+ post "/sales-logs/#{sales_log.id}/confirm-clear-answer", params:
+ end
+
+ it "displays correct clear links" do
+ expect(page).to have_content("Are you sure you want to clear all")
+ expect(page).to have_content("You've selected 3 answers to clear")
+ expect(page).to have_content("You will not be able to undo this action")
+ expect(page).to have_link("Cancel")
+ expect(page).to have_button("Confirm and continue")
+ end
+ end
+ end
+ end
+
describe "clear answer" do
context "when user is not signed in" do
it "redirects to sign in page for lettings" do
@@ -219,7 +280,7 @@ RSpec.describe CheckErrorsController, type: :request do
earnings: "100000",
incfreq: "1",
hhmemb: "2",
- clear_question_id: "hhmemb",
+ clear_question_ids: "hhmemb",
page: "income_amount",
},
check_errors: "",
@@ -247,7 +308,7 @@ RSpec.describe CheckErrorsController, type: :request do
income1: "100000",
la: "E09000001",
ownershipsch: "1",
- clear_question_id: "income1",
+ clear_question_ids: "income1",
page: "buyer_1_income",
},
check_errors: "",
@@ -327,4 +388,68 @@ RSpec.describe CheckErrorsController, type: :request do
end
end
end
+
+ describe "clear all answers" do
+ context "when user is signed in" do
+ context "and clearing all lettings question" do
+ let(:params) do
+ {
+ id: lettings_log.id,
+ lettings_log: {
+ earnings: "100000",
+ incfreq: "1",
+ hhmemb: "2",
+ clear_question_ids: "earnings incfreq hhmemb",
+ page: "income_amount",
+ },
+ check_errors: "",
+ }
+ end
+
+ before do
+ sign_in user
+ post "/lettings-logs/#{lettings_log.id}/income-amount", params:
+ end
+
+ it "correctly clears the values" do
+ expect(page).to have_content("Make sure these answers are correct")
+ expect(page).to have_content("You didn’t answer this question")
+ expect(page.all(:button, value: "Clear").count).to eq(0)
+ expect(lettings_log.reload.earnings).to eq(nil)
+ expect(lettings_log.reload.incfreq).to eq(nil)
+ expect(lettings_log.reload.hhmemb).to eq(nil)
+ end
+ end
+
+ context "and clearing all sales question" do
+ let(:params) do
+ {
+ id: sales_log.id,
+ sales_log: {
+ income1: "100000",
+ la: "E09000001",
+ ownershipsch: "1",
+ clear_question_ids: "income1 la ownershipsch",
+ page: "buyer_1_income",
+ },
+ check_errors: "",
+ }
+ end
+
+ before do
+ sign_in user
+ post "/sales-logs/#{sales_log.id}/buyer-1-income", params:
+ end
+
+ it "displays correct clear links" do
+ expect(page).to have_content("Make sure these answers are correct")
+ expect(page).to have_content("You didn’t answer this question")
+ expect(page.all(:button, value: "Clear").count).to eq(0)
+ expect(sales_log.reload.income1).to eq(nil)
+ expect(sales_log.reload.la).to eq(nil)
+ expect(sales_log.reload.ownershipsch).not_to eq(nil)
+ end
+ end
+ end
+ end
end