Skip to content

Commit 9d04353

Browse files
authored
Merge pull request #6526 from tacoda/add-new-case-contact-table-feature-flag
Add new_case_contact_table feature flag
2 parents 6a9faf1 + 4023820 commit 9d04353

File tree

4 files changed

+91
-23
lines changed

4 files changed

+91
-23
lines changed

app/controllers/case_contacts/case_contacts_new_design_controller.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class CaseContacts::CaseContactsNewDesignController < ApplicationController
22
include LoadsCaseContacts
3+
before_action :check_feature_flag
34

45
def index
56
load_case_contacts
@@ -12,4 +13,12 @@ def datatable
1213

1314
render json: datatable
1415
end
16+
17+
private
18+
19+
def check_feature_flag
20+
unless Flipper.enabled?(:new_case_contact_table)
21+
redirect_to case_contacts_path, alert: "This feature is not available."
22+
end
23+
end
1524
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@
9292

9393
get "case_contacts/leave", to: "case_contacts#leave", as: "leave_case_contacts_form"
9494
get "case_contacts/drafts", to: "case_contacts#drafts"
95+
96+
# Feature flag for new case contact table design
9597
get "case_contacts/new_design", to: "case_contacts/case_contacts_new_design#index"
9698
resources :case_contacts, except: %i[create update show], concerns: %i[with_datatable] do
9799
member do

spec/controllers/concerns/loads_case_contacts_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,37 @@
1212
expect(host.private_instance_methods)
1313
.to include(:load_case_contacts, :current_organization_groups, :all_case_contacts)
1414
end
15+
16+
describe "integration with Flipper flags", type: :request do
17+
let(:organization) { create(:casa_org) }
18+
let(:admin) { create(:casa_admin, casa_org: organization) }
19+
let!(:casa_case) { create(:casa_case, casa_org: organization) }
20+
let!(:case_contact) { create(:case_contact, :active, casa_case: casa_case) }
21+
22+
before { sign_in admin }
23+
24+
context "when new_case_contact_table flag is enabled" do
25+
before do
26+
allow(Flipper).to receive(:enabled?).with(:new_case_contact_table).and_return(true)
27+
end
28+
29+
it "loads case contacts successfully through the new design controller" do
30+
get case_contacts_new_design_path
31+
expect(response).to have_http_status(:success)
32+
expect(assigns(:filtered_case_contacts)).to be_present
33+
end
34+
end
35+
36+
context "when new_case_contact_table flag is disabled" do
37+
before do
38+
allow(Flipper).to receive(:enabled?).with(:new_case_contact_table).and_return(false)
39+
end
40+
41+
it "does not load case contacts and redirects instead" do
42+
get case_contacts_new_design_path
43+
expect(response).to redirect_to(case_contacts_path)
44+
expect(assigns(:filtered_case_contacts)).to be_nil
45+
end
46+
end
47+
end
1548
end

spec/requests/case_contacts/case_contacts_new_design_spec.rb

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,62 @@
66

77
before { sign_in admin }
88

9-
describe "GET /index" do
10-
subject(:request) do
11-
get case_contacts_new_design_path
12-
13-
response
9+
context "when new_case_contact_table flag is disabled" do
10+
before do
11+
allow(Flipper).to receive(:enabled?).with(:new_case_contact_table).and_return(false)
1412
end
1513

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) }
14+
describe "GET /index" do
15+
it "redirects to case_contacts_path" do
16+
get case_contacts_new_design_path
17+
expect(response).to redirect_to(case_contacts_path)
18+
end
2219

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)
20+
it "sets an alert message" do
21+
get case_contacts_new_design_path
22+
expect(flash[:alert]).to eq("This feature is not available.")
23+
end
2724
end
25+
end
2826

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)
27+
context "when new_case_contact_table flag is enabled" do
28+
before do
29+
allow(Flipper).to receive(:enabled?).with(:new_case_contact_table).and_return(true)
3230
end
3331

34-
it "orders contacts by occurred_at desc" do
35-
body = request.body
32+
describe "GET /index" do
33+
subject(:request) do
34+
get case_contacts_new_design_path
35+
36+
response
37+
end
38+
39+
let!(:casa_case) { create(:casa_case, casa_org: organization) }
40+
let!(:past_contact) { create(:case_contact, :active, casa_case: casa_case, occurred_at: 3.weeks.ago) }
41+
let!(:recent_contact) { create(:case_contact, :active, casa_case: casa_case, occurred_at: 3.days.ago) }
42+
let!(:draft_contact) { create(:case_contact, casa_case: casa_case, occurred_at: 5.days.ago, status: "started") }
43+
44+
it { is_expected.to have_http_status(:success) }
45+
46+
it "lists exactly two active contacts and one draft" do
47+
doc = Nokogiri::HTML(request.body)
48+
case_contact_rows = doc.css('[data-testid="case_contact-row"]')
49+
expect(case_contact_rows.size).to eq(3)
50+
end
51+
52+
it "shows the draft badge exactly once" do
53+
doc = Nokogiri::HTML(request.body)
54+
expect(doc.css('[data-testid="draft-badge"]').count).to eq(1)
55+
end
56+
57+
it "orders contacts by occurred_at desc" do
58+
body = request.body
3659

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))
60+
recent_index = body.index(I18n.l(recent_contact.occurred_at, format: :full))
61+
past_index = body.index(I18n.l(past_contact.occurred_at, format: :full))
3962

40-
expect(recent_index).to be < past_index
63+
expect(recent_index).to be < past_index
64+
end
4165
end
4266
end
4367
end

0 commit comments

Comments
 (0)