From 336dc8349a088d32818a26f6e330f4ac56df475d Mon Sep 17 00:00:00 2001 From: Yann Marquet <100796+StupidCodeFactory@users.noreply.github.com> Date: Fri, 12 Jun 2020 14:13:04 +0100 Subject: [PATCH] Supporting informations page (#656) * basic skeleton * add page basics * [WIP] - supporting informations page * [WIP] - Split attachment tab Image tab * [WIP] - test for each type of supporting information * Test rake task * Fix rubocop style issues * Simplify rake testing setup All that support boilerplating was unnecessary * Allow to setup rake task specs with metadata flag This way we will be able to execute rake tasks by the test class description when either the test is located in spec/tasks or has the "type: task" flag in the test block. * added test cases for correspondence and tests * fix some test * tidy up * address some of the n+1 queries * fix queries * first spec and add warning abourt incorrectness of the current implementation regarding the new view implementation * remove unecessary code * tidy up * Update psd-web/app/views/investigations/tabs/_images.html.erb Co-authored-by: Ed Horsford * TIL: information is an unquantifiable word * fix spec * rename stuff and add more tests * remove unused partials * fix informations -> informations * added tables * [WIP] - need to add more test and use of correct date * add decorators for table cells * quick tidy up * refactor * remove unused code * Fix class inheritance of correspondces * tidy up * fix class inheritence * renane all the things * finishing up supporting information view * Few adjustments and query optimisation * add links to view pages * Fix TestDecorator * tidy up * fix rubocop offenses * fix test * add permissions to links * add spec test for view corrective action * adjust spec * only show table when supporting information are present * tidy up partial * clean up the view from nested conditionals * fix back link and fix header * tweak headers * re-add header * Update psd-web/app/views/investigations/tabs/_supporting_information.erb Co-authored-by: Ed Horsford Co-authored-by: Marc Sardon Co-authored-by: Ed Horsford --- .../supporting_information_controller.rb | 2 +- .../concerns/supporting_information_helper.rb | 10 ++++ .../decorators/corrective_action_decorator.rb | 18 ++++++ .../correspondence/email_decorator.rb | 8 ++- .../correspondence/meeting_decorator.rb | 8 ++- .../correspondence/phone_call_decorator.rb | 8 ++- .../decorators/correspondence_decorator.rb | 30 ++++++++++ .../app/decorators/investigation_decorator.rb | 6 ++ .../app/decorators/test/result_decorator.rb | 40 ++++++++++++++ psd-web/app/decorators/test_decorator.rb | 15 +---- .../investigations/display_text_helper.rb | 10 ++-- psd-web/app/models/investigation.rb | 14 ++--- .../corrective_actions/show.html.erb | 4 +- .../views/investigations/emails/show.html.erb | 4 +- .../investigations/meetings/show.html.erb | 4 +- .../investigations/phone_calls/show.html.erb | 2 +- .../_activity_table_cell_no_link.erb | 1 + .../_activity_table_cell_with_link.erb | 1 + .../_supporting_information_row.erb | 14 +++++ .../tabs/_supporting_information.erb | 55 +++++++++++++------ .../investigations/test_results/show.html.erb | 4 +- psd-web/config/application.rb | 1 + .../initializers/date_and_time_formats.rb | 4 +- .../correspondence_decorator_spec.rb | 24 ++++++++ .../investigation_decorator_spec.rb | 16 ++++++ .../features/add_corrective_action_spec.rb | 4 +- .../supporting_information_tab_spec.rb | 39 ++++++++++--- .../shared_contexts/supporting_information.rb | 12 ++-- 28 files changed, 276 insertions(+), 82 deletions(-) create mode 100644 psd-web/app/decorators/concerns/supporting_information_helper.rb create mode 100644 psd-web/app/decorators/correspondence_decorator.rb create mode 100644 psd-web/app/decorators/test/result_decorator.rb create mode 100644 psd-web/app/views/investigations/supporting_information/_activity_table_cell_no_link.erb create mode 100644 psd-web/app/views/investigations/supporting_information/_activity_table_cell_with_link.erb create mode 100644 psd-web/app/views/investigations/supporting_information/_supporting_information_row.erb create mode 100644 psd-web/spec/decorators/correspondence_decorator_spec.rb diff --git a/psd-web/app/controllers/investigations/supporting_information_controller.rb b/psd-web/app/controllers/investigations/supporting_information_controller.rb index dd3e5a676c..5242300271 100644 --- a/psd-web/app/controllers/investigations/supporting_information_controller.rb +++ b/psd-web/app/controllers/investigations/supporting_information_controller.rb @@ -7,7 +7,7 @@ def index authorize investigation, :view_non_protected_details? @investigation = investigation.decorate - @supporting_information = investigation.supporting_information_attachments.decorate + @supporting_information = investigation.supporting_information.map(&:decorate) @other_supporting_information = investigation.generic_supporting_information_attachments.decorate @breadcrumbs = { diff --git a/psd-web/app/decorators/concerns/supporting_information_helper.rb b/psd-web/app/decorators/concerns/supporting_information_helper.rb new file mode 100644 index 0000000000..592b98883b --- /dev/null +++ b/psd-web/app/decorators/concerns/supporting_information_helper.rb @@ -0,0 +1,10 @@ +module SupportingInformationHelper + extend ActiveSupport::Concern + def supporting_information_type + object.class.model_name.human + end + + def activity_cell_partial(_viewing_user) + "activity_table_cell_with_link" + end +end diff --git a/psd-web/app/decorators/corrective_action_decorator.rb b/psd-web/app/decorators/corrective_action_decorator.rb index 27838d2e31..3c3ccb86b2 100644 --- a/psd-web/app/decorators/corrective_action_decorator.rb +++ b/psd-web/app/decorators/corrective_action_decorator.rb @@ -1,6 +1,24 @@ class CorrectiveActionDecorator < ApplicationDecorator delegate_all + include SupportingInformationHelper + def details h.simple_format(object.details) end + + def supporting_information_title + summary + end + + def date_of_activity + date_decided.to_s(:govuk) + end + + def date_added + created_at.to_s(:govuk) + end + + def show_path + h.investigation_action_path(investigation, object) + end end diff --git a/psd-web/app/decorators/correspondence/email_decorator.rb b/psd-web/app/decorators/correspondence/email_decorator.rb index b21b4164ed..ed7278fb93 100644 --- a/psd-web/app/decorators/correspondence/email_decorator.rb +++ b/psd-web/app/decorators/correspondence/email_decorator.rb @@ -1,8 +1,12 @@ class Correspondence < ApplicationRecord require_dependency "correspondence" - class EmailDecorator < InvestigationDecorator + class EmailDecorator < CorrespondenceDecorator def title - overview.presence || "Email on #{correspondence_date.to_s(:govuk)}" + super || "Email on #{correspondence_date.to_s(:govuk)}" + end + + def show_path + h.investigation_email_path(investigation, object) end end end diff --git a/psd-web/app/decorators/correspondence/meeting_decorator.rb b/psd-web/app/decorators/correspondence/meeting_decorator.rb index 7d9d0c8589..a7d383ac18 100644 --- a/psd-web/app/decorators/correspondence/meeting_decorator.rb +++ b/psd-web/app/decorators/correspondence/meeting_decorator.rb @@ -1,8 +1,12 @@ class Correspondence < ApplicationRecord require_dependency "correspondence" - class MeetingDecorator < InvestigationDecorator + class MeetingDecorator < CorrespondenceDecorator def title - overview.presence || "Meeting on #{correspondence_date.to_s(:govuk)}" + super || "Meeting on #{correspondence_date.to_s(:govuk)}" + end + + def show_path + h.investigation_meeting_path(investigation, object) end end end diff --git a/psd-web/app/decorators/correspondence/phone_call_decorator.rb b/psd-web/app/decorators/correspondence/phone_call_decorator.rb index 633fd8178c..ab514c735c 100644 --- a/psd-web/app/decorators/correspondence/phone_call_decorator.rb +++ b/psd-web/app/decorators/correspondence/phone_call_decorator.rb @@ -1,8 +1,12 @@ class Correspondence < ApplicationRecord require_dependency "correspondence" - class PhoneCallDecorator < InvestigationDecorator + class PhoneCallDecorator < CorrespondenceDecorator def title - overview.presence || "Phone call on #{correspondence_date.to_s(:govuk)}" + super || "Phone call on #{correspondence_date.to_s(:govuk)}" + end + + def show_path + h.investigation_phone_call_path(investigation, object) end end end diff --git a/psd-web/app/decorators/correspondence_decorator.rb b/psd-web/app/decorators/correspondence_decorator.rb new file mode 100644 index 0000000000..2f2af97baa --- /dev/null +++ b/psd-web/app/decorators/correspondence_decorator.rb @@ -0,0 +1,30 @@ +class CorrespondenceDecorator < ApplicationDecorator + include SupportingInformationHelper + delegate_all + + def title + overview.presence + end + + def supporting_information_title + title + end + + def date_of_activity + correspondence_date.to_s(:govuk) + end + + def date_added + created_at.to_s(:govuk) + end + + def supporting_information_type + ("Correspondence" + h.tag.span(super, class: "govuk-caption-m")).html_safe + end + + def activity_cell_partial(viewing_user) + return "activity_table_cell_no_link" unless Pundit.policy!(viewing_user, investigation).view_protected_details?(user: viewing_user) + + super + end +end diff --git a/psd-web/app/decorators/investigation_decorator.rb b/psd-web/app/decorators/investigation_decorator.rb index 8f9c22cbed..90e8e3e8a3 100644 --- a/psd-web/app/decorators/investigation_decorator.rb +++ b/psd-web/app/decorators/investigation_decorator.rb @@ -93,6 +93,12 @@ def owner_display_name_for(viewer:) owner.owner_short_name(viewer: viewer) end + def generic_attachment_partial(viewing_user) + return "documents/restricted_generic_document_card" unless Pundit.policy!(viewing_user, object).view_protected_details?(user: viewing_user) + + "documents/generic_document_card" + end + private def category diff --git a/psd-web/app/decorators/test/result_decorator.rb b/psd-web/app/decorators/test/result_decorator.rb new file mode 100644 index 0000000000..d7cf871823 --- /dev/null +++ b/psd-web/app/decorators/test/result_decorator.rb @@ -0,0 +1,40 @@ +class Test < ApplicationRecord + require_dependency "test" + class ResultDecorator < TestDecorator + def title + result_text = if passed? + "Passed test" + elsif failed? + "Failed test" + else + "Test result" + end + + "#{result_text}: #{product.name}" + end + + def supporting_information_title + title + end + + def date_of_activity + date.to_s(:govuk) + end + + def date_added + created_at.to_s(:govuk) + end + + def supporting_information_type + "Test result" + end + + def show_path + h.investigation_test_result_path(investigation, object) + end + + def activity_cell_partial(_viewing_user) + "activity_table_cell_with_link" + end + end +end diff --git a/psd-web/app/decorators/test_decorator.rb b/psd-web/app/decorators/test_decorator.rb index 51361e942d..a5b171a577 100644 --- a/psd-web/app/decorators/test_decorator.rb +++ b/psd-web/app/decorators/test_decorator.rb @@ -1,15 +1,4 @@ -class TestDecorator < Draper::Decorator +class TestDecorator < ApplicationDecorator delegate_all - - def title - result_text = if passed? - "Passed test" - elsif failed? - "Failed test" - else - "Test result" - end - - "#{result_text}: #{product.name}" - end + include SupportingInformationHelper end diff --git a/psd-web/app/helpers/investigations/display_text_helper.rb b/psd-web/app/helpers/investigations/display_text_helper.rb index 6ecee349b9..211b008705 100644 --- a/psd-web/app/helpers/investigations/display_text_helper.rb +++ b/psd-web/app/helpers/investigations/display_text_helper.rb @@ -14,30 +14,30 @@ def investigation_sub_nav(investigation, current_tab: "overview") { href: investigation_products_path(investigation), text: "Products", - count: " (#{@investigation.products.size})", + count: " (#{investigation.products.size})", active: is_current_tab.products? }, { href: investigation_businesses_path(investigation), text: "Businesses", - count: " (#{@investigation.businesses.size})", + count: " (#{investigation.businesses.size})", active: is_current_tab.businesses? }, { href: investigation_images_path(investigation), text: "Images", - count: " (#{@investigation.images.size})", + count: " (#{investigation.images.size})", active: is_current_tab.images? }, { href: investigation_supporting_information_index_path(investigation), text: "Supporting information", - count: " (#{@investigation.supporting_information_count})", + count: " (#{investigation.supporting_information.size + investigation.generic_supporting_information_attachments.size})", active: is_current_tab.supporting_information? }, { - href: investigation_activity_path(@investigation), + href: investigation_activity_path(investigation), text: "Activity", active: is_current_tab.activity? } diff --git a/psd-web/app/models/investigation.rb b/psd-web/app/models/investigation.rb index 95cfea5d0f..27bddccfad 100644 --- a/psd-web/app/models/investigation.rb +++ b/psd-web/app/models/investigation.rb @@ -76,7 +76,7 @@ def initialize(*args) end def images - documents + @images ||= documents .includes(:blob) .joins(:blob) .where("left(content_type, 5) = 'image'") @@ -84,21 +84,15 @@ def images end def generic_supporting_information_attachments - documents + @generic_supporting_information_attachments ||= documents .includes(:blob) .joins(:blob) .where.not("left(content_type, 5) = 'image'") .where.not(record: [corrective_actions, correspondences, tests]) end - def supporting_information_attachments - ActiveStorage::Attachment.includes(:blob).where( - record: [corrective_actions, correspondences, tests] - ) - end - - def supporting_information_count - (supporting_information_attachments + generic_supporting_information_attachments).size + def supporting_information + @supporting_information ||= (corrective_actions + correspondences + test_results.includes(:product)).sort_by(&:created_at).reverse end def owner_team diff --git a/psd-web/app/views/investigations/corrective_actions/show.html.erb b/psd-web/app/views/investigations/corrective_actions/show.html.erb index 234918db51..2294b0086e 100644 --- a/psd-web/app/views/investigations/corrective_actions/show.html.erb +++ b/psd-web/app/views/investigations/corrective_actions/show.html.erb @@ -4,7 +4,7 @@ <% content_for :after_header do %> <%= govukBackLink( text: "Back", - href: investigation_path(@investigation) + href: investigation_supporting_information_index_path(@investigation) ) %> <% end %> @@ -63,7 +63,7 @@ <% if @corrective_action.documents.any? %>
-

Attachments

+

Attachments

<% @corrective_action.documents.each do |document| %>

<%= link_to document.filename, document, class: "govuk-link" %>

diff --git a/psd-web/app/views/investigations/emails/show.html.erb b/psd-web/app/views/investigations/emails/show.html.erb index 3297c3723c..9029ca6bd6 100644 --- a/psd-web/app/views/investigations/emails/show.html.erb +++ b/psd-web/app/views/investigations/emails/show.html.erb @@ -4,7 +4,7 @@ <% content_for :after_header do %> <%= govukBackLink( text: "Back", - href: investigation_path(@investigation) + href: investigation_supporting_information_index_path(@investigation) ) %> <% end %> @@ -77,7 +77,7 @@ <% if @email.email_attachment.attached? %>
-

Attachments

+

Attachments

<%= link_to @email.email_attachment.filename, @email.email_attachment, class: "govuk-link" %>

<%= document_placeholder(document_file_extension(@email.email_attachment)) %> diff --git a/psd-web/app/views/investigations/meetings/show.html.erb b/psd-web/app/views/investigations/meetings/show.html.erb index 07f55cb087..191e9e75c3 100644 --- a/psd-web/app/views/investigations/meetings/show.html.erb +++ b/psd-web/app/views/investigations/meetings/show.html.erb @@ -4,7 +4,7 @@ <% content_for :after_header do %> <%= govukBackLink( text: "Back", - href: investigation_path(@investigation) + href: investigation_supporting_information_index_path(@investigation) ) %> <% end %> @@ -57,7 +57,7 @@ <% if @meeting.related_attachment.attached? %>
-

Attachments

+

Attachments

<%= link_to @meeting.related_attachment.filename, @meeting.related_attachment, class: "govuk-link" %>

<%= document_placeholder(document_file_extension(@meeting.related_attachment)) %> diff --git a/psd-web/app/views/investigations/phone_calls/show.html.erb b/psd-web/app/views/investigations/phone_calls/show.html.erb index 55f9607e8e..868387b564 100644 --- a/psd-web/app/views/investigations/phone_calls/show.html.erb +++ b/psd-web/app/views/investigations/phone_calls/show.html.erb @@ -4,7 +4,7 @@ <% content_for :after_header do %> <%= govukBackLink( text: "Back", - href: investigation_path(@investigation) + href: investigation_supporting_information_index_path(@investigation) ) %> <% end %> diff --git a/psd-web/app/views/investigations/supporting_information/_activity_table_cell_no_link.erb b/psd-web/app/views/investigations/supporting_information/_activity_table_cell_no_link.erb new file mode 100644 index 0000000000..7289488f15 --- /dev/null +++ b/psd-web/app/views/investigations/supporting_information/_activity_table_cell_no_link.erb @@ -0,0 +1 @@ +Only teams added to the case can view correspondence diff --git a/psd-web/app/views/investigations/supporting_information/_activity_table_cell_with_link.erb b/psd-web/app/views/investigations/supporting_information/_activity_table_cell_with_link.erb new file mode 100644 index 0000000000..b37163467d --- /dev/null +++ b/psd-web/app/views/investigations/supporting_information/_activity_table_cell_with_link.erb @@ -0,0 +1 @@ +<%= link_to supporting_information_row.supporting_information_title, supporting_information_row.show_path %> diff --git a/psd-web/app/views/investigations/supporting_information/_supporting_information_row.erb b/psd-web/app/views/investigations/supporting_information/_supporting_information_row.erb new file mode 100644 index 0000000000..7b530867d6 --- /dev/null +++ b/psd-web/app/views/investigations/supporting_information/_supporting_information_row.erb @@ -0,0 +1,14 @@ + + + <%= render supporting_information_row.activity_cell_partial(current_user), supporting_information_row: supporting_information_row %> + + + <%= supporting_information_row.supporting_information_type %> + + + <%= supporting_information_row.date_of_activity %> + + + <%= supporting_information_row.date_added %> + + diff --git a/psd-web/app/views/investigations/tabs/_supporting_information.erb b/psd-web/app/views/investigations/tabs/_supporting_information.erb index f65e4dc832..655800528a 100644 --- a/psd-web/app/views/investigations/tabs/_supporting_information.erb +++ b/psd-web/app/views/investigations/tabs/_supporting_information.erb @@ -15,25 +15,44 @@
- -<% @supporting_information.each do |attachement| %> - <%= render "documents/document_card", document: attachement, parent: @investigation %> -<% end %> - -<% if policy(@investigation).view_protected_details?(user: current_user) %> - <% @other_supporting_information.each do |attachment| %> - <%= render "documents/generic_document_card", document: attachment, parent: @investigation %> - <% end %> -<% else %> - <% @other_supporting_information.each do |attachment| %> - <%= render "documents/restricted_generic_document_card", document: attachment %> - <% end %> -<% end %> - -<% if @supporting_information.none? && @other_supporting_information.none? %> +<% if @supporting_information.any? %>
-
-

No supporting information

+
+

Documents

+ + + + + + + + + <%= render partial: "supporting_information_row", collection: @supporting_information, locals: { investigation: @investigation } %> + +
TitleTypeDate of activityDate added
<% end %> + +
+
+ <% if @supporting_information.none? && @other_supporting_information.none? %> + +
+
+

No supporting information

+
+
+ + <% elsif @other_supporting_information.any? %> + +

Other files and attachments

+ + <%= render partial: @investigation.generic_attachment_partial(current_user), + collection: @other_supporting_information, + as: :document, + locals: { parent: @investigation } + %> + <% end %> +
+
diff --git a/psd-web/app/views/investigations/test_results/show.html.erb b/psd-web/app/views/investigations/test_results/show.html.erb index ca5ccf16d5..8cb1bde4cc 100644 --- a/psd-web/app/views/investigations/test_results/show.html.erb +++ b/psd-web/app/views/investigations/test_results/show.html.erb @@ -4,7 +4,7 @@ <% content_for :after_header do %> <%= govukBackLink( text: "Back", - href: investigation_path(@investigation) + href: investigation_supporting_information_index_path(@investigation) ) %> <% end %> @@ -23,7 +23,7 @@ <%= govukSummaryList(rows: test_result_summary_rows(@test_result)) %>
-

Attachments

+

Attachments

<% @test_result.documents.each do |document| %>

<%= link_to document.filename, document, class: "govuk-link" %>

diff --git a/psd-web/config/application.rb b/psd-web/config/application.rb index 7c2fbb7d93..64a50ded1e 100644 --- a/psd-web/config/application.rb +++ b/psd-web/config/application.rb @@ -22,6 +22,7 @@ class Application < Rails::Application # the framework and any gems in your application. config.eager_load_paths << Rails.root.join("presenters") config.autoload_paths << Rails.root.join("app/forms/concerns") + config.autoload_paths << Rails.root.join("app/decorators/concerns") config.sidekiq_queue = ENV.fetch("SIDEKIQ_QUEUE", "psd") config.active_job.queue_adapter = :sidekiq diff --git a/psd-web/config/initializers/date_and_time_formats.rb b/psd-web/config/initializers/date_and_time_formats.rb index dec7e1700e..3f5ee68b68 100644 --- a/psd-web/config/initializers/date_and_time_formats.rb +++ b/psd-web/config/initializers/date_and_time_formats.rb @@ -1,2 +1,2 @@ -Time::DATE_FORMATS[:govuk] = "%e %B %Y" -Date::DATE_FORMATS[:govuk] = ->(date) { date.strftime("%e %B %Y").lstrip } +Time::DATE_FORMATS[:govuk] = "%-d %B %Y" +Date::DATE_FORMATS[:govuk] = "%-d %B %Y" diff --git a/psd-web/spec/decorators/correspondence_decorator_spec.rb b/psd-web/spec/decorators/correspondence_decorator_spec.rb new file mode 100644 index 0000000000..310ba8948a --- /dev/null +++ b/psd-web/spec/decorators/correspondence_decorator_spec.rb @@ -0,0 +1,24 @@ +require "rails_helper" + +RSpec.describe CorrespondenceDecorator, :with_stubbed_elasticsearch, :with_stubbed_mailer do + subject { build(:correspondence_email, investigation: investigation).decorate } + + let(:user) { create(:user) } + let(:investigation) { create(:allegation, owner: user.team) } + + describe "#activity_cell_partial" do + let(:partial) { subject.activity_cell_partial(viewing_user) } + + context "when the viewing user has the view protected details permission" do + let(:viewing_user) { user } + + it { expect(partial).to eq("activity_table_cell_with_link") } + end + + context "when the viewing does not has the view protected details permission" do + let(:viewing_user) { create(:user, team: create(:team)) } + + it { expect(partial).to eq("activity_table_cell_no_link") } + end + end +end diff --git a/psd-web/spec/decorators/investigation_decorator_spec.rb b/psd-web/spec/decorators/investigation_decorator_spec.rb index 1a365249fd..c0d6a4d105 100644 --- a/psd-web/spec/decorators/investigation_decorator_spec.rb +++ b/psd-web/spec/decorators/investigation_decorator_spec.rb @@ -247,4 +247,20 @@ def expect_to_display_protect_details_message it { expect(decorated_investigation.owner_display_name_for(viewer: viewer)).to eq("No case owner") } end end + + describe "#generic_attachment_partial" do + let(:partial) { decorated_investigation.generic_attachment_partial(viewing_user) } + + context "when the viewer has accees to view the restricted details" do + let(:viewing_user) { investigation.owner } + + it { expect(partial).to eq("documents/generic_document_card") } + end + + context "when the viewer does not has accees to view the restricted details" do + let(:viewing_user) { create(:user) } + + it { expect(partial).to eq("documents/restricted_generic_document_card") } + end + end end diff --git a/psd-web/spec/features/add_corrective_action_spec.rb b/psd-web/spec/features/add_corrective_action_spec.rb index 274b127e5f..cbc97e5fe7 100644 --- a/psd-web/spec/features/add_corrective_action_spec.rb +++ b/psd-web/spec/features/add_corrective_action_spec.rb @@ -120,9 +120,7 @@ def expect_case_activity_page_to_show_entered_data end def expect_case_supporting_information_page_to_show_file - expect(page).to have_selector("h1", text: "Supporting information") - expect(page).to have_selector("h2", text: summary) - expect(page).to have_selector("p", text: file_description) + expect(page).to have_css("h1", text: "Supporting information") end def fill_and_submit_form diff --git a/psd-web/spec/features/supporting_information_tab_spec.rb b/psd-web/spec/features/supporting_information_tab_spec.rb index 5a96520da6..3e58375749 100644 --- a/psd-web/spec/features/supporting_information_tab_spec.rb +++ b/psd-web/spec/features/supporting_information_tab_spec.rb @@ -9,16 +9,37 @@ context "when the team from the user viewing the information owns the investigation" do before { sign_in user } - scenario "completing the add attachment flow saves the attachment" do + scenario "listing supporting information" do visit "/cases/#{investigation.pretty_id}" - click_link "Supporting information" - expect(page).to have_css("h2", text: corrective_action.documents.first.title) - expect(page).to have_css("h2", text: email.email_file.decorate.title) - expect(page).to have_css("h2", text: phone_call.transcript.decorate.title) - expect(page).to have_css("h2", text: meeting.transcript.decorate.title) - expect(page).to have_css("h2", text: test_request.documents.first.decorate.title) - expect(page).to have_css("h2", text: test_result.documents.first.decorate.title) - expect(page).to have_css("h2", text: investigation.documents.first.title) + + click_on "Supporting information (6)" + + within page.first("table") do + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell a", text: email.supporting_information_title) + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell", text: "CorrespondenceEmail") + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell", text: email.date_of_activity) + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell", text: email.date_added) + + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell a", text: phone_call.supporting_information_title) + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell", text: "CorrespondencePhone call") + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell", text: phone_call.date_of_activity) + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell", text: phone_call.date_added) + + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell a", text: meeting.supporting_information_title) + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell", text: "CorrespondenceMeeting") + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell", text: meeting.date_of_activity) + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell", text: meeting.date_added) + + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell a", text: corrective_action.supporting_information_title) + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell", text: corrective_action.supporting_information_type) + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell", text: corrective_action.date_of_activity) + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell", text: corrective_action.date_added) + + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell a", text: test_result.supporting_information_title) + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell", text: test_result.supporting_information_type) + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell", text: test_result.date_of_activity) + expect(page).to have_css("tr.govuk-table__row td.govuk-table__cell", text: test_result.date_added) + end end end diff --git a/psd-web/spec/support/shared_contexts/supporting_information.rb b/psd-web/spec/support/shared_contexts/supporting_information.rb index f90c95e32d..25b6a5a9a9 100644 --- a/psd-web/spec/support/shared_contexts/supporting_information.rb +++ b/psd-web/spec/support/shared_contexts/supporting_information.rb @@ -1,10 +1,10 @@ RSpec.shared_context "with all types of supporting information", :with_stubbed_antivirus do - let!(:corrective_action) { create(:corrective_action, :with_file, owner_id: user.id, investigation: investigation) } - let!(:email) { create(:correspondence_email, investigation: investigation) } - let!(:phone_call) { create(:correspondence_phone_call, investigation: investigation) } - let!(:meeting) { create(:correspondence_meeting, investigation: investigation) } + let!(:corrective_action) { create(:corrective_action, :with_file, owner_id: user.id, investigation: investigation).decorate } + let!(:email) { create(:correspondence_email, investigation: investigation).decorate } + let!(:phone_call) { create(:correspondence_phone_call, investigation: investigation).decorate } + let!(:meeting) { create(:correspondence_meeting, investigation: investigation).decorate } let(:product) { create(:product) } - let!(:test_request) { create(:test_request, product: product, investigation: investigation) } - let!(:test_result) { create(:test_result, product: product, investigation: investigation) } + let!(:test_request) { create(:test_request, product: product, investigation: investigation).decorate } + let!(:test_result) { create(:test_result, product: product, investigation: investigation).decorate } end