-
Create new Log
+ <%= link_to "Create new log", case_logs_path, method: :post, class: "govuk-button" %>
<%= render partial: "log_list", locals: { case_logs: @in_progress_case_logs, title: "Logs you need to complete", date_title: "Last Changed" } %>
diff --git a/app/views/case_logs/new.html.erb b/app/views/case_logs/new.html.erb
deleted file mode 100644
index e19709917..000000000
--- a/app/views/case_logs/new.html.erb
+++ /dev/null
@@ -1,8 +0,0 @@
-<%= form_with model: @case_log, builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
- <%= f.govuk_number_field :age,
- hint: { text: "More detail" },
- label: { text: "What is the tenant's age?", size: "l"},
- min: 0, max: 150, step: 1, width: 20
- %>
- <%= f.govuk_submit %>
-<% end %>
diff --git a/app/views/case_logs/household/tenant_age.html.erb b/app/views/form/questions/household/tenant_age.html.erb
similarity index 67%
rename from app/views/case_logs/household/tenant_age.html.erb
rename to app/views/form/questions/household/tenant_age.html.erb
index 35aa64708..5c8f02ca0 100644
--- a/app/views/case_logs/household/tenant_age.html.erb
+++ b/app/views/form/questions/household/tenant_age.html.erb
@@ -1,11 +1,12 @@
<%= turbo_frame_tag "case_log_form" do %>
- <%= form_with action: '/form', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
+ <%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_number_field :tenant_age,
hint: { text: "More detail" },
label: { text: "What is the tenant's age?", size: "l"},
min: 0, max: 150, step: 1, width: 20
%>
<%= f.hidden_field :previous_question, value: :tenant_age %>
+ <%= f.hidden_field :case_log_id, value: case_log_id %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
<% end %>
diff --git a/app/views/case_logs/household/tenant_code.html.erb b/app/views/form/questions/household/tenant_code.html.erb
similarity index 65%
rename from app/views/case_logs/household/tenant_code.html.erb
rename to app/views/form/questions/household/tenant_code.html.erb
index 3b3774a8b..d850ef2a5 100644
--- a/app/views/case_logs/household/tenant_code.html.erb
+++ b/app/views/form/questions/household/tenant_code.html.erb
@@ -1,11 +1,12 @@
<%= turbo_frame_tag "case_log_form" do %>
- <%= form_with action: '/form', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
+ <%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_text_field :tenant_code,
hint: { text: "More detail" },
label: { text: "What is the tenant code?", size: "l"},
width: 20
%>
<%= f.hidden_field :previous_question, value: :tenant_code %>
+ <%= f.hidden_field :case_log_id, value: case_log_id %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
<% end %>
diff --git a/app/views/case_logs/household/tenant_gender.html.erb b/app/views/form/questions/household/tenant_gender.html.erb
similarity index 75%
rename from app/views/case_logs/household/tenant_gender.html.erb
rename to app/views/form/questions/household/tenant_gender.html.erb
index d98d7da8c..429944959 100644
--- a/app/views/case_logs/household/tenant_gender.html.erb
+++ b/app/views/form/questions/household/tenant_gender.html.erb
@@ -6,9 +6,10 @@
] %>
<%= turbo_frame_tag "case_log_form" do %>
- <%= form_with action: '/form', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
+ <%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_collection_radio_buttons :tenant_gender, genders, :id, :name, legend: { text: "Which of these best describes the tenant's gender identity?", size: "l" } %>
<%= f.hidden_field :previous_question, value: :tenant_gender %>
+ <%= f.hidden_field :case_log_id, value: case_log_id %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 733dfc2cb..50e4a4e36 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -2,8 +2,8 @@ Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
get "about", to: "about#index"
get "/", to: "test#index"
- get "form", to: "form#next_question"
- post "form", to: "form#next_question"
+ get "form", to: "case_logs#next_question"
+ post "form", to: "case_logs#next_question"
resources :case_logs
end
diff --git a/package.json b/package.json
index 4a3ba390c..1bf8be47c 100644
--- a/package.json
+++ b/package.json
@@ -10,6 +10,8 @@
"@rails/ujs": "^6.0.0",
"@rails/webpacker": "5.4.0",
"govuk-frontend": "^3.13.0",
+ "stimulus": "^2.0.0",
+ "stimulus-use": "^0.26.0",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12"
},
diff --git a/spec/controllers/case_logs_controller_spec.rb b/spec/controllers/case_logs_controller_spec.rb
index 75c80705c..5526f8cb3 100644
--- a/spec/controllers/case_logs_controller_spec.rb
+++ b/spec/controllers/case_logs_controller_spec.rb
@@ -11,10 +11,16 @@ RSpec.describe CaseLogsController, type: :controller do
end
end
- describe "GET #new" do
- it "returns a success response" do
- get :new, params: {}, session: valid_session
- expect(response).to be_successful
+ describe "Post #create" do
+ it "creates a new case log record" do
+ expect {
+ post :create, params: {}, session: valid_session
+ }.to change(CaseLog, :count).by(1)
+ end
+
+ it "redirects to that case log" do
+ post :create, params: {}, session: valid_session
+ expect(response.status).to eq(302)
end
end
end
diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb
index 6aafbd976..5d2c6e3ad 100644
--- a/spec/features/case_log_spec.rb
+++ b/spec/features/case_log_spec.rb
@@ -4,25 +4,30 @@ RSpec.describe "Test Features" do
let(:id) { case_log.id }
let(:status) { case_log.status }
- it "displays a tasklist header" do
- visit("/case_logs/342351")
- expect(page).to have_content("Tasklist for log #{id}")
- expect(page).to have_content("This submission is #{status}")
+ describe "Create new log" do
+ it "redirects to the task list for the new log" do
+ visit("/case_logs")
+ click_link("Create new log")
+ id = CaseLog.first.id
+ expect(page).to have_content("Tasklist for log #{id}")
+ end
end
- it "has an edit form" do
- visit("/case_logs/new")
- expect(page).to have_field("age")
- expect(page).to have_button("Continue")
- end
+ describe "Viewing a log" do
+ it "displays a tasklist header" do
+ visit("/case_logs/342351")
+ expect(page).to have_content("Tasklist for log #{id}")
+ expect(page).to have_content("This submission is #{status}")
+ end
- it "displays the household questions when you click into that section" do
- visit("/case_logs/#{id}")
- click_link("Household characteristics")
- expect(page).to have_field("tenant-code-field")
- click_button("Save and continue")
- expect(page).to have_field("tenant-age-field")
- click_button("Save and continue")
- expect(page).to have_field("tenant-gender-0-field")
+ it "displays the household questions when you click into that section" do
+ visit("/case_logs/#{id}")
+ click_link("Household characteristics")
+ expect(page).to have_field("tenant-code-field")
+ click_button("Save and continue")
+ expect(page).to have_field("tenant-age-field")
+ click_button("Save and continue")
+ expect(page).to have_field("tenant-gender-0-field")
+ end
end
end
diff --git a/yarn.lock b/yarn.lock
index b7dd73218..003e61009 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -972,6 +972,30 @@
webpack-cli "^3.3.12"
webpack-sources "^1.4.3"
+"@stimulus/core@^2.0.0":
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/@stimulus/core/-/core-2.0.0.tgz#140c85318d6a8a8210c0faf182223b8459348877"
+ integrity sha512-ff70GafKtzc8zQ1/cG+UvL06GcifPWovf2wBEdjLMh9xO2GOYURO3y2RYgzIGYUIBefQwyfX2CLfJdZFJrEPTw==
+ dependencies:
+ "@stimulus/mutation-observers" "^2.0.0"
+
+"@stimulus/multimap@^2.0.0":
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/@stimulus/multimap/-/multimap-2.0.0.tgz#420cfa096ed6538df4a91dbd2b2842c1779952b2"
+ integrity sha512-pMBCewkZCFVB3e5mEMoyO9+9aKzHDITmf3OnPun51YWxlcPdHcwbjqm1ylK63fsoduIE+RowBpFwFqd3poEz4w==
+
+"@stimulus/mutation-observers@^2.0.0":
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/@stimulus/mutation-observers/-/mutation-observers-2.0.0.tgz#3dbe37453bda47a6c795a90204ee8d77a799fb87"
+ integrity sha512-kx4VAJdPhIGBQKGIoUDC2tupEKorG3A+ckc2b1UiwInKTMAC1axOHU8ebcwhaJIxRqIrs8//4SJo9YAAOx6FEg==
+ dependencies:
+ "@stimulus/multimap" "^2.0.0"
+
+"@stimulus/webpack-helpers@^2.0.0":
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/@stimulus/webpack-helpers/-/webpack-helpers-2.0.0.tgz#54296d2a2dffd4f962d2e802d99a3fdd84b8845f"
+ integrity sha512-D6tJWsAC024MwGEIKlUVYU8Ln87mlrmiwHvYAjipg+s8H4eLxUMQ3PZkWyPevfipH+oR3leuHsjYsK1gN5ViQA==
+
"@types/glob@^7.1.1":
version "7.1.4"
resolved "https://registry.npmjs.org/@types/glob/-/glob-7.1.4.tgz"
@@ -3219,6 +3243,11 @@ homedir-polyfill@^1.0.1:
dependencies:
parse-passwd "^1.0.0"
+hotkeys-js@>=3:
+ version "3.8.7"
+ resolved "https://registry.yarnpkg.com/hotkeys-js/-/hotkeys-js-3.8.7.tgz#c16cab978b53d7242f860ca3932e976b92399981"
+ integrity sha512-ckAx3EkUr5XjDwjEHDorHxRO2Kb7z6Z2Sxul4MbBkN8Nho7XDslQsgMJT+CiJ5Z4TgRxxvKHEpuLE3imzqy4Lg==
+
hpack.js@^2.1.6:
version "2.1.6"
resolved "https://registry.npmjs.org/hpack.js/-/hpack.js-2.1.6.tgz"
@@ -6121,6 +6150,21 @@ static-extend@^0.1.1:
resolved "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz"
integrity sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=
+stimulus-use@^0.26.0:
+ version "0.26.0"
+ resolved "https://registry.yarnpkg.com/stimulus-use/-/stimulus-use-0.26.0.tgz#eb3f874bf2ec1ff213589cb5fbe2d314fe5d2741"
+ integrity sha512-p9uqV/STRR3QJb9r1ijPiPOmF+vQtcvs8/9D4eDF2OdWOafr0prG/Cd9lZNzamGrejhOqh90mOgrK+RTBP9HLA==
+ dependencies:
+ hotkeys-js ">=3"
+
+stimulus@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/stimulus/-/stimulus-2.0.0.tgz#713c8b91a72ef90914b90955f0e705f004403047"
+ integrity sha512-xipy7BS5TVpg4fX6S8LhrYZp7cmHGjmk09WSAiVx1gF5S5g43IWsuetfUhIk8HfHUG+4MQ9nY0FQz4dRFLs/8w==
+ dependencies:
+ "@stimulus/core" "^2.0.0"
+ "@stimulus/webpack-helpers" "^2.0.0"
+
stream-browserify@^2.0.1:
version "2.0.2"
resolved "https://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.2.tgz"