-
Notifications
You must be signed in to change notification settings - Fork 241
Expand file tree
/
Copy pathdashboards_controller_test.rb
More file actions
100 lines (87 loc) · 3.21 KB
/
dashboards_controller_test.rb
File metadata and controls
100 lines (87 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
require 'test_helper'
class DashboardsControllerTest < ActionDispatch::IntegrationTest
before do
@user = create :user
@line = create :line
@patient = create :patient,
name: 'Susie Everyteen',
primary_phone: '123-456-7890',
other_phone: '333-444-5555',
line: @line
sign_in @user
choose_line @line
end
describe 'index method' do
before do
get dashboard_path
end
it 'should return success' do
assert_response :success
end
end
describe 'follow-up patients on dashboard' do
before do
@follow_up_patient = create :patient,
name: 'Follow Up Needed',
line: @line,
follow_up_date: 1.day.ago.to_date,
follow_up_reason: 'Check insurance status'
end
it 'should include follow-up patients in the dashboard' do
get dashboard_path
assert_response :success
assert_match(/Follow Up Needed/, response.body)
end
it 'should not include patients without a follow-up date' do
get dashboard_path
assert_response :success
assert_no_match(/Susie Everyteen/, response.body.scan(/follow-ups-due.*?<\/div>/m).join)
end
it 'should not include patients with future follow-up dates' do
@follow_up_patient.update! follow_up_date: 3.days.from_now.to_date
get dashboard_path
assert_response :success
assert_no_match(/Follow Up Needed/, response.body.scan(/follow-ups-due.*?<\/div>/m).join)
end
it 'should not include follow-up patients from a different line' do
other_line = create :line, name: 'Other Line'
create :patient,
name: 'Other Line Patient',
line: other_line,
follow_up_date: 1.day.ago.to_date,
follow_up_reason: 'Belongs to other line'
get dashboard_path
assert_response :success
follow_ups_html = response.body.scan(/follow-ups-due.*?<\/table>/m).join
assert_no_match(/Other Line Patient/, follow_ups_html)
end
end
describe 'search method' do
it 'should return on name, primary phone, and other phone' do
['Susie Everyteen', '123-456-7890', '333-444-5555'].each do |searcher|
post search_path, params: { search: searcher }, xhr: true
assert_response :success
end
end
end
describe 'budget bar method' do
it 'should return success' do
get budget_bar_path, xhr: true
assert_response :success
end
describe 'budget bar calculations' do
it 'handles the empty case' do
assert_equal DashboardsController.new.budget_bar_calculations(@line),
{ limit: 1_000, expenditures: { sent: [], pledged: [] } }
end
it 'calculates if information is set' do
create :clinic
@patient.update appointment_date: 3.days.from_now,
clinic_id: Clinic.first.id,
fund_pledge: 50
assert_equal DashboardsController.new.budget_bar_calculations(@line),
{ limit: 1_000, expenditures: Patient.pledged_status_summary(@line) }
end
end
end
end