From 9e0702c389dc1cd5f3245f079a41c4996885fcd3 Mon Sep 17 00:00:00 2001 From: Bilal Date: Tue, 7 Jul 2020 20:24:02 +0200 Subject: [PATCH] add specs --- .../_medical_release.html.erb | 2 +- config/locales/en.yml | 1 + config/locales/es.yml | 2 + .../medical_releases_controller_spec.rb | 23 +++ .../user_managing_medical_releases_spec.rb | 133 ++++++++++++++++++ 5 files changed, 160 insertions(+), 1 deletion(-) diff --git a/app/views/medical_releases/_medical_release.html.erb b/app/views/medical_releases/_medical_release.html.erb index 74cc105..8adc402 100644 --- a/app/views/medical_releases/_medical_release.html.erb +++ b/app/views/medical_releases/_medical_release.html.erb @@ -50,7 +50,7 @@ <%= link_to fa_icon("tags fw", text: "Tags"), [:new, medical_release, :acts_as_taggable_on_tag], class: "dropdown-item", remote: true %> <% end %> <% if policy(MedicalRelease).review? %> - <%= link_to fa_icon("search fw", text: "Review"), review_medical_release_path(medical_release), class: "dropdown-item" %> + <%= link_to fa_icon("search fw", text: t('.actions.review')), review_medical_release_path(medical_release), class: "dropdown-item" %> <% end %> <% if policy(MedicalRelease).download_single? && policy(Contract).show? && (medical_release.contract.attached? || medical_release.contract_template.present?) %> <%= link_to fa_icon("download fw", text: "Download"), [medical_release, :contracts, format: "pdf"], class: "dropdown-item", target: "_blank" %> diff --git a/config/locales/en.yml b/config/locales/en.yml index ee0a356..3a6b39c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -799,6 +799,7 @@ en: medical_release: actions: manage: Manage + review: Review messages: approved_tooltip: Approved by %{user} on %{timestamp} review: diff --git a/config/locales/es.yml b/config/locales/es.yml index d45f7d6..31d7f2c 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -302,6 +302,8 @@ es: table_headers: approved: Approved (ES) medical_release: + actions: + review: Review (ES) messages: approved_tooltip: "" review: diff --git a/spec/controllers/medical_releases_controller_spec.rb b/spec/controllers/medical_releases_controller_spec.rb index e7dfa51..7a5cc5b 100644 --- a/spec/controllers/medical_releases_controller_spec.rb +++ b/spec/controllers/medical_releases_controller_spec.rb @@ -88,4 +88,27 @@ RSpec.describe MedicalReleasesController, type: :controller do }.to change(MedicalRelease, :count).by(-1) end end + + describe "#review" do + let!(:medical_release) { create(:medical_release, project: project) } + + it "responds successfully" do + get :review, params: { project_id: project, id: medical_release } + + expect(response).to be_successful + end + end + + describe "#approve" do + it "changes approval status successfully" do + medical_release = create(:medical_release, project: project) + + expect(MedicalRelease.last.approved?).to eq false + + patch :approve, params: { project_id: project, id: medical_release } + + expect(response).to redirect_to [project, :medical_releases] + expect(MedicalRelease.last.approved?).to eq true + end + end end diff --git a/spec/features/user_managing_medical_releases_spec.rb b/spec/features/user_managing_medical_releases_spec.rb index ad395f1..31dcbaa 100644 --- a/spec/features/user_managing_medical_releases_spec.rb +++ b/spec/features/user_managing_medical_releases_spec.rb @@ -182,6 +182,18 @@ feature "User managing medical releases" do sign_in current_user end + scenario "Approved releases have checkmark and non-approved releases don't have checkmarks" do + create(:medical_release_with_contract_template, :native, project: project) + + visit project_medical_releases_path(project) + expect(page).to have_css('i.fa.fa-check-circle.fa-2x', count: 0) + + create(:medical_release_with_contract_template, :native, project: project, approved_by_user_email: "some@email.com", approved_at: DateTime.now) + visit project_medical_releases_path(project) + + expect(page).to have_css('i.fa.fa-check-circle.fa-2x', count: 1) + end + scenario "Download All is visible" do create(:medical_release_with_contract_template, :native, project: project) create(:medical_release_with_contract_template, :non_native, project: project) @@ -200,6 +212,15 @@ feature "User managing medical releases" do expect(page).to have_link("Download", exact: true, count: 2) end + scenario "Review action in Manage menu is visible" do + create(:medical_release_with_contract_template, :native, project: project) + create(:medical_release_with_contract_template, :non_native, project: project) + + visit project_medical_releases_path(project) + + expect(page).to have_link(review_action, exact: true) + end + scenario "Downloading PDF of native medical release is possible" do native_release = create(:medical_release_with_contract_template, :native, project: project) @@ -208,6 +229,64 @@ feature "User managing medical releases" do click_link *view_release_pdf_link_for(native_release) expect(content_type).to eq('application/pdf') end + + scenario "Reviewing release" do + create(:medical_release_with_contract_template, :native, project: project) + + visit project_medical_releases_path(project) + + click_link review_action + + expect(page).to have_content review_page_heading + expect(page).to have_content approve_button + end + + scenario 'When viewing the contract PDF of approved release there is page for office use only' do + medical_release = create(:medical_release_with_contract_template, + :native, + project: project, + person_first_name: 'Jane', + person_last_name: 'Doe', + approved_by_user_name: "Big Joe", + approved_by_user_email: "some@email.com", + approved_at: DateTime.now) + + sign_in(current_user) + visit project_medical_releases_path(project) + click_link *view_release_pdf_link_for(medical_release) + + expect(content_type).to eq('application/pdf') + expect(content_disposition).to include('inline') + expect(pdf_body).to have_content for_office_use_only.upcase + expect(pdf_body).to have_content producer_label + expect(pdf_body).to have_content production_label + expect(pdf_body).to have_content employee_issued_to_label + expect(pdf_body).to have_content issued_by_label + expect(pdf_body).to have_content date_issued + expect(pdf_body).to have_content 'Big Joe' + end + + scenario 'When viewing the contract PDF of not approved release there is no page for office use only' do + medical_release = create(:medical_release_with_contract_template, + :native, + project: project, + person_first_name: 'Jane', + person_last_name: 'Doe') + + sign_in(current_user) + visit project_medical_releases_path(project) + click_link *view_release_pdf_link_for(medical_release) + + expect(content_type).to eq('application/pdf') + expect(content_disposition).to include('inline') + expect(pdf_body).not_to have_content for_office_use_only.upcase + expect(pdf_body).not_to have_content producer_label + expect(pdf_body).not_to have_content production_label + expect(pdf_body).not_to have_content employee_issued_to_label + expect(pdf_body).not_to have_content issued_by_label + expect(pdf_body).not_to have_content date_issued + expect(pdf_body).not_to have_content 'Big Joe' + end end context "when the user is manager(project manager)" do @@ -235,6 +314,15 @@ feature "User managing medical releases" do expect(page).to have_link("Download", exact: true, count: 0) end + scenario "Review action in Manage menu is not visible" do + create(:medical_release_with_contract_template, :native, project: project) + create(:medical_release_with_contract_template, :non_native, project: project) + + visit project_medical_releases_path(project) + + expect(page).not_to have_link(review_action, exact: true) + end + scenario "Downloading PDF of native medical release is not possible" do native_release = create(:medical_release_with_contract_template, :native, project: project) @@ -279,6 +367,15 @@ feature "User managing medical releases" do expect(page).to have_link("Download", exact: true, count: 0) end + scenario "Review action in Manage menu is not visible" do + create(:medical_release_with_contract_template, :native, project: project) + create(:medical_release_with_contract_template, :non_native, project: project) + + visit project_medical_releases_path(project) + + expect(page).not_to have_link(review_action, exact: true) + end + scenario "Downloading PDF of native medical release is not possible" do native_release = create(:medical_release_with_contract_template, :native, project: project) @@ -458,4 +555,40 @@ feature "User managing medical releases" do def dummy_signature_legal_text 'Some signature legal language' end + + def review_action + t 'medical_releases.medical_release.actions.review' + end + + def review_page_heading + t 'medical_releases.review.heading' + end + + def approve_button + t 'medical_releases.review.actions.approve' + end + + def for_office_use_only + t 'contracts.for_office_use_only.heading' + end + + def producer_label + t 'contracts.for_office_use_only.description_labels.producer' + end + + def production_label + t 'contracts.for_office_use_only.description_labels.production' + end + + def employee_issued_to_label + t 'contracts.for_office_use_only.description_labels.employee_issued_to' + end + + def issued_by_label + t 'contracts.for_office_use_only.description_labels.issued_by' + end + + def date_issued + t 'contracts.for_office_use_only.description_labels.date_issued' + end end