Skip to content

Commit

Permalink
Update some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kosiakkatrina committed Dec 9, 2024
1 parent 8fee431 commit ede13b6
Show file tree
Hide file tree
Showing 20 changed files with 166 additions and 145 deletions.
2 changes: 1 addition & 1 deletion app/components/search_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_with model: @user, url: path(current_user), method: "get", local: true do |f| %>
<%= form_with url: path(current_user), method: "get", local: true do |f| %>
<div class="app-search govuk-!-margin-bottom-4">
<%= f.govuk_text_field :search,
form_group: {
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
class SessionsController < ApplicationController
def clear_filters
session[session_name_for(params[:filter_type])] = "{}"
path_params = params[:path_params].presence || {}
filter_path_params = params[:filter_path_params].presence || {}

if path_params[:organisation_id].present?
redirect_to send("#{params[:filter_type]}_organisation_path", id: path_params[:organisation_id], scheme_id: path_params[:scheme_id], search: path_params[:search])
if filter_path_params[:organisation_id].present?
redirect_to send("#{params[:filter_type]}_organisation_path", id: filter_path_params[:organisation_id], scheme_id: filter_path_params[:scheme_id], search: filter_path_params[:search])
elsif params[:filter_type].include?("bulk_uploads")
bulk_upload_type = params[:filter_type].split("_").first
uploading_organisation = params[:organisation_id].presence
if uploading_organisation.present?
redirect_to send("bulk_uploads_#{bulk_upload_type}_logs_path", search: path_params[:search], uploading_organisation:)
redirect_to send("bulk_uploads_#{bulk_upload_type}_logs_path", search: filter_path_params[:search], uploading_organisation:)
else
redirect_to send("bulk_uploads_#{bulk_upload_type}_logs_path", search: path_params[:search])
redirect_to send("bulk_uploads_#{bulk_upload_type}_logs_path", search: filter_path_params[:search])
end
else
redirect_to send("#{params[:filter_type]}_path", scheme_id: path_params[:scheme_id], search: path_params[:search])
redirect_to send("#{params[:filter_type]}_path", scheme_id: filter_path_params[:scheme_id], search: filter_path_params[:search])
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/filters_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ def filters_applied_text(filter_type)
applied_filters_count(filter_type).zero? ? "No filters applied" : "#{pluralize(applied_filters_count(filter_type), 'filter')} applied"
end

def reset_filters_link(filter_type, path_params = {})
def reset_filters_link(filter_type, filter_path_params = {})
if applied_filters_count(filter_type).positive?
govuk_link_to "Clear", clear_filters_path(filter_type:, path_params:)
govuk_link_to "Clear", clear_filters_path(filter_type:, filter_path_params:)
end
end

Expand Down
17 changes: 17 additions & 0 deletions config/locales/test.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
en:
forms:
2021:
lettings:
guidance:
what_counts_as_income:
title: "What counts as income?"
content: "What counts as income?"
finding_scheme:
title: "Can’t find your scheme?"
content: "<p>Schemes are attached to the organisation that owns the property. Check you have correctly answered question 1 \"Which organisation owns this property?\"</p>
<p>If your organisation’s schemes were migrated from old CORE, they may have new names and codes. Search by postcode to find your scheme.</p>"
scheme_changes_link_text: "Read more about how schemes have changed"
view_schemes_link_text: "View your organisation’s schemes"
soft_validations:
net_income:
hint_text: "hint text"
2 changes: 1 addition & 1 deletion spec/controllers/errors_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
describe "GET #unprocessable_entity" do
it "returns unprocessable_entity" do
get :unprocessable_entity
expect(response).to have_http_status(:unprocessable_entity)
expect(response).to have_http_status(:unprocessable_content)
end
end
end
6 changes: 3 additions & 3 deletions spec/features/organisation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@
it "can filter lettings logs by year" do
check("years-2022-field")
click_button("Apply filters")
expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?years[]=&years[]=2022&status[]=&needstypes[]=&assigned_to=all&user_text_search=&user=&owning_organisation_select=all&owning_organisation_text_search=&owning_organisation=&managing_organisation_select=all&managing_organisation_text_search=&managing_organisation=")
expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?%5Byears%5D[]=&years[]=2022&%5Bstatus%5D[]=&%5Bneedstypes%5D[]=&assigned_to=all&user_text_search=&user=&owning_organisation_select=all&owning_organisation_text_search=&owning_organisation=&managing_organisation_select=all&managing_organisation_text_search=&managing_organisation=")
expect(page).not_to have_link first_log.id.to_s, href: "/lettings-logs/#{first_log.id}"
end

it "can filter lettings logs by needstype" do
check("needstypes-1-field")
click_button("Apply filters")
expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?years[]=&status[]=&needstypes[]=&needstypes[]=1&assigned_to=all&user_text_search=&user=&owning_organisation_select=all&owning_organisation_text_search=&owning_organisation=&managing_organisation_select=all&managing_organisation_text_search=&managing_organisation=")
expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?%5Byears%5D[]=&%5Bstatus%5D[]=&%5Bneedstypes%5D[]=&needstypes[]=1&assigned_to=all&user_text_search=&user=&owning_organisation_select=all&owning_organisation_text_search=&owning_organisation=&managing_organisation_select=all&managing_organisation_text_search=&managing_organisation=")
other_general_needs_logs.each do |general_needs_log|
expect(page).to have_link general_needs_log.id.to_s, href: "/lettings-logs/#{general_needs_log.id}"
end
Expand Down Expand Up @@ -256,7 +256,7 @@
end
check("years-2022-field")
click_button("Apply filters")
expect(page).to have_current_path("/organisations/#{org_id}/sales-logs?years[]=&years[]=2022&status[]=&assigned_to=all&user_text_search=&user=&owning_organisation_select=all&owning_organisation_text_search=&owning_organisation=&managing_organisation_select=all&managing_organisation_text_search=&managing_organisation=")
expect(page).to have_current_path("/organisations/#{org_id}/sales-logs?%5Byears%5D[]=&years[]=2022&%5Bstatus%5D[]=&assigned_to=all&user_text_search=&user=&owning_organisation_select=all&owning_organisation_text_search=&owning_organisation=&managing_organisation_select=all&managing_organisation_text_search=&managing_organisation=")
expect(page).not_to have_link first_log.id.to_s, href: "/sales-logs/#{first_log.id}"
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/features/schemes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

it "displays the filters component with a correct count and clear button" do
expect(page).to have_content("2 filters applied")
expect(page).to have_link("Clear", href: /clear-filters\?filter_type=schemes/)
expect(page).to have_link("Clear", href: /clear-filters\?.*filter_type=schemes/)
end

context "when clearing the filters" do
Expand Down Expand Up @@ -326,7 +326,7 @@

it "displays the filters component with a correct count and clear button" do
expect(page).to have_content("2 filters applied")
expect(page).to have_link("Clear", href: /\/clear-filters\?filter_type=scheme_locations/)
expect(page).to have_link("Clear", href: /\/clear-filters\?.*filter_type=scheme_locations/)
end

context "when clearing the filters" do
Expand Down
6 changes: 3 additions & 3 deletions spec/features/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@

it "displays the filters component with a correct count and clear button" do
expect(page).to have_content("2 filters applied")
expect(page).to have_link("Clear", href: /clear-filters\?filter_type=users/)
expect(page).to have_link("Clear", href: /clear-filters\?.*filter_type=users/)
end

context "when clearing the filters" do
Expand Down Expand Up @@ -678,7 +678,7 @@
fill_in("code", with: otp)
click_button("Submit")
expect(page).to have_content("Check your email")
expect(page).to have_http_status(:unprocessable_entity)
expect(page).to have_http_status(:unprocessable_content)
expect(page).to have_title("Error")
expect(page).to have_selector(".govuk-error-summary__title")
end
Expand All @@ -691,7 +691,7 @@
fill_in("code", with: otp)
click_button("Submit")
expect(page).to have_content("Check your email")
expect(page).to have_http_status(:unprocessable_entity)
expect(page).to have_http_status(:unprocessable_content)
expect(page).to have_title("Error")
expect(page).to have_selector(".govuk-error-summary__title")
end
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/auth/passwords_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@

it "shows an error on the same page" do
put "/account/password", headers: headers, params: params
expect(response).to have_http_status(:unprocessable_entity)
expect(response).to have_http_status(:unprocessable_content)
expect(page).to have_css("h1", text: "Reset your password")
expect(page).to have_content("passwords you entered do not match")
end
Expand Down
32 changes: 20 additions & 12 deletions spec/requests/delete_logs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@
allow(FilterManager).to receive(:filter_logs).and_return LettingsLog.all
end

it "throws an error if selected ids are not provided" do
expect { post delete_logs_lettings_logs_path }.to raise_error ActionController::ParameterMissing
it "returns bad request if selected ids are not provided" do
post delete_logs_lettings_logs_path
expect(response).to have_http_status(:bad_request)
end

it "calls the filter service with the filters in the session and the search term from the query params" do
Expand Down Expand Up @@ -120,7 +121,8 @@
end

it "requires delete logs form data to be provided" do
expect { post delete_logs_confirmation_lettings_logs_path }.to raise_error(ActionController::ParameterMissing)
post delete_logs_confirmation_lettings_logs_path
expect(response).to have_http_status(:bad_request)
end

it "shows the correct title" do
Expand Down Expand Up @@ -346,8 +348,9 @@
allow(FilterManager).to receive(:filter_logs).and_return SalesLog.all
end

it "throws an error if selected ids are not provided" do
expect { post delete_logs_sales_logs_path }.to raise_error ActionController::ParameterMissing
it "returns bad request if selected ids are not provided" do
post delete_logs_sales_logs_path
expect(response).to have_http_status(:bad_request)
end

it "calls the filter service with the filters in the session and the search term from the query params" do
Expand Down Expand Up @@ -405,7 +408,8 @@
end

it "requires delete logs form data to be provided" do
expect { post delete_logs_confirmation_sales_logs_path }.to raise_error(ActionController::ParameterMissing)
post delete_logs_confirmation_sales_logs_path
expect(response).to have_http_status(:bad_request)
end

it "shows the correct title" do
Expand Down Expand Up @@ -635,8 +639,9 @@
allow(FilterManager).to receive(:filter_logs).and_return LettingsLog.all
end

it "throws an error if selected ids are not provided" do
expect { post delete_lettings_logs_organisation_path(id: organisation) }.to raise_error ActionController::ParameterMissing
it "returns bad request if selected ids are not provided" do
post delete_lettings_logs_organisation_path(id: organisation)
expect(response).to have_http_status(:bad_request)
end

it "calls the filter service with the filters in the session and the search term from the query params" do
Expand Down Expand Up @@ -694,7 +699,8 @@
end

it "requires delete logs form data to be provided" do
expect { post delete_lettings_logs_confirmation_organisation_path(id: organisation) }.to raise_error(ActionController::ParameterMissing)
post delete_lettings_logs_confirmation_organisation_path(id: organisation)
expect(response).to have_http_status(:bad_request)
end

it "shows the correct title" do
Expand Down Expand Up @@ -858,8 +864,9 @@
allow(FilterManager).to receive(:filter_logs).and_return SalesLog.all
end

it "throws an error if selected ids are not provided" do
expect { post delete_sales_logs_organisation_path(id: organisation) }.to raise_error ActionController::ParameterMissing
it "returns bad request if selected ids are not provided" do
post delete_sales_logs_organisation_path(id: organisation)
expect(response).to have_http_status(:bad_request)
end

it "calls the filter service with the filters in the session and the search term from the query params" do
Expand Down Expand Up @@ -917,7 +924,8 @@
end

it "requires delete logs form data to be provided" do
expect { post delete_sales_logs_confirmation_organisation_path(id: organisation) }.to raise_error(ActionController::ParameterMissing)
post delete_sales_logs_confirmation_organisation_path
expect(response).to have_http_status(:bad_request)
end

it "shows the correct title" do
Expand Down
2 changes: 0 additions & 2 deletions spec/requests/form_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,6 @@

it "displays a success banner" do
follow_redirect!
follow_redirect!

expect(response.body).to include("You have successfully updated Q31: lead tenant’s age")
end
Expand All @@ -1163,7 +1162,6 @@
end

it "displays a success banner without crashing" do
follow_redirect!
follow_redirect!
expect(response.body).to include("You have successfully updated")
end
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/lettings_logs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

it "validates lettings log parameters" do
json_response = JSON.parse(response.body)
expect(response).to have_http_status(:unprocessable_entity)
expect(response).to have_http_status(:unprocessable_content)
expect(json_response["errors"]).to match_array([["offered", [I18n.t("validations.shared.numeric.within_range", field: "Times previously offered since becoming available", min: 0, max: 20)]], ["age1", [I18n.t("validations.shared.numeric.within_range", field: "Lead tenant’s age", min: 16, max: 120)]]])
end
end
Expand Down Expand Up @@ -1615,7 +1615,7 @@
let(:params) { { age1: 200 } }

it "returns 422" do
expect(response).to have_http_status(:unprocessable_entity)
expect(response).to have_http_status(:unprocessable_content)
end

it "returns an error message" do
Expand Down
Loading

0 comments on commit ede13b6

Please sign in to comment.