-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcourse_helper_test.rb
More file actions
164 lines (140 loc) · 4.98 KB
/
course_helper_test.rb
File metadata and controls
164 lines (140 loc) · 4.98 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
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
# typed: strict
# frozen_string_literal: true
require "test_helper"
class CourseHelperTest < ActionView::TestCase
include CourseHelper
describe "course_badge_label" do
it "returns the number of sections for an offered course" do
term = create_current_term
course = create(:course, subject_area: create(:subject_area))
create_list(:section, 4, course:, term:, instructor: create(:instructor))
assert_equal("4 sections", course_badge_label(T.must(Course.with_section_counts.first)))
end
it "returns 'Not Offered' if the course is not offered" do
create_current_term
course = create(:course, subject_area: create(:subject_area))
create_list(:section, 4, course:, term: create(:term, term: "20F"), instructor: create(:instructor))
assert_equal("Not offered", course_badge_label(T.must(Course.with_section_counts.first)))
end
it "returns nil if the course does not have a section count" do
term = create(:term)
course = create(:course, subject_area: create(:subject_area))
create_list(:section, 4, course:, term:, instructor: create(:instructor))
assert_nil(course_badge_label(course))
end
end
describe "course_badge_color" do
it "returns gray if the course is not offered" do
assert_equal(ColorHelper::Color::Gray, course_badge_color("Not offered"))
end
it "returns green if the course is offered" do
assert_equal(ColorHelper::Color::Green, course_badge_color("3 sections"))
end
it "returns nil if given nil" do
assert_nil(course_badge_color(nil))
end
end
describe "#course_detail_label" do
describe "has_group_project" do
it "returns the correct string when the course has a group project" do
course_detail = {
label: :has_group_project,
value: true,
}
assert_equal("Has a group project", course_detail_label(course_detail))
end
it "returns the correct string when the course does not have a group project" do
course_detail = {
label: :has_group_project,
value: false,
}
assert_equal("No group projects", course_detail_label(course_detail))
end
end
describe "requires_attendance" do
it "returns the correct string when the course requires attendance" do
course_detail = {
label: :requires_attendance,
value: true,
}
assert_equal("Attendance required", course_detail_label(course_detail))
end
it "returns the correct string when the course does not require attendance" do
course_detail = {
label: :requires_attendance,
value: false,
}
assert_equal("Attendance not required", course_detail_label(course_detail))
end
end
describe "final" do
it "returns the correct string when a course has a finals week final" do
course_detail = {
label: :final,
value: "finals",
}
assert_equal("Finals week final", course_detail_label(course_detail))
end
it "returns the correct string when a course has a 10th week final" do
course_detail = {
label: :final,
value: "10th",
}
assert_equal("10th week final", course_detail_label(course_detail))
end
it "returns the correct string when a course does not have a final" do
course_detail = {
label: :final,
value: "none",
}
assert_equal("No final", course_detail_label(course_detail))
end
end
describe "midterm_count" do
it "returns 'no midterms' for a course with no midterms" do
course_detail = {
label: :midterm_count,
value: 0,
}
assert_equal("No midterms", course_detail_label(course_detail))
end
it "does not pluralize a single midterm" do
course_detail = {
label: :midterm_count,
value: 1,
}
assert_equal("1 midterm", course_detail_label(course_detail))
end
it "pluralizes multiple midterms" do
course_detail = {
label: :midterm_count,
value: 2,
}
assert_equal("2 midterms", course_detail_label(course_detail))
end
end
describe "recommend_textbook" do
it "returns a string if the value is true" do
course_detail = {
label: :recommend_textbook,
value: true,
}
assert_equal("Recommends textbook", course_detail_label(course_detail))
end
it "returns a string if the value is false" do
course_detail = {
label: :recommend_textbook,
value: false,
}
assert_equal("Does not recommend textbook", course_detail_label(course_detail))
end
it "returns a percentage if given a number" do
course_detail = {
label: :recommend_textbook,
value: 65,
}
assert_equal("65% recommend the textbook", course_detail_label(course_detail))
end
end
end
end