Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add learn-to-drive-a-car task list page #400

Merged
merged 2 commits into from
Nov 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

require File.expand_path('../config/application', __FILE__)

task default: [:lint]
Collections::Application.load_tasks
5 changes: 5 additions & 0 deletions app/controllers/tasklist_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class TasklistController < ApplicationController
def show
render :show, locals: { tasklist: TasklistContent.learn_to_drive_config }
end
end
9 changes: 9 additions & 0 deletions app/services/tasklist_content.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class TasklistContent
def self.learn_to_drive_config
@learn_to_drive_config ||= JSON.parse(
File.read(
Rails.root.join("config", "tasklists", "learn-to-drive-a-car.json")
)
).deep_symbolize_keys
end
end
22 changes: 22 additions & 0 deletions app/views/tasklist/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<% content_for :title, "Learn to drive a car: step by step" %>

<% content_for :breadcrumbs do %>
<%= render 'govuk_component/beta_label' %>
<%= render 'govuk_component/breadcrumbs', tasklist[:links] %>
<% end %>

<div class="grid-row">
<div class="column-two-thirds">
<%= render 'govuk_component/title',
title: tasklist[:title],
average_title_length: 'long' %>

<%= render 'govuk_component/lead_paragraph',
text: tasklist[:description] %>
</div>
</div>
<div class="grid-row">
<div class="column-two-thirds">
<%= render "govuk_component/task_list", tasklist[:tasklist] %>
</div>
</div>
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
mount JasmineRails::Engine => '/specs' if defined?(JasmineRails)
mount GovukPublishingComponents::Engine, at: "/component-guide" if defined?(GovukPublishingComponents)

get "/learn-to-drive-a-car", to: 'tasklist#show'

get "/browse.json" => redirect("/api/content/browse")

resources :browse, only: [:index, :show], param: :top_level_slug do
Expand Down Expand Up @@ -34,7 +36,5 @@
to: "services_and_information#index",
as: :services_and_information

get '/learn-to-drive-a-car', to: 'tasklist#show'

get '*taxon_base_path', to: 'taxons#show'
end
156 changes: 156 additions & 0 deletions config/tasklists/learn-to-drive-a-car.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"title": "Learn to drive a car: step by step",
"base_path": "/learn-to-drive-a-car",
"description": "Check what you need to do to learn to drive.",
"links": {
"breadcrumbs": [
{ "title": "Home", "url": "/" },
{ "title": "Driving and transport", "url": "/browse/driving"},
{ "title": "Learning to drive", "url": "/browse/driving/learning-to-drive"}
]
},
"tasklist": {
"steps": [
[
{
"title": "Check you're allowed to drive",
"panel_descriptions": ["Most people can start learning to drive when they’re 17."],
"panel_links": [
{
"href": "/vehicles-can-drive",
"text": "Check what age you can drive"
},
{
"href": "/legal-obligations-drivers-riders",
"text": "Requirements for driving legally"
},
{
"href": "/driving-eyesight-rules",
"text": "Driving eyesight rules"
}
]
}
],
[
{
"title": "Get a provisional driving licence",
"panel_links": [
{
"href": "/apply-first-provisional-driving-licence",
"text": "Apply for your first provisional driving licence"
}
]
}
],
[
{
"title": "Driving lessons and practice",
"panel_descriptions": ["You need a provisional driving licence to take lessons or practice."],
"panel_links": [
{
"href": "/guidance/the-highway-code",
"text": "The Highway Code"
},
{
"href": "/driving-lessons-learning-to-drive",
"text": "Taking driving lessons"
},
{
"href": "/find-driving-schools-and-lessons",
"text": "Find driving schools, lessons and instructors"
},
{
"href": "/government/publications/car-show-me-tell-me-vehicle-safety-questions",
"text": "Practise vehicle safety questions"
}
]
},
{
"title": "Prepare for your theory test",
"panel_links": [
{
"href": "/theory-test/revision-and-practice",
"text": "Theory test revision and practice"
},
{
"href": "/take-practice-theory-test",
"text": "Take a practice theory test"
},
{
"href": "https://www.safedrivingforlife.info/shop/product/official-dvsa-theory-test-kit-app-app",
"text": "Theory and hazard perception test app"
}
]
}
],
[
{
"title": "Book and manage your theory test",
"panel_descriptions": ["You need a provisional driving licence to book your theory test."],
"panel_links": [
{
"href": "/book-theory-test",
"text": "Book your theory test"
},
{
"href": "/theory-test/what-to-take",
"text": "What to take to your test"
},
{
"href": "/change-theory-test",
"text": "Change your theory test appointment"
},
{
"href": "/check-theory-test",
"text": "Check your theory test appointment details"
},
{
"href": "/cancel-theory-test",
"text": "Cancel your theory test"
}
]
}
],
[
{
"title": "Book and manage your driving test",
"panel_descriptions": ["You must pass your theory test before you can book your driving test."],
"panel_links": [
{
"href": "/book-driving-test",
"text": "Book your driving test"
},
{
"href": "/driving-test/what-to-take",
"text": "What to take to your test"
},
{
"href": "/change-driving-test",
"text": "Change your driving test appointment"
},
{
"href": "/check-driving-test",
"text": "Check your driving test appointment details"
},
{
"href": "/cancel-driving-test",
"text": "Cancel your driving test"
}
]
}
],
[
{
"title": "When you pass",
"panel_descriptions": ["You can start driving as soon as you pass your driving test."],
"panel_links": [
{
"href": "/pass-plus",
"text": "Find out about Pass Plus training courses"
}
]
}
]
]
}
}
4 changes: 4 additions & 0 deletions lib/tasks/lint.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
desc "Run govuk-lint with similar params to CI"
task "lint" do
sh "bundle exec govuk-lint-ruby --rails --diff --format clang app test lib config"
end
47 changes: 47 additions & 0 deletions test/integration/tasklist_page_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require 'integration_test_helper'

class TasklistPageTest < ActionDispatch::IntegrationTest
it "renders the learn to drive page" do
visit "/learn-to-drive-a-car"

assert page.has_css?(shared_component_selector('breadcrumbs'))

within_static_component 'breadcrumbs' do |breadcrumb_arg|
assert_equal [
{ "title" => "Home", "url" => "/" },
{ "title" => "Driving and transport", "url" => "/browse/driving" },
{ "title" => "Learning to drive", "url" => "/browse/driving/learning-to-drive" }
], breadcrumb_arg[:breadcrumbs]
end

assert page.has_css?(shared_component_selector('title'))

within_static_component 'title' do |component_args|
assert_equal "Learn to drive a car: step by step", component_args[:title]
end

assert page.has_css?(shared_component_selector('lead_paragraph'))

within_static_component 'lead_paragraph' do |paragraph_args|
assert_equal "Check what you need to do to learn to drive.", paragraph_args[:text]
end

assert page.has_css?(shared_component_selector('task_list'))

within_static_component('task_list') do |tasklist_args|
assert_equal 6, tasklist_args[:steps].count

assert_equal [], tasklist_step_keys(tasklist_args) - %w(title panel panel_descriptions panel_links)

assert_equal [], tasklist_panel_links_keys(tasklist_args) - %w(href text), []
end
end

def tasklist_step_keys(tasklist_args)
tasklist_args[:steps].flatten.flat_map(&:keys).uniq
end

def tasklist_panel_links_keys(tasklist_args)
tasklist_args[:steps].flatten.flat_map { |step| step["panel_links"] }.flat_map(&:keys).uniq
end
end