From 9716df77420c619f65368e2313a58498b2106b38 Mon Sep 17 00:00:00 2001 From: David May-Miller Date: Fri, 30 Sep 2022 11:32:24 +0100 Subject: [PATCH] CLDC-1625 Added create new sales log for this organisation button on organisation view (#920) --- app/views/logs/index.html.erb | 4 +-- app/views/organisations/logs.html.erb | 7 ++++- spec/features/organisation_spec.rb | 37 +++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/app/views/logs/index.html.erb b/app/views/logs/index.html.erb index 7c75230d4..f84a487df 100644 --- a/app/views/logs/index.html.erb +++ b/app/views/logs/index.html.erb @@ -7,10 +7,10 @@
- <% if current_page?(:controller => 'lettings_logs', :action => 'index') %> + <% if current_page?(controller: 'lettings_logs', action: 'index') %> <%= govuk_button_to "Create a new lettings log", lettings_logs_path %> <% end %> - <% if FeatureToggle.sales_log_enabled? && current_page?(:controller => 'sales_logs', :action => 'index') %> + <% if FeatureToggle.sales_log_enabled? && current_page?(controller: 'sales_logs', action: 'index') %> <%= govuk_button_to "Create a new sales log", sales_logs_path %> <% end %> <%#= govuk_link_to "Upload logs", bulk_upload_lettings_logs_path %> diff --git a/app/views/organisations/logs.html.erb b/app/views/organisations/logs.html.erb index 3b03e55e4..f954a0839 100644 --- a/app/views/organisations/logs.html.erb +++ b/app/views/organisations/logs.html.erb @@ -14,7 +14,12 @@
- <%= govuk_button_to "Create a new lettings log for this organisation", lettings_logs_path(lettings_log: { owning_organisation_id: @organisation.id }, method: :post) %> + <% if current_page?(controller: 'organisations', action: 'lettings_logs') %> + <%= govuk_button_to "Create a new lettings log for this organisation", lettings_logs_path(lettings_log: { owning_organisation_id: @organisation.id }, method: :post) %> + <% end %> + <% if current_page?(controller: 'organisations', action: 'sales_logs') %> + <%= govuk_button_to "Create a new sales log for this organisation", sales_logs_path(sales_log: { owning_organisation_id: @organisation.id }, method: :post) %> + <% end %>
<%= render partial: "logs/log_filters" %> diff --git a/spec/features/organisation_spec.rb b/spec/features/organisation_spec.rb index a0558d167..09d6130e4 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,39 @@ RSpec.describe "User Features" do end end + context "when viewing sales logs for specific organisation" do + let(:first_log) { organisation.sales_logs.first } + let(:number_of_sales_logs) { SalesLog.count } + + before do + FactoryBot.create_list(:sales_log, 4, owning_organisation_id: organisation.id, managing_organisation_id: organisation.id) + 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 sales 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) }