|
| 1 | +require "rails_helper" |
| 2 | + |
| 3 | +RSpec.describe "/case_contacts_new_design", type: :request do |
| 4 | + let(:organization) { create(:casa_org) } |
| 5 | + let(:admin) { create(:casa_admin, casa_org: organization) } |
| 6 | + |
| 7 | + before { sign_in admin } |
| 8 | + |
| 9 | + describe "GET /index" do |
| 10 | + subject(:request) do |
| 11 | + get case_contacts_new_design_path |
| 12 | + |
| 13 | + response |
| 14 | + end |
| 15 | + |
| 16 | + let!(:casa_case) { create(:casa_case, casa_org: organization) } |
| 17 | + let!(:past_contact) { create(:case_contact, :active, casa_case: casa_case, occurred_at: 3.weeks.ago) } |
| 18 | + let!(:recent_contact) { create(:case_contact, :active, casa_case: casa_case, occurred_at: 3.days.ago) } |
| 19 | + let!(:draft_contact) { create(:case_contact, casa_case: casa_case, occurred_at: 5.days.ago, status: "started") } |
| 20 | + |
| 21 | + it { is_expected.to have_http_status(:success) } |
| 22 | + |
| 23 | + it "lists exactly two active contacts and one draft" do |
| 24 | + doc = Nokogiri::HTML(request.body) |
| 25 | + case_contact_rows = doc.css('[data-testid="case_contact-row"]') |
| 26 | + expect(case_contact_rows.size).to eq(3) |
| 27 | + end |
| 28 | + |
| 29 | + it "shows the draft badge exactly once" do |
| 30 | + doc = Nokogiri::HTML(request.body) |
| 31 | + expect(doc.css('[data-testid="draft-badge"]').count).to eq(1) |
| 32 | + end |
| 33 | + |
| 34 | + it "orders contacts by occurred_at desc" do |
| 35 | + body = request.body |
| 36 | + |
| 37 | + recent_index = body.index(I18n.l(recent_contact.occurred_at, format: :full)) |
| 38 | + past_index = body.index(I18n.l(past_contact.occurred_at, format: :full)) |
| 39 | + |
| 40 | + expect(recent_index).to be < past_index |
| 41 | + end |
| 42 | + end |
| 43 | +end |
0 commit comments