|
7 | 7 |
|
8 | 8 | let(:score) { 3 } |
9 | 9 | let(:show_decimal_score) { nil } |
| 10 | + let(:decimal_places) { 1 } |
| 11 | + let(:highlight_stars) { false } |
10 | 12 |
|
11 | 13 | before do |
12 | | - render_inline described_class.new(score: score.presence, show_decimal_score: show_decimal_score.presence) |
| 14 | + render_inline described_class.new(score: score.presence, |
| 15 | + show_decimal_score: show_decimal_score.presence, |
| 16 | + decimal_places: decimal_places.presence, |
| 17 | + highlight_stars: highlight_stars) |
13 | 18 | end |
14 | 19 |
|
15 | 20 | it { is_expected.to have_text "3 out of 5" } |
|
39 | 44 | it { is_expected.to have_no_css ".stars" } |
40 | 45 | end |
41 | 46 |
|
| 47 | + context "when the score highlights the stars" do |
| 48 | + let(:highlight_stars) { true } |
| 49 | + |
| 50 | + it { is_expected.to have_css ".stars" } |
| 51 | + it { is_expected.to have_css ".stars--highlight" } |
| 52 | + end |
| 53 | + |
42 | 54 | context "when the score is shown as a decimal" do |
43 | 55 | let(:score) { 1.2 } |
44 | 56 | let(:show_decimal_score) { true } |
45 | 57 |
|
46 | | - it { is_expected.to have_text "1.2 out of 5" } |
47 | | - it { is_expected.to have_css ".stars--highlight" } |
| 58 | + context "when the decimal_places is set to 1" do |
| 59 | + it { is_expected.to have_text "1.2 out of 5" } |
| 60 | + end |
| 61 | + |
| 62 | + context "when decimal_places is set to 2" do |
| 63 | + let(:decimal_places) { 2 } |
| 64 | + |
| 65 | + context "when there is a single decimal digit" do |
| 66 | + it { is_expected.to have_text "1.20 out of 5" } |
| 67 | + end |
| 68 | + |
| 69 | + context "when there are two decimal digits" do |
| 70 | + let(:score) { 1.23 } |
| 71 | + |
| 72 | + it { is_expected.to have_text "1.23 out of 5" } |
| 73 | + end |
| 74 | + end |
48 | 75 | end |
49 | 76 |
|
50 | 77 | context "when content is provided" do |
|
0 commit comments