@ -238,8 +238,6 @@ RSpec.describe LettingsLogsController, type: :request do
let ( :headers ) { { " Accept " = > " text/html " } }
let ( :headers ) { { " Accept " = > " text/html " } }
context " when you visit the index page " do
context " when you visit the index page " do
let ( :user ) { FactoryBot . create ( :user , :support ) }
before do
before do
allow ( user ) . to receive ( :need_two_factor_authentication? ) . and_return ( false )
allow ( user ) . to receive ( :need_two_factor_authentication? ) . and_return ( false )
sign_in user
sign_in user
@ -308,6 +306,13 @@ RSpec.describe LettingsLogsController, type: :request do
expect ( page ) . to have_link ( " Download (CSV, codes only) " , href : " /lettings-logs/csv-download?codes_only=true " )
expect ( page ) . to have_link ( " Download (CSV, codes only) " , href : " /lettings-logs/csv-download?codes_only=true " )
end
end
it " does not show a notification banner even if there are duplicate logs for this user " do
allow_any_instance_of ( DuplicateLogsHelper ) . to receive ( :duplicates_for_user ) . and_return ( { lettings : [ [ 1 , 2 ] ] , sales : [ ] } ) # rubocop:disable RSpec/AnyInstance
get lettings_logs_path
expect ( page ) . not_to have_content " duplicate logs "
expect ( page ) . not_to have_link " Review logs "
end
context " when there are no logs in the database " do
context " when there are no logs in the database " do
before do
before do
LettingsLog . destroy_all
LettingsLog . destroy_all
@ -615,6 +620,12 @@ RSpec.describe LettingsLogsController, type: :request do
expect ( page ) . not_to have_link ( " Download (CSV, codes only) " )
expect ( page ) . not_to have_link ( " Download (CSV, codes only) " )
end
end
it " does not show a notification banner even if there are duplicate logs for this user " do
get lettings_logs_path
expect ( page ) . not_to have_content " duplicate logs "
expect ( page ) . not_to have_link " Review logs "
end
context " when using a search query " do
context " when using a search query " do
let ( :logs ) { FactoryBot . create_list ( :lettings_log , 3 , :completed , owning_organisation : user . organisation , created_by : user ) }
let ( :logs ) { FactoryBot . create_list ( :lettings_log , 3 , :completed , owning_organisation : user . organisation , created_by : user ) }
let ( :log_to_search ) { FactoryBot . create ( :lettings_log , :completed , owning_organisation : user . organisation , created_by : user ) }
let ( :log_to_search ) { FactoryBot . create ( :lettings_log , :completed , owning_organisation : user . organisation , created_by : user ) }
@ -871,6 +882,38 @@ RSpec.describe LettingsLogsController, type: :request do
end
end
end
end
end
end
context " and there are duplicate logs for this user " do
let ( :duplicates ) { { lettings : , sales : } }
let ( :lettings ) { [ [ 1 , 2 ] ] }
let ( :sales ) { [ ] }
before do
allow_any_instance_of ( DuplicateLogsHelper ) . to receive ( :duplicates_for_user ) . and_return duplicates # rubocop:disable RSpec/AnyInstance
end
it " displays a notification banner with a link to review logs " do
get lettings_logs_path
expect ( page ) . to have_content " duplicate logs "
expect ( page ) . to have_link " Review logs " # add an href when routing done
end
context " when there is one set of duplicates " do
it " displays the correct copy in the banner " do
get lettings_logs_path
expect ( page ) . to have_content " There is 1 set of duplicate logs "
end
end
context " when there are multiple sets of duplicates " do
let ( :sales ) { [ [ 3 , 4 ] ] }
it " displays the correct copy in the banner " do
get lettings_logs_path
expect ( page ) . to have_content " There are 2 sets of duplicate logs "
end
end
end
end
end
end
end