From 6b375c2048e2d9ba8b2bef3e79d98d17c1afbc31 Mon Sep 17 00:00:00 2001 From: Dushan Despotovic Date: Fri, 13 May 2022 16:12:18 +0100 Subject: [PATCH] set up failing test for organisation logs page --- app/controllers/organisations_controller.rb | 3 ++- app/views/organisations/logs.erb | 2 +- spec/features/user_spec.rb | 17 +++++++++++++++++ spec/rails_helper.rb | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 4fee2b2a9..0b98b2dbe 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -43,7 +43,8 @@ class OrganisationsController < ApplicationController end def logs - unless current_user.support? + if current_user.support? + @pagy, @case_logs = pagy(CaseLog.all.where(owning_organisation_id: @organisation.id)) redirect_to "/logs" end end diff --git a/app/views/organisations/logs.erb b/app/views/organisations/logs.erb index 97c6174a9..b845d8fe9 100644 --- a/app/views/organisations/logs.erb +++ b/app/views/organisations/logs.erb @@ -1 +1 @@ -wubwub \ No newline at end of file +<%= render partial: "case_logs/log_list", locals: { case_logs: @case_logs, title: "Logs", pagy: @pagy } %> \ No newline at end of file diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index 18de6444e..7a64c6503 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -551,6 +551,12 @@ RSpec.describe "User Features" do end context "when the user is logged in as a support user" do let!(:support_user) { FactoryBot.create(:user, :support) } + let!(:test_org_1) { FactoryBot.create(:organisation, name: "Test1") } + let!(:test_org_2) { FactoryBot.create(:organisation, name: "Test2") } + let!(:test_org_3) { FactoryBot.create(:organisation, name: "Test3") } + let!(:test_org_4) { FactoryBot.create(:organisation, name: "Test4") } + let!(:test_org_5) { FactoryBot.create(:organisation, name: "Test5") } + let!(:case_log) { FactoryBot.create(:case_log, owning_organisation_id: test_org_3.id, managing_organisation_id: test_org_3.id) } before do FactoryBot.create_list(:organisation, 50) @@ -573,6 +579,17 @@ RSpec.describe "User Features" do expect(page).to have_css("#all-organisations-table") expect(page).to have_css(".app-pagination__link") end + + context "when the support user is on the organisations list page" do + it "they can click on an organisation to see their logs page", js: true do + visit("/organisations") + click_link("Test3") + expect(page).to have_selector("a", text: "#{case_log.id}") + visit("/organisations") + click_link("Test5") + expect(page).not_to have_selector("a", text: "#{case_log.id}") + end + end end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 5787ffe66..40d2bc73a 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -11,7 +11,7 @@ require "view_component/test_helpers" Capybara.register_driver :headless do |app| options = Selenium::WebDriver::Firefox::Options.new - options.add_argument("--headless") + # options.add_argument("--headless") Capybara::Selenium::Driver.new(app, browser: :firefox, capabilities: options) end