-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4090 from alphagov/rspec-conversion-test
Convert Frontend Test Runner from Minitest to RSpec
- Loading branch information
Showing
176 changed files
with
6,915 additions
and
7,687 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
RSpec.describe "AllComponents" do | ||
Dir.glob("app/views/components/*.erb").each do |filename| | ||
template = filename.split("/").last | ||
component_name = template.sub("_", "").sub(".html", "").sub(".erb", "").gsub("-", "_") | ||
|
||
describe(component_name) do | ||
yaml_file = "#{__dir__}/../../app/views/components/docs/#{component_name}.yml" | ||
|
||
it "is documented" do | ||
expect(File).to exist(yaml_file) | ||
end | ||
|
||
it "has the correct documentation" do | ||
yaml = YAML.safe_load_file(yaml_file, permitted_classes: [Time]) | ||
expect(yaml["name"]).not_to be_empty | ||
expect(yaml["description"]).not_to be_empty | ||
expect(yaml["examples"]).not_to be_empty | ||
expect((yaml["accessibility_criteria"] or yaml["shared_accessibility_criteria"])).to be_truthy | ||
end | ||
|
||
it "has the correct class in the ERB template" do | ||
erb = File.read(filename) | ||
class_name = "app-c-#{component_name.dasherize}" | ||
expect(erb).to include(class_name) | ||
end | ||
|
||
it "has a correctly named template file" do | ||
template_file = "#{__dir__}/../../app/views/components/_#{component_name}.html.erb" | ||
expect(File).to exist(template_file) | ||
end | ||
|
||
it "has a correctly named spec file" do | ||
rspec_file = "#{__dir__}/../../spec/components/#{component_name.tr('-', '_')}_spec.rb" | ||
expect(File).to exist(rspec_file) | ||
end | ||
|
||
it "has a correctly named SCSS file" do | ||
css_file = "#{__dir__}/../../app/assets/stylesheets/components/_#{component_name.tr('_', '-')}.scss" | ||
expect(File).to exist(css_file) | ||
end | ||
|
||
it "does not use `html_safe` in it's partial" do | ||
file = File.read(filename) | ||
expect(file).not_to include("html_safe") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
RSpec.describe "CalendarComponent", type: :view do | ||
def component_name | ||
"calendar" | ||
end | ||
|
||
it "renders the basic component" do | ||
render_component({}) | ||
|
||
expect(rendered).to have_css(".app-c-calendar") | ||
end | ||
|
||
it "renders the component with correct data passed" do | ||
render_component( | ||
title: "Marvel films", | ||
year: "2008 onwards", | ||
headings: [ | ||
{ text: "Date" }, | ||
{ text: "Day of the week" }, | ||
{ text: "Film" }, | ||
], | ||
events: [ | ||
{ | ||
title: "Iron Man", | ||
date: Date.parse("2-5-2008"), | ||
notes: "first film in the MCU", | ||
}, | ||
{ | ||
title: "The Incredible Hulk", | ||
date: Date.parse("13-6-2008"), | ||
notes: "", | ||
}, | ||
], | ||
) | ||
|
||
expect(rendered).to have_css(".govuk-table__caption .govuk-visually-hidden", text: "Marvel films") | ||
expect(rendered).to have_css(".govuk-table__caption", text: "Marvel films 2008 onwards") | ||
expect(rendered).to have_css(".govuk-table__head .govuk-table__header:nth-child(1)", text: "Date") | ||
expect(rendered).to have_css(".govuk-table__head .govuk-table__header:nth-child(2)", text: "Day of the week") | ||
expect(rendered).to have_css(".govuk-table__head .govuk-table__header:nth-child(3)", text: "Film") | ||
expect(rendered).to have_css(".govuk-table__row:nth-child(1) .govuk-table__header", text: "2 May") | ||
expect(rendered).to have_css(".govuk-table__row:nth-child(1) .govuk-table__cell:nth-child(2)", text: "Friday") | ||
expect(rendered).to have_css(".govuk-table__row:nth-child(1) .govuk-table__cell:nth-child(3)", text: "Iron Man (first film in the mcu)") | ||
expect(rendered).to have_css(".govuk-table__row:nth-child(2) .govuk-table__header", text: "13 June") | ||
expect(rendered).to have_css(".govuk-table__row:nth-child(2) .govuk-table__cell:nth-child(2)", text: "Friday") | ||
expect(rendered).to have_css(".govuk-table__row:nth-child(2) .govuk-table__cell:nth-child(3)", text: "The Incredible Hulk") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
RSpec.describe "SubscribeComponent", type: :view do | ||
def component_name | ||
"subscribe" | ||
end | ||
|
||
it "fails to render when no parameters given" do | ||
expect { render_component({}) }.to raise_error(ActionView::Template::Error) | ||
end | ||
|
||
it "renders the component when link data is passed" do | ||
render_component( | ||
label: "label", | ||
url: "https://www.gov.uk", | ||
title: "title", | ||
) | ||
|
||
expect(rendered).to have_css(".app-c-subscribe a[href='https://www.gov.uk'][title='title']", text: "label") | ||
end | ||
|
||
it "renders the component with data attributes" do | ||
render_component( | ||
label: "label", | ||
url: "https://www.gov.uk", | ||
title: "title", | ||
data: { | ||
module: "test-module", | ||
ok: "go", | ||
}, | ||
) | ||
|
||
expect(rendered).to have_css(".app-c-subscribe a[href='https://www.gov.uk'][title='title']", text: "label") | ||
expect(rendered).to have_css(".app-c-subscribe a[data-module='test-module'][data-ok='go']") | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
RSpec.describe ApplicationHelper do | ||
include ContentStoreHelpers | ||
|
||
def dummy_publication | ||
ContentItemPresenter.new(content_store_has_random_item(base_path: "/dummy")) | ||
end | ||
|
||
describe "#page_title" do | ||
it "doesn't contain consecutive pipes" do | ||
expect(page_title(dummy_publication)).not_to match(/\|\s*\|/) | ||
end | ||
|
||
it "doesn't fail if the publication titles are nil" do | ||
publication = OpenStruct.new(title: nil) | ||
|
||
expect(page_title(publication)).to be_truthy | ||
end | ||
end | ||
|
||
describe "#wrapper_class" do | ||
it "marks local transactions as a service" do | ||
local_transaction = OpenStruct.new(format: "local_transaction") | ||
|
||
expect(wrapper_class(local_transaction).split.include?("service")).to be true | ||
end | ||
end | ||
|
||
it "builds title from content items" do | ||
publication = OpenStruct.new(title: "Title") | ||
|
||
expect(page_title(publication)).to eq("Title - GOV.UK") | ||
end | ||
|
||
it "omits first part of title if publication is omitted" do | ||
expect(page_title).to eq("GOV.UK") | ||
end | ||
|
||
describe "#current_path_without_query_string" do | ||
it "returns the path of the current request" do | ||
allow(self).to receive(:request).and_return(ActionDispatch::TestRequest.new("PATH_INFO" => "/foo/bar")) | ||
|
||
expect(current_path_without_query_string).to eq("/foo/bar") | ||
end | ||
|
||
it "returns the path of the current request stripping off any query string parameters" do | ||
allow(self).to receive(:request).and_return(ActionDispatch::TestRequest.new("PATH_INFO" => "/foo/bar")) | ||
|
||
expect(current_path_without_query_string).to eq("/foo/bar") | ||
end | ||
end | ||
end |
Oops, something went wrong.