Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
5.0 KiB

require "rails_helper"
RSpec.describe "form/page" do
let(:lettings_log) { FactoryBot.create(:lettings_log, :in_progress) }
let(:form) { lettings_log.form }
let(:subsection) { form.get_subsection("income_and_benefits") }
let(:page) { form.get_page("net_income") }
let(:question) { page.questions.find { |q| q.id == "earnings" } }
let(:initial_page_attributes) { { description: nil, hide_subsection_label: nil } }
let(:initial_question_attributes) { { type: "numeric", answer_options: nil, prefix: "£", suffix: " every week" } }
let(:page_attributes) { {} }
let(:question_attributes) { {} }
def assign_attributes(object, attrs)
attrs.each_pair do |attr, value|
object.public_send("#{attr}=", value)
end
end
CLDC-1917 Add Startdate Validation (#1378) * feat: add validation with feature flag, typo fix and update tests * feat: flip feature toggle * feat: update feature toggle name * feat: fix form handler inequality * refactor: linting * refactor: use between in form handler * feat: remove feature toggle * feat: add dynamic date to lettings log factory * feat: fix log_summary_component_spec.rb tests * feat: update lettings_log.rb and start fixing lettings_log_spec.rb * feat: fix more tests * feat: fix more tests * feat: fix lettings log import service * refactor: linting * feat: fix checkboxes_spec.rb * feat: fix interruption_screen_helper_spec.rb * feat: fix check_answers_helper_spec.rb * feat: fix page_routing_spec.rb * feat: fix lettings_logs_field_import_service_spec.rb * feat: fix lettings_log_spec.rb * feat: fix question_spec.rb * feat: fix lettings_logs_controller_spec.rb * feat: fix check_answers_page_lettings_logs_spec.rb * feat: fix tenancy_validations_spec.rb * feat: fix validations_spec.rb * feat: fix accessible_autocomplete_spec.rb * feat: fix form_navigation_spec.rb * feat: fix soft_validations_spec.rb * feat: fix lettings_log_export_service_spec.rb * feat: fix saving_data_spec.rb * feat: fix page_spec.rb * feat: fix form_controller_spec.rb * refactor: linting * feat: fix subsection_spec.rb * feat: fix lettings_log_spec.rb * feat: fix financial_validations_spec.rb * feat: fix tasklist_page_spec.rb * feat: fix conditional_questions_spec.rb * feat: fix form_page_error_helper_spec.rb and log_summary_component_spec.rb * feat: fix lettings_log_csv_service_spec.rb * feat: fix tasklist_helper_spec.rb * refactor: linting * refactor: linting * feat: fix lettings_log_spec.rb * refactor: linting * refactor: replace financial year with collection yaer * feat: respond to PR comments pt. 1 * feat: respond to PR comments pt. 2
2 years ago
around do |example|
Timecop.freeze(Time.zone.local(2022, 1, 1)) do
Singleton.__init__(FormHandler)
example.run
end
end
before do
assign(:log, lettings_log)
assign(:page, page)
assign(:subsection, subsection)
assign_attributes(page, page_attributes)
assign_attributes(question, question_attributes)
render
end
after do
# Revert any changes we've made to avoid affecting other specs as the form,
# subsection, page, question objects being acted on are in memory
assign_attributes(page, initial_page_attributes)
assign_attributes(question, initial_question_attributes)
end
context "with a page containing a description" do
let(:description) { "Test description <a class=\"govuk-link\" href=\"/test-link\">with link</a>." }
3 years ago
let(:page_attributes) { { description: } }
CLDC-2290 implement delete multiple logs story (#1657) * add a button to the logs list to delete multiple logs style and position of button helpers for displaying the button conditionally depending on user role and what filters and search are active * correct indentation from 4 spaces to 2 in view file * test appearance of delete logs button on index page for lettings logs * write a happy path feature test for the entire journey * create basic tests for the view component for listing logs to delete * create request tests for the GET delete-logs path * create request tests for the GET delete-logs-confirmation path * create request tests for the DELETE delete-logs path * comprehensive reworking after code review ensure that we are not passing lists of ids through params in the query string, risking overflowing the maximum URL length, adjust tests accordingly, do not attempt to reuse the same table for sales and lettings * alter config to allow creating controllers from the command line with associated spec files that matches how we test * extract controller methods and associated tests to do with the delete logs feature into their own controller, amend routes accordingly * implement same work for sales as for lettings * implement the story for lettings and sales logs under the organisation tab routing and controller methods testing for deleting sales logs, lettings or sales logs for an organisation move storage of relevant routes inside the form object as a comprehensive view model * merge the delete pages for lettings logs and sales logs, add to the tests for the lettings page to test sales specific content * minor refactor to delete logs controller: ensure session filters are only fetched from teh session when needed and extract discard logs method to private method * extract tables for lettings and sales to own partials * refactor delete logs controller after tech review improve the private method that builds the form object so that it has the flexibility to do so for all controller methods ensure that the search term is passed to the delete logs controller when navigating through the organisations tab ensure that noly logs for that organisation are displayed when navigating to delete logs through the organisations tab * remove unnecessary untested arguments * test new helper methods * implement dirty fiddle to get the checkboxes smaller and also not misaligned * ensure delete logs button is always visible on log lists when in the organisations tab * minor linting corrections * revert change, causing errors and outside the scope of this ticket * simplify tests for whether delete logs button appears on index page * replicate request specs from lettings for sales and organisations controllers * minor refactor of lettings log feature spec setup, replicate happy path for sales * minor refactors after rebasing onto Nat's work * temp * write tests for the delete logs form object * lint: add new line at end of file * respond to PO feedback the log id in the delte logs table should be a link to the log the delete logs button should be visible when the user is in a bulk upload journey updated associated tests
1 year ago
let(:expected_html) { "<p class=\"govuk-body govuk-body-m\">#{description}</p>" }
it "renders the description" do
expect(rendered).to match(expected_html)
end
end
context "with a page containing a header" do
it "renders the header and the subsection label" do
expect(rendered).to match(page.header)
expect(rendered).to match(subsection.label)
end
end
context "with a page containing a header and hide_subsection_label true" do
let(:page_attributes) { { hide_subsection_label: true } }
it "renders the header but not the subsection label" do
expect(rendered).to match(page.header)
expect(rendered).not_to match(subsection.label)
end
end
context "when rendering a numeric question with prefix and suffix" do
let(:question_attributes) { { type: "numeric", prefix: "£", suffix: "every week" } }
it "renders prefix and suffix text" do
expect(rendered).to match(/govuk-input__prefix/)
expect(rendered).to match(/£/)
expect(rendered).to match(/govuk-input__suffix/)
expect(rendered).to match("every week")
end
context "when the suffix is conditional and not a string" do
let(:question_attributes) do
{
type: "numeric",
prefix: "£",
suffix: [
{ "label": "every week", "depends_on": { "incfreq": "Weekly" } },
{ "label": "every month", "depends_on": { "incfreq": "Monthly" } },
{ "label": "every month", "depends_on": { "incfreq": "Yearly" } },
],
}
end
it "does not render the suffix" do
expect(rendered).not_to match(/govuk-input__suffix/)
expect(rendered).not_to match("every week")
expect(rendered).not_to match("every month")
expect(rendered).not_to match("every year")
end
end
end
context "with a question containing extra guidance" do
let(:expected_guidance) { /What counts as income?/ }
context "with radio type" do
let(:question_attributes) { { type: "radio", answer_options: { "1": "A", "2": "B" } } }
it "renders the guidance partial for radio questions" do
expect(rendered).to match(expected_guidance)
end
end
context "with text type" do
let(:question_attributes) { { type: "text", answer_options: nil } }
it "renders the guidance partial for text questions" do
expect(rendered).to match(expected_guidance)
end
end
context "with numeric type" do
let(:question_attributes) { { type: "numeric", answer_options: nil } }
it "renders the guidance partial for numeric questions" do
expect(rendered).to match(expected_guidance)
end
end
context "with select type" do
let(:question_attributes) { { type: "select", answer_options: { "1": "A", "2": "B" } } }
it "renders the guidance partial for select questions" do
expect(rendered).to match(expected_guidance)
end
end
context "with checkbox type" do
let(:question_attributes) { { type: "checkbox", answer_options: { "1": "A", "2": "B" } } }
it "renders the guidance partial for checkbox questions" do
expect(rendered).to match(expected_guidance)
end
end
context "with date type" do
let(:question_attributes) { { type: "date", answer_options: nil } }
it "renders the guidance partial for date questions" do
expect(rendered).to match(expected_guidance)
end
end
end
end