Browse Source

feat: add more tests

pull/1768/head
natdeanlewissoftwire 3 years ago
parent
commit
52e9d73594
  1. 45
      spec/features/lettings_log_spec.rb
  2. 43
      spec/helpers/filters_helper_spec.rb

45
spec/features/lettings_log_spec.rb

@ -57,6 +57,51 @@ RSpec.describe "Lettings Log Features" do
end
end
context "when filtering logs" do
let(:user) { create(:user, last_sign_in_at: Time.zone.now) }
context "when I am signed in" do
before do
visit("/lettings-logs")
fill_in("user[email]", with: user.email)
fill_in("user[password]", with: user.password)
click_button("Sign in")
end
context "when no filters are selected" do
it "displays the filters component with no clear button" do
expect(page).to have_content("No filters applied")
expect(page).not_to have_content("Clear")
end
end
context "when I have selected filters" do
before do
check("Not started")
check("In progress")
choose("Yours")
click_button("Apply filters")
end
it "displays the filters component with a correct count and clear button" do
expect(page).to have_content("3 filters applied")
expect(page).to have_content("Clear")
end
context "when clearing the filters" do
before do
click_link("Clear")
end
it "clears the filters and displays the filter component as before" do
expect(page).to have_content("No filters applied")
expect(page).not_to have_content("Clear")
end
end
end
end
end
context "when the signed is user is a Support user" do
let(:organisation) { create(:organisation, name: "User org") }
let(:support_user) { create(:user, :support, last_sign_in_at: Time.zone.now, organisation:) }

43
spec/helpers/filters_helper_spec.rb

@ -132,7 +132,7 @@ RSpec.describe FiltersHelper do
end
end
context "when a range of filters are applied" do
context "when a range of filters is applied" do
let(:filters) do
{
"user" => "all",
@ -204,4 +204,45 @@ RSpec.describe FiltersHelper do
)
end
end
describe "#filters_applied_text" do
let(:filter_type) { "lettings_logs" }
let(:result) { filters_applied_text(filter_type) }
let(:serialised_filters) { filters&.to_json }
let(:filters) { nil }
before do
session[:lettings_logs_filters] = serialised_filters if serialised_filters
end
context "when no filters are applied" do
let(:filters) do
{
"user" => "all",
"status" => [""],
"years" => [""],
"organisation" => "all",
}
end
it "returns the correct filters count" do
expect(result).to eq "No filters applied"
end
end
context "when a range of filters is applied" do
let(:filters) do
{
"user" => "all",
"status" => %w[in_progress completed],
"years" => [""],
"organisation" => 2,
}
end
it "returns the correct filters count" do
expect(result).to eq "3 filters applied"
end
end
end
end

Loading…
Cancel
Save