Skip to content

Commit 7d962ce

Browse files
committed
Add specs covering new half star logic
1 parent f8d9858 commit 7d962ce

1 file changed

Lines changed: 88 additions & 13 deletions

File tree

spec/components/csr_table/stars_component_spec.rb

Lines changed: 88 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
let(:score) { 3 }
99
let(:highlight_stars) { nil }
10+
let(:half_stars) { false }
1011

1112
before do
12-
render_inline described_class.new(highlight_stars: highlight_stars.presence, score: score.presence)
13+
render_inline described_class.new(highlight_stars: highlight_stars.presence, score: score.presence, half_stars: half_stars)
1314
end
1415

1516
it { is_expected.to have_css ".star--full", count: 3 }
@@ -19,22 +20,96 @@
1920
context "when the stars are highlighted" do
2021
let(:highlight_stars) { true }
2122

22-
context "when the score is decimal" do
23-
let(:score) { 2.8 }
23+
context "when half stars is set to true" do
24+
let(:half_stars) { true }
2425

25-
it { is_expected.to have_css ".stars--highlight" }
26-
it { is_expected.to have_css ".star--full", count: 2 }
27-
it { is_expected.to have_css ".star--empty", count: 2 }
28-
it { is_expected.to have_css ".star--half", count: 1 }
26+
context "when the score is decimal" do
27+
let(:score) { 2.8 }
28+
29+
it { is_expected.to have_css ".stars--highlight" }
30+
it { is_expected.to have_css ".star--full", count: 2 }
31+
it { is_expected.to have_css ".star--empty", count: 2 }
32+
it { is_expected.to have_css ".star--half", count: 1 }
33+
end
34+
35+
context "when the score is a decimal, but less than .5 of the whole number" do
36+
let(:score) { 2.3 }
37+
38+
it { is_expected.to have_css ".stars--highlight" }
39+
it { is_expected.to have_css ".star--full", count: 2 }
40+
it { is_expected.to have_css ".star--empty", count: 3 }
41+
it { is_expected.to have_no_css ".star--half" }
42+
end
43+
end
44+
45+
context "when half stars is set to false" do
46+
let(:half_stars) { false }
47+
48+
context "when the score is decimal" do
49+
let(:score) { 2.8 }
50+
51+
it { is_expected.to have_css ".stars--highlight" }
52+
it { is_expected.to have_css ".star--full", count: 2 }
53+
it { is_expected.to have_css ".star--empty", count: 3 }
54+
it { is_expected.to have_css ".star--half", count: 0 }
55+
end
56+
57+
context "when the score is a decimal, but less than .5 of the whole number" do
58+
let(:score) { 2.3 }
59+
60+
it { is_expected.to have_css ".stars--highlight" }
61+
it { is_expected.to have_css ".star--full", count: 2 }
62+
it { is_expected.to have_css ".star--empty", count: 3 }
63+
it { is_expected.to have_no_css ".star--half" }
64+
end
65+
end
66+
end
67+
68+
context "when the stars are not highlighted" do
69+
let(:highlight_stars) { false }
70+
71+
context "when half stars is set to true" do
72+
let(:half_stars) { true }
73+
74+
context "when the score is decimal" do
75+
let(:score) { 2.8 }
76+
77+
it { is_expected.to have_no_css ".stars--highlight" }
78+
it { is_expected.to have_css ".star--full", count: 2 }
79+
it { is_expected.to have_css ".star--empty", count: 2 }
80+
it { is_expected.to have_css ".star--half", count: 1 }
81+
end
82+
83+
context "when the score is a decimal, but less than .5 of the whole number" do
84+
let(:score) { 2.3 }
85+
86+
it { is_expected.to have_no_css ".stars--highlight" }
87+
it { is_expected.to have_css ".star--full", count: 2 }
88+
it { is_expected.to have_css ".star--empty", count: 3 }
89+
it { is_expected.to have_no_css ".star--half" }
90+
end
2991
end
3092

31-
context "when the score is not decimal" do
32-
let(:score) { 2 }
93+
context "when half stars is set to false" do
94+
let(:half_stars) { false }
95+
96+
context "when the score is decimal" do
97+
let(:score) { 2.8 }
98+
99+
it { is_expected.to have_no_css ".stars--highlight" }
100+
it { is_expected.to have_css ".star--full", count: 2 }
101+
it { is_expected.to have_css ".star--empty", count: 3 }
102+
it { is_expected.to have_css ".star--half", count: 0 }
103+
end
104+
105+
context "when the score is a decimal, but less than .5 of the whole number" do
106+
let(:score) { 2.3 }
33107

34-
it { is_expected.to have_css ".stars--highlight" }
35-
it { is_expected.to have_css ".star--full", count: 2 }
36-
it { is_expected.to have_css ".star--empty", count: 3 }
37-
it { is_expected.to have_no_css ".star--half" }
108+
it { is_expected.to have_no_css ".stars--highlight" }
109+
it { is_expected.to have_css ".star--full", count: 2 }
110+
it { is_expected.to have_css ".star--empty", count: 3 }
111+
it { is_expected.to have_no_css ".star--half" }
112+
end
38113
end
39114
end
40115
end

0 commit comments

Comments
 (0)