diff --git a/app/views/datasets/_timeseries_data.html.erb b/app/views/datasets/_timeseries_data.html.erb index ce910d2f..c28c4a3d 100644 --- a/app/views/datasets/_timeseries_data.html.erb +++ b/app/views/datasets/_timeseries_data.html.erb @@ -1,8 +1,6 @@ <% - accordion_items = [] - - group_and_order(datafiles).each do |year, datafiles| - accordion_items << { + accordion_items = group_and_order(datafiles).map do |year, datafiles| + { heading: { text: year.presence || t('.other_data_files') }, @@ -14,5 +12,6 @@ %> <%= render "govuk_publishing_components/components/accordion", { + id: "dgu-datafiles-year", items: accordion_items -} %> +} %> \ No newline at end of file diff --git a/spec/features/dataset_show_page_spec.rb b/spec/features/dataset_show_page_spec.rb index dcac74b9..56b8bb91 100644 --- a/spec/features/dataset_show_page_spec.rb +++ b/spec/features/dataset_show_page_spec.rb @@ -357,15 +357,17 @@ scenario "are grouped by year when they contain timeseries datafiles" do index_and_visit(dataset) - expect(page).to have_css(".dgu-datafiles__year", count: 2) + expect(page).to have_css("#dgu-datafiles-year") - correct_order = [ - Time.zone.parse(datafile2["start_date"]).year.to_s, - Time.zone.parse(datafile1["start_date"]).year.to_s, - ] + within("#dgu-datafiles-year") do + correct_order = [ + Time.zone.parse(datafile2["start_date"]).year.to_s, + Time.zone.parse(datafile1["start_date"]).year.to_s, + ] - actual_order = all("button.dgu-datafiles__year").map(&:text) - expect(actual_order).to eq correct_order + actual_order = all(".govuk-accordion__section-button").map(&:text) + expect(actual_order).to eq correct_order + end end scenario "are not grouped when they contain non timeseries datafiles" do