-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
relations_spec.rb
145 lines (106 loc) · 4.51 KB
/
relations_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
require "rails_helper"
describe "SDG Relations", :js do
before do
login_as(create(:administrator).user)
Setting["feature.sdg"] = true
Setting["sdg.process.budgets"] = true
Setting["sdg.process.debates"] = true
Setting["sdg.process.legislation"] = true
Setting["sdg.process.polls"] = true
Setting["sdg.process.proposals"] = true
end
scenario "navigation" do
visit sdg_management_root_path
within("#side_menu") { click_link "Participatory budgets" }
expect(page).to have_current_path "/sdg_management/budget/investments"
expect(page).to have_css "h2", exact_text: "Participatory budgets"
within("#side_menu") { click_link "Debates" }
expect(page).to have_current_path "/sdg_management/debates"
expect(page).to have_css "h2", exact_text: "Debates"
within("#side_menu") { click_link "Collaborative legislation" }
expect(page).to have_current_path "/sdg_management/legislation/processes"
expect(page).to have_css "h2", exact_text: "Collaborative legislation"
within("#side_menu") { click_link "Polls" }
expect(page).to have_current_path "/sdg_management/polls"
expect(page).to have_css "h2", exact_text: "Polls"
within("#side_menu") { click_link "Proposals" }
expect(page).to have_current_path "/sdg_management/proposals"
expect(page).to have_css "h2", exact_text: "Proposals"
end
describe "Index" do
scenario "list records for the current model" do
create(:debate, title: "I'm a debate")
create(:proposal, title: "And I'm a proposal")
visit sdg_management_debates_path
expect(page).to have_text "I'm a debate"
expect(page).not_to have_text "I'm a proposal"
visit sdg_management_proposals_path
expect(page).to have_text "I'm a proposal"
expect(page).not_to have_text "I'm a debate"
end
scenario "list goals and target for all records" do
redistribute = create(:proposal, title: "Resources distribution")
redistribute.sdg_goals = [SDG::Goal[1]]
redistribute.sdg_targets = [SDG::Target["1.1"]]
treatment = create(:proposal, title: "Treatment system")
treatment.sdg_goals = [SDG::Goal[6]]
treatment.sdg_targets = [SDG::Target["6.1"], SDG::Target["6.2"]]
visit sdg_management_proposals_path
within("tr", text: "Resources distribution") do
expect(page).to have_content "1.1"
end
within("tr", text: "Treatment system") do
expect(page).to have_content "6.1, 6.2"
end
end
scenario "shows link to edit a record" do
create(:budget_investment, title: "Build a hospital")
visit sdg_management_budget_investments_path
within("tr", text: "Build a hospital") do
click_link "Manage goals and targets"
end
expect(page).to have_css "h2", exact_text: "Build a hospital"
end
describe "search" do
scenario "search by terms" do
create(:poll, name: "Internet speech freedom")
create(:poll, name: "SDG interest")
visit sdg_management_polls_path
fill_in "search", with: "speech"
click_button "Search"
expect(page).to have_content "Internet speech freedom"
expect(page).not_to have_content "SDG interest"
end
scenario "goal filter" do
create(:budget_investment, title: "School", sdg_goals: [SDG::Goal[4]])
create(:budget_investment, title: "Hospital", sdg_goals: [SDG::Goal[3]])
visit sdg_management_budget_investments_path
select "4. Quality Education", from: "goal_code"
click_button "Search"
expect(page).to have_content "School"
expect(page).not_to have_content "Hospital"
end
end
scenario "target filter" do
create(:budget_investment, title: "School", sdg_targets: [SDG::Target[4.1]])
create(:budget_investment, title: "Preschool", sdg_targets: [SDG::Target[4.2]])
visit sdg_management_budget_investments_path
select "4.1", from: "target_code"
click_button "Search"
expect(page).to have_content "School"
expect(page).not_to have_content "Preschool"
end
end
describe "Edit" do
scenario "allows changing the targets" do
process = create(:legislation_process, title: "SDG process")
process.sdg_targets = [SDG::Target["3.3"]]
visit sdg_management_edit_legislation_process_path(process)
fill_in "Targets", with: "1.2, 2.1"
click_button "Update Process"
within("tr", text: "SDG process") do
expect(page).to have_css "td", exact_text: "1.2, 2.1"
end
end
end
end