Browse Source

Complete case log home page

pull/22/head
baarkerlounger 3 years ago
parent
commit
fae8ee67e5
  1. 2
      app/views/case_logs/_log_list.html.erb
  2. 8
      app/views/case_logs/index.html.erb
  3. 7
      db/migrate/20210921121533_add_postcode_to_case_logs.rb
  4. 3
      db/schema.rb
  5. 13
      spec/factories/case_log.rb
  6. 6
      spec/features/case_log_spec.rb
  7. 42
      spec/views/case_log_index_view_spec.rb

2
app/views/case_logs/_log_list.html.erb

@ -15,8 +15,10 @@
<%= link_to log.id, case_log_path(log) %>
</th>
<td class="govuk-table__cell govuk-table__cell">
<%= log.postcode %>
</td>
<td class="govuk-table__cell govuk-table__cell">
<%= log.tenant_code %>
</td>
<td id="last-changed" class="govuk-table__cell">
<%= log.updated_at.strftime("%d %b %Y") %>

8
app/views/case_logs/index.html.erb

@ -6,9 +6,13 @@
<%= 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" } %>
<% if @in_progress_case_logs.present? %>
<%= render partial: "log_list", locals: { case_logs: @in_progress_case_logs, title: "Logs you need to complete", date_title: "Last Changed" } %>
<% end %>
<%= render partial: "log_list", locals: { case_logs: @submitted_case_logs, title: "Logs you've submitted", date_title: "Date Submitted" } %>
<% if @submitted_case_logs.present? %>
<%= render partial: "log_list", locals: { case_logs: @submitted_case_logs, title: "Logs you've submitted", date_title: "Date Submitted" } %>
<% end %>
<p><a href="#" class="govuk-link">See all completed logs (<%= @submitted_case_logs.count %>)</a></p>
</div>

7
db/migrate/20210921121533_add_postcode_to_case_logs.rb

@ -0,0 +1,7 @@
class AddPostcodeToCaseLogs < ActiveRecord::Migration[6.1]
def change
change_table :case_logs, bulk: true do |t|
t.column :postcode, :string
end
end
end

3
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_09_14_101759) do
ActiveRecord::Schema.define(version: 2021_09_21_121533) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -27,6 +27,7 @@ ActiveRecord::Schema.define(version: 2021_09_14_101759) do
t.string "previous_housing_situation"
t.integer "prior_homelessness"
t.string "armed_forces"
t.string "postcode"
end
end

13
spec/factories/case_log.rb

@ -1,6 +1,15 @@
FactoryBot.define do
factory :case_log do
id { 342_351 }
status { 0 }
sequence(:id) { |i| i }
trait :in_progress do
status { 0 }
tenant_code { "TH356" }
postcode { "SW2 6HI" }
end
trait :submitted do
status { 1 }
tenant_code { "BZ737" }
postcode { "NW1 7TY" }
end
end
end

6
spec/features/case_log_spec.rb

@ -1,6 +1,6 @@
require "rails_helper"
RSpec.describe "Test Features" do
let!(:case_log) { FactoryBot.create(:case_log) }
let!(:case_log) { FactoryBot.create(:case_log, :in_progress) }
let(:id) { case_log.id }
let(:status) { case_log.status }
@ -8,14 +8,14 @@ RSpec.describe "Test Features" do
it "redirects to the task list for the new log" do
visit("/case_logs")
click_link("Create new log")
id = CaseLog.first.id
id = CaseLog.order(created_at: :desc).first.id
expect(page).to have_content("Tasklist for log #{id}")
end
end
describe "Viewing a log" do
it "displays a tasklist header" do
visit("/case_logs/342351")
visit("/case_logs/#{id}")
expect(page).to have_content("Tasklist for log #{id}")
expect(page).to have_content("This submission is #{status}")
end

42
spec/views/case_log_index_view_spec.rb

@ -0,0 +1,42 @@
require "rails_helper"
RSpec.describe "case_logs/index" do
let(:in_progress_log) { FactoryBot.create(:case_log, :in_progress) }
let(:submitted_log) { FactoryBot.create(:case_log, :submitted) }
context 'given an in progress log list' do
it 'renders a table for in progress logs only' do
assign(:in_progress_case_logs, [in_progress_log])
assign(:submitted_case_logs, [])
render
expect(rendered).to match(/<table class="govuk-table">/)
expect(rendered).to match(/Logs you need to complete/)
expect(rendered).not_to match(/Logs you&#39;ve submitted/)
expect(rendered).to match(in_progress_log.tenant_code)
expect(rendered).to match(in_progress_log.postcode)
end
end
context 'given a submitted log list' do
it 'renders a table for in progress logs only' do
assign(:in_progress_case_logs, [])
assign(:submitted_case_logs, [submitted_log])
render
expect(rendered).to match(/<table class="govuk-table">/)
expect(rendered).to match(/Logs you&#39;ve submitted/)
expect(rendered).not_to match(/Logs you need to complete/)
expect(rendered).to match(submitted_log.tenant_code)
expect(rendered).to match(submitted_log.postcode)
end
end
context 'given a submitted log list and an in_progress log list' do
it 'renders two tables, one for each status' do
assign(:in_progress_case_logs, [in_progress_log])
assign(:submitted_case_logs, [submitted_log])
render
expect(rendered).to match(/<table class="govuk-table">/)
expect(rendered).to match(/Logs you&#39;ve submitted/)
expect(rendered).to match(/Logs you need to complete/)
end
end
end
Loading…
Cancel
Save