From b8950ab7d988d9f106c40eb62426ddb6252bbe1b Mon Sep 17 00:00:00 2001 From: Laura Porter Date: Thu, 4 Jan 2024 11:11:48 +0000 Subject: [PATCH 1/3] (Refactor) Rename method to show it is for conversion projects We are about to add an export for Transfer projects for the Grant management and finance users. Rename this method to make it explicit it is for Conversion projects, so we can later add a Transfer version. --- .../conversions/projects_controller.rb | 2 +- app/services/projects_for_export_service.rb | 2 +- spec/services/projects_for_export_service_spec.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/all/export/grant_management_and_finance_unit/conversions/projects_controller.rb b/app/controllers/all/export/grant_management_and_finance_unit/conversions/projects_controller.rb index 2bf5f2f92..a9e862f70 100644 --- a/app/controllers/all/export/grant_management_and_finance_unit/conversions/projects_controller.rb +++ b/app/controllers/all/export/grant_management_and_finance_unit/conversions/projects_controller.rb @@ -8,7 +8,7 @@ def index def csv authorize Project, :index? - projects = ProjectsForExportService.new.grant_management_and_finance_unit_projects(month: month, year: year) + projects = ProjectsForExportService.new.grant_management_and_finance_unit_conversion_projects(month: month, year: year) csv = Export::Conversions::GrantManagementAndFinanceUnitCsvExportService.new(projects).call send_data csv, filename: "#{year}-#{month}_grant_management_and_finance_unit_conversions_export.csv", type: :csv, disposition: "attachment" diff --git a/app/services/projects_for_export_service.rb b/app/services/projects_for_export_service.rb index 76ef1208f..d226c73a8 100644 --- a/app/services/projects_for_export_service.rb +++ b/app/services/projects_for_export_service.rb @@ -9,7 +9,7 @@ def funding_agreement_letters_projects(month:, year:) AcademiesApiPreFetcherService.new.call!(projects) end - def grant_management_and_finance_unit_projects(month:, year:) + def grant_management_and_finance_unit_conversion_projects(month:, year:) projects = conversion_projects_by_advisory_board_date(month, year) AcademiesApiPreFetcherService.new.call!(projects) end diff --git a/spec/services/projects_for_export_service_spec.rb b/spec/services/projects_for_export_service_spec.rb index ed82f226c..cf7a45752 100644 --- a/spec/services/projects_for_export_service_spec.rb +++ b/spec/services/projects_for_export_service_spec.rb @@ -50,14 +50,14 @@ end end - describe "#grant_management_and_finance_unit_projects" do - it "returns only projects with an advisory board date of the supplied month and year" do + describe "#grant_management_and_finance_unit_conversion_projects" do + it "returns only conversion projects with an advisory board date of the supplied month and year" do mock_academies_api_client_get_establishments_and_trusts matching_project = create(:conversion_project, conversion_date_provisional: false, advisory_board_date: Date.parse("2023-1-1")) mismatching_project = create(:conversion_project, conversion_date_provisional: false, advisory_board_date: Date.parse("2023-2-1")) - projects_for_export = described_class.new.grant_management_and_finance_unit_projects(month: 1, year: 2023) + projects_for_export = described_class.new.grant_management_and_finance_unit_conversion_projects(month: 1, year: 2023) expect(projects_for_export).to include(matching_project) expect(projects_for_export).not_to include(mismatching_project) From 78acc6bb58a6c9a935c872c8532d38d77f88cecb Mon Sep 17 00:00:00 2001 From: Laura Porter Date: Thu, 4 Jan 2024 11:17:53 +0000 Subject: [PATCH 2/3] Add method to return Transfer projects by advisory board date As with Conversions, we need a method to return Transfer projects with an Advisory board date in a particular month. --- app/services/projects_for_export_service.rb | 9 +++++++++ spec/services/projects_for_export_service_spec.rb | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/app/services/projects_for_export_service.rb b/app/services/projects_for_export_service.rb index d226c73a8..930b4c306 100644 --- a/app/services/projects_for_export_service.rb +++ b/app/services/projects_for_export_service.rb @@ -14,6 +14,11 @@ def grant_management_and_finance_unit_conversion_projects(month:, year:) AcademiesApiPreFetcherService.new.call!(projects) end + def grant_management_and_finance_unit_transfer_projects(month:, year:) + projects = transfer_projects_by_advisory_board_date(month, year) + AcademiesApiPreFetcherService.new.call!(projects) + end + def transfer_by_month_projects(month:, year:) projects = transfer_projects_by_month_and_year(month, year) AcademiesApiPreFetcherService.new.call!(projects) @@ -30,4 +35,8 @@ def transfer_by_month_projects(month:, year:) private def conversion_projects_by_advisory_board_date(month, year) Conversion::Project.confirmed.filtered_by_advisory_board_date(month, year) end + + private def transfer_projects_by_advisory_board_date(month, year) + Transfer::Project.confirmed.filtered_by_advisory_board_date(month, year) + end end diff --git a/spec/services/projects_for_export_service_spec.rb b/spec/services/projects_for_export_service_spec.rb index cf7a45752..2cc55a99b 100644 --- a/spec/services/projects_for_export_service_spec.rb +++ b/spec/services/projects_for_export_service_spec.rb @@ -64,6 +64,21 @@ end end + describe "#grant_management_and_finance_unit_transfer_projects" do + it "returns only transfer projects with an advisory board date of the supplied month and year" do + mock_academies_api_client_get_establishments_and_trusts + + matching_project = create(:transfer_project, significant_date_provisional: false, advisory_board_date: Date.parse("2023-1-1")) + mismatching_project_1 = create(:conversion_project, significant_date_provisional: false, advisory_board_date: Date.parse("2023-2-1")) + mismatching_project_2 = create(:transfer_project, significant_date_provisional: false, advisory_board_date: Date.parse("2023-2-1")) + + projects_for_export = described_class.new.grant_management_and_finance_unit_transfer_projects(month: 1, year: 2023) + + expect(projects_for_export).to include(matching_project) + expect(projects_for_export).not_to include(mismatching_project_1, mismatching_project_2) + end + end + describe "#transfer_by_month_projects" do it "returns only transfer projects transferring in the supplied month & year" do mock_academies_api_client_get_establishments_and_trusts From ed99951a91e27c95d903d0843e44e2bfab5ba7b3 Mon Sep 17 00:00:00 2001 From: Laura Porter Date: Thu, 4 Jan 2024 17:14:15 +0000 Subject: [PATCH 3/3] Allow Grant managment and finance team users to download an export of Transfers We previously added a very basic Csv download of Conversions for the Grant management and finance team. We have now added Tranfers to this, and changed the existing Conversions download pages to accommodate Transfers as well. Users can now access Grant management and finance team downloads for both Conversions and Transfers from the Exports landing page. The Conversion & Transfer Grant management and finance team download pages are tabbed, to allow easy switching between Transfers and Conversions. There is now a page between the index page & Csv download giving information about the Csv contents. --- CHANGELOG.md | 11 +++ .../conversions/projects_controller.rb | 16 ++- .../transfers/projects_controller.rb | 40 ++++++++ .../conversions/projects/index.html.erb | 64 ++++++++---- .../conversions/projects/show.html.erb | 18 ++++ .../transfers/projects/index.html.erb | 49 ++++++++++ .../transfers/projects/show.html.erb | 18 ++++ app/views/all/export/projects/index.html.erb | 1 + config/locales/en.yml | 2 + ...agement_and_finance_unit_csv_export.en.yml | 24 ++++- config/locales/export/landing_page.en.yml | 1 + config/locales/project.en.yml | 2 + config/routes.rb | 5 + ..._finance_users_can_export_download_spec.rb | 97 ++++++++++++++++--- 14 files changed, 310 insertions(+), 38 deletions(-) create mode 100644 app/controllers/all/export/grant_management_and_finance_unit/transfers/projects_controller.rb create mode 100644 app/views/all/export/grant_management_and_finance_unit/conversions/projects/show.html.erb create mode 100644 app/views/all/export/grant_management_and_finance_unit/transfers/projects/index.html.erb create mode 100644 app/views/all/export/grant_management_and_finance_unit/transfers/projects/show.html.erb diff --git a/CHANGELOG.md b/CHANGELOG.md index ec9944731..2dd8e67d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). outgoing trust sharepoint link field. - Fix statistics page to show accurate data for Transfer's `by region` table. +### Added + +- Add the ability to download Transfer projects for the Grant management and + finance team + +### Changed + +- Changed the existing Grant management and finance team Conversions download + page to include an information page about the download, and a tabbed view on + the index page to switch between Transfers and Conversions + ## [Release-49][release-49] ### Changed diff --git a/app/controllers/all/export/grant_management_and_finance_unit/conversions/projects_controller.rb b/app/controllers/all/export/grant_management_and_finance_unit/conversions/projects_controller.rb index a9e862f70..66c0d2c5f 100644 --- a/app/controllers/all/export/grant_management_and_finance_unit/conversions/projects_controller.rb +++ b/app/controllers/all/export/grant_management_and_finance_unit/conversions/projects_controller.rb @@ -2,7 +2,17 @@ class All::Export::GrantManagementAndFinanceUnit::Conversions::ProjectsControlle def index authorize Project, :index? - @months = export_months + @data = export_months.map do |month| + { + month: month, + count: ProjectsForExportService.new.grant_management_and_finance_unit_conversion_projects(month: month.month, year: month.year).count + } + end + end + + def show + authorize Project, :show? + @month = Date.new(year, month) end def csv @@ -15,11 +25,11 @@ def csv end private def month - params[:month] + params[:month].to_i end private def year - params[:year] + params[:year].to_i end private def export_months diff --git a/app/controllers/all/export/grant_management_and_finance_unit/transfers/projects_controller.rb b/app/controllers/all/export/grant_management_and_finance_unit/transfers/projects_controller.rb new file mode 100644 index 000000000..58e310d11 --- /dev/null +++ b/app/controllers/all/export/grant_management_and_finance_unit/transfers/projects_controller.rb @@ -0,0 +1,40 @@ +class All::Export::GrantManagementAndFinanceUnit::Transfers::ProjectsController < ApplicationController + def index + authorize Project, :index? + + @data = export_months.map do |month| + { + month: month, + count: ProjectsForExportService.new.grant_management_and_finance_unit_transfer_projects(month: month.month, year: month.year).count + } + end + end + + def show + authorize Project, :show? + @month = Date.new(year, month) + end + + def csv + authorize Project, :index? + + projects = ProjectsForExportService.new.grant_management_and_finance_unit_transfer_projects(month: month, year: year) + csv = Export::Transfers::GrantManagementAndFinanceUnitCsvExportService.new(projects).call + + send_data csv, filename: "#{year}-#{month}_grant_management_and_finance_unit_transfers_export.csv", type: :csv, disposition: "attachment" + end + + private def month + params[:month].to_i + end + + private def year + params[:year].to_i + end + + private def export_months + 12.times.map do |index| + Date.today.at_beginning_of_month - index.months + end + end +end diff --git a/app/views/all/export/grant_management_and_finance_unit/conversions/projects/index.html.erb b/app/views/all/export/grant_management_and_finance_unit/conversions/projects/index.html.erb index 13e666673..318abbbfd 100644 --- a/app/views/all/export/grant_management_and_finance_unit/conversions/projects/index.html.erb +++ b/app/views/all/export/grant_management_and_finance_unit/conversions/projects/index.html.erb @@ -2,24 +2,48 @@ <%= render partial: "shared/navigation/all_projects_primary_navigation" %> <% end %> -

<%= t("export.grant_management_and_finance_unit.conversions.index.title") %>

-

<%= t("export.grant_management_and_finance_unit.conversions.index.body") %>

+<% content_for :page_title do %> + <%= page_title(t("export.grant_management_and_finance_unit.conversions.index.title")) %> +<% end %> + +
+
+ +

+ <%= t("export.grant_management_and_finance_unit.conversions.index.title") %> +

+

<%= t("export.grant_management_and_finance_unit.conversions.index.body") %>

+ + - - - - - - - - - <% @months.each do |month| %> - - - - - <% end %> - -
<%= t("project.table.headers.date") %><%= t("project.table.headers.export") %>
<%= month.to_fs(:govuk_month) %> - <%= link_to t("project.table.body.export_for_html", date: month.to_fs(:govuk_month)), csv_all_export_grant_management_and_finance_unit_conversions_projects_path(month.month, month.year) %> -
+ + + + + + + + + + <% @data.each do |month| %> + "> + + + + + <% end %> + +
<%= t("project.table.headers.date") %><%= t("project.table.headers.number_of_conversions") %><%= t("project.table.headers.export") %>
<%= month[:month].to_fs(:govuk_month) %><%= month[:count] %> + <%= link_to t("project.table.body.export_for_html", date: month[:month].to_fs(:govuk_month)), show_all_export_grant_management_and_finance_unit_conversions_projects_path(month[:month].month, month[:month].year) %> +
+
+
diff --git a/app/views/all/export/grant_management_and_finance_unit/conversions/projects/show.html.erb b/app/views/all/export/grant_management_and_finance_unit/conversions/projects/show.html.erb new file mode 100644 index 000000000..67ca71100 --- /dev/null +++ b/app/views/all/export/grant_management_and_finance_unit/conversions/projects/show.html.erb @@ -0,0 +1,18 @@ +<% content_for :primary_navigation do %> + <%= render partial: "shared/navigation/all_projects_primary_navigation" %> +<% end %> + +<% content_for :page_title do %> + <%= page_title(t("export.grant_management_and_finance_unit.conversions.show.title", date: @month.to_fs(:govuk_month))) %> +<% end %> + +
+
+ <%= govuk_back_link(href: all_export_grant_management_and_finance_unit_conversions_projects_path) %> +

<%= t("export.grant_management_and_finance_unit.conversions.show.title", date: @month.to_fs(:govuk_month)) %>

+ <%= t("export.grant_management_and_finance_unit.conversions.show.body_html") %> +
+ <%= govuk_button_link_to t("export.funding_agreement_letters.show.button"), "/projects/all/export/grant-management-and-finance-unit/conversions/#{@month.month}/#{@month.year}/csv" %> +
+
+
diff --git a/app/views/all/export/grant_management_and_finance_unit/transfers/projects/index.html.erb b/app/views/all/export/grant_management_and_finance_unit/transfers/projects/index.html.erb new file mode 100644 index 000000000..e9ef7bd1b --- /dev/null +++ b/app/views/all/export/grant_management_and_finance_unit/transfers/projects/index.html.erb @@ -0,0 +1,49 @@ +<% content_for :primary_navigation do %> + <%= render partial: "shared/navigation/all_projects_primary_navigation" %> +<% end %> + +<% content_for :page_title do %> + <%= page_title(t("export.grant_management_and_finance_unit.transfers.index.title")) %> +<% end %> + +
+
+ +

+ <%= t("export.grant_management_and_finance_unit.transfers.index.title") %> +

+

<%= t("export.grant_management_and_finance_unit.transfers.index.body") %>

+ + + + + + + + + + + + + <% @data.each do |month| %> + "> + + + + + <% end %> + +
<%= t("project.table.headers.date") %><%= t("project.table.headers.number_of_transfers") %><%= t("project.table.headers.export") %>
<%= month[:month].to_fs(:govuk_month) %><%= month[:count] %> + <%= link_to t("project.table.body.export_for_html", date: month[:month].to_fs(:govuk_month)), show_all_export_grant_management_and_finance_unit_transfers_projects_path(month[:month].month, month[:month].year) %> +
+
+
diff --git a/app/views/all/export/grant_management_and_finance_unit/transfers/projects/show.html.erb b/app/views/all/export/grant_management_and_finance_unit/transfers/projects/show.html.erb new file mode 100644 index 000000000..ba6c8a27f --- /dev/null +++ b/app/views/all/export/grant_management_and_finance_unit/transfers/projects/show.html.erb @@ -0,0 +1,18 @@ +<% content_for :primary_navigation do %> + <%= render partial: "shared/navigation/all_projects_primary_navigation" %> +<% end %> + +<% content_for :page_title do %> + <%= page_title(t("export.grant_management_and_finance_unit.transfers.show.title", date: @month.to_fs(:govuk_month))) %> +<% end %> + +
+
+ <%= govuk_back_link(href: all_export_grant_management_and_finance_unit_transfers_projects_path) %> +

<%= t("export.grant_management_and_finance_unit.transfers.show.title", date: @month.to_fs(:govuk_month)) %>

+ <%= t("export.grant_management_and_finance_unit.transfers.show.body_html") %> +
+ <%= govuk_button_link_to t("export.funding_agreement_letters.show.button"), "/projects/all/export/grant-management-and-finance-unit/transfers/#{@month.month}/#{@month.year}/csv" %> +
+
+
diff --git a/app/views/all/export/projects/index.html.erb b/app/views/all/export/projects/index.html.erb index fd32990d4..751ec67e9 100644 --- a/app/views/all/export/projects/index.html.erb +++ b/app/views/all/export/projects/index.html.erb @@ -28,5 +28,6 @@

<%= t("export.landing_page.transfers.title") %>

<%= t("export.landing_page.transfers.body") %>

<%= t("export.landing_page.transfers.academies_due_to_transfer_html", link: all_export_by_month_transfers_projects_path) %>

+

<%= t("export.landing_page.transfers.grant_management_html", link: all_export_grant_management_and_finance_unit_transfers_projects_path) %>

diff --git a/config/locales/en.yml b/config/locales/en.yml index e19c9c6e4..ea95a34ea 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -101,6 +101,8 @@ en: revised: Revised date active_users: Active users inactive_users: Inactive users + conversions: Conversions + transfers: Transfers pages: academies_api_client_timeout: title: Sorry, there was a problem diff --git a/config/locales/export/grant_management_and_finance_unit_csv_export.en.yml b/config/locales/export/grant_management_and_finance_unit_csv_export.en.yml index 6ca1d87ee..c74053ebd 100644 --- a/config/locales/export/grant_management_and_finance_unit_csv_export.en.yml +++ b/config/locales/export/grant_management_and_finance_unit_csv_export.en.yml @@ -4,7 +4,29 @@ en: conversions: index: title: Grant management and finance unit exports - body: Conversions by Advisory board date + body: Check which projects were approved at each advisory board meeting. + show: + title: "%{date} Grants Management and Finance Unit export" + body_html: +

This export contains data to help you process pre-opening grants for new academies, including:

+
    +
  • converter grant
  • +
  • sponsored grant (fast track, intermediate or full sponsored)
  • +
+

It can take a little time to create these files. Thank you for your patience.

+ transfers: + index: + title: Grant management and finance unit exports + body: Check which projects were approved at each advisory board meeting. + show: + title: "%{date} Grants Management and Finance Unit export" + body_html: +

This export contains data to help you process pre-opening grants for transferring academies, including:

+
    +
  • standard transfer support grant element
  • +
  • academy transfer grant fund (fast track, intermediate or full sponsored)
  • +
+

It can take a little time to create these files. Thank you for your patience.

show: title: "%{date} grant management and funding unit export" body_html: diff --git a/config/locales/export/landing_page.en.yml b/config/locales/export/landing_page.en.yml index 6087a77b0..e91772be7 100644 --- a/config/locales/export/landing_page.en.yml +++ b/config/locales/export/landing_page.en.yml @@ -13,3 +13,4 @@ en: title: Transfer project data body: View tables and download spreadsheets that show information about transfers. academies_due_to_transfer_html: You can check which academies are due to transfer in an particular month. + grant_management_html: You can get information pre-opening grants for transferring academies. diff --git a/config/locales/project.en.yml b/config/locales/project.en.yml index bb953a32d..a09714330 100644 --- a/config/locales/project.en.yml +++ b/config/locales/project.en.yml @@ -198,6 +198,8 @@ en: confirmed_transfer_date: Confirmed transfer date revised_transfer_date: Revised transfer date all_transfers: All transfers + number_of_conversions: Number of conversions + number_of_transfers: Number of transfers body: type_name: conversion_project: Conversion diff --git a/config/routes.rb b/config/routes.rb index b61b65771..fb3ea165f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -155,6 +155,11 @@ get ":month/:year", to: "projects#show", constraints: {month: MONTH_1_12_REGEX, year: YEAR_2000_2499_REGEX}, as: :show get ":month/:year/csv", to: "projects#csv", constraints: {month: MONTH_1_12_REGEX, year: YEAR_2000_2499_REGEX}, as: :csv end + namespace :transfers do + get "/", to: "projects#index" + get ":month/:year", to: "projects#show", constraints: {month: MONTH_1_12_REGEX, year: YEAR_2000_2499_REGEX}, as: :show + get ":month/:year/csv", to: "projects#csv", constraints: {month: MONTH_1_12_REGEX, year: YEAR_2000_2499_REGEX}, as: :csv + end end namespace :by_month, path: "by-month" do namespace :transfers do diff --git a/spec/features/all_projects/export/grant_management_and_finance_users_can_export_download_spec.rb b/spec/features/all_projects/export/grant_management_and_finance_users_can_export_download_spec.rb index 6f4a13b8e..863bff360 100644 --- a/spec/features/all_projects/export/grant_management_and_finance_users_can_export_download_spec.rb +++ b/spec/features/all_projects/export/grant_management_and_finance_users_can_export_download_spec.rb @@ -1,26 +1,95 @@ require "rails_helper" RSpec.feature "Grant management and finance unit users can export projects by Advisory board date" do - scenario "they can view the last year in months" do + before do user = create(:user) sign_in_with_user(user) - visit all_export_grant_management_and_finance_unit_conversions_projects_path + mock_all_academies_api_responses + end + + context "conversions" do + scenario "they can view the last year in months" do + visit all_export_grant_management_and_finance_unit_conversions_projects_path + + expect(page).to have_content(Date.today.to_fs(:govuk_month)) + expect(page).to have_content((Date.today - 1.month).to_fs(:govuk_month)) + expect(page).to have_content((Date.today - 11.months).to_fs(:govuk_month)) + end + + scenario "the list of months still works on a leap year & in February" do + travel_to(Time.zone.local(2024, 3, 1, 1, 0, 0)) + + visit all_export_grant_management_and_finance_unit_conversions_projects_path + + expect(page).to have_content("March 2024") + expect(page).to have_content("February 2024") + expect(page).to have_content("January 2024") + expect(page).to have_content("April 2023") + travel_back + end + + scenario "they can see the counts for each month" do + _this_month_project = create(:conversion_project, advisory_board_date: Date.today.at_beginning_of_month, significant_date_provisional: false) + _last_month_project = create(:conversion_project, advisory_board_date: (Date.today - 1.month).at_beginning_of_month, significant_date_provisional: false) + + visit all_export_grant_management_and_finance_unit_conversions_projects_path + + this_month_row = page.find("##{Date.today.at_beginning_of_month.to_fs(:govuk_month).tr(" ", "_")}") + expect(this_month_row).to have_css("td.govuk-table__cell", text: "1") + + last_month_row = page.find("##{(Date.today - 1.month).at_beginning_of_month.to_fs(:govuk_month).tr(" ", "_")}") + expect(last_month_row).to have_css("td.govuk-table__cell", text: "1") + end + + scenario "they can download a CSV for each month of the last year" do + visit all_export_grant_management_and_finance_unit_conversions_projects_path - expect(page).to have_content(Date.today.to_fs(:govuk_month)) - expect(page).to have_content((Date.today - 1.month).to_fs(:govuk_month)) - expect(page).to have_content((Date.today - 11.months).to_fs(:govuk_month)) + expect(page).to have_link("Export for #{Date.today.to_fs(:govuk_month)}") + expect(page).to have_link("Export for #{(Date.today - 1.month).to_fs(:govuk_month)}") + expect(page).to have_link("Export for #{(Date.today - 11.months).to_fs(:govuk_month)}") + + click_on "Export for #{Date.today.to_fs(:govuk_month)}" + expect(page).to have_content("#{Date.today.to_fs(:govuk_month)} Grants Management and Finance Unit export") + + click_on "Download csv file" + expect(page.response_headers["Content-Disposition"]).to include("#{Date.today.year}-#{Date.today.month}_grant_management_and_finance_unit_conversions_export.csv") + end end - scenario "they can download a CSV for each month of the last year" do - user = create(:user) - sign_in_with_user(user) - visit all_export_grant_management_and_finance_unit_conversions_projects_path + context "transfers" do + scenario "they can view the last year in months" do + visit all_export_grant_management_and_finance_unit_transfers_projects_path + + expect(page).to have_content(Date.today.to_fs(:govuk_month)) + expect(page).to have_content((Date.today - 1.month).to_fs(:govuk_month)) + expect(page).to have_content((Date.today - 11.months).to_fs(:govuk_month)) + end + + scenario "they can see the counts for each month" do + _this_month_project = create(:transfer_project, advisory_board_date: Date.today.at_beginning_of_month, significant_date_provisional: false) + _last_month_project = create(:transfer_project, advisory_board_date: (Date.today - 1.month).at_beginning_of_month, significant_date_provisional: false) + + visit all_export_grant_management_and_finance_unit_transfers_projects_path + + this_month_row = page.find("##{Date.today.at_beginning_of_month.to_fs(:govuk_month).tr(" ", "_")}") + expect(this_month_row).to have_css("td.govuk-table__cell", text: "1") + + last_month_row = page.find("##{(Date.today - 1.month).at_beginning_of_month.to_fs(:govuk_month).tr(" ", "_")}") + expect(last_month_row).to have_css("td.govuk-table__cell", text: "1") + end + + scenario "they can download a CSV for each month of the last year" do + visit all_export_grant_management_and_finance_unit_transfers_projects_path + + expect(page).to have_link("Export for #{Date.today.to_fs(:govuk_month)}") + expect(page).to have_link("Export for #{(Date.today - 1.month).to_fs(:govuk_month)}") + expect(page).to have_link("Export for #{(Date.today - 11.months).to_fs(:govuk_month)}") - expect(page).to have_link("Export for #{Date.today.to_fs(:govuk_month)}") - expect(page).to have_link("Export for #{(Date.today - 1.month).to_fs(:govuk_month)}") - expect(page).to have_link("Export for #{(Date.today - 11.months).to_fs(:govuk_month)}") + click_on "Export for #{Date.today.to_fs(:govuk_month)}" + expect(page).to have_content("#{Date.today.to_fs(:govuk_month)} Grants Management and Finance Unit export") - click_on "Export for #{Date.today.to_fs(:govuk_month)}" - expect(page.response_headers["Content-Disposition"]).to include("#{Date.today.year}-#{Date.today.month}_grant_management_and_finance_unit_conversions_export.csv") + click_on "Download csv file" + expect(page.response_headers["Content-Disposition"]).to include("#{Date.today.year}-#{Date.today.month}_grant_management_and_finance_unit_transfers_export.csv") + end end end