|
|
|
|
@ -3,16 +3,14 @@ require "rails_helper"
|
|
|
|
|
RSpec.describe "Sales Log Features" do |
|
|
|
|
context "when searching for specific sales logs" do |
|
|
|
|
context "when I am signed in and there are sales logs in the database" do |
|
|
|
|
let(:user) { FactoryBot.create(:user, last_sign_in_at: Time.zone.now) } |
|
|
|
|
let(:user) { FactoryBot.create(:user, last_sign_in_at: Time.zone.now, name: "Jimbo") } |
|
|
|
|
let!(:log_to_search) { FactoryBot.create(:sales_log, owning_organisation: user.organisation) } |
|
|
|
|
let!(:same_organisation_log) { FactoryBot.create(:sales_log, owning_organisation: user.organisation) } |
|
|
|
|
let!(:another_organisation_log) { FactoryBot.create(:sales_log) } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
visit("/sales-logs") |
|
|
|
|
fill_in("user[email]", with: user.email) |
|
|
|
|
fill_in("user[password]", with: user.password) |
|
|
|
|
click_button("Sign in") |
|
|
|
|
sign_in user |
|
|
|
|
visit sales_logs_path |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "displays the logs belonging to the same organisation" do |
|
|
|
|
@ -23,34 +21,75 @@ RSpec.describe "Sales Log Features" do
|
|
|
|
|
|
|
|
|
|
context "when returning to the list of logs via breadcrumbs link" do |
|
|
|
|
before do |
|
|
|
|
visit("/sales-logs") |
|
|
|
|
click_button("Create a new sales log") |
|
|
|
|
click_link("Logs") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "navigates you to the sales logs page" do |
|
|
|
|
expect(page).to have_current_path("/sales-logs") |
|
|
|
|
expect(page).to have_current_path sales_logs_path |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when completing the setup sales log section" do |
|
|
|
|
it "includes the purchaser code and sale completion date questions" do |
|
|
|
|
visit("/sales-logs") |
|
|
|
|
click_button("Create a new sales log") |
|
|
|
|
click_link("Set up this sales log") |
|
|
|
|
click_button "Create a new sales log" |
|
|
|
|
click_link "Set up this sales log" |
|
|
|
|
fill_in("sales_log[saledate(1i)]", with: Time.zone.today.year) |
|
|
|
|
fill_in("sales_log[saledate(2i)]", with: Time.zone.today.month) |
|
|
|
|
fill_in("sales_log[saledate(3i)]", with: Time.zone.today.day) |
|
|
|
|
click_button("Save and continue") |
|
|
|
|
fill_in("sales_log[purchid]", with: "PC123") |
|
|
|
|
click_button("Save and continue") |
|
|
|
|
click_button "Save and continue" |
|
|
|
|
fill_in "sales_log[purchid]", with: "PC123" |
|
|
|
|
click_button "Save and continue" |
|
|
|
|
log_id = page.current_path.scan(/\d/).join |
|
|
|
|
visit("sales-logs/#{log_id}/setup/check-answers") |
|
|
|
|
expect(page).to have_content("Sale completion date") |
|
|
|
|
visit sales_log_setup_check_answers_path(log_id) |
|
|
|
|
expect(page).to have_content "Sale completion date" |
|
|
|
|
expect(page).to have_content(Time.zone.today.year) |
|
|
|
|
expect(page).to have_content("Purchaser code") |
|
|
|
|
expect(page).to have_content("PC123") |
|
|
|
|
expect(page).to have_content "Purchaser code" |
|
|
|
|
expect(page).to have_content "PC123" |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "is possible to delete multiple logs" do |
|
|
|
|
log_card_selector = "article.app-log-summary" |
|
|
|
|
logs_by_user = create_list(:sales_log, 2, created_by: user) |
|
|
|
|
|
|
|
|
|
visit sales_logs_path |
|
|
|
|
expect(page).to have_selector log_card_selector, count: 4 |
|
|
|
|
expect(page).not_to have_link "Delete logs" |
|
|
|
|
|
|
|
|
|
within ".app-filter" do |
|
|
|
|
choose "user-yours-field" |
|
|
|
|
click_button |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
expect(page).to have_selector log_card_selector, count: 2 |
|
|
|
|
expect(page).to have_link "Delete logs" |
|
|
|
|
|
|
|
|
|
click_link "Delete logs" |
|
|
|
|
|
|
|
|
|
expect(page).to have_current_path delete_logs_sales_logs_path |
|
|
|
|
|
|
|
|
|
rows = page.find_all "tbody tr" |
|
|
|
|
expect(rows.count).to be 2 |
|
|
|
|
id_to_delete, id_to_keep = rows.map { |row| row.first("td").text.to_i } |
|
|
|
|
expect([id_to_delete, id_to_keep]).to match_array logs_by_user.map(&:id) |
|
|
|
|
check "forms-delete-logs-form-selected-ids-#{id_to_delete}-field" |
|
|
|
|
uncheck "forms-delete-logs-form-selected-ids-#{id_to_keep}-field" |
|
|
|
|
click_button "Continue" |
|
|
|
|
|
|
|
|
|
expect(page).to have_current_path delete_logs_confirmation_sales_logs_path |
|
|
|
|
expect(page.text).to include "You've selected 1 log to delete" |
|
|
|
|
button = page.find("form.button_to") |
|
|
|
|
expect(button[:action]).to eq delete_logs_sales_logs_path |
|
|
|
|
expect(button.text).to eq "Delete logs" |
|
|
|
|
click_button "Delete logs" |
|
|
|
|
|
|
|
|
|
expect(page).to have_current_path sales_logs_path |
|
|
|
|
expect(page).to have_selector "article.app-log-summary", count: 1 |
|
|
|
|
expect(page.find("article.app-log-summary h2").text).to eq "Log #{id_to_keep}" |
|
|
|
|
deleted_log = SalesLog.find(id_to_delete) |
|
|
|
|
expect(deleted_log.status).to eq "deleted" |
|
|
|
|
expect(deleted_log.discarded_at).not_to be nil |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|