forked from codeforamerica/ohana-web-search
/
filters_spec.rb
188 lines (154 loc) · 7.54 KB
/
filters_spec.rb
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
require 'spec_helper'
feature "results page search", :js do
background do
page.set_rack_session('aggregate_locations' => [])
search_from_home(keyword: 'asdfg')
end
# test filter fieldset legend toggling across all filters
scenario 'when location filter has no cached values and legend is toggled', :vcr do
test_filter_legend("location")
end
scenario 'when service-area filter has no cached values and legend is toggled', :vcr do
test_filter_legend("service-area","San Mateo County, CA")
end
scenario 'when kind filter has no cached values and legend is toggled', :vcr do
test_filter_legend("kind", "Human Services",13)
end
scenario 'when agency filter has no cached values and legend is toggled', :vcr do
test_filter_legend("org-name")
end
# test filter fieldset toggle toggling across all filters
scenario 'when location filter has no cached values and toggle is toggled', :vcr do
test_filter_toggle("location")
end
scenario 'when service-area filter has no cached values and toggle is toggled', :vcr do
test_filter_toggle("service-area","San Mateo County, CA")
end
scenario 'when kind filter has no cached values and toggle is toggled', :vcr do
test_filter_toggle("kind", "Human Services",13)
end
scenario 'when agency filter has no cached values and toggle is toggled', :vcr do
test_filter_toggle("org-name")
end
# test adding custom value to filters that accept custom values
scenario 'when location filter has no cached values and custom value is added', :vcr do
fill_in('keyword', with: '')
set_filter("location", "location", "94403")
all(".toggle-group-wrapper.add label").first.trigger("mousedown")
expect(page).to have_content("41 results within 5 miles of '94403'")
end
scenario 'when agency filter has no cached values and custom value is added', :vcr do
fill_in('keyword', with: '')
set_filter("org-name", "org_name", "vincent")
all(".toggle-group-wrapper.add label").first.trigger("mousedown")
expect(page).to have_content("4 results")
end
# test adding custom value to filters and retrieving no results
scenario 'when location filter has custom value and no results', :vcr do
set_filter("location", "location", "San Mateo, CA")
find('#find-btn').click
within("#location-options") do
find(".closed").trigger('mousedown')
expect(find(".available-options")).to have_css(".toggle-group", :count => 2)
expect(find_by_id("location-option-input").value).to eq "San Mateo, CA"
end
end
scenario 'when agency filter has custom value and no results', :vcr do
set_filter("org-name", "org_name", "United States Government")
find('#find-btn').click
within("#org-name-options") do
find(".closed").trigger('mousedown')
expect(find(".available-options")).to have_css(".toggle-group", :count => 2)
expect(find_by_id("org-name-option-input").value).to eq "United States Government"
end
end
# test adding custom value to filters and retrieving results
scenario 'when location filter has custom value and has results', :vcr do
set_filter("location", "location", "San Mateo, CA")
fill_in('keyword', :with => '') # clear keyword
find('#find-btn').click
find(".require-loaded")
within("#location-options") do
find(".closed").click
expect(find(".available-options")).to have_css(".toggle-group", :count=>3)
expect(page).not_to have_css("location")
end
end
scenario 'when agency filter has custom value and has results', :vcr do
set_filter("org-name", "org_name", "United States Government")
fill_in('keyword', :with => '') # clear keyword
find('#find-btn').click
find(".require-loaded")
within("#org-name-options") do
find(".closed").click
expect(find(".available-options")).to have_css(".toggle-group", :count=>3)
expect(page).not_to have_css("org_name")
end
end
# test filter selection across all filters
scenario 'when location filter has cached values and new option is selected', :vcr do
fill_in('keyword', :with => '') # clear keyword
find('#find-btn').click
set_filter("location", "location", "San Mateo, CA", false)
find('#find-btn').click
expect(page).to have_content("40 results")
expect(all("#location-options .current-option label").last).to have_content("San Mateo, CA")
end
scenario 'when service-area filter has cached values and new option is selected', :vcr do
fill_in('keyword', :with => '') # clear keyword
set_filter("service-area", "service_area", "All", false)
find('#find-btn').click
expect(page).to have_content("130 results")
expect(all("#service-area-options .current-option label").last).to have_content("All")
end
scenario 'when kind filter has cached values and new option is selected', :vcr do
fill_in('keyword', :with => '') # clear keyword
set_filter("kind", "kind", "Other", false)
find('#find-btn').click
expect(page).to have_content("35 results")
expect(all("#kind-options .current-option label").last).to have_content("Other")
end
scenario 'when agency filter has cached values and new option is selected', :vcr do
fill_in('keyword', :with => '') # clear keyword
find('#find-btn').click
set_filter("org-name", "org_name", "San Mateo County Human Services Agency", false)
find('#find-btn').click
expect(page).to have_content("11 results")
expect(all("#org-name-options .current-option label").last).to have_content("San Mateo County Human Services Agency")
end
# user clicks filter links in results list
scenario 'when clicking organization link in results', :vcr do
search(:keyword => "St. Vincent de Paul Society")
first("#list-view li").click_link("St. Vincent de Paul Society")
expect(page).not_to have_content("Shelter Network")
expect(page).to have_content("San Mateo Homeless Help Center")
# check filter settings
expect(all("#location-options .current-option label").last).to have_content("All")
expect(all("#service-area-options .current-option label").last).to have_content("All")
expect(all("#kind-options .current-option label").last).to have_content("All")
expect(all("#org-name-options .current-option label").last).to have_content("St. Vincent de Paul Society")
end
scenario 'when clicking kind link in results', :vcr do
search(:keyword => "St. Vincent de Paul Society")
first("#list-view li").click_link("Human Services")
expect(page).not_to have_content("Shelter Network")
expect(page).to have_content("San Mateo County Human Services Agency")
# check filter settings
expect(all("#location-options .current-option label").last).to have_content("All")
expect(all("#service-area-options .current-option label").last).to have_content("All")
expect(all("#kind-options .current-option label").last).to have_content("Human Services")
expect(all("#org-name-options .current-option label").last).to have_content("All")
end
scenario 'when clicking the reset button', :vcr do
expect(page).to have_content("No results")
find_by_id('reset-btn').click
# check filter settings
expect(find_field("keyword").value).to eq ""
expect(all("#location-options .current-option label").last).to have_content("All")
expect(all("#service-area-options .current-option label").last).to have_content("All")
expect(all("#kind-options .current-option label").last).to have_content("All")
expect(all("#org-name-options .current-option label").last).to have_content("All")
find('#find-btn').click
expect(page).to have_content("339 results")
end
end