doop 0.0.3.1 → 0.0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +8 -8
  2. data/app/assets/images/nino-icon.png +0 -0
  3. data/app/assets/images/passport-icon.png +0 -0
  4. data/app/assets/images/time-icon.png +0 -0
  5. data/app/helpers/doop_helper.rb +14 -7
  6. data/doop.gemspec +4 -2
  7. data/lib/doop-rspec.rb +82 -0
  8. data/lib/doop.rb +3 -1
  9. data/lib/doop/version.rb +1 -1
  10. data/lib/doop_controller.rb +14 -9
  11. data/lib/generators/doopgovuk/doopgovuk_generator.rb +3 -0
  12. data/lib/generators/doopgovuk/templates/app/assets/javascripts/demo.js.coffee +7 -0
  13. data/lib/generators/doopgovuk/templates/app/assets/javascripts/demo/application.js +2 -0
  14. data/lib/generators/doopgovuk/templates/app/assets/stylesheets/demo.css.scss +50 -8
  15. data/lib/generators/doopgovuk/templates/app/assets/stylesheets/demo/application.css +3 -0
  16. data/lib/generators/doopgovuk/templates/app/controllers/demo_controller.rb +202 -68
  17. data/lib/generators/doopgovuk/templates/app/views/demo/_about_you.html.erb +84 -0
  18. data/lib/generators/doopgovuk/templates/app/views/demo/_before_you_begin.html.erb +56 -0
  19. data/lib/generators/doopgovuk/templates/app/views/demo/_children.html.erb +64 -0
  20. data/lib/generators/doopgovuk/templates/app/views/demo/_declaration.html.erb +32 -0
  21. data/lib/generators/doopgovuk/templates/app/views/demo/_preamble.html.erb +36 -27
  22. data/lib/generators/doopgovuk/templates/app/views/demo/harness.html.erb +1 -1
  23. data/lib/generators/doopgovuk/templates/app/views/demo/index.html.erb +6 -0
  24. data/lib/generators/doopgovuk/templates/app/views/demo/index.js.erb +1 -1
  25. data/lib/generators/doopgovuk/templates/app/views/doop/_change_answer_tooltip.html.erb +1 -1
  26. data/lib/generators/doopgovuk/templates/app/views/doop/_debug.html.erb +4 -0
  27. data/lib/generators/doopgovuk/templates/app/views/doop/_error.html.erb +1 -3
  28. data/lib/generators/doopgovuk/templates/app/views/doop/_navbar.html.erb +4 -3
  29. data/lib/generators/doopgovuk/templates/app/views/doop/_question.html.erb +11 -7
  30. data/lib/generators/doopgovuk/templates/app/views/doop/_question_form.html.erb +5 -6
  31. data/lib/generators/doopgovuk/templates/app/views/doop/_textfield.html.erb +14 -0
  32. data/lib/generators/doopgovuk/templates/app/views/doop/_tooltip.html.erb +1 -1
  33. data/lib/generators/doopgovuk/templates/spec/features/demo_spec.rb +121 -48
  34. data/lib/generators/doopgovuk/templates/spec/rails_helper.rb +4 -73
  35. data/spec/doop_spec.rb +47 -0
  36. metadata +22 -12
  37. data/lib/generators/doopgovuk/templates/app/views/demo/_summary.html.erb +0 -10
  38. data/lib/generators/doopgovuk/templates/app/views/demo/_your_details.html.erb +0 -55
@@ -1,3 +1,3 @@
1
- <div class="tooltip">
1
+ <div class="tooltip" id="<%=id%>-tooltip">
2
2
  <% content.call %>
3
3
  </div>
@@ -2,69 +2,142 @@ require 'rails_helper'
2
2
  require 'pry'
3
3
 
4
4
 
5
- feature "Doop questionnaire" do
5
+ feature "Child Benefit online form" do
6
6
 
7
- scenario "Quick run through", :js => true do
8
- load_completed_form
7
+ scenario "Complete Child Benefit form", :js => true do
8
+ before_you_begin
9
+ preamble
10
+ about_you
11
+ children
12
+ declaration
9
13
  end
10
14
 
11
- scenario "Changing an answer, causes change_answer_tool_tip_text to appear", :js => true do
12
- load_completed_form
13
- change_page( "Apply Online" )
14
- change_question( "Have you enrolled for this service before") do
15
- expect(change_answer_tooltip_text).to match /additional questions may be asked/
16
- end
15
+ def before_you_begin
16
+ visit '/demo/index'
17
+ wait_for_page( "before_you_begin" )
18
+ click_button "Start"
17
19
  end
18
20
 
19
- scenario "Answering a question results in a tooltip appearing", :js => true do
20
- load_completed_form
21
- change_page( "Apply Online" )
22
- change_question( "Turn debug on") do
23
- click_button "No"
24
- expect(tooltip_text).to match /Are you sure/
21
+ def preamble
22
+ wait_for_page( "preamble" )
23
+
24
+ # check income_more_than_50000 alternate flows
25
+ answer_question( "income_more_than_50000") do
26
+ click_button "No,"
27
+ expect( tooltip ).to be_visible
28
+ end
29
+ expect( question "do_you_still_want_to_apply" ).to be_disabled
30
+
31
+ change_question( "income_more_than_50000") do
32
+ expect( change_answer_tooltip ).to be_visible
33
+ click_button "Yes,"
25
34
  end
35
+
36
+ expect( question "do_you_still_want_to_apply" ).to be_enabled
37
+
38
+ answer_question( "do_you_still_want_to_apply") { click_button "Yes," }
39
+ click_button "Continue"
26
40
  end
27
41
 
28
- scenario "Answering a question results in a new question being asked", :js => true do
29
- load_completed_form
30
- change_page( "Apply Online" )
31
- change_question( "Have you enrolled for this service before") { click_button "Yes" }
32
- expect( question "What year did you last apply" ).to be_enabled
33
- change_question( "Have you enrolled for this service before") { click_button "No" }
34
- expect( question "What year did you last apply" ).to be_disabled
42
+
43
+ def about_you
44
+ wait_for_page( "about_you" )
45
+ answer_question( "your_name") do
46
+ b_fill_in( "title" => "Mr", "surname" => "Middleton", "firstname" => "Mark", "middlenames" => "Alan")
47
+ click_button "Continue"
48
+ expect( rollup_text ).to eq( "Mr Mark Alan Middleton" )
49
+ end
50
+ answer_question( "known_by_other_name" ) { click_button "No," }
51
+ expect( question "previous_name" ).to be_disabled
52
+ change_question( "known_by_other_name" ) { click_button "Yes," }
53
+ expect( question "previous_name" ).to be_enabled
54
+
55
+ answer_question( "previous_name" ) { b_fill_in( "answer" => "Bob Smith"); click_button "Continue" }
56
+
57
+ answer_question( "dob" ) do
58
+ b_fill_in( "answer" => "25/02/1977")
59
+ click_button "Continue"
60
+ expect( rollup_text ).to eq( "25 February 1977" )
61
+ end
62
+
63
+ answer_question( "your_address" ) do
64
+ b_fill_in( "address1" => "1 Runswick Avenue", "address2" => "Woolston", "address3" => "Leeds", "postcode" => "LE31 4WP" )
65
+ click_button "Continue"
66
+ expect( rollup_text ).to eq( "1 Runswick Avenue, LE31 4WP" )
67
+ end
68
+
69
+ answer_question( "lived_at_address_for_more_than_12_months" ) { click_button "Yes," }
70
+ expect( question "last_address" ).to be_disabled
71
+ change_question( "lived_at_address_for_more_than_12_months" ) { click_button "No," }
72
+ expect( question "last_address" ).to be_enabled
73
+
74
+ answer_question( "last_address" ) do
75
+ b_fill_in( "address1" => "5 Runswick Avenue", "address2" => "Woolston", "address3" => "Leeds", "postcode" => "LE31 4WP" )
76
+ click_button "Continue"
77
+ expect( rollup_text ).to eq( "5 Runswick Avenue, LE31 4WP" )
78
+ end
79
+
80
+ answer_question( "your_phone_numbers" ) do
81
+ b_fill_in( "daytime" => "01235 6789117", "evening" => "01235 678117" )
82
+ click_button "Continue"
83
+ expect( rollup_text ).to eq( "Provided" )
84
+ end
85
+
86
+ answer_question( "have_nino" ) { click_button "No," }
87
+ expect( question "nino" ).to be_disabled
88
+
89
+ change_question( "have_nino" ) { click_button "Yes," }
90
+ expect( question "nino" ).to be_enabled
91
+
92
+ answer_question( "nino" ) do
93
+ b_fill_in( "answer" => "00123456A" )
94
+ click_button "Continue"
95
+ expect( rollup_text ).to eq( "00123456A" )
96
+ end
97
+
98
+ click_button "Continue"
35
99
  end
36
100
 
37
- def load_completed_form
38
-
39
- if $completed_form_yaml != nil
40
- visit '/demo/harness'
41
- fill_in( "doop_data", :with => $completed_form_yaml )
42
- click_button "Render"
43
- return
101
+ def children
102
+ wait_for_page( "children" )
103
+
104
+ answer_question( "how_many_birth_certs" ) do
105
+ b_fill_in( "answer" => "1" ); click_button "Continue"
44
106
  end
45
107
 
46
- visit '/demo/index'
47
- wait_for_page( "Apply Online" )
48
- answer_question( "Turn debug on") { click_button "Yes" }
49
- answer_question( "Have you enrolled for this service before") { click_button "Yes" }
50
- answer_question( "What year did you last apply") { select( '2012', :from => 'b_answer' ); click_button "Continue" }
51
- answer_question( "Why are you applying") { fill_in( 'b_answer', :with => "My circumstances have changed" ); click_button "Continue"}
52
- click_button "Continue and Save"
53
-
54
- wait_for_page( "Your Details" )
55
- answer_question( "What is your name") do
56
- b_fill_in( "firstname" => "mark", "surname" => "middleton" )
57
- click_button "Continue"
58
- expect(rollup_text).to be == "Mark Middleton"
108
+ # child__1
109
+ answer_question( "name" ) do
110
+ b_fill_in( "firstname" => "Padraig", "middlenames" => "Alan", "surname" => "Middleton" ); click_button "Continue"
111
+ expect( rollup_text ).to eq ( "Padraig Alan Middleton" )
112
+ end
113
+ answer_question( "gender" ) { click_button "Male" }
114
+ answer_question( "dob" ) { b_fill_in( "answer" => "30/09/2006" ); click_button "Continue" }
115
+ answer_question( "own_child" ) { click_button "Yes," }
116
+ answer_question( "child__1" ) { click_button "Continue" }
117
+
118
+ # child__2
119
+ click_button "Add another child"
120
+ answer_question( "name" ) do
121
+ b_fill_in( "firstname" => "Annie", "middlenames" => "", "surname" => "Middleton" ); click_button "Continue"
122
+ expect( rollup_text ).to eq ( "Annie Middleton" )
59
123
  end
60
- address = { "address1" => "1 Runswick Avenue", "address2" => "Telford", "address3" => "Shropshire", "postcode" => "T56 HDJ" }
61
- answer_question( "Address 1") { b_fill_in( address); click_button "Continue" }
124
+ answer_question( "gender" ) { click_button "Female" }
125
+ answer_question( "dob" ) { b_fill_in( "answer" => "24/02/2008" ); click_button "Continue" }
126
+ answer_question( "own_child" ) { click_button "Yes," }
127
+ answer_question( "child__2" ) { click_button "Continue" }
128
+
129
+ # remove child__2
130
+ change_question( "child__2" ) {
131
+ click_button "Remove child"
132
+ }
133
+
134
+ expect( question "child__2" ).to be_disabled
62
135
  click_button "Continue"
63
- click_button "Continue and Save"
64
136
 
65
- wait_for_page( "Summary" )
66
- answer_question( "Terms and conditions") { click_button "I have read" }
67
- $completed_form_yaml = page.find_by_id( "doop_data", :visible => false).value
68
137
  end
69
138
 
139
+
140
+ def declaration
141
+ wait_for_page( "declaration" )
142
+ end
70
143
  end
@@ -8,6 +8,8 @@ require 'capybara/rspec'
8
8
  require 'capybara-webkit'
9
9
  require 'headless'
10
10
  require 'capybara-screenshot/rspec'
11
+ require 'doop-rspec'
12
+
11
13
 
12
14
 
13
15
  Capybara.javascript_driver = :webkit
@@ -44,6 +46,8 @@ RSpec.configure do |config|
44
46
  @headless.destroy
45
47
  end
46
48
 
49
+ config.filter_run_excluding :broken => true
50
+
47
51
  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
48
52
  #config.fixture_path = "#{::Rails.root}/spec/fixtures"
49
53
 
@@ -67,76 +71,3 @@ RSpec.configure do |config|
67
71
  # https://relishapp.com/rspec/rspec-rails/docs
68
72
  #config.infer_spec_type_from_file_location!
69
73
  end
70
-
71
- RSpec::Matchers.define :be_asked do
72
- match do |q_title|
73
- page.has_css?( '.question-open h2', :text => q_title )
74
- end
75
-
76
- failure_message do |q_title|
77
- actual = page.all( '.question-open h2', ).last.text
78
- "Expected question to be asked: #{q_title}, but was asked #{actual}"
79
- end
80
-
81
- end
82
-
83
- RSpec::Matchers.define :be_enabled do
84
- match do |q_title|
85
- page.has_css?( '.question_title', :text => q_title )
86
- end
87
- end
88
-
89
- RSpec::Matchers.define :be_disabled do
90
- match do |q_title|
91
- page.has_no_css?( '.question_title', :text => q_title )
92
- end
93
- end
94
-
95
- def question text
96
- text
97
- end
98
-
99
- def change_question q_title, &block
100
- @q_title = q_title
101
- page.find( '.question-closed div.title', :text => q_title ).find(:xpath, "..").find( 'div.answer a' ).click
102
- expect( question q_title ).to be_asked
103
- yield block
104
- end
105
-
106
- def answer_question q_title, &block
107
- @q_title = q_title
108
- expect( question q_title ).to be_asked
109
- yield block
110
- page.find( '.question-closed div.title', :text => q_title )
111
- end
112
-
113
- def rollup_text
114
- page.find( '.question-closed div.title', :text => @q_title ).find(:xpath, '..').find( 'div.answer').text
115
- end
116
-
117
- def tooltip_text
118
- page.find( '.tooltip' ).text
119
- end
120
-
121
- def change_answer_tooltip_text
122
- page.find( '.change_answer_tooltip' ).text
123
- end
124
-
125
- def wait_for_page p_title
126
- page.find_by_id( "page_title", :text=>p_title)
127
- end
128
-
129
- def page_title
130
- page.find_by_id( "page_title").text
131
- end
132
-
133
- def b_fill_in options = {}
134
- options.keys.each do |key|
135
- page.fill_in( "b_#{key}", :with => options[key] )
136
- end
137
- end
138
-
139
- def change_page page_name
140
- page.find_link( page_name ).click
141
- wait_for_page page_name
142
- end
@@ -2,6 +2,53 @@ require "spec_helper"
2
2
 
3
3
  describe "Doop" do
4
4
 
5
+ describe "answering in sequence" do
6
+
7
+ let(:question) {
8
+ q = Doop::Doop.new
9
+ q.yaml=
10
+ <<-EOS
11
+
12
+ pages: {
13
+ about_you: {
14
+ dob: { _question: "What is your dob" }
15
+ },
16
+ about_your_partner: {
17
+ dob: { _question: "What is your dob" }
18
+ }
19
+ }
20
+
21
+ EOS
22
+ q.init
23
+ q.ask_next
24
+ q
25
+ }
26
+
27
+ it "can handle questions with similar names" do
28
+ expect(question.currently_asked).to eq( "/pages/about_you/dob" )
29
+ question.answer( { "answer" => "aa"} )
30
+ expect(question.currently_asked).to eq( "/pages/about_you" )
31
+ question.answer( { "answer" => "bb"} )
32
+ expect(question.currently_asked).to eq( "/pages/about_your_partner/dob" )
33
+ question.answer( { "answer" => "cc"} )
34
+ expect(question.currently_asked).to eq( "/pages/about_your_partner" )
35
+ question.answer( { "answer" => "dd"} )
36
+ expect(question.currently_asked).to eq( "/pages" )
37
+ question.answer( { "answer" => "ee"} )
38
+
39
+ expect( question["/pages/about_you/dob/_answer"] ).to eq("aa")
40
+ expect( question["/pages/about_you/_answer"] ).to eq("bb")
41
+ expect( question["/pages/about_your_partner/dob/_answer"] ).to eq("cc")
42
+ expect( question["/pages/about_your_partner/_answer"] ).to eq("dd")
43
+ expect( question["/pages/_answer"] ).to eq("ee")
44
+
45
+ question.change( "/pages/about_you/dob" )
46
+ question.answer( { "answer" => "ff"} )
47
+ expect(question.currently_asked).to eq( "/pages/about_you" )
48
+ end
49
+
50
+ end
51
+
5
52
  describe "automatic binding" do
6
53
 
7
54
  let(:question) {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.1
4
+ version: 0.0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Middleton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-03 00:00:00.000000000 Z
11
+ date: 2014-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,30 +42,30 @@ dependencies:
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '3.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '4.1'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '4.1'
69
69
  description: A question framework for govuk sites, inspired by the work GDS have done
70
70
  to standardize the cross government internet presence.
71
71
  email:
@@ -83,30 +83,40 @@ files:
83
83
  - Rakefile
84
84
  - app/assets/images/dash.gif
85
85
  - app/assets/images/info-icon.png
86
+ - app/assets/images/nino-icon.png
87
+ - app/assets/images/passport-icon.png
86
88
  - app/assets/images/progress-tick-large.png
89
+ - app/assets/images/time-icon.png
87
90
  - app/helpers/doop_helper.rb
88
91
  - bin/.gitignore
89
92
  - doop.gemspec
93
+ - lib/doop-rspec.rb
90
94
  - lib/doop.rb
91
95
  - lib/doop/version.rb
92
96
  - lib/doop_controller.rb
93
97
  - lib/generators/doopgovuk/USAGE
94
98
  - lib/generators/doopgovuk/doopgovuk_generator.rb
95
99
  - lib/generators/doopgovuk/templates/app/assets/javascripts/demo.js.coffee
100
+ - lib/generators/doopgovuk/templates/app/assets/javascripts/demo/application.js
96
101
  - lib/generators/doopgovuk/templates/app/assets/stylesheets/demo.css.scss
102
+ - lib/generators/doopgovuk/templates/app/assets/stylesheets/demo/application.css
97
103
  - lib/generators/doopgovuk/templates/app/controllers/demo_controller.rb
104
+ - lib/generators/doopgovuk/templates/app/views/demo/_about_you.html.erb
105
+ - lib/generators/doopgovuk/templates/app/views/demo/_before_you_begin.html.erb
106
+ - lib/generators/doopgovuk/templates/app/views/demo/_children.html.erb
107
+ - lib/generators/doopgovuk/templates/app/views/demo/_declaration.html.erb
98
108
  - lib/generators/doopgovuk/templates/app/views/demo/_preamble.html.erb
99
- - lib/generators/doopgovuk/templates/app/views/demo/_summary.html.erb
100
- - lib/generators/doopgovuk/templates/app/views/demo/_your_details.html.erb
101
109
  - lib/generators/doopgovuk/templates/app/views/demo/harness.html.erb
102
110
  - lib/generators/doopgovuk/templates/app/views/demo/index.html.erb
103
111
  - lib/generators/doopgovuk/templates/app/views/demo/index.js.erb
104
112
  - lib/generators/doopgovuk/templates/app/views/doop/_change_answer_tooltip.html.erb
113
+ - lib/generators/doopgovuk/templates/app/views/doop/_debug.html.erb
105
114
  - lib/generators/doopgovuk/templates/app/views/doop/_error.html.erb
106
115
  - lib/generators/doopgovuk/templates/app/views/doop/_info_box.html.erb
107
116
  - lib/generators/doopgovuk/templates/app/views/doop/_navbar.html.erb
108
117
  - lib/generators/doopgovuk/templates/app/views/doop/_question.html.erb
109
118
  - lib/generators/doopgovuk/templates/app/views/doop/_question_form.html.erb
119
+ - lib/generators/doopgovuk/templates/app/views/doop/_textfield.html.erb
110
120
  - lib/generators/doopgovuk/templates/app/views/doop/_tooltip.html.erb
111
121
  - lib/generators/doopgovuk/templates/app/views/layouts/application.html.erb
112
122
  - lib/generators/doopgovuk/templates/spec/features/demo_spec.rb
@@ -1,10 +0,0 @@
1
-
2
- <%=question_form doop, res do %>
3
- <%=question "/page/summary" do |root, answer| %>
4
- <%=question "/page/summary/terms_and_conditions" do |root, answer| %>
5
- <p>I have answered the questions to the best of my knowledge and agree to abide by the terms and conditions of this service.</p>
6
- <button>I have read and understood the terms and conditions</button>
7
- <% end %>
8
-
9
- <% end %>
10
- <% end %>