Skip to content

Commit

Permalink
Merge pull request #106 from DFE-Digital/1724-add-feature-specs
Browse files Browse the repository at this point in the history
Add feature specs for search
  • Loading branch information
slawosz authored Mar 8, 2024
2 parents 6a1858d + 76a1bd0 commit 9b12fff
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/aks_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

runs-on: ubuntu-latest
env:
ORDNANCE_SURVEY_API_KEY: someapikey
ORDNANCE_SURVEY_API_KEY: geocoderkey

services:
postgres:
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ end
group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "capybara-screenshot"
gem "selenium-webdriver"
gem "shoulda-matchers"
gem "webdrivers"
Expand All @@ -47,4 +48,6 @@ group :test, :development do
gem "brakeman", require: false
gem "debug", platforms: %i[ mri mingw x64_mingw ]
gem 'rubocop-govuk', require: false
gem 'vcr'
gem 'webmock'
end
18 changes: 18 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ GEM
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
bigdecimal (3.1.6)
bindex (0.8.1)
bootsnap (1.18.3)
msgpack (~> 1.2)
Expand All @@ -88,8 +89,14 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
capybara-screenshot (1.0.26)
capybara (>= 1.0, < 4)
launchy
coderay (1.1.3)
concurrent-ruby (1.2.3)
crack (1.0.0)
bigdecimal
rexml
crass (1.0.6)
cssbundling-rails (1.4.0)
railties (>= 6.0.0)
Expand All @@ -115,6 +122,7 @@ GEM
activemodel (>= 6.1)
activesupport (>= 6.1)
html-attributes-utils (~> 1)
hashdiff (1.1.0)
html-attributes-utils (1.0.2)
activesupport (>= 6.1.4.4)
i18n (1.14.1)
Expand All @@ -127,6 +135,8 @@ GEM
railties (>= 6.0.0)
json (2.7.1)
language_server-protocol (3.17.0.3)
launchy (2.5.2)
addressable (~> 2.8)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand Down Expand Up @@ -295,6 +305,7 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
vcr (6.2.0)
view_component (3.9.0)
activesupport (>= 5.2.0, < 8.0)
concurrent-ruby (~> 1.0)
Expand All @@ -308,6 +319,10 @@ GEM
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0, < 4.11)
webmock (3.23.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
websocket (1.2.10)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
Expand All @@ -328,6 +343,7 @@ DEPENDENCIES
bundler (~> 2.4)
byebug
capybara
capybara-screenshot
cssbundling-rails
debug
dotenv-rails
Expand All @@ -351,8 +367,10 @@ DEPENDENCIES
selenium-webdriver
shoulda-matchers
tzinfo-data
vcr
web-console
webdrivers
webmock

RUBY VERSION
ruby 3.1.2p20
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ This project depends on:

When updating the `db/data/hubs.csv` file, please make sure to run `rails r 'Hub::Importer.new.reload!'` locally first to make sure all changes were applied.

## Testing

### Mocking with VCR for feature specs

Your default test geocoder key should be `ORDNANCE_SURVEY_API_KEY='geocoderkey'`, and its VERY IMPORTANT not to leak
key to the repository. This key is being set in github actions as well.
Every time you re-record VCR cassete, you need to modify the key.

### Linting

To run the linters:
Expand Down
1 change: 0 additions & 1 deletion app/lib/local_authority/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def geo_result
def search_polygon
return @search_polygon if defined? @search_polygon

#binding.pry
json = geo_result && geo_result.data['geojson']
return @search_polygon = nil unless json

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"dependencies": {
"esbuild": "^0.17.19",
"govuk-frontend": "4.6.0",
"sass": "^1.62.1"
"sass": "^1.62.1",
"yarn": "^1.22.21"
},
"scripts": {
"build:css": "sass ./app/assets/stylesheets/application.sass.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules --quiet-deps",
Expand Down
24 changes: 24 additions & 0 deletions spec/features/happy_path_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "rails_helper"

RSpec.feature "Happy path", type: :feature do
before do
LocalAuthority::Importer.new.reload!
Hub::Importer.new.reload!
end

let(:expected_hubs_names) do
["Chiltern Teaching School Hub", "Chiltern Teaching School Hub", "Alban Teaching School Hub"]
end

scenario "Performs search" do
VCR.use_cassette("geocoder") do
visit root_path
click_link("Start now")
expect(page).to have_text("Where do you want to find teaching school hubs?")
fill_in "Where do you want to find teaching school hubs?", with: "Luton"
click_button('Continue')
hubs = all('h3 a').map(&:text)
expect(hubs).to eq(expected_hubs_names)
end
end
end
154 changes: 154 additions & 0 deletions spec/fixtures/vcr_cassettes/geocoder.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'

VCR.configure do |config|
config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
config.hook_into :webmock
end

begin
ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
Expand Down
Loading

0 comments on commit 9b12fff

Please sign in to comment.