Skip to content

Commit

Permalink
Set some basic rules and apply autocorrections
Browse files Browse the repository at this point in the history
  • Loading branch information
scruti committed Jun 18, 2024
1 parent 9e85874 commit 7fe70ee
Show file tree
Hide file tree
Showing 269 changed files with 1,433 additions and 1,385 deletions.
11 changes: 11 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,14 @@ Metrics/PerceivedComplexity:
Max: 18 # Default 8
Exclude:
- "spec/**/*"

##
# Testing Rules
FactoryBot/AssociationStyle:
EnforcedStyle: explicit

RSpec/NamedSubject:
Enabled: false

RSpec/AnyInstance:
Enabled: false
4 changes: 2 additions & 2 deletions spec/components/card_component_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require "rails_helper"

RSpec.describe CardComponent, type: :component do
let(:kwargs) { {} }

subject! { render_inline(described_class.new(**kwargs)) }

let(:kwargs) { {} }

it_behaves_like "a component that accepts custom classes"
it_behaves_like "a component that accepts custom HTML attributes"

Expand Down
16 changes: 8 additions & 8 deletions spec/components/dashboard_component_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
require "rails_helper"

RSpec.describe DashboardComponent, type: :component do
let(:publisher) { create(:publisher) }
let(:sort) { Publishers::VacancySort.new(organisation, selected_type).update(sort_by: "job_title") }
let(:selected_type) { "published" }
let(:publisher_preference) { create(:publisher_preference, publisher: publisher, organisation: organisation) }

subject do
described_class.new(
organisation: organisation, sort: sort, selected_type: selected_type, publisher_preference: publisher_preference,
)
end

let(:publisher) { create(:publisher) }
let(:sort) { Publishers::VacancySort.new(organisation, selected_type).update(sort_by: "job_title") }
let(:selected_type) { "published" }
let(:publisher_preference) { create(:publisher_preference, publisher: publisher, organisation: organisation) }

context "when organisation has no active vacancies" do
let(:organisation) { create(:school, name: "A school with no published or draft jobs") }
let!(:vacancy) { create(:vacancy, :trashed, organisations: [organisation]) }
Expand Down Expand Up @@ -141,7 +141,7 @@
end

it "does not render the link to view applicants" do
expect(page).not_to have_content(I18n.t("jobs.manage.view_applicants", count: 1))
expect(page).to have_no_content(I18n.t("jobs.manage.view_applicants", count: 1))
end

it "renders the local authority's name in the table" do
Expand Down Expand Up @@ -186,7 +186,7 @@

it "renders plain text of 0 applicants" do
expect(page).to have_content(I18n.t("jobs.manage.view_applicants", count: 0))
expect(page).not_to have_link(href: Rails.application.routes.url_helpers.organisation_job_job_applications_path(vacancy.id))
expect(page).to have_no_link(href: Rails.application.routes.url_helpers.organisation_job_job_applications_path(vacancy.id))
end
end
end
Expand All @@ -209,7 +209,7 @@
end

it "does not render the vacancy in Cambridge" do
expect(page).not_to have_content(vacancy_cambridge.job_title)
expect(page).to have_no_content(vacancy_cambridge.job_title)
end
end

Expand Down
10 changes: 5 additions & 5 deletions spec/components/detail_component_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require "rails_helper"

RSpec.describe DetailComponent, type: :component do
subject! { render_inline(described_class.new(**kwargs)) }

let(:title) { "Detail title" }
let(:kwargs) { { title: title } }

subject! { render_inline(described_class.new(**kwargs)) }

it_behaves_like "a component that accepts custom classes"
it_behaves_like "a component that accepts custom HTML attributes"

Expand All @@ -22,21 +22,21 @@

it "renders the detail without a title" do
expect(page).to have_css("div", class: "detail-component") do |detail|
expect(detail).not_to have_css("div", class: "govuk-summary-card__title")
expect(detail).to have_no_css("div", class: "govuk-summary-card__title")
end
end
end

context "when body and action slots are not defined" do
it "renders the detail without body" do
expect(page).to have_css("div", class: "detail-component") do |detail|
expect(detail).not_to have_css("div", class: "govuk-summary-card__content")
expect(detail).to have_no_css("div", class: "govuk-summary-card__content")
end
end

it "renders the detail without actions" do
expect(page).to have_css("div", class: "detail-component") do |detail|
expect(detail).not_to have_css("div", class: "govuk-summary-card__action")
expect(detail).to have_no_css("div", class: "govuk-summary-card__action")
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion spec/components/editor_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
subject! do
render_inline(described_class.new(**kwargs))
end

it "renders label text" do
expect(page).to have_css("label[for=#{field_name}-field]", class: "govuk-label", text: label[:text])
end
Expand All @@ -41,10 +42,12 @@
end

context "when hint is not defined" do
let(:hint) { "" }
subject! do
render_inline(described_class.new(**kwargs))
end

let(:hint) { "" }

it "renders a default hint text" do
expect(page).to have_css("div", class: "govuk-hint", text: "You can copy and paste bullet points into the text box.")
end
Expand Down
6 changes: 3 additions & 3 deletions spec/components/empty_section_component_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require "rails_helper"

RSpec.describe EmptySectionComponent, type: :component do
subject! { render_inline(described_class.new(**kwargs)) }

let(:title) { "A lovely title" }
let(:kwargs) { { title: title } }

subject! { render_inline(described_class.new(**kwargs)) }

it_behaves_like "a component that accepts custom classes"
it_behaves_like "a component that accepts custom HTML attributes"

Expand All @@ -20,7 +20,7 @@

it "renders the empty section without a title" do
expect(page).to have_css("div", class: "empty-section-component") do |section|
expect(section).not_to have_css("h3", class: "govuk-heading-m")
expect(section).to have_no_css("h3", class: "govuk-heading-m")
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/components/environment_banner_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
let(:app_role) { "production" }

it "does not render" do
expect(subject.render?).to eq(false)
expect(subject.render?).to be(false)
end
end

context "when app_role is unknown" do
let(:app_role) { "unknown" }

it "does not render" do
expect(subject.render?).to eq(false)
expect(subject.render?).to be(false)
end
end

context "when app_role is anything else" do
let(:app_role) { "wow" }

it "renders" do
expect(subject.render?).to eq(true)
expect(subject.render?).to be(true)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/components/filters_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@
end

context "when there are no selected filters" do
let(:filters) { {} }
let(:options) { { remove_filter_links: true } }

subject! do
render_inline(described_class.new(**kwargs)) do |c|
c.with_remove_filter_links do |rb|
Expand All @@ -58,6 +55,9 @@
end
end

let(:filters) { {} }
let(:options) { { remove_filter_links: true } }

it "filters remove UI is not visible" do
expect(subject.css(".filters-component__remove").to_html).to be_blank
end
Expand Down
4 changes: 2 additions & 2 deletions spec/components/job_application_review_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

it "does not render a task list by default" do
render_inline(component)
expect(page).not_to have_css("ul.review-component__sections")
expect(page).to have_no_css("ul.review-component__sections")
end

context "if sections are provided" do
Expand Down Expand Up @@ -59,7 +59,7 @@

it "does not render the 'train tracks' component" do
render_inline(component)
expect(page).not_to have_css(".steps-component")
expect(page).to have_no_css(".steps-component")
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
it "does not render the list by default" do
render_inline(component)

expect(page).not_to have_css(".govuk-summary-list")
expect(page).to have_no_css(".govuk-summary-list")
end

context "when rows are defined" do
Expand Down
10 changes: 5 additions & 5 deletions spec/components/map_component_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "rails_helper"

RSpec.describe MapComponent, type: :component do
subject! { render_inline(described_class.new(**kwargs)) }

let(:kwargs) { { markers: markers } }
let(:markers) do
[
Expand All @@ -12,16 +14,14 @@
]
end

subject! { render_inline(described_class.new(**kwargs)) }

it_behaves_like "a component that accepts custom classes"
it_behaves_like "a component that accepts custom HTML attributes"

context "renders map component" do
it "renders a list of markers" do
expect(page).to have_selector("div[data-map-target='marker'][data-point=GeoJSONPoint]")
expect(page).to have_selector("div[data-id='id']")
expect(page).to have_selector("div[data-parent-id='parent']")
expect(page).to have_css("div[data-map-target='marker'][data-point=GeoJSONPoint]")
expect(page).to have_css("div[data-id='id']")
expect(page).to have_css("div[data-parent-id='parent']")
end

it "renders a map container" do
Expand Down
8 changes: 4 additions & 4 deletions spec/components/navigation_list_component_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require "rails_helper"

RSpec.describe NavigationListComponent, type: :component do
subject! { render_inline(described_class.new(**kwargs)) }

let(:title) { "A title" }
let(:kwargs) { { title: title } }

subject! { render_inline(described_class.new(**kwargs)) }

it_behaves_like "a component that accepts custom classes"
it_behaves_like "a component that accepts custom HTML attributes"

Expand All @@ -22,7 +22,7 @@

it "does not render the title" do
expect(page).to have_css("div", class: "navigation-list-component") do |navigation|
expect(navigation).not_to have_css("h2", class: "govuk-heading-m")
expect(navigation).to have_no_css("h2", class: "govuk-heading-m")
end
end
end
Expand Down Expand Up @@ -53,7 +53,7 @@
context "when anchors are not defined" do
it "does not render the anchors" do
expect(page).to have_css("div", class: "navigation-list-component") do |navigation|
expect(navigation).not_to have_css("div", class: "navigation-list-component__anchors")
expect(navigation).to have_no_css("div", class: "navigation-list-component__anchors")
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/components/panel_component.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require "rails_helper"

RSpec.describe PanelComponent, type: :component do
let(:kwargs) { { button_text: "button-text", heading_text: "heading text" } }

subject! { render_inline(described_class.new(**kwargs)) }

let(:kwargs) { { button_text: "button-text", heading_text: "heading text" } }

it_behaves_like "a component that accepts custom classes"
it_behaves_like "a component that accepts custom HTML attributes"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

RSpec.describe ScheduledMaintenanceBannerComponent, type: :component do
describe "#render" do
subject(:component) { described_class.new(date:, start_time:, end_time:) }

RSpec.shared_examples "does not render" do
it "does not render" do
expect(component.render?).to eq(false)
expect(component.render?).to be(false)
end
end

subject(:component) { described_class.new(date:, start_time:, end_time:) }

let(:app_role) { "production" }
let(:date) { "5th October 2023" }
let(:start_time) { "8:00" }
Expand Down Expand Up @@ -53,7 +53,7 @@
let(:app_role) { "production" }

it "does render" do
expect(component.render?).to eq(true)
expect(component.render?).to be(true)
end
end
end
Expand Down
26 changes: 12 additions & 14 deletions spec/components/searchable_collection_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@

RSpec.describe SearchableCollectionComponent, type: :component do
let(:subject) { described_class.new(**base.merge!(options)) }

let(:form) { instance_double(GOVUKDesignSystemFormBuilder::FormBuilder) }
let(:collection) { [1, 2, 3, 4, 5].freeze }
let(:options) { {} }

let(:inline_component) { render_inline(subject) }

before do
allow(form).to receive(:govuk_collection_check_boxes)
end

let(:base) do
{
text: { aria_label: "search collection" },
Expand All @@ -24,15 +13,24 @@
collection_count: collection.count,
}
end

let(:kwargs) { { collection: collection, collection_count: collection.count } }

let(:form) { instance_double(GOVUKDesignSystemFormBuilder::FormBuilder) }
let(:collection) { [1, 2, 3, 4, 5].freeze }
let(:options) { {} }

let(:inline_component) { render_inline(subject) }

before do
allow(form).to receive(:govuk_collection_check_boxes)
end

it_behaves_like "a component that accepts custom classes"
it_behaves_like "a component that accepts custom HTML attributes"

context "when providing an item threshold higher in number than the collection size" do
it "is not searchable" do
expect(subject.searchable?).to be_falsey
expect(subject).not_to be_searchable
expect(inline_component.css(".searchable-collection-component__search")).to be_blank
expect(inline_component.css(".searchable-collection-component--border")).to be_blank
end
Expand All @@ -46,7 +44,7 @@
let(:options) { { options: { threshold: collection.size, border: true } } }

it "is searchable" do
expect(subject.searchable?).to be_truthy
expect(subject).to be_searchable
expect(inline_component.css(".searchable-collection-component__search").count).to eq(1)
expect(inline_component.css(".searchable-collection-component--border").count).to eq(1)
end
Expand Down
Loading

0 comments on commit 7fe70ee

Please sign in to comment.