diff --git a/app/views/reports/selection_questions/summary.html.erb b/app/views/reports/selection_questions/summary.html.erb
index 93f287c6e..1343c0f93 100644
--- a/app/views/reports/selection_questions/summary.html.erb
+++ b/app/views/reports/selection_questions/summary.html.erb
@@ -1,5 +1,5 @@
<% set_page_title(t(".title")) %>
-<% content_for :back_link, govuk_back_link_to(report_features_path, t(".back_link")) %>
+<% content_for :back_link, govuk_back_link_to(report_features_path(tag: :live), t(".back_link")) %>
<%= t(".title") %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 61178485a..d4a9dcb7b 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1377,18 +1377,18 @@ en:
heading: Answer type usage
table_headings:
answer_type: Answer type
- number_of_forms: Number of live forms with this answer type
- number_of_pages: Number of uses of this answer type in live forms
+ number_of_forms: Number of %{tag} forms with this answer type
+ number_of_pages: Number of uses of this answer type in %{tag} forms
features:
+ forms_with_add_another_answer: "%{tag} forms with add another answer"
+ forms_with_csv_submission_enabled: "%{tag} forms with CSV submission enabled"
+ forms_with_payments: "%{tag} forms with payments"
+ forms_with_routes: "%{tag} forms with routes"
heading: Feature usage
- live_forms_with_add_another_answer: Live forms with add another answer
- live_forms_with_csv_submission_enabled: Live forms with CSV submission enabled
- live_forms_with_payments: Live forms with payments
- live_forms_with_routes: Live forms with routes
- total_live_forms: Total live forms
+ total_forms: Total %{tag} forms
long_list_usage:
title: Selection from a list of options feature usage in live forms
- title: Feature and answer type usage in live forms
+ title: Feature and answer type usage in %{tag} forms
form_or_questions_list_table:
headings:
form_name: Form name
@@ -1396,14 +1396,14 @@ en:
organisation: Organisation
question_text: Question text
forms_with_csv_submission_enabled:
- download_csv: Download data about all live forms with CSV submission enabled as a CSV file
- heading: Live forms with CSV submission enabled
+ download_csv: Download data about all %{tag} forms with CSV submission enabled as a CSV file
+ heading: "%{tag} forms with CSV submission enabled"
forms_with_payments:
- download_csv: Download data about all live forms with payments as a CSV file
- heading: Live forms with payments
+ download_csv: Download data about all %{tag} forms with payments as a CSV file
+ heading: "%{tag} forms with payments"
forms_with_routes:
- download_csv: Download data about all live forms with routes as a CSV file
- heading: Live forms with routes
+ download_csv: Download data about all %{tag} forms with routes as a CSV file
+ heading: "%{tag} forms with routes"
index:
title: Reports
last_signed_in_at:
@@ -1413,11 +1413,11 @@ en:
not_since_last_signed_in_at_added: People who last signed in sometime between 3 November 2023 and 4 November 2024
title: When users last signed in
questions_with_add_another_answer:
- download_csv: Download all questions with add another answer in live forms as a CSV file
- heading: Questions with add another answer in live forms
+ download_csv: Download all questions with add another answer in %{tag} forms as a CSV file
+ heading: Questions with add another answer in %{tag} forms
questions_with_answer_type:
- download_csv: Download all questions in live forms with this answer type as a CSV file
- heading: Live questions with %{answer_type} answer type
+ download_csv: Download all questions in %{tag} forms with this answer type as a CSV file
+ heading: "%{tag} questions with %{answer_type} answer type"
selection_questions:
autocomplete:
title: Questions where you can select one from over 30 options
diff --git a/config/routes.rb b/config/routes.rb
index 554cf79c7..5cdb36664 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -195,7 +195,7 @@
scope "/reports" do
get "/", to: "reports#index", as: :reports
- scope "/features" do
+ scope "/features/:tag", constraints: { tag: /(draft|live)/ } do
get "/", to: "reports#features", as: :report_features
get "/questions-with-answer-type/:answer_type", to: "reports#questions_with_answer_type", as: :report_questions_with_answer_type
get "/:report", constraints: Reports::FeatureReportService::Constraint, to: "reports#feature_report", as: :feature_report
diff --git a/spec/requests/reports_controller_spec.rb b/spec/requests/reports_controller_spec.rb
index 7fcdce372..71df3c13b 100644
--- a/spec/requests/reports_controller_spec.rb
+++ b/spec/requests/reports_controller_spec.rb
@@ -77,7 +77,7 @@
before do
login_as_standard_user
- get report_features_path
+ get report_features_path(tag: :live)
end
it "returns http code 403" do
@@ -93,7 +93,7 @@
before do
login_as_organisation_admin_user
- get report_features_path
+ get report_features_path(tag: :live)
end
it "returns http code 403" do
@@ -109,7 +109,7 @@
before do
login_as_super_admin_user
- get report_features_path
+ get report_features_path(tag: :live)
end
it "returns http code 200" do
@@ -135,7 +135,7 @@
before do
login_as_standard_user
- get report_questions_with_answer_type_path(answer_type: "email")
+ get report_questions_with_answer_type_path(tag: :live, answer_type: "email")
end
it "returns http code 403" do
@@ -151,7 +151,7 @@
before do
login_as_organisation_admin_user
- get report_questions_with_answer_type_path(answer_type: "email")
+ get report_questions_with_answer_type_path(tag: :live, answer_type: "email")
end
it "returns http code 403" do
@@ -167,7 +167,7 @@
before do
login_as_super_admin_user
- get report_questions_with_answer_type_path(answer_type: "email")
+ get report_questions_with_answer_type_path(tag: :live, answer_type: "email")
end
it "returns http code 200" do
@@ -193,7 +193,7 @@
before do
login_as_standard_user
- get feature_report_path(report: "questions-with-add-another-answer")
+ get feature_report_path(tag: :live, report: "questions-with-add-another-answer")
end
it "returns http code 403" do
@@ -209,7 +209,7 @@
before do
login_as_organisation_admin_user
- get feature_report_path(report: "questions-with-add-another-answer")
+ get feature_report_path(tag: :live, report: "questions-with-add-another-answer")
end
it "returns http code 403" do
@@ -225,7 +225,7 @@
before do
login_as_super_admin_user
- get feature_report_path(report: "questions-with-add-another-answer")
+ get feature_report_path(tag: :live, report: "questions-with-add-another-answer")
end
it "returns http code 200" do
@@ -251,7 +251,7 @@
before do
login_as_standard_user
- get feature_report_path(report: "forms-with-routes")
+ get feature_report_path(tag: :live, report: "forms-with-routes")
end
it "returns http code 403" do
@@ -267,7 +267,7 @@
before do
login_as_organisation_admin_user
- get feature_report_path(report: "forms-with-routes")
+ get feature_report_path(tag: :live, report: "forms-with-routes")
end
it "returns http code 403" do
@@ -283,7 +283,7 @@
before do
login_as_super_admin_user
- get feature_report_path(report: "forms-with-routes")
+ get feature_report_path(tag: :live, report: "forms-with-routes")
end
it "returns http code 200" do
@@ -309,7 +309,7 @@
before do
login_as_standard_user
- get feature_report_path(report: "forms-with-payments")
+ get feature_report_path(tag: :live, report: "forms-with-payments")
end
it "returns http code 403" do
@@ -325,7 +325,7 @@
before do
login_as_organisation_admin_user
- get feature_report_path(report: "forms-with-payments")
+ get feature_report_path(tag: :live, report: "forms-with-payments")
end
it "returns http code 403" do
@@ -341,7 +341,7 @@
before do
login_as_super_admin_user
- get feature_report_path(report: "forms-with-payments")
+ get feature_report_path(tag: :live, report: "forms-with-payments")
end
it "returns http code 200" do
@@ -367,7 +367,7 @@
before do
login_as_standard_user
- get feature_report_path(report: "forms-with-csv-submission-enabled")
+ get feature_report_path(tag: :live, report: "forms-with-csv-submission-enabled")
end
it "returns http code 403" do
@@ -383,7 +383,7 @@
before do
login_as_organisation_admin_user
- get feature_report_path(report: "forms-with-csv-submission-enabled")
+ get feature_report_path(tag: :live, report: "forms-with-csv-submission-enabled")
end
it "returns http code 403" do
@@ -399,7 +399,7 @@
before do
login_as_super_admin_user
- get feature_report_path(report: "forms-with-csv-submission-enabled")
+ get feature_report_path(tag: :live, report: "forms-with-csv-submission-enabled")
end
it "returns http code 200" do
@@ -736,7 +736,7 @@
travel_to Time.utc(2025, 5, 15, 15, 31, 57)
- get feature_report_path(report: "forms-with-routes", format: :csv)
+ get feature_report_path(tag: :live, report: "forms-with-routes", format: :csv)
end
it_behaves_like "csv response"
@@ -762,7 +762,7 @@
travel_to Time.utc(2025, 5, 15, 15, 31, 57)
- get feature_report_path(report: "forms-with-payments", format: :csv)
+ get feature_report_path(tag: :live, report: "forms-with-payments", format: :csv)
end
it_behaves_like "csv response"
@@ -787,7 +787,7 @@
travel_to Time.utc(2025, 5, 15, 15, 31, 57)
- get feature_report_path(report: "forms-with-csv-submission-enabled", format: :csv)
+ get feature_report_path(tag: :live, report: "forms-with-csv-submission-enabled", format: :csv)
end
it_behaves_like "csv response"
@@ -834,7 +834,7 @@
travel_to Time.utc(2025, 5, 15, 15, 31, 57)
- get feature_report_path(report: "questions-with-add-another-answer", format: :csv)
+ get feature_report_path(tag: :live, report: "questions-with-add-another-answer", format: :csv)
end
it_behaves_like "csv response"
diff --git a/spec/routing/reports_routing_spec.rb b/spec/routing/reports_routing_spec.rb
index 77ab3808d..be7b06a77 100644
--- a/spec/routing/reports_routing_spec.rb
+++ b/spec/routing/reports_routing_spec.rb
@@ -3,66 +3,82 @@
RSpec.describe ReportsController, type: :routing do
describe "feature reports" do
describe "routing" do
- it "routes to#features" do
- expect(get: "/reports/features").to route_to("reports#features")
+ %w[draft live].each do |tag|
+ context "with #{tag} tag" do
+ it "routes to#features for #{tag} forms" do
+ expect(get: "/reports/features/#{tag}").to route_to("reports#features", tag:)
+ end
+ end
end
- it "routes to questions_with_answer_type" do
- expect(get: "/reports/features/questions-with-answer-type/text").to route_to("reports#questions_with_answer_type", answer_type: "text")
+ it "routes to questions_with_answer_type for draft forms" do
+ expect(get: "/reports/features/draft/questions-with-answer-type/text").to route_to("reports#questions_with_answer_type", answer_type: "text", tag: "draft")
end
- it "routes to #feature_report with questions_with_add_another_answer" do
- expect(get: "/reports/features/questions-with-add-another-answer").to route_to("reports#feature_report", report: "questions-with-add-another-answer")
+ it "routes to questions_with_answer_type for live forms" do
+ expect(get: "/reports/features/live/questions-with-answer-type/text").to route_to("reports#questions_with_answer_type", answer_type: "text", tag: "live")
end
- it "routes to #feature_report with questions_with_add_another_answer and csv format" do
- expect(get: "/reports/features/questions-with-add-another-answer.csv").to route_to("reports#feature_report", report: "questions-with-add-another-answer", format: "csv")
+ it "does not route to questions_with_answer_type for invalid tag" do
+ expect(get: "/reports/features/foo/questions-with-answer-type/text").not_to route_to("reports#questions_with_answer_type", answer_type: "text", tag: "foo")
end
- it "routes to #feature_report with forms_with_routes" do
- expect(get: "/reports/features/forms-with-routes").to route_to("reports#feature_report", report: "forms-with-routes")
- end
+ %w[draft live].each do |tag|
+ context "with #{tag} tag" do
+ it "routes to #feature_report with questions_with_add_another_answer for #{tag} forms" do
+ expect(get: "/reports/features/#{tag}/questions-with-add-another-answer").to route_to("reports#feature_report", report: "questions-with-add-another-answer", tag:)
+ end
- it "routes to #feature_report with forms_with_routes and csv format" do
- expect(get: "/reports/features/forms-with-routes.csv").to route_to("reports#feature_report", report: "forms-with-routes", format: "csv")
- end
+ it "routes to #feature_report with questions_with_add_another_answer for #{tag} and csv format" do
+ expect(get: "/reports/features/#{tag}/questions-with-add-another-answer.csv").to route_to("reports#feature_report", report: "questions-with-add-another-answer", tag:, format: "csv")
+ end
- it "routes to #feature_report with forms_with_payments" do
- expect(get: "/reports/features/forms-with-payments").to route_to("reports#feature_report", report: "forms-with-payments")
- end
+ it "routes to #feature_report with forms_with_routes for #{tag} forms" do
+ expect(get: "/reports/features/#{tag}/forms-with-routes").to route_to("reports#feature_report", report: "forms-with-routes", tag:)
+ end
- it "routes to #feature_report with forms_with_payments and csv format" do
- expect(get: "/reports/features/forms-with-payments.csv").to route_to("reports#feature_report", report: "forms-with-payments", format: "csv")
- end
+ it "routes to #feature_report with forms_with_routes for #{tag} forms and csv format" do
+ expect(get: "/reports/features/#{tag}/forms-with-routes.csv").to route_to("reports#feature_report", report: "forms-with-routes", tag:, format: "csv")
+ end
- it "routes to #feature_report with forms_with_csv_submission_enabled" do
- expect(get: "/reports/features/forms-with-csv-submission-enabled").to route_to("reports#feature_report", report: "forms-with-csv-submission-enabled")
- end
+ it "routes to #feature_report with forms_with_payments for #{tag} forms" do
+ expect(get: "/reports/features/#{tag}/forms-with-payments").to route_to("reports#feature_report", report: "forms-with-payments", tag:)
+ end
- it "routes to #feature_report with forms_with_csv_submission_enabled and csv format" do
- expect(get: "/reports/features/forms-with-csv-submission-enabled.csv").to route_to("reports#feature_report", report: "forms-with-csv-submission-enabled", format: "csv")
- end
+ it "routes to #feature_report with forms_with_payments for #{tag} forms and csv format" do
+ expect(get: "/reports/features/#{tag}/forms-with-payments.csv").to route_to("reports#feature_report", report: "forms-with-payments", tag:, format: "csv")
+ end
+
+ it "routes to #feature_report with forms_with_csv_submission_enabled for #{tag} forms" do
+ expect(get: "/reports/features/#{tag}/forms-with-csv-submission-enabled").to route_to("reports#feature_report", report: "forms-with-csv-submission-enabled", tag:)
+ end
+
+ it "routes to #feature_report with forms_with_csv_submission_enabled for #{tag} forms and csv format" do
+ expect(get: "/reports/features/#{tag}/forms-with-csv-submission-enabled.csv").to route_to("reports#feature_report", report: "forms-with-csv-submission-enabled", tag:, format: "csv")
+ end
+ end
- it "does not route to #feature_report if param does not match defined report" do
- expect(get: "/reports/features/foobar").not_to route_to("reports#feature_report", report: "foobar")
+ it "does not route to #feature_report if param does not match defined report" do
+ expect(get: "/reports/features/foobar").not_to route_to("reports#feature_report", report: "foobar")
+ end
end
end
describe "path helpers" do
- it "routes to #questions_with_add_another_answer as csv" do
- expect(get: feature_report_path(report: "questions-with-add-another-answer", format: :csv)).to route_to("reports#feature_report", report: "questions-with-add-another-answer", format: "csv")
+ it "routes to #questions_with_add_another_answer for live forms as csv" do
+ expect(get: feature_report_path(report: "questions-with-add-another-answer", tag: :live, format: :csv)).to route_to("reports#feature_report", report: "questions-with-add-another-answer", tag: "live", format: "csv")
end
- it "routes to #forms_with_routes as csv" do
- expect(get: feature_report_path(report: "forms-with-routes", format: :csv)).to route_to("reports#feature_report", report: "forms-with-routes", format: "csv")
+ it "routes to #forms_with_routes for live forms as csv" do
+ expect(get: feature_report_path(report: "forms-with-routes", tag: :live, format: :csv)).to route_to("reports#feature_report", report: "forms-with-routes", tag: "live", format: "csv")
end
- it "routes to #forms_with_payments as csv" do
- expect(get: feature_report_path(report: "forms-with-payments", format: :csv)).to route_to("reports#feature_report", report: "forms-with-payments", format: "csv")
+ it "routes to #forms_with_payments for live forms as csv" do
+ expect(get: feature_report_path(report: "forms-with-payments", tag: :live, format: :csv)).to route_to("reports#feature_report", report: "forms-with-payments", tag: "live", format: "csv")
end
- it "routes to #forms_with_csv_submission_enabled as csv" do
- expect(get: feature_report_path(report: "forms-with-csv-submission-enabled", format: :csv)).to route_to("reports#feature_report", report: "forms-with-csv-submission-enabled", format: "csv")
+ it "routes to #forms_with_csv_submission_enabled for live forms as csv" do
+ expect(get: feature_report_path(report: "forms-with-csv-submission-enabled", tag: :live, format: :csv)).to route_to("reports#feature_report", report: "forms-with-csv-submission-enabled", tag: "live", format: "csv")
end
end
end
diff --git a/spec/services/reports/form_documents_service_spec.rb b/spec/services/reports/form_documents_service_spec.rb
index c4639a0fd..d64ac5227 100644
--- a/spec/services/reports/form_documents_service_spec.rb
+++ b/spec/services/reports/form_documents_service_spec.rb
@@ -1,39 +1,84 @@
require "rails_helper"
RSpec.describe Reports::FormDocumentsService do
- describe ".live_form_documents" do
+ describe ".form_documents" do
let(:form_documents_url) { "#{Settings.forms_api.base_url}/api/v2/form-documents".freeze }
# This response JSON was generated by making a real API request to forms-api with the data from the database seeds.
# Once we have transitioned to using the V2 API in forms-admin, it might make more sense to use factories to generate
# the response.
let(:form_documents_response_json) { file_fixture("form_documents_response.json").read }
+ let(:tag) { "live" }
before do
allow(Settings.reports).to receive(:forms_api_forms_per_request_page).and_return 4
stub_request(:get, form_documents_url)
- .with(query: { page: "1", per_page: "4", tag: "live" })
+ .with(query: { page: "1", per_page: "4", tag: })
.to_return(body: form_documents_response_json, headers: response_headers(12, 0, 4))
stub_request(:get, form_documents_url)
- .with(query: { page: "2", per_page: "4", tag: "live" })
+ .with(query: { page: "2", per_page: "4", tag: })
.to_return(body: form_documents_response_json, headers: response_headers(12, 4, 4))
stub_request(:get, form_documents_url)
- .with(query: { page: "3", per_page: "4", tag: "live" })
+ .with(query: { page: "3", per_page: "4", tag: })
.to_return(body: form_documents_response_json, headers: response_headers(12, 8, 4))
end
- it "makes request to forms-api for each page of results" do
- form_documents = described_class.live_form_documents.to_a
- expect(form_documents.size).to eq(12)
- assert_requested(:get, form_documents_url, query: { page: "1", per_page: "4", tag: "live" }, headers:, times: 1)
- assert_requested(:get, form_documents_url, query: { page: "2", per_page: "4", tag: "live" }, headers:, times: 1)
- assert_requested(:get, form_documents_url, query: { page: "3", per_page: "4", tag: "live" }, headers:, times: 1)
+ context "with draft tag" do
+ let(:tag) { "draft" }
+
+ it "makes request to forms-api for each page of results" do
+ form_documents = described_class.form_documents(tag:).to_a
+ expect(form_documents.size).to eq(12)
+ assert_requested(:get, form_documents_url, query: { page: "1", per_page: "4", tag: "draft" }, headers:, times: 1)
+ assert_requested(:get, form_documents_url, query: { page: "2", per_page: "4", tag: "draft" }, headers:, times: 1)
+ assert_requested(:get, form_documents_url, query: { page: "3", per_page: "4", tag: "draft" }, headers:, times: 1)
+ end
+
+ it "returns form documents" do
+ form_document = described_class.form_documents(tag:).first
+ expect(form_document).to be_a(Hash)
+ expect(form_document).to have_key("form_id")
+ end
end
- it "returns form documents" do
- form_document = described_class.live_form_documents.first
- expect(form_document).to be_a(Hash)
- expect(form_document).to have_key("form_id")
+ context "with live tag" do
+ let(:tag) { :live }
+
+ it "makes request to forms-api for each page of results" do
+ form_documents = described_class.form_documents(tag:).to_a
+ expect(form_documents.size).to eq(12)
+ assert_requested(:get, form_documents_url, query: { page: "1", per_page: "4", tag: "live" }, headers:, times: 1)
+ assert_requested(:get, form_documents_url, query: { page: "2", per_page: "4", tag: "live" }, headers:, times: 1)
+ assert_requested(:get, form_documents_url, query: { page: "3", per_page: "4", tag: "live" }, headers:, times: 1)
+ end
+
+ it "returns form documents" do
+ form_document = described_class.form_documents(tag:).first
+ expect(form_document).to be_a(Hash)
+ expect(form_document).to have_key("form_id")
+ end
+
+ context "when there are forms from internal organisations" do
+ let(:organisation) { build :organisation, id: 1, internal: false }
+ let(:internal_organisation) { build :organisation, id: 1, internal: true }
+ let(:group) { build :group, id: 1, organisation: }
+ let(:internal_group) { build :group, id: 1, organisation: internal_organisation }
+ let(:group_form) { GroupForm.new(group:) }
+ let(:internal_group_form) { GroupForm.new(group: internal_group) }
+
+ before do
+ allow(GroupForm).to receive(:find_by_form_id).and_return(group_form)
+ allow(GroupForm).to receive(:find_by_form_id).with(3).and_return(internal_group_form)
+ end
+
+ it "does not include these forms in the live_form_documents output" do
+ form_documents = described_class.live_form_documents.to_a
+ expect(form_documents.size).to eq(9)
+
+ form_documents_with_internal_id = form_documents.filter { it["id"] == 3 }
+ expect(form_documents_with_internal_id).to be_empty
+ end
+ end
end
context "when forms-api responds with a non-success status code" do
@@ -44,7 +89,7 @@
end
it "raises a StandardError" do
- expect { described_class.live_form_documents.first }.to raise_error(
+ expect { described_class.form_documents(tag: "live").first }.to raise_error(
StandardError, "Forms API responded with a non-success HTTP code when retrieving form documents: status 400"
)
end
@@ -63,8 +108,8 @@
allow(GroupForm).to receive(:find_by_form_id).with(3).and_return(internal_group_form)
end
- it "does not include these forms in the live_form_documents output" do
- form_documents = described_class.live_form_documents.to_a
+ it "does not include these forms in the draft_form_documents output" do
+ form_documents = described_class.form_documents(tag: "live").to_a
expect(form_documents.size).to eq(9)
form_documents_with_internal_id = form_documents.filter { it["id"] == 3 }
diff --git a/spec/views/reports/feature_report.html.erb_spec.rb b/spec/views/reports/feature_report.html.erb_spec.rb
index 095b9b3f4..4afc71453 100644
--- a/spec/views/reports/feature_report.html.erb_spec.rb
+++ b/spec/views/reports/feature_report.html.erb_spec.rb
@@ -3,11 +3,13 @@
describe "reports/feature_report" do
let(:report) {}
let(:records) { [] }
+ let(:tag) { "live" }
before do
controller.request.path_parameters[:report] = report.dasherize
+ controller.request.path_parameters[:tag] = tag
- render locals: { report:, records: }
+ render locals: { tag:, report:, records: }
end
context "with forms_with_csv_submission_enabled report" do
@@ -22,6 +24,7 @@
describe "page title" do
it "matches the heading" do
expect(view.content_for(:title)).to eq "Live forms with CSV submission enabled"
+ expect(rendered).to have_css "h1", text: view.content_for(:title)
end
end
@@ -68,6 +71,7 @@
describe "page title" do
it "matches the heading" do
expect(view.content_for(:title)).to eq "Live forms with payments"
+ expect(rendered).to have_css "h1", text: view.content_for(:title)
end
end
@@ -114,6 +118,7 @@
describe "page title" do
it "matches the heading" do
expect(view.content_for(:title)).to eq "Live forms with routes"
+ expect(rendered).to have_css "h1", text: view.content_for(:title)
end
end
@@ -163,6 +168,7 @@
describe "page title" do
it "matches the heading" do
expect(view.content_for(:title)).to eq "Questions with add another answer in live forms"
+ expect(rendered).to have_css "h1", text: view.content_for(:title)
end
end
diff --git a/spec/views/reports/features.html.erb_spec.rb b/spec/views/reports/features.html.erb_spec.rb
index e1976b111..6b426e469 100644
--- a/spec/views/reports/features.html.erb_spec.rb
+++ b/spec/views/reports/features.html.erb_spec.rb
@@ -34,9 +34,12 @@
forms_with_csv_submission_enabled: 2,
}
end
+ let(:tag) { "live" }
before do
- render template: "reports/features", locals: { data: report }
+ controller.request.path_parameters[:tag] = tag
+
+ render template: "reports/features", locals: { tag:, data: report }
end
describe "page title" do
@@ -57,6 +60,16 @@
expect(rendered).to have_css(".govuk-summary-list__row", text: "Total live forms#{report[:total_forms]}")
end
+ it "has a table of answer type usage" do
+ expect(rendered).to have_table "Answer type usage" do |table|
+ expect(table.find_all("thead th").map(&:text)).to eq [
+ "Answer type",
+ "Number of live forms with this answer type",
+ "Number of uses of this answer type in live forms",
+ ]
+ end
+ end
+
Page::ANSWER_TYPES.map(&:to_sym).each do |answer_type|
it "contains a heading for #{answer_type}" do
expect(rendered).to have_css("th", text: I18n.t("helpers.label.page.answer_type_options.names.#{answer_type}"))
@@ -108,4 +121,18 @@
it "includes the number of live forms with CSV submission enabled" do
expect(rendered).to have_css(".govuk-summary-list__row", text: "Live forms with CSV submission enabled#{report[:forms_with_csv_submission_enabled]}")
end
+
+ context "with live tag" do
+ it "has a link to the selection questions summary report" do
+ expect(rendered).to have_link href: report_selection_questions_summary_path
+ end
+ end
+
+ context "with draft tag" do
+ let(:tag) { "draft" }
+
+ it "does not have a link to the selection questions summary report" do
+ expect(rendered).not_to have_link href: report_selection_questions_summary_path
+ end
+ end
end
diff --git a/spec/views/reports/index.html.erb_spec.rb b/spec/views/reports/index.html.erb_spec.rb
index 0d8edd0f4..52f94be33 100644
--- a/spec/views/reports/index.html.erb_spec.rb
+++ b/spec/views/reports/index.html.erb_spec.rb
@@ -16,6 +16,6 @@
end
it "includes a link to the features report" do
- expect(rendered).to have_link("Feature and answer type usage in live forms", href: report_features_path)
+ expect(rendered).to have_link("Feature and answer type usage in live forms", href: report_features_path(tag: :live))
end
end
diff --git a/spec/views/reports/questions_with_answer_type.html.erb_spec.rb b/spec/views/reports/questions_with_answer_type.html.erb_spec.rb
index 1c72a4add..def3ea1f3 100644
--- a/spec/views/reports/questions_with_answer_type.html.erb_spec.rb
+++ b/spec/views/reports/questions_with_answer_type.html.erb_spec.rb
@@ -7,14 +7,18 @@
{ "data" => { "question_text" => "What’s your email address?" }, "form" => { "form_id" => 3, "content" => { "name" => "Branch route form" }, "group" => { "organisation" => { "name" => "Government Digital Service" } } } },
]
end
+ let(:tag) { "live" }
before do
- render locals: { answer_type: "email", questions: }
+ controller.request.path_parameters[:tag] = tag
+
+ render locals: { tag:, answer_type: "email", questions: }
end
describe "page title" do
it "matches the heading" do
expect(view.content_for(:title)).to eq "Live questions with email address answer type"
+ expect(rendered).to have_css "h1", text: view.content_for(:title)
end
end
diff --git a/spec/views/reports/selection_questions/summary.html.erb_spec.rb b/spec/views/reports/selection_questions/summary.html.erb_spec.rb
index b3a440c91..7010a291a 100644
--- a/spec/views/reports/selection_questions/summary.html.erb_spec.rb
+++ b/spec/views/reports/selection_questions/summary.html.erb_spec.rb
@@ -30,7 +30,7 @@
end
it "has a back link to the selection from a list of options usage report" do
- expect(view.content_for(:back_link)).to have_link("Back to feature usage", href: report_features_path)
+ expect(view.content_for(:back_link)).to have_link("Back to feature usage", href: report_features_path(tag: :live))
end
it "has statistics about questions with autocomplete" do