-
Notifications
You must be signed in to change notification settings - Fork 0
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 #28 from alphagov/tests
Move to RSpec
- Loading branch information
Showing
13 changed files
with
231 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,5 @@ | |
/config/master.key | ||
|
||
/node_modules | ||
|
||
/spec/examples.txt |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require "spec_helper" | ||
ENV["RAILS_ENV"] ||= "test" | ||
require_relative "../config/environment" | ||
abort("The Rails environment is running in production mode!") if Rails.env.production? | ||
require "rspec/rails" | ||
|
||
# We're using rack-test for simplicity, but we need to be able to find fields in <details> elements | ||
Capybara.ignore_hidden_elements = false | ||
|
||
RSpec.configure do |config| | ||
config.before(:each, type: :system) do | ||
# We don't have JS, so rack_test will suffice | ||
driven_by :rack_test | ||
end | ||
|
||
config.expect_with :rspec do |expectations| | ||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true | ||
end | ||
|
||
config.mock_with :rspec do |mocks| | ||
mocks.verify_partial_doubles = true | ||
end | ||
|
||
config.shared_context_metadata_behavior = :apply_to_host_groups | ||
|
||
config.filter_run_when_matching :focus | ||
config.disable_monkey_patching! | ||
config.example_status_persistence_file_path = "spec/examples.txt" | ||
config.order = :random | ||
Kernel.srand config.seed | ||
|
||
config.use_active_record = false | ||
|
||
config.infer_spec_type_from_file_location! | ||
config.filter_rails_from_backtrace! | ||
|
||
if config.files_to_run.one? | ||
# Use the documentation formatter for detailed output, | ||
# unless a formatter has already been configured | ||
# (e.g. via a command-line flag). | ||
config.default_formatter = "doc" | ||
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,155 @@ | ||
require "google/cloud/bigquery" | ||
|
||
RSpec.describe "Submitting feedback", type: :system do | ||
let(:search_service) { double("Search service", search:) } | ||
let(:search) do | ||
{ "results" => [ | ||
{ "content_id" => "3fc2d1a1-bc9b-4875-899a-54a1fd968175", | ||
"title" => "GDS blog", | ||
"link" => "https://gds.blog.gov.uk/", | ||
"content_purpose_supergroup" => "other", | ||
"_id" => "3fc2d1a1-bc9b-4875-899a-54a1fd968175", | ||
"description_with_highlighting" => | ||
"The Government Digital Service (GDS) blog about how the government is transforming digital public services.", | ||
"format" => "external_content", | ||
"public_timestamp" => "2017-12-21T09:45:01+00:00", | ||
"content_store_document_type" => "external_content", | ||
"is_historic" => false }, | ||
{ "content_id" => "af07d5a5-df63-4ddc-9383-6a666845ebe9", | ||
"title" => "Government Digital Service", | ||
"link" => "/government/organisations/government-digital-service", | ||
"content_purpose_supergroup" => "other", | ||
"_id" => "/government/organisations/government-digital-service", | ||
"description_with_highlighting" => | ||
"We are here to make digital government simpler, clearer and faster for everyone. GDS is part of the Cabinet Office .", | ||
"format" => "organisation", | ||
"public_timestamp" => "2023-08-08T17:10:39+01:00", | ||
"content_store_document_type" => "organisation", | ||
"is_historic" => false }, | ||
{ "content_id" => "27f58621-a0d0-44fc-8c3a-4548245c6079", | ||
"title" => "Government Digital Service IT platform privacy notice", | ||
"link" => "/government/publications/government-digital-service-it-platform-privacy-notice", | ||
"content_purpose_supergroup" => "guidance_and_regulation", | ||
"government_name" => "2015 Conservative government", | ||
"_id" => "/government/publications/government-digital-service-it-platform-privacy-notice", | ||
"description_with_highlighting" => | ||
"Find details here about the privacy policy for the Government Digital Service's internal IT platform, and how we collect and process your data. ", | ||
"format" => "guidance", | ||
"public_timestamp" => "2022-11-18T12:00:04+00:00", | ||
"content_store_document_type" => "guidance", | ||
"is_historic" => false }, | ||
], | ||
"total" => 28_766, | ||
"start" => 0 } | ||
end | ||
|
||
let(:bigquery) { double("BigQuery client", dataset: bigquery_dataset) } | ||
let(:bigquery_dataset) { double("BigQuery dataset") } | ||
let(:bigquery_table) { double("BigQuery table", insert: nil) } | ||
|
||
before do | ||
allow(Plek).to receive(:find).with("search-api-v2").and_return("https://example.com/v2") | ||
allow(GdsApi::SearchApiV2).to receive(:new).with("https://example.com/v2") | ||
.and_return(search_service) | ||
allow(Google::Cloud::Bigquery).to receive(:new).and_return(bigquery) | ||
allow(bigquery).to receive(:dataset).with("search_feedback").and_return(bigquery_dataset) | ||
allow(bigquery_dataset).to receive(:table).with("evaluator_ratings").and_return(bigquery_table) | ||
end | ||
|
||
scenario "performing a basic search and submitting result-level feedback" do | ||
perform_search | ||
|
||
# Makes the right query to the search API v2 | ||
expect(search_service).to have_received(:search).with(count: 5, q: "government digital service") | ||
|
||
# Renders the proper results | ||
expect(page).to have_content("Showing top 3 results (out of 28,766)") | ||
|
||
# Renders external and internal links properly | ||
expect(page).to have_link("GDS blog", href: "https://gds.blog.gov.uk/") | ||
expect(page).to have_link("Government Digital Service", href: "http://www.dev.gov.uk/government/organisations/government-digital-service") | ||
end | ||
|
||
scenario "submitting feedback" do | ||
perform_search | ||
|
||
# Allows the user to submit feedback for results (and leave some blank) | ||
within(all(".search-results__ranking")[0]) { choose "Perfect" } | ||
within(all(".search-results__ranking")[2]) { choose "Bad" } | ||
click_on "Submit feedback" | ||
|
||
# Sends the right data to Bigquery | ||
expect(bigquery_table).to have_received(:insert).with( | ||
{ | ||
anonymised_user_id: "not-yet-available", | ||
comments: "", | ||
query_id: anything, | ||
result_ratings: [{ content_id: "3fc2d1a1-bc9b-4875-899a-54a1fd968175", | ||
position: 1, | ||
rating: 3, | ||
url: "https://gds.blog.gov.uk/" }, | ||
{ content_id: "af07d5a5-df63-4ddc-9383-6a666845ebe9", | ||
position: 2, | ||
rating: nil, | ||
url: "http://www.dev.gov.uk/government/organisations/government-digital-service" }, | ||
{ content_id: "27f58621-a0d0-44fc-8c3a-4548245c6079", | ||
position: 3, | ||
rating: 0, | ||
url: "http://www.dev.gov.uk/government/publications/government-digital-service-it-platform-privacy-notice" }], | ||
search_query: "government digital service", | ||
suggested_url: "", | ||
timestamp: a_string_matching(Time.zone.now.strftime("%Y-%m-%d")), | ||
}, | ||
) | ||
|
||
# Shows a nice message | ||
expect(page).to have_content("Thank you for your feedback") | ||
end | ||
|
||
scenario "submitting feedback with a suggested URL and comments" do | ||
perform_search | ||
|
||
# Allows the user to give a suggested URL | ||
fill_in "URL for the best possible result", with: "https://www.gov.uk/" | ||
|
||
# Allows the user to give comments | ||
fill_in "Your comments about these results", with: "Looking good!" | ||
|
||
click_on "Submit feedback" | ||
|
||
expect(bigquery_table).to have_received(:insert).with( | ||
hash_including( | ||
{ | ||
comments: "Looking good!", | ||
suggested_url: "https://www.gov.uk/", | ||
}, | ||
), | ||
) | ||
end | ||
|
||
scenario "submitting feedback with an invalid suggested URL fails but doesn't lose input" do | ||
perform_search | ||
|
||
fill_in "URL for the best possible result", with: "bad url" | ||
within(all(".search-results__ranking")[1]) { choose "Good" } | ||
click_on "Submit feedback" | ||
|
||
# Doesn't send the data to Bigquery | ||
expect(bigquery_table).not_to have_received(:insert) | ||
|
||
# Shows an error message | ||
expect(page).to have_content("URL for the best possible result must be a valid URL") | ||
|
||
# Doesn't lose the input | ||
within(all(".search-results__ranking")[1]) do | ||
expect(page).to have_checked_field("Good") | ||
end | ||
expect(page).to have_field("URL for the best possible result", with: "bad url") | ||
end | ||
|
||
def perform_search | ||
visit "/" | ||
fill_in "Search GOV.UK using the new search engine", with: "government digital service" | ||
click_on "Search" | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.