From 050f61cc657e094b187b043b84f7dae61d8f076b Mon Sep 17 00:00:00 2001 From: David May-Miller Date: Fri, 30 Sep 2022 10:06:38 +0100 Subject: [PATCH] CLDC-1625 Added tests for Sales logs tab of organisation view for support users Tests do not currently include searching as this isn't fully implemented yet --- spec/features/organisation_spec.rb | 38 ++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/spec/features/organisation_spec.rb b/spec/features/organisation_spec.rb index a0558d167..623ce7dd0 100644 --- a/spec/features/organisation_spec.rb +++ b/spec/features/organisation_spec.rb @@ -134,7 +134,7 @@ RSpec.describe "User Features" do click_button("Submit") end - context "when viewing logs for specific organisation" do + context "when viewing lettings logs for specific organisation" do let(:first_log) { organisation.lettings_logs.first } let!(:log_to_search) { FactoryBot.create(:lettings_log, owning_organisation: user.organisation, managing_organisation_id: organisation.id) } let!(:other_logs) { FactoryBot.create_list(:lettings_log, 4, owning_organisation_id: organisation.id, managing_organisation_id: organisation.id) } @@ -189,7 +189,7 @@ RSpec.describe "User Features" do expect(page).to have_link("Clear search") end - it "displays the logs belonging to the same organisation after I clear the search result after I clear the search resultss" do + it "displays the logs belonging to the same organisation after I clear the search result after I clear the search results" do click_link("Clear search") expect(page).to have_link(log_to_search.id.to_s) end @@ -210,6 +210,40 @@ RSpec.describe "User Features" do end end + context "when viewing sales logs for specific organisation" do + let(:first_log) { organisation.sales_logs.first } + let!(:log_to_search) { FactoryBot.create(:sales_log, owning_organisation: user.organisation, managing_organisation_id: organisation.id) } + let!(:other_logs) { FactoryBot.create_list(:sales_log, 4, owning_organisation_id: organisation.id, managing_organisation_id: organisation.id) } + let(:number_of_sales_logs) { SalesLog.count } + + before do + visit("/organisations/#{org_id}/sales-logs") + end + + it "shows a create button for that organisation" do + expect(page).to have_button("Create a new sales log for this organisation") + end + + context "when creating a log for that organisation" do + it "pre-fills the value for owning organisation for that log" do + click_button("Create a new sales log for this organisation") + click_link("Set up this sales log") + expect(page).to have_content(org_name) + end + end + + it "can filter lettings logs" do + expect(page).to have_content("#{number_of_sales_logs} total logs") + organisation.sales_logs.map(&:id).each do |sales_log_id| + expect(page).to have_link sales_log_id.to_s, href: "/sales-logs/#{sales_log_id}" + end + check("years-2021-field") + click_button("Apply filters") + expect(page).to have_current_path("/organisations/#{org_id}/sales-logs?years[]=&years[]=2021&status[]=&user=all") + expect(page).not_to have_link first_log.id.to_s, href: "/sales-logs/#{first_log.id}" + end + end + context "when I search for users belonging to a specific organisation" do context "when I am signed in and there are users in the database" do let!(:user_list) { FactoryBot.create_list(:user, 4, organisation: user.organisation) }