Skip to content

Commit

Permalink
CDD-2220: Update alt text for simplified chart when there is no trend
Browse files Browse the repository at this point in the history
  • Loading branch information
phill-stanley committed Sep 19, 2024
1 parent 86ae6e9 commit 7ef044c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
9 changes: 8 additions & 1 deletion metrics/domain/models/plots_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ def _get_trend_direction(cls, *, plot_parameters: PlotParameters) -> str:
return "positive"
case RGBAChartLineColours.TREND_LINE_NEUTRAL.name:
return "neutral"
case _:
return "none"

def _describe_plot_type(self, *, plot_parameters: PlotParameters) -> str:
line_type: str = self._get_line_type_or_default(plot_parameters=plot_parameters)
Expand All @@ -357,7 +359,12 @@ def _describe_plot_type(self, *, plot_parameters: PlotParameters) -> str:

if self._plot_is_simplified_chart(plot_parameters=plot_parameters):
trend_type: str = self._get_trend_direction(plot_parameters=plot_parameters)
return f"This is a {line_type} {plot_type} chart, showing a {trend_type} trend in the data. "
plot_description = f"This is a {line_type} {plot_type} chart, "

if trend_type != "none":
plot_description += f"showing a {trend_type} trend in the data. "

return plot_description

return f"This is a {line_colour} {line_type} {plot_type} plot. "

Expand Down
21 changes: 21 additions & 0 deletions tests/unit/metrics/domain/models/test_plots_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,27 @@ def test_returns_correct_trend_type_when_line_colour_provided_is_for_trend_line(
)
assert expected_text_about_parameters in text

def test_returns_no_trend_type_when_line_colour_is_trend_line_none(
self,
fake_plot_data: PlotData,
):
"""
Given a valid plot where the `line_colour` that is not a `TREND_LINE` colour
When the `construct_text()` method is called
Then no trend type is returned in the response.
"""
fake_plot_data.parameters.line_colour = "COLOUR_1_DARK_BLUE"
fake_plot_data.parameters.line_type = "SOLID"
fake_plot_data.parameters.chart_type = ChartTypes.line_single_simplified.value
plots_text = PlotsText(plots_data=[fake_plot_data])

# When
text: str = plots_text.construct_text()

# Then
expected_text_about_parameters = f"This is a solid line chart,"
assert expected_text_about_parameters in text

def test_returns_correct_text_about_parameters_for_multiple_plots(
self, fake_plot_data: PlotData
):
Expand Down

0 comments on commit 7ef044c

Please sign in to comment.