From 6c044fd03683b4bb6928bd3c6648b2db44167f24 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Thu, 11 Jan 2024 11:23:38 +0000 Subject: [PATCH 1/6] CLDC-3034 Fix bulk upload error on empty field bug (#2135) * feat: don't add empty assignments in field_mapping_for_errors * feat: use empty arrays * feat: revert previous commit * feat: add previously failing test --- .../lettings/year2023/row_parser.rb | 10 +++++----- config/locales/en.yml | 2 +- .../lettings/year2023/row_parser_spec.rb | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/services/bulk_upload/lettings/year2023/row_parser.rb b/app/services/bulk_upload/lettings/year2023/row_parser.rb index c1a19ef93..508ddea90 100644 --- a/app/services/bulk_upload/lettings/year2023/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2023/row_parser.rb @@ -893,10 +893,10 @@ private owning_organisation_id: [:field_1], managing_organisation_id: [:field_2], renewal: [:field_6], - scheme_id: [scheme_field], - scheme: [scheme_field], - location_id: [location_field], - location: [location_field], + scheme_id: (scheme_field.present? ? [scheme_field] : nil), + scheme: (scheme_field.present? ? [scheme_field] : nil), + location_id: (location_field.present? ? [location_field] : nil), + location: (location_field.present? ? [location_field] : nil), created_by: [:field_3], needstype: [:field_4], rent_type: %i[field_5 field_10 field_11], @@ -1040,7 +1040,7 @@ private address_line2: [:field_20], town_or_city: [:field_21], county: [:field_22], - } + }.compact end def attribute_set diff --git a/config/locales/en.yml b/config/locales/en.yml index 0c7d3c58f..ef28a05a3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -353,7 +353,7 @@ en: financial: tshortfall: outstanding_amount_not_expected: "You cannot answer the outstanding amount question if you don’t have outstanding rent or charges" - more_than_rent: "Enter a value less less than the basic rent amount" + more_than_rent: "Enter a value less than the basic rent amount" must_be_positive: "Enter a value over £0.01 as you told us there is an outstanding amount" hbrentshortfall: outstanding_amount_not_expected: "Answer must be ‘yes’ as you have answered the outstanding amount question" diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index 63531deb5..04044655d 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -617,6 +617,24 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do end end + context "when the rent range validation is triggered but the log has no scheme or location id" do + let(:attributes) do + setup_section_params.merge({ field_15: nil, + field_16: nil, + field_17: nil, + field_128: 300, + field_126: 1, + field_32: 1, + field_4: 1, + field_5: "3", + field_25: "E09000008" }) + end + + it "is not a valid row" do + expect(parser).not_to be_valid + end + end + context "when a hidden log already exists in db" do before do parser.log.status = "pending" From d5d86c90b10c5d2cb98c373b861ede2424cc5131 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Thu, 11 Jan 2024 14:34:47 +0000 Subject: [PATCH 2/6] feat: use new slot syntax (#2137) --- app/views/layouts/_footer.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb index cadc13db6..bf455a6cd 100644 --- a/app/views/layouts/_footer.html.erb +++ b/app/views/layouts/_footer.html.erb @@ -1,5 +1,5 @@ <%= govuk_footer do |footer| %> - <%= footer.meta do %> + <%= footer.with_meta do %> diff --git a/app/views/start/guidance.html.erb b/app/views/start/guidance.html.erb new file mode 100644 index 000000000..127b56b3b --- /dev/null +++ b/app/views/start/guidance.html.erb @@ -0,0 +1,68 @@ +

+ Guidance for submitting social housing lettings and sales data +

+ +
+
+

This page includes details of when a CORE log is and is not required, what to do if a tenant or buyer is reluctant to answer questions in a log, and other information about submitting logs using CORE.

+ <%= govuk_accordion do |accordion| %> + <%= accordion.with_section(heading_text: "How to create logs", expanded: true) do %> +

There are 2 ways to create logs on CORE.

+

You can create logs one at a time by answering questions using the online form. Click the “Create a new log” button on the logs page to create logs this way.

+

You can also create many logs at once by uploading a CSV file. This might be faster than creating logs individually if your organisation has its own database and a way to export the data. Click the “Upload logs in bulk” button on the logs page to create logs this way. For more information, <%= govuk_link_to "read the full guidance on bulk upload", bulk_upload_lettings_log_path(id: "guidance", form: { year: current_collection_start_year }) %>.

+

Once you have created and completed a log, there is nothing more you need to do to submit the data.

+ <% end %> + + <%= accordion.with_section(heading_text: "What scenarios require a new log?") do %> +

For general needs, you should complete a log for each new tenancy intended to last 2 years or more if it is social rent or affordable rent, or of any length if it is intermediate rent.

+

For supported housing, you should complete a log for each new letting of any length.

+

If a new tenancy agreement is signed, create a new log.

+ <% end %> + + <%= accordion.with_section(heading_text: "Types of lettings you should create logs for") do %> +

You’ll need to create a log for:

+ + <% end %> + + <%= accordion.with_section(heading_text: "Types of lettings you should not create logs for") do %> +

You don’t need to create a log for:

+ + <% end %> + + <%= accordion.with_section(heading_text: "What if someone is reluctant to answer any questions?") do %> +

If a tenant or buyer is reluctant to answer questions as part of a log, you should explain that:

+ +

If a tenant or buyer is still unwilling or unable to answer questions, select the ‘Don’t know’ or ‘Tenant/person prefers not to say’ options.

+ <% end %> + <% end %> +
+
diff --git a/app/views/start/index.html.erb b/app/views/start/index.html.erb index 3c10232d2..79abb5df7 100644 --- a/app/views/start/index.html.erb +++ b/app/views/start/index.html.erb @@ -16,13 +16,16 @@ href: start_path, ) %> +
+

Before you start

Use your account details to sign in.

If you need to set up a new account, speak to your organisation’s CORE data coordinator. If you don’t know who that is, <%= govuk_link_to("contact the helpdesk", GlobalConstants::HELPDESK_URL) %>.

You can <%= govuk_mail_to("dluhc.digital-services@levellingup.gov.uk", "request an account", subject: "CORE: Request a new account") %> if your organisation doesn’t have one.

- - -
+

<%= govuk_link_to guidance_path do %>Guidance for submitting social housing lettings and sales data (CORE)<% end %>

+


<%= render partial: "layouts/collection_resources" %> +
+ <%= render partial: "layouts/about_this_service" %>
diff --git a/config/routes.rb b/config/routes.rb index af0b95d07..06cb4f8d3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -30,6 +30,7 @@ Rails.application.routes.draw do resource :cookies, only: %i[show update] root to: "start#index" + get "/guidance", to: "start#guidance" get "/logs", to: redirect("lettings-logs") get "/accessibility-statement", to: "content#accessibility_statement" @@ -127,6 +128,10 @@ Rails.application.routes.draw do end end + resource :notifications do + get "dismiss", to: "notifications#dismiss" + end + resources :organisations do get "duplicates", to: "duplicate_logs#index" diff --git a/db/migrate/20240108145545_create_notification.rb b/db/migrate/20240108145545_create_notification.rb new file mode 100644 index 000000000..dc69a8efe --- /dev/null +++ b/db/migrate/20240108145545_create_notification.rb @@ -0,0 +1,14 @@ +class CreateNotification < ActiveRecord::Migration[7.0] + def change + create_table :notifications do |t| + t.string :title + t.string :link_text + t.string :page_content + t.datetime :start_date + t.datetime :end_date + t.boolean :show_on_unauthenticated_pages + + t.timestamps + end + end +end diff --git a/db/migrate/20240108152935_unread_migration.rb b/db/migrate/20240108152935_unread_migration.rb new file mode 100644 index 000000000..25067b439 --- /dev/null +++ b/db/migrate/20240108152935_unread_migration.rb @@ -0,0 +1,25 @@ +class UnreadMigration < ActiveRecord::Migration[6.0] + def self.up + create_table ReadMark, force: true, options: create_options do |t| + t.references :readable, polymorphic: { null: false } + t.references :reader, polymorphic: { null: false } + t.datetime :timestamp, null: false + t.timestamps + end + + add_index ReadMark, %i[reader_id reader_type readable_type readable_id], name: "read_marks_reader_readable_index", unique: true + end + + def self.down + drop_table ReadMark + end + + def self.create_options + options = "" + if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) \ + && ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) + options = "DEFAULT CHARSET=latin1" + end + options + end +end diff --git a/db/schema.rb b/db/schema.rb index 22d67bb9f..e75f47e60 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_12_18_105226) do +ActiveRecord::Schema[7.0].define(version: 2024_01_08_152935) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -393,6 +393,17 @@ ActiveRecord::Schema[7.0].define(version: 2023_12_18_105226) do t.string "new_organisation_telephone_number" end + create_table "notifications", force: :cascade do |t| + t.string "title" + t.string "link_text" + t.string "page_content" + t.datetime "start_date" + t.datetime "end_date" + t.boolean "show_on_unauthenticated_pages" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "organisation_relationships", force: :cascade do |t| t.integer "child_organisation_id" t.integer "parent_organisation_id" @@ -446,6 +457,17 @@ ActiveRecord::Schema[7.0].define(version: 2023_12_18_105226) do t.index ["old_visible_id"], name: "index_organisations_on_old_visible_id", unique: true end + create_table "read_marks", force: :cascade do |t| + t.string "readable_type", null: false + t.bigint "readable_id" + t.string "reader_type", null: false + t.bigint "reader_id" + t.datetime "timestamp", precision: nil, null: false + t.index ["readable_type", "readable_id"], name: "index_read_marks_on_readable_type_and_readable_id" + t.index ["reader_id", "reader_type", "readable_type", "readable_id"], name: "read_marks_reader_readable_index", unique: true + t.index ["reader_type", "reader_id"], name: "index_read_marks_on_reader_type_and_reader_id" + end + create_table "sales_logs", force: :cascade do |t| t.integer "status", default: 0 t.datetime "saledate" diff --git a/spec/factories/notification.rb b/spec/factories/notification.rb new file mode 100644 index 000000000..05d4faa3f --- /dev/null +++ b/spec/factories/notification.rb @@ -0,0 +1,10 @@ +FactoryBot.define do + factory :notification do + title { "Notification title" } + link_text { "Link text" } + page_content { "Some html content" } + start_date { Time.zone.yesterday } + end_date { Time.zone.tomorrow } + show_on_unauthenticated_pages { false } + end +end diff --git a/spec/features/home_page_spec.rb b/spec/features/home_page_spec.rb new file mode 100644 index 000000000..871616b8e --- /dev/null +++ b/spec/features/home_page_spec.rb @@ -0,0 +1,276 @@ +require "rails_helper" +require_relative "form/helpers" + +RSpec.describe "Home Page Features" do + include Helpers + + context "when there are notifications" do + let!(:user) { FactoryBot.create(:user) } + + context "when the notifications are currently active" do + before do + create(:notification, title: "Notification title 1") + create(:notification, title: "Notification title 2") + create(:notification, title: "Notification title 3") + sign_in user + visit(root_path) + end + + it "shows the latest notification with count and dismiss link" do + expect(page).to have_content("Notification 1 of 3") + expect(page).to have_content("Notification title 3") + expect(page).to have_link("Dismiss") + expect(page).to have_link("Link text") + end + + context "when the user clicks a notification link" do + before do + click_link("Link text") + end + + it "takes them to the notification details page" do + expect(page).to have_current_path(notifications_path) + expect(page).to have_content("Notification title 3") + expect(page).to have_content("Some html content") + expect(page).to have_link("Back to Home") + end + + context "when they return" do + before do + click_link("Back to Home") + end + + it "the notification has not been dismissed" do + expect(page).to have_current_path(root_path) + expect(page).to have_content("Notification 1 of 3") + expect(page).to have_content("Notification title 3") + expect(page).to have_link("Dismiss") + expect(page).to have_link("Link text") + end + end + end + + context "when the user clicks a dismiss link" do + before do + click_link("Dismiss") + end + + it "dismisses the notification and takes them back" do + expect(page).to have_current_path(root_path) + expect(page).to have_content("Notification 1 of 2") + expect(page).to have_content("Notification title 2") + expect(page).to have_link("Dismiss") + expect(page).to have_link("Link text") + end + + context "when the user dismisses the penultimate notification" do + before do + click_link("Dismiss") + end + + it "no longer displays the count" do + expect(page).to have_current_path(root_path) + expect(page).not_to have_content("Notification 1 of") + expect(page).to have_content("Notification title 1") + end + + context "when the user dismisses the final notification" do + before do + click_link("Dismiss") + end + + it "no longer displays any notification" do + expect(page).to have_current_path(root_path) + expect(page).not_to have_content("Notification") + expect(page).not_to have_link("Dismiss") + expect(page).not_to have_link("Link_text") + end + end + end + end + + context "when another user has dismissed all their notifications" do + before do + other_user = create(:user) + Notification.mark_as_read! :all, for: other_user + visit(root_path) + end + + it "the first user can still see the notifications" do + expect(page).to have_content("Notification 1 of 3") + expect(page).to have_content("Notification title 3") + expect(page).to have_link("Dismiss") + expect(page).to have_link("Link text") + end + end + end + + context "when the notifications are not currently active" do + before do + create(:notification, end_date: Time.zone.yesterday, title: "Notification title 1") + create(:notification, start_date: Time.zone.tomorrow, title: "Notification title 2") + sign_in user + visit(root_path) + end + + it "does not show any notifications" do + expect(page).not_to have_content("Notification title") + expect(page).not_to have_content("Notification 1 of") + expect(page).not_to have_link("Dismiss") + expect(page).not_to have_link("Link text") + end + end + end + + context "when the user is a data provider" do + let(:user) { FactoryBot.create(:user, name: "Provider") } + + before do + create_list(:lettings_log, 6, :in_progress, owning_organisation: user.organisation, created_by: user) + create_list(:lettings_log, 2, :in_progress, owning_organisation: user.organisation) + create_list(:lettings_log, 4, :completed, owning_organisation: user.organisation, created_by: user) + create_list(:lettings_log, 2, :completed) + sign_in user + visit(root_path) + end + + it "displays the correct welcome text" do + expect(page).to have_current_path("/") + expect(page).to have_content("Welcome back, Provider") + expect(page).to have_content("Complete your logs") + end + + context "when their organisation has submitted sales logs" do + before do + create_list(:sales_log, 5, :in_progress, owning_organisation: user.organisation, created_by: user) + create_list(:sales_log, 3, :completed, owning_organisation: user.organisation, created_by: user) + visit(root_path) + end + + it "displays correct data boxes, counts and links" do + data_boxes = page.find_all(class: "app-data-box-one-half") + expect(data_boxes.count).to eq(2) + expect(data_boxes[0].all("a").map(&:text)).to eq(["6", "Your lettings in progress", "View all lettings"]) + expect(data_boxes[0].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: [:in_progress], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: [:in_progress], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "lettings_logs")]) + expect(data_boxes[1].all("a").map(&:text)).to eq(["5", "Your sales in progress", "View all sales"]) + expect(data_boxes[1].all("a").map { |line| line["href"] }).to eq([sales_logs_path(status: [:in_progress], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), sales_logs_path(status: [:in_progress], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "sales_logs")]) + end + end + + context "when their organisation has never submitted sales logs" do + before do + visit(root_path) + end + + it "displays correct data boxes, counts and links" do + data_boxes = page.find_all(class: "app-data-box-one-half") + expect(data_boxes.count).to eq(2) + expect(data_boxes[0].all("a").map(&:text)).to eq(["6", "Your lettings in progress", "View all lettings"]) + expect(data_boxes[0].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: [:in_progress], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: [:in_progress], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "lettings_logs")]) + expect(data_boxes[1].all("a").map(&:text)).to eq(["4", "Your completed lettings", "View all schemes"]) + expect(data_boxes[1].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: [:completed], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: [:completed], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "schemes")]) + end + end + end + + context "when the user is a data coordinator" do + before do + create_list(:lettings_log, 6, :in_progress, owning_organisation: user.organisation) + create_list(:lettings_log, 2, :in_progress, owning_organisation: user.organisation, created_by: user) + create_list(:lettings_log, 4, :completed, owning_organisation: user.organisation) + create_list(:lettings_log, 2, :completed) + create_list(:scheme, 1, :incomplete, owning_organisation: user.organisation) + sign_in user + visit(root_path) + end + + let(:user) { FactoryBot.create(:user, :data_coordinator, name: "Coordinator") } + + it "displays the correct welcome text" do + expect(page).to have_current_path("/") + expect(page).to have_content("Welcome back, Coordinator") + expect(page).to have_content("Manage your data") + end + + context "when their organisation has submitted sales logs" do + before do + create_list(:sales_log, 5, :in_progress, owning_organisation: user.organisation) + create_list(:sales_log, 3, :completed, owning_organisation: user.organisation) + visit(root_path) + end + + it "displays correct data boxes, counts and links" do + data_boxes = page.find_all(class: "app-data-box-one-third") + expect(data_boxes.count).to eq(3) + expect(data_boxes[0].all("a").map(&:text)).to eq(["8", "Lettings in progress", "View all lettings"]) + expect(data_boxes[0].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: [:in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: [:in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "lettings_logs")]) + expect(data_boxes[1].all("a").map(&:text)).to eq(["5", "Sales in progress", "View all sales"]) + expect(data_boxes[1].all("a").map { |line| line["href"] }).to eq([sales_logs_path(status: [:in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), sales_logs_path(status: [:in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "sales_logs")]) + expect(data_boxes[2].all("a").map(&:text)).to eq(["1", "Incomplete schemes", "View all schemes"]) + expect(data_boxes[2].all("a").map { |line| line["href"] }).to eq([schemes_path(status: [:incomplete], owning_organisation_select: "all"), schemes_path(status: [:incomplete], owning_organisation_select: "all"), clear_filters_path(filter_type: "schemes")]) + end + end + + context "when their organisation has never submitted sales logs" do + before do + visit(root_path) + end + + it "displays correct data boxes, counts and links" do + data_boxes = page.find_all(class: "app-data-box-one-half") + expect(data_boxes.count).to eq(2) + expect(data_boxes[0].all("a").map(&:text)).to eq(["8", "Lettings in progress", "View all lettings"]) + expect(data_boxes[0].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: [:in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: [:in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "lettings_logs")]) + expect(data_boxes[1].all("a").map(&:text)).to eq(["1", "Incomplete schemes", "View all schemes"]) + expect(data_boxes[1].all("a").map { |line| line["href"] }).to eq([schemes_path(status: [:incomplete], owning_organisation_select: "all"), schemes_path(status: [:incomplete], owning_organisation_select: "all"), clear_filters_path(filter_type: "schemes")]) + end + end + end + + context "when the user is a support user" do + let(:support_user) { FactoryBot.create(:user, :support, name: "Support") } + let(:notify_client) { instance_double(Notifications::Client) } + let(:confirmation_token) { "MCDH5y6Km-U7CFPgAMVS" } + let(:devise_notify_mailer) { DeviseNotifyMailer.new } + let(:otp) { "999111" } + + before do + create_list(:lettings_log, 2, :in_progress) + create_list(:lettings_log, 1, :completed) + create_list(:sales_log, 3, :in_progress) + create_list(:sales_log, 1, :completed) + create_list(:scheme, 1, :incomplete) + completed_scheme = create(:scheme) + create(:location, scheme: completed_scheme) + allow(DeviseNotifyMailer).to receive(:new).and_return(devise_notify_mailer) + allow(devise_notify_mailer).to receive(:notify_client).and_return(notify_client) + allow(Devise).to receive(:friendly_token).and_return(confirmation_token) + allow(notify_client).to receive(:send_email).and_return(true) + allow(SecureRandom).to receive(:random_number).and_return(otp) + visit("/lettings-logs") + fill_in("user[email]", with: support_user.email) + fill_in("user[password]", with: support_user.password) + click_button("Sign in") + fill_in("code", with: otp) + click_button("Submit") + visit(root_path) + end + + it "displays the correct welcome text" do + expect(page).to have_current_path("/") + expect(page).to have_content("Welcome back, Support") + expect(page).to have_content("Manage all data") + end + + it "displays correct data boxes, counts and links" do + data_boxes = page.find_all(class: "app-data-box-one-third") + expect(data_boxes.count).to eq(3) + expect(data_boxes[0].all("a").map(&:text)).to eq(["2", "Lettings in progress", "View all lettings"]) + expect(data_boxes[0].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: [:in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: [:in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "lettings_logs")]) + expect(data_boxes[1].all("a").map(&:text)).to eq(["3", "Sales in progress", "View all sales"]) + expect(data_boxes[1].all("a").map { |line| line["href"] }).to eq([sales_logs_path(status: [:in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), sales_logs_path(status: [:in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "sales_logs")]) + expect(data_boxes[2].all("a").map(&:text)).to eq(["1", "Incomplete schemes", "View all schemes"]) + expect(data_boxes[2].all("a").map { |line| line["href"] }).to eq([schemes_path(status: [:incomplete], owning_organisation_select: "all"), schemes_path(status: [:incomplete], owning_organisation_select: "all"), clear_filters_path(filter_type: "schemes")]) + end + end +end diff --git a/spec/features/notifications_page_spec.rb b/spec/features/notifications_page_spec.rb new file mode 100644 index 000000000..97bbeb7eb --- /dev/null +++ b/spec/features/notifications_page_spec.rb @@ -0,0 +1,41 @@ +require "rails_helper" +require_relative "form/helpers" + +RSpec.describe "Notifications Page Features" do + include Helpers + + context "when there are notifications" do + let!(:user) { FactoryBot.create(:user) } + + context "when the notifications are currently active" do + before do + create(:notification, title: "Notification title 1") + create(:notification, title: "Notification title 2") + create(:notification, title: "Notification title 3") + sign_in user + visit(notifications_path) + end + + it "does not show the notification banner" do + expect(page).not_to have_content("Notification 1 of") + expect(page).not_to have_link("Dismiss") + expect(page).not_to have_link("Link text") + end + end + + context "when the notifications are not currently active" do + before do + create(:notification, end_date: Time.zone.yesterday, title: "Notification title 1") + create(:notification, start_date: Time.zone.tomorrow, title: "Notification title 2") + sign_in user + visit(notifications_path) + end + + it "does not show the notifications banner" do + expect(page).not_to have_content("Notification 1 of") + expect(page).not_to have_link("Dismiss") + expect(page).not_to have_link("Link text") + end + end + end +end diff --git a/spec/features/start_page_spec.rb b/spec/features/start_page_spec.rb index 569ea4cfa..d90a0c1f0 100644 --- a/spec/features/start_page_spec.rb +++ b/spec/features/start_page_spec.rb @@ -10,21 +10,38 @@ RSpec.describe "Start Page Features" do sign_in user end - it "takes you to logs" do - visit("/") - expect(page).to have_current_path("/lettings-logs") + it "takes you to the home page" do + visit(root_path) + expect(page).to have_current_path("/") + expect(page).to have_content("Welcome back") end end context "when the user is not signed in" do - it "takes you to sign in and then to logs" do - visit("/") + it "takes you to sign in and then to the home page" do + visit(root_path) click_link("Start now") expect(page).to have_current_path("/account/sign-in?start=true") fill_in("user[email]", with: user.email) fill_in("user[password]", with: user.password) click_button("Sign in") - expect(page).to have_current_path("/lettings-logs") + expect(page).to have_current_path("/") + expect(page).to have_content("Welcome back") + end + + context "when the unauthenticated user clicks a notification link" do + before do + create(:notification, show_on_unauthenticated_pages: true) + visit(root_path) + click_link("Link text") + end + + it "takes them to the notification details page" do + expect(page).to have_current_path(notifications_path) + expect(page).to have_content("Notification title") + expect(page).to have_content("Some html content") + expect(page).to have_link("Back to Start") + end end end end diff --git a/spec/features/test_spec.rb b/spec/features/test_spec.rb index ef54fa631..6dc977a9b 100644 --- a/spec/features/test_spec.rb +++ b/spec/features/test_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" RSpec.describe "Test Features" do it "Displays the name of the app" do - visit("/") + visit(root_path) expect(page).to have_content("Submit social housing lettings and sales data (CORE)") end diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index f298616f2..e898c1b0a 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -126,13 +126,14 @@ RSpec.describe "User Features" do end it "Can navigate and sign in page with sign in button" do - visit("/") + visit(root_path) expect(page).to have_link("Sign in") click_link("Sign in") fill_in("user[email]", with: user.email) fill_in("user[password]", with: "pAssword1") click_button("Sign in") - expect(page).to have_current_path("/lettings-logs") + expect(page).to have_current_path("/") + expect(page).to have_content("Welcome back") end it "tries to access account page, redirects to log in page" do diff --git a/spec/helpers/collection_time_helper_spec.rb b/spec/helpers/collection_time_helper_spec.rb index 3eef01b5e..859431c57 100644 --- a/spec/helpers/collection_time_helper_spec.rb +++ b/spec/helpers/collection_time_helper_spec.rb @@ -109,4 +109,34 @@ RSpec.describe CollectionTimeHelper do end end end + + describe "#quarter_for_date" do + it "returns correct cutoff date for curent quarter" do + quarter = quarter_for_date(date: Time.zone.local(2023, 10, 1)) + expect(quarter.cutoff_date).to eq(Time.zone.local(2024, 1, 12)) + expect(quarter.quarter_start_date).to eq(Time.zone.local(2023, 10, 1)) + expect(quarter.quarter_end_date).to eq(Time.zone.local(2023, 12, 31)) + end + + it "returns correct cutoff date for the first quarter of 2024/25" do + quarter = quarter_for_date(date: Time.zone.local(2024, 4, 1)) + expect(quarter.cutoff_date).to eq(Time.zone.local(2024, 7, 12)) + expect(quarter.quarter_start_date).to eq(Time.zone.local(2024, 4, 1)) + expect(quarter.quarter_end_date).to eq(Time.zone.local(2024, 6, 30)) + end + + it "returns correct cutoff date for the second quarter of 2024/25" do + quarter = quarter_for_date(date: Time.zone.local(2024, 9, 30)) + expect(quarter.cutoff_date).to eq(Time.zone.local(2024, 10, 11)) + expect(quarter.quarter_start_date).to eq(Time.zone.local(2024, 7, 1)) + expect(quarter.quarter_end_date).to eq(Time.zone.local(2024, 9, 30)) + end + + it "returns correct cutoff date for the third quarter of 2024/25" do + quarter = quarter_for_date(date: Time.zone.local(2024, 10, 25)) + expect(quarter.cutoff_date).to eq(Time.zone.local(2025, 1, 10)) + expect(quarter.quarter_start_date).to eq(Time.zone.local(2024, 10, 1)) + expect(quarter.quarter_end_date).to eq(Time.zone.local(2024, 12, 31)) + end + end end diff --git a/spec/helpers/navigation_items_helper_spec.rb b/spec/helpers/navigation_items_helper_spec.rb index 2538b10a8..13b634e2f 100644 --- a/spec/helpers/navigation_items_helper_spec.rb +++ b/spec/helpers/navigation_items_helper_spec.rb @@ -12,6 +12,7 @@ RSpec.describe NavigationItemsHelper do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", true), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), @@ -21,7 +22,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the lettings logs item set as current" do expect(primary_items("/lettings-logs", current_user)).to eq(expected_navigation_items) end @@ -34,6 +35,7 @@ RSpec.describe NavigationItemsHelper do let(:stock_owner) { create(:organisation) } let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", true), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), @@ -44,15 +46,35 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the lettings logs item set as current" do expect(primary_items("/lettings-logs", current_user)).to eq(expected_navigation_items) end end end + context "when the user is on the home page" do + let(:expected_navigation_items) do + [ + NavigationItemsHelper::NavigationItem.new("Home", "/", true), + NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), + NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), + NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), + NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), + NavigationItemsHelper::NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}/details", false), + NavigationItemsHelper::NavigationItem.new("Stock owners", "/organisations/#{current_user.organisation.id}/stock-owners", false), + NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false), + ] + end + + it "returns navigation items with the home item set as current" do + expect(primary_items("/", current_user)).to eq(expected_navigation_items) + end + end + context "when the user is on the lettings logs page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", true), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), @@ -63,7 +85,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the lettings logs item set as current" do expect(primary_items("/lettings-logs", current_user)).to eq(expected_navigation_items) end end @@ -71,6 +93,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the sales logs page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", true), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), @@ -81,7 +104,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the sales logs item set as current" do expect(primary_items("/sales-logs", current_user)).to eq(expected_navigation_items) end end @@ -89,6 +112,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the users page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), @@ -107,6 +131,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on their organisation details page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), @@ -117,7 +142,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the organisation item set as current" do expect(primary_items("/organisations/#{current_user.organisation.id}/details", current_user)).to eq(expected_navigation_items) end end @@ -125,6 +150,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the account page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), @@ -135,7 +161,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with no items set as current" do expect(primary_items("/account", current_user)).to eq(expected_navigation_items) end end @@ -143,6 +169,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the individual user's page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), @@ -161,6 +188,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the individual scheme's page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", true), @@ -171,7 +199,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with Schemes item set as current" do + it "returns navigation items with schemes item set as current" do expect(primary_items("/schemes/1", current_user)).to eq(expected_navigation_items) end end @@ -191,6 +219,7 @@ RSpec.describe NavigationItemsHelper do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", true), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), @@ -200,7 +229,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the lettings logs item set as current" do expect(primary_items("/lettings-logs", current_user)).to eq(expected_navigation_items) end @@ -213,6 +242,7 @@ RSpec.describe NavigationItemsHelper do let(:stock_owner) { create(:organisation) } let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", true), NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), @@ -223,7 +253,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the lettings logs item set as current" do expect(primary_items("/lettings-logs", current_user)).to eq(expected_navigation_items) end end @@ -233,9 +263,27 @@ RSpec.describe NavigationItemsHelper do context "when the user is a support user" do let(:current_user) { create(:user, :support) } + context "when the user is on the home page" do + let(:expected_navigation_items) do + [ + NavigationItemsHelper::NavigationItem.new("Home", "/", true), + NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), + NavigationItemsHelper::NavigationItem.new("Users", "/users", false), + NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), + NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), + NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), + ] + end + + it "returns navigation items with the home item set as current" do + expect(primary_items("/", current_user)).to eq(expected_navigation_items) + end + end + context "when the user is on the lettings logs page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", true), @@ -244,7 +292,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the lettings logs item set as current" do expect(primary_items("/lettings-logs", current_user)).to eq(expected_navigation_items) end end @@ -252,6 +300,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the sales logs page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -260,7 +309,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the sales logs item set as current" do expect(primary_items("/sales-logs", current_user)).to eq(expected_navigation_items) end end @@ -268,6 +317,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the users page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", true), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -284,6 +334,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the account page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -292,7 +343,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the no items set as current" do expect(primary_items("/account", current_user)).to eq(expected_navigation_items) end end @@ -300,6 +351,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the Schemes page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -308,7 +360,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the users item set as current" do + it "returns navigation items with the schemes item set as current" do expect(primary_items("/schemes", current_user)).to eq(expected_navigation_items) end end @@ -316,6 +368,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the individual user's page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", true), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -332,6 +385,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the individual scheme's page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -347,7 +401,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with Schemes item set as current" do + it "returns navigation items with schemes item set as current" do expect(primary_items("/schemes/1", current_user)).to eq(expected_navigation_items) expect(scheme_items("/schemes/1", 1)).to eq(expected_scheme_items) end @@ -356,6 +410,7 @@ RSpec.describe NavigationItemsHelper do context "when the user is on the scheme locations page" do let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -371,7 +426,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with Schemes item set as current" do + it "returns navigation items with schemes item set as current" do expect(primary_items("/schemes/1/locations", current_user)).to eq(expected_navigation_items) expect(scheme_items("/schemes/1/locations", 1)).to eq(expected_scheme_items) end @@ -382,6 +437,7 @@ RSpec.describe NavigationItemsHelper do let(:required_sub_path) { "lettings-logs" } let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -402,7 +458,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the logs item set as current" do + it "returns navigation items with the lettings logs item set as current" do expect(primary_items("/organisations/#{current_user.organisation.id}/#{required_sub_path}", current_user)).to eq(expected_navigation_items) expect(secondary_items("/organisations/#{current_user.organisation.id}/#{required_sub_path}", current_user.organisation.id)).to eq(expected_secondary_navigation_items) end @@ -412,6 +468,7 @@ RSpec.describe NavigationItemsHelper do let(:required_sub_path) { "users" } let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -432,7 +489,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the logs item set as current" do + it "returns navigation items with the users item set as current" do expect(primary_items("/organisations/#{current_user.organisation.id}/#{required_sub_path}", current_user)).to eq(expected_navigation_items) expect(secondary_items("/organisations/#{current_user.organisation.id}/#{required_sub_path}", current_user.organisation.id)).to eq(expected_secondary_navigation_items) end @@ -442,6 +499,7 @@ RSpec.describe NavigationItemsHelper do let(:required_sub_path) { "schemes" } let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -472,6 +530,7 @@ RSpec.describe NavigationItemsHelper do let(:required_sub_path) { "details" } let(:expected_navigation_items) do [ + NavigationItemsHelper::NavigationItem.new("Home", "/", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Lettings logs", "/lettings-logs", false), @@ -492,7 +551,7 @@ RSpec.describe NavigationItemsHelper do ] end - it "returns navigation items with the logs item set as current" do + it "returns navigation items with the organisation item set as current" do expect(primary_items("/organisations/#{current_user.organisation.id}/#{required_sub_path}", current_user)).to eq(expected_navigation_items) expect(secondary_items("/organisations/#{current_user.organisation.id}/#{required_sub_path}", current_user.organisation.id)).to eq(expected_secondary_navigation_items) end diff --git a/spec/requests/auth/passwords_controller_spec.rb b/spec/requests/auth/passwords_controller_spec.rb index 92c36608c..333985d9e 100644 --- a/spec/requests/auth/passwords_controller_spec.rb +++ b/spec/requests/auth/passwords_controller_spec.rb @@ -67,7 +67,6 @@ RSpec.describe Auth::PasswordsController, type: :request do put "/account/password", params: update_password_params # Devise redirects once after re-sign in with new password and then root redirects as well. follow_redirect! - follow_redirect! expect(page).to have_css("div", class: "govuk-notification-banner__heading", text: message) end end diff --git a/spec/requests/maintenance_controller_spec.rb b/spec/requests/maintenance_controller_spec.rb index 4d7f8ab8c..39e587302 100644 --- a/spec/requests/maintenance_controller_spec.rb +++ b/spec/requests/maintenance_controller_spec.rb @@ -153,7 +153,6 @@ RSpec.describe MaintenanceController, type: :request do end it "the cookie banner is visible" do - follow_redirect! follow_redirect! expect(page).to have_content("We’d like to use analytics cookies so we can understand how you use the service and make improvements.") end diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 97665f8ca..68de93c51 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -310,42 +310,6 @@ RSpec.describe OrganisationsController, type: :request do it "redirects to details" do expect(response).to have_http_status(:redirect) end - - context "and 2022 collection window is open" do - let(:set_time) { allow(Time).to receive(:now).and_return(Time.zone.local(2023, 1, 1)) } - - it "displays correct resources for 2022/23 and 2023/24 collection years" do - follow_redirect! - expect(page).to have_content("Lettings 2023/24") - expect(page).to have_content("Sales 2023/24") - expect(page).to have_content("Lettings 2022/23") - expect(page).to have_content("Sales 2022/23") - end - end - - context "and 2022 collection window is closed for editing" do - let(:set_time) { allow(Time).to receive(:now).and_return(Time.zone.local(2024, 1, 1)) } - - it "displays correct resources for 2022/23 and 2023/24 collection years" do - follow_redirect! - expect(page).to have_content("Lettings 2023/24") - expect(page).to have_content("Sales 2023/24") - expect(page).not_to have_content("Lettings 2022/23") - expect(page).not_to have_content("Sales 2022/23") - end - end - - context "and 2023 collection window is closed for editing" do - let(:set_time) { allow(Time).to receive(:now).and_return(Time.zone.local(2025, 1, 1)) } - - it "displays correct resources for 2022/23 and 2023/24 collection years" do - follow_redirect! - expect(page).not_to have_content("Lettings 2023/24") - expect(page).not_to have_content("Sales 2023/24") - expect(page).not_to have_content("Lettings 2022/23") - expect(page).not_to have_content("Sales 2022/23") - end - end end context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do diff --git a/spec/requests/start_controller_spec.rb b/spec/requests/start_controller_spec.rb new file mode 100644 index 000000000..edca4d7c4 --- /dev/null +++ b/spec/requests/start_controller_spec.rb @@ -0,0 +1,90 @@ +require "rails_helper" + +RSpec.describe StartController, type: :request do + let(:user) { create(:user) } + let(:headers) { { "Accept" => "text/html" } } + let(:page) { Capybara::Node::Simple.new(response.body) } + let(:notify_client) { instance_double(Notifications::Client) } + let(:devise_notify_mailer) { DeviseNotifyMailer.new } + + before do + allow(DeviseNotifyMailer).to receive(:new).and_return(devise_notify_mailer) + allow(devise_notify_mailer).to receive(:notify_client).and_return(notify_client) + allow(notify_client).to receive(:send_email).and_return(true) + end + + describe "GET" do + context "when the user is not signed in" do + it "routes user to the start page" do + get "/", headers: headers, params: {} + expect(path).to eq("/") + expect(page).to have_content("Start now") + end + end + + context "when the user is signed in" do + before do + sign_in user + end + + it "routes user to the home page" do + get "/", headers:, params: {} + expect(page).to have_content("Welcome back") + end + + context "and 2023 collection window is open for editing" do + before do + allow(Time).to receive(:now).and_return(Time.zone.local(2024, 1, 1)) + end + + it "displays correct resources for 2022/23 and 2023/24 collection years" do + get "/", headers: headers, params: {} + expect(page).to have_content("Lettings 2023/24") + expect(page).to have_content("Sales 2023/24") + end + end + + context "and 2023 collection window is closed for editing" do + before do + allow(Time).to receive(:now).and_return(Time.zone.local(2025, 1, 1)) + end + + it "displays correct resources for 2022/23 and 2023/24 collection years" do + get "/", headers: headers, params: {} + expect(page).not_to have_content("Lettings 2023/24") + expect(page).not_to have_content("Sales 2023/24") + end + end + + it "shows guidance link" do + get "/", headers: headers, params: {} + expect(page).to have_content("Guidance for submitting social housing lettings and sales data (CORE)") + end + + it "displays About this service section" do + get "/", headers:, params: {} + expect(page).to have_content("About this service") + end + end + end + + describe "guidance page" do + context "when the user is not signed in" do + it "routes user to the guidance page" do + get "/guidance", headers:, params: {} + expect(page).to have_content("Guidance for submitting social housing lettings and sales data") + end + end + + context "when the user is signed in" do + before do + sign_in user + end + + it "routes user to the guidance page" do + get "/guidance", headers:, params: {} + expect(page).to have_content("Guidance for submitting social housing lettings and sales data") + end + end + end +end diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 90b49c2be..48cc0f064 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -73,11 +73,11 @@ RSpec.describe UsersController, type: :request do end describe "title link" do - it "routes user to the /logs page" do + it "routes user to the home page" do sign_in user get "/", headers:, params: {} - follow_redirect! - expect(path).to include("/lettings-logs") + expect(path).to eq("/") + expect(page).to have_content("Welcome back") expected_link = "" expect(CGI.unescape_html(response.body)).to include(expected_link) end @@ -2025,10 +2025,10 @@ RSpec.describe UsersController, type: :request do sign_in user end - it "routes user to the /logs page" do + it "routes user to the home page" do get "/", headers:, params: {} - follow_redirect! - expect(path).to include("/lettings-logs") + expect(path).to eq("/") + expect(page).to have_content("Welcome back") expected_link = "" expect(CGI.unescape_html(response.body)).to include(expected_link) end diff --git a/spec/views/layouts/application_layout_spec.rb b/spec/views/layouts/application_layout_spec.rb index ac4a10a98..55e97bc20 100644 --- a/spec/views/layouts/application_layout_spec.rb +++ b/spec/views/layouts/application_layout_spec.rb @@ -54,4 +54,35 @@ RSpec.describe "layouts/application" do include_examples "analytics cookie elements", banner: false, scripts: false end + + context "with a notification present" do + context "when notification is shown on unauthenticated pages" do + before do + create(:notification, title: "Old notification title", show_on_unauthenticated_pages: true) + create(:notification, title: "New notification title", show_on_unauthenticated_pages: true) + render + end + + it "shows the most recent notification without dismiss link or count" do + expect(rendered).to have_content("New notification title") + expect(rendered).to have_link("Link text") + expect(rendered).not_to have_link("Dismiss") + expect(rendered).not_to have_content("Notification 1 of") + end + end + + context "when notification is not shown on unauthenticated pages" do + before do + create(:notification) + render + end + + it "does not show the notification banner" do + expect(rendered).not_to have_content("Notification title") + expect(rendered).not_to have_link("Link text") + expect(rendered).not_to have_link("Dismiss") + expect(rendered).not_to have_content("Notification 1 of") + end + end + end end From 8aa511aff2d160f97e201228391bf6aa95d9d0b5 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 15 Jan 2024 14:26:24 +0000 Subject: [PATCH 5/6] Fix a test (#2143) --- spec/helpers/navigation_items_helper_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/helpers/navigation_items_helper_spec.rb b/spec/helpers/navigation_items_helper_spec.rb index 13b634e2f..e987ada91 100644 --- a/spec/helpers/navigation_items_helper_spec.rb +++ b/spec/helpers/navigation_items_helper_spec.rb @@ -60,7 +60,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Sales logs", "/sales-logs", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), - NavigationItemsHelper::NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}/details", false), + NavigationItemsHelper::NavigationItem.new("Your organisation", "/organisations/#{current_user.organisation.id}/details", false), NavigationItemsHelper::NavigationItem.new("Stock owners", "/organisations/#{current_user.organisation.id}/stock-owners", false), NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false), ] From 7333d2bb398897872f21e6fbc06098078b07f61d Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Mon, 15 Jan 2024 15:41:15 +0000 Subject: [PATCH 6/6] feat: typo fix (#2139) --- app/views/devise/passwords/reset_resend_confirmation.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/devise/passwords/reset_resend_confirmation.html.erb b/app/views/devise/passwords/reset_resend_confirmation.html.erb index 40e8f4871..b89717844 100644 --- a/app/views/devise/passwords/reset_resend_confirmation.html.erb +++ b/app/views/devise/passwords/reset_resend_confirmation.html.erb @@ -7,7 +7,7 @@

We’ve sent a link to reset your password to <%= @email %>.

-

You’ll only this receive this link if your email address already exists in our system.

+

You’ll only receive this link if your email address already exists in our system.

If you don’t receive the email within 5 minutes, check your spam or junk folders. Try again if you still haven’t received the email.