diff --git a/app/assets/stylesheets/application.tailwind.css.scss b/app/assets/stylesheets/application.tailwind.css.scss
index 85d0c905..4d09a528 100644
--- a/app/assets/stylesheets/application.tailwind.css.scss
+++ b/app/assets/stylesheets/application.tailwind.css.scss
@@ -108,6 +108,10 @@ main {
dd {
@apply text-right;
}
+
+ .guidance {
+ @apply text-sm mt-2 p-4;
+ }
}
.sharing {
diff --git a/app/components/prediction_component.html.erb b/app/components/prediction_component.html.erb
index d89d7328..a1c3ffd2 100644
--- a/app/components/prediction_component.html.erb
+++ b/app/components/prediction_component.html.erb
@@ -3,7 +3,7 @@
<%= name_for_label %>
<%= daqi_level_for_label %>
- <%= details_panel_colour %>" data-prediction-target="guidance">
+
<%= guidance_panel_colour %>" data-prediction-target="guidance">
<%= guidance%>
diff --git a/app/components/prediction_component.rb b/app/components/prediction_component.rb
index 38a9691b..3ed03e4e 100644
--- a/app/components/prediction_component.rb
+++ b/app/components/prediction_component.rb
@@ -21,19 +21,8 @@ def daqi_level_for_label
@prediction.daqi_label
end
- def details_panel_colour
- case @prediction.daqi_level
- when :low
- "bg-green-50"
- when :moderate
- "text-amber-50"
- when :high
- "text-red-50"
- when :very_high
- "text-stone-50"
- else
- raise "DAQI level '#{@prediction.daqi_level}' not known"
- end
+ def guidance_panel_colour
+ "bg-#{@prediction.daqi_label.parameterize}-alert-guidance-panel"
end
def guidance
diff --git a/spec/components/prediction_component_spec.rb b/spec/components/prediction_component_spec.rb
index 877cc427..83d17ada 100644
--- a/spec/components/prediction_component_spec.rb
+++ b/spec/components/prediction_component_spec.rb
@@ -36,7 +36,7 @@
end
end
- describe "details" do
+ describe "guidance" do
it "includes the prediction's guidance from the translation system" do
expect(page).to have_css(
".guidance",
@@ -48,14 +48,14 @@
context "when the DAQI level is low" do
let(:component) {
PredictionComponent.new(
- prediction: OpenStruct.new(name: "Solar Rays", daqi_level: :low)
+ prediction: OpenStruct.new(name: "Solar Rays", daqi_level: :low, daqi_label: "Low")
)
}
before { render_inline(component) }
it "hides the panel" do
- expect(page).to have_css(".details.hidden")
+ expect(page).to have_css(".guidance.hidden")
end
end
@@ -63,82 +63,22 @@
[:moderate, :high, :very_high].each do |level|
let(:component) {
PredictionComponent.new(
- prediction: OpenStruct.new(name: "Solar Rays", daqi_level: level)
+ prediction: OpenStruct.new(name: "Solar Rays", daqi_level: level, daqi_label: level.to_s)
)
}
before { render_inline(component) }
it "shows the panel" do
- expect(page).to have_css(".details.visible")
+ expect(page).to have_css(".guidance.visible")
end
end
end
end
- it "includes the details_panel_colour as a class" do
+ it "includes the guidance_panel_colour as a class" do
component = PredictionComponent.new(prediction: prediction)
- expect(page).to have_css(".#{component.details_panel_colour}.details")
- end
-
- describe "the colour of the details panel (#details_panel_colour)" do
- context "when the daqi level is low" do
- let(:component) {
- PredictionComponent.new(
- prediction: OpenStruct.new(daqi_level: :low)
- )
- }
- it "uses an green colour" do
- expect(component.details_panel_colour).to match(/green/)
- end
- end
-
- context "when the daqi level is moderate" do
- let(:component) {
- PredictionComponent.new(
- prediction: OpenStruct.new(daqi_level: :moderate)
- )
- }
- it "uses an amber colour" do
- expect(component.details_panel_colour).to match(/amber/)
- end
- end
-
- context "when the daqi level is high" do
- let(:component) {
- PredictionComponent.new(
- prediction: OpenStruct.new(daqi_level: :high)
- )
- }
-
- it "uses a red colour" do
- expect(component.details_panel_colour).to match(/red/)
- end
- end
-
- context "when the daqi level is very high" do
- let(:component) {
- PredictionComponent.new(
- prediction: OpenStruct.new(daqi_level: :very_high)
- )
- }
-
- it "uses a black-ish" do
- expect(component.details_panel_colour).to match(/stone/)
- end
- end
-
- context "when the daqi level is not known" do
- let(:component) {
- PredictionComponent.new(
- prediction: OpenStruct.new(daqi_level: :unknown)
- )
- }
-
- it "raises an error" do
- expect { component.details_panel_colour }.to raise_error(/DAQI level 'unknown' not known/)
- end
- end
+ expect(page).to have_css(".#{component.guidance_panel_colour}.guidance")
end
end
end