Browse Source

feat: update tests

pull/1775/head
natdeanlewissoftwire 3 years ago
parent
commit
940b124f13
  1. 2
      app/helpers/log_list_helper.rb
  2. 2
      spec/features/lettings_log_spec.rb
  3. 4
      spec/features/organisation_spec.rb
  4. 2
      spec/features/sales_log_spec.rb
  5. 4
      spec/features/user_spec.rb
  6. 19
      spec/helpers/filters_helper_spec.rb
  7. 2
      spec/jobs/email_csv_job_spec.rb
  8. 2
      spec/models/forms/delete_logs_form_spec.rb
  9. 8
      spec/models/lettings_log_spec.rb
  10. 16
      spec/requests/delete_logs_controller_spec.rb
  11. 2
      spec/requests/lettings_logs_controller_spec.rb

2
app/helpers/log_list_helper.rb

@ -1,7 +1,7 @@
module LogListHelper module LogListHelper
def display_delete_logs?(current_user, search_term, filter_type) def display_delete_logs?(current_user, search_term, filter_type)
if current_user.data_provider? if current_user.data_provider?
filter_selected?("user", "yours", filter_type) filter_selected?("assigned_to", "you", filter_type)
else else
any_filter_selected?(filter_type) || search_term.present? any_filter_selected?(filter_type) || search_term.present?
end end

2
spec/features/lettings_log_spec.rb

@ -253,7 +253,7 @@ RSpec.describe "Lettings Log Features" do
expect(page).not_to have_link "Delete logs" expect(page).not_to have_link "Delete logs"
within ".app-filter" do within ".app-filter" do
check "status-in-progress-field" check "status-in-progress-field"
choose "user-yours-field" choose "assigned-to-you-field"
click_button click_button
end end
expect(page).to have_selector "article.app-log-summary", count: 2 expect(page).to have_selector "article.app-log-summary", count: 2

4
spec/features/organisation_spec.rb

@ -194,7 +194,7 @@ RSpec.describe "User Features" do
end end
check("years-2021-field") check("years-2021-field")
click_button("Apply filters") click_button("Apply filters")
expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?years[]=&years[]=2021&status[]=&assigned_to=all") expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?years[]=&years[]=2021&status[]=&assigned_to=all&user=")
expect(page).not_to have_link first_log.id.to_s, href: "/lettings-logs/#{first_log.id}" expect(page).not_to have_link first_log.id.to_s, href: "/lettings-logs/#{first_log.id}"
end end
end end
@ -227,7 +227,7 @@ RSpec.describe "User Features" do
end end
check("years-2021-field") check("years-2021-field")
click_button("Apply filters") click_button("Apply filters")
expect(page).to have_current_path("/organisations/#{org_id}/sales-logs?years[]=&years[]=2021&status[]=&assigned_to=all") expect(page).to have_current_path("/organisations/#{org_id}/sales-logs?years[]=&years[]=2021&status[]=&assigned_to=all&user=")
expect(page).not_to have_link first_log.id.to_s, href: "/sales-logs/#{first_log.id}" expect(page).not_to have_link first_log.id.to_s, href: "/sales-logs/#{first_log.id}"
end end
end end

2
spec/features/sales_log_spec.rb

@ -58,7 +58,7 @@ RSpec.describe "Sales Log Features" do
expect(page).not_to have_link "Delete logs" expect(page).not_to have_link "Delete logs"
within ".app-filter" do within ".app-filter" do
choose "user-yours-field" choose "assigned-to-you-field"
click_button click_button
end end

4
spec/features/user_spec.rb

@ -724,10 +724,10 @@ RSpec.describe "User Features" do
expect(page).to have_field("organisation-field", with: "") expect(page).to have_field("organisation-field", with: "")
find("#organisation-field").click.native.send_keys("F", "i", "l", "t", :down, :enter) find("#organisation-field").click.native.send_keys("F", "i", "l", "t", :down, :enter)
click_button("Apply filters") click_button("Apply filters")
expect(page).to have_current_path("/lettings-logs?%5Byears%5D%5B%5D=&%5Bstatus%5D%5B%5D=&user=all&organisation_select=specific_org&organisation=#{organisation.id}") expect(page).to have_current_path("/lettings-logs?%5Byears%5D%5B%5D=&%5Bstatus%5D%5B%5D=&assigned_to=all&organisation_select=specific_org&organisation=#{organisation.id}")
choose("organisation-select-all-field", allow_label_click: true) choose("organisation-select-all-field", allow_label_click: true)
click_button("Apply filters") click_button("Apply filters")
expect(page).to have_current_path("/lettings-logs?%5Byears%5D%5B%5D=&%5Bstatus%5D%5B%5D=&user=all&organisation_select=all") expect(page).to have_current_path("/lettings-logs?%5Byears%5D%5B%5D=&%5Bstatus%5D%5B%5D=&assigned_to=all&organisation_select=all")
end end
end end
end end

19
spec/helpers/filters_helper_spec.rb

@ -16,8 +16,9 @@ RSpec.describe FiltersHelper do
context "when looking at the all value" do context "when looking at the all value" do
it "returns true if no filters have been set yet" do it "returns true if no filters have been set yet" do
expect(filter_selected?("user", :all, "lettings_logs")).to be true expect(filter_selected?("assigned_to", :all, "lettings_logs")).to be true
expect(filter_selected?("user", :yours, "lettings_logs")).to be false expect(filter_selected?("assigned_to", :you, "lettings_logs")).to be false
expect(filter_selected?("assigned_to", :specific_user, "lettings_logs")).to be false
end end
end end
end end
@ -60,7 +61,7 @@ RSpec.describe FiltersHelper do
context "when the specific organisation filter is not set" do context "when the specific organisation filter is not set" do
before do before do
session[:lettings_logs_filters] = { "status" => [""], "years" => [""], "user" => "all" }.to_json session[:lettings_logs_filters] = { "status" => [""], "years" => [""], "assigned_to" => "all" }.to_json
end end
it "marks the all options as checked" do it "marks the all options as checked" do
@ -85,15 +86,15 @@ RSpec.describe FiltersHelper do
end end
context "when organisation and user are set to all" do context "when organisation and user are set to all" do
let(:filters) { { "organisation_select" => "all", "user" => "all" } } let(:filters) { { "organisation_select" => "all", "assigned_to" => "all" } }
it "returns false" do it "returns false" do
expect(result).to be_falsey expect(result).to be_falsey
end end
end end
context "when user is set to 'yours'" do context "when user is set to 'you'" do
let(:filters) { { "user" => "yours" } } let(:filters) { { "user" => "you" } }
it "returns true" do it "returns true" do
expect(result).to be true expect(result).to be true
@ -135,7 +136,7 @@ RSpec.describe FiltersHelper do
context "when a range of filters is applied" do context "when a range of filters is applied" do
let(:filters) do let(:filters) do
{ {
"user" => "all", "assigned_to" => "all",
"status" => %w[in_progress completed], "status" => %w[in_progress completed],
"years" => [""], "years" => [""],
"organisation" => 2, "organisation" => 2,
@ -218,7 +219,7 @@ RSpec.describe FiltersHelper do
context "when no filters are applied" do context "when no filters are applied" do
let(:filters) do let(:filters) do
{ {
"user" => "all", "assigned_to" => "all",
"status" => [""], "status" => [""],
"years" => [""], "years" => [""],
"organisation" => "all", "organisation" => "all",
@ -233,7 +234,7 @@ RSpec.describe FiltersHelper do
context "when a range of filters is applied" do context "when a range of filters is applied" do
let(:filters) do let(:filters) do
{ {
"user" => "all", "assigned_to" => "all",
"status" => %w[in_progress completed], "status" => %w[in_progress completed],
"years" => [""], "years" => [""],
"organisation" => 2, "organisation" => 2,

2
spec/jobs/email_csv_job_spec.rb

@ -12,7 +12,7 @@ describe EmailCsvJob do
let(:sales_log_csv_service) { instance_double(Csv::SalesLogCsvService) } let(:sales_log_csv_service) { instance_double(Csv::SalesLogCsvService) }
let(:lettings_log_csv_service) { instance_double(Csv::LettingsLogCsvService) } let(:lettings_log_csv_service) { instance_double(Csv::LettingsLogCsvService) }
let(:search_term) { "meaning" } let(:search_term) { "meaning" }
let(:filters) { { "user" => "yours", "status" => %w[in_progress] } } let(:filters) { { "user" => "you", "status" => %w[in_progress] } }
let(:all_orgs) { false } let(:all_orgs) { false }
let(:organisation) { build(:organisation) } let(:organisation) { build(:organisation) }
let(:codes_only_export) { true } let(:codes_only_export) { true }

2
spec/models/forms/delete_logs_form_spec.rb

@ -22,7 +22,7 @@ RSpec.describe Forms::DeleteLogsForm do
{ {
"years" => [""], "years" => [""],
"status" => ["", "completed"], "status" => ["", "completed"],
"user" => "yours", "user" => "you",
} }
end end
let(:selected_ids) { [visible_logs.first.id] } let(:selected_ids) { [visible_logs.first.id] }

8
spec/models/lettings_log_spec.rb

@ -2786,15 +2786,11 @@ RSpec.describe LettingsLog do
end end
it "allows filtering on current user" do it "allows filtering on current user" do
expect(described_class.filter_by_user(%w[you]).count).to eq(2) expect(described_class.filter_by_user(created_by_user.id.to_s).count).to eq(2)
end end
it "returns all logs when all logs selected" do it "returns all logs when all logs selected" do
expect(described_class.filter_by_user(%w[all]).count).to eq(3) expect(described_class.filter_by_user(nil).count).to eq(3)
end
it "returns all logs when all and your users selected" do
expect(described_class.filter_by_user(%w[all you]).count).to eq(3)
end end
end end

16
spec/requests/delete_logs_controller_spec.rb

@ -22,7 +22,7 @@ RSpec.describe "DeleteLogs", type: :request do
logs_filters = { logs_filters = {
"years" => [""], "years" => [""],
"status" => ["", "in_progress"], "status" => ["", "in_progress"],
"user" => "all", "assigned_to" => "all",
} }
get lettings_logs_path(logs_filters) # adds the filters to the session get lettings_logs_path(logs_filters) # adds the filters to the session
@ -71,7 +71,7 @@ RSpec.describe "DeleteLogs", type: :request do
logs_filters = { logs_filters = {
"years" => [""], "years" => [""],
"status" => ["", "in_progress"], "status" => ["", "in_progress"],
"user" => "all", "assigned_to" => "all",
} }
get lettings_logs_path(logs_filters) # adds the filters to the session get lettings_logs_path(logs_filters) # adds the filters to the session
@ -262,7 +262,7 @@ RSpec.describe "DeleteLogs", type: :request do
logs_filters = { logs_filters = {
"years" => [""], "years" => [""],
"status" => ["", "in_progress"], "status" => ["", "in_progress"],
"user" => "all", "assigned_to" => "all",
} }
get sales_logs_path(logs_filters) # adds the filters to the session get sales_logs_path(logs_filters) # adds the filters to the session
@ -311,7 +311,7 @@ RSpec.describe "DeleteLogs", type: :request do
logs_filters = { logs_filters = {
"years" => [""], "years" => [""],
"status" => ["", "in_progress"], "status" => ["", "in_progress"],
"user" => "all", "assigned_to" => "all",
} }
get sales_logs_path(logs_filters) # adds the filters to the session get sales_logs_path(logs_filters) # adds the filters to the session
@ -506,7 +506,7 @@ RSpec.describe "DeleteLogs", type: :request do
logs_filters = { logs_filters = {
"years" => [""], "years" => [""],
"status" => ["", "in_progress"], "status" => ["", "in_progress"],
"user" => "all", "assigned_to" => "all",
} }
get lettings_logs_path(logs_filters) # adds the filters to the session get lettings_logs_path(logs_filters) # adds the filters to the session
@ -555,7 +555,7 @@ RSpec.describe "DeleteLogs", type: :request do
logs_filters = { logs_filters = {
"years" => [""], "years" => [""],
"status" => ["", "in_progress"], "status" => ["", "in_progress"],
"user" => "all", "assigned_to" => "all",
} }
get lettings_logs_path(logs_filters) # adds the filters to the session get lettings_logs_path(logs_filters) # adds the filters to the session
@ -731,7 +731,7 @@ RSpec.describe "DeleteLogs", type: :request do
logs_filters = { logs_filters = {
"years" => [""], "years" => [""],
"status" => ["", "in_progress"], "status" => ["", "in_progress"],
"user" => "all", "assigned_to" => "all",
} }
get sales_logs_path(logs_filters) # adds the filters to the session get sales_logs_path(logs_filters) # adds the filters to the session
@ -780,7 +780,7 @@ RSpec.describe "DeleteLogs", type: :request do
logs_filters = { logs_filters = {
"years" => [""], "years" => [""],
"status" => ["", "in_progress"], "status" => ["", "in_progress"],
"user" => "all", "assigned_to" => "all",
} }
get sales_logs_path(logs_filters) # adds the filters to the session get sales_logs_path(logs_filters) # adds the filters to the session

2
spec/requests/lettings_logs_controller_spec.rb

@ -801,7 +801,7 @@ RSpec.describe LettingsLogsController, type: :request do
context "when the support user has filtered by organisation, then switches back to all organisations" do context "when the support user has filtered by organisation, then switches back to all organisations" do
it "shows all organisations" do it "shows all organisations" do
get "http://localhost:3000/lettings-logs?%5Byears%5D%5B%5D=&%5Bstatus%5D%5B%5D=&user=all&organisation_select=all&organisation=#{org_1.id}", headers:, params: {} get "http://localhost:3000/lettings-logs?%5Byears%5D%5B%5D=&%5Bstatus%5D%5B%5D=&assigned_to=all&organisation_select=all&organisation=#{org_1.id}", headers:, params: {}
expect(page).to have_content(tenant_code_1) expect(page).to have_content(tenant_code_1)
expect(page).to have_content(tenant_code_2) expect(page).to have_content(tenant_code_2)
end end

Loading…
Cancel
Save