Skip to content

Commit

Permalink
Merge pull request #2659 from alphagov/use-text-version-of-question-p…
Browse files Browse the repository at this point in the history
…ages-as-regression-test-artefacts

Use text version of question pages as regression test artefacts
  • Loading branch information
floehopper authored Jul 26, 2016
2 parents 3248750 + 6f6065b commit 1989f6f
Show file tree
Hide file tree
Showing 809 changed files with 8,241 additions and 66,542 deletions.
6 changes: 1 addition & 5 deletions app/controllers/smart_answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def show
title: @presenter.current_node.title
}
}
if render_text?(@presenter)
if Rails.application.config.expose_govspeak
format.text {
render
}
Expand Down Expand Up @@ -58,10 +58,6 @@ def json_request?
request.format == Mime::JSON
end

def render_text?(presenter)
Rails.application.config.expose_govspeak && presenter.render_txt?
end

def with_format(format, &block)
old_formats = self.formats
self.formats = [format]
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/checkbox_question_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CheckboxQuestionPresenter < QuestionPresenter
class CheckboxQuestionPresenter < QuestionWithOptionsPresenter
def response_labels(values)
values.split(',').map do |value|
if value == SmartAnswer::Question::Checkbox::NONE_OPTION
Expand Down
6 changes: 4 additions & 2 deletions app/presenters/country_select_question_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
class CountrySelectQuestionPresenter < QuestionPresenter
def response_label(value)
options.find { |option| option.slug == value }.name
options.find { |option| option.value == value }.label
end

def options
@node.options
@node.options.map do |option|
OpenStruct.new(label: option.name, value: option.slug)
end
end
end
4 changes: 0 additions & 4 deletions app/presenters/flow_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ def finished?
current_node.outcome?
end

def render_txt?
finished? || !started?
end

def current_state
@current_state ||= @flow.process(all_responses)
end
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/multiple_choice_question_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class MultipleChoiceQuestionPresenter < QuestionPresenter
class MultipleChoiceQuestionPresenter < QuestionWithOptionsPresenter
def response_label(value)
options.find { |option| option.value == value }.label
end
Expand Down
12 changes: 3 additions & 9 deletions app/presenters/question_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,12 @@ def body(html: true)
@renderer.content_for(:body, html: html)
end

def post_body
@renderer.content_for(:post_body, html: true)
def post_body(html: true)
@renderer.content_for(:post_body, html: html)
end

def options
@node.options.map do |option|
OpenStruct.new(label: render_option(option), value: option)
end
end

def render_option(key)
@renderer.option_text(key.to_sym)
[]
end

def to_response(input)
Expand Down
11 changes: 11 additions & 0 deletions app/presenters/question_with_options_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class QuestionWithOptionsPresenter < QuestionPresenter
def options
@node.options.map do |option|
OpenStruct.new(label: render_option(option), value: option)
end
end

def render_option(key)
@renderer.option_text(key.to_sym)
end
end
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= select_tag "response", options_from_collection_for_select(question.options, :slug, :name, prefill_value_for(question)) %>
<%= select_tag "response", options_from_collection_for_select(question.options, :value, :label, prefill_value_for(question)) %>
16 changes: 16 additions & 0 deletions app/views/smart_answers/show.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,20 @@
<%= @presenter.current_node.body(html: false) %>

<%= @presenter.current_node.next_steps(html: false) %>
<% else %>
<%= @presenter.current_node.title %>

<%= @presenter.current_node.body(html: false) %>

<%= @presenter.current_node.hint %>

<% @presenter.current_node.options.each do |option| %>
* <%= option.value %>: <%= option.label %>
<% end -%>

<%= @presenter.current_node.label %>

<%= @presenter.current_node.suffix_label %>

<%= @presenter.current_node.post_body(html: false) %>
<% end %>
12 changes: 9 additions & 3 deletions doc/viewing-templates-as-govspeak.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# Viewing a Smart Answer as Govspeak

Seeing [Govspeak](https://github.com/alphagov/govspeak) markup of Smart Answer pages can be useful to content designers when preparing content change requests or developers inspecting generated Govspeak that later gets translated to HTML. This feature can be enabled by setting `EXPOSE_GOVSPEAK` to a non-empty value. It can be accessed by appending `.txt` to URLs (currently govspeak is available for landing and outcome pages, but not question pages).
Seeing [Govspeak](https://github.com/alphagov/govspeak) markup of Smart Answer pages can be useful to content designers when preparing content change requests or to developers inspecting generated Govspeak that later gets translated to HTML.

## In Development
This feature can be enabled by setting `EXPOSE_GOVSPEAK` to a non-empty value. It is enabled by default in the Integration environment and in Heroku apps deployed via the `startup_heroku.sh` script.

The Govspeak version of the pages can be accessed by appending `.txt` to URLs.

## In Development environment

* [Marriage abroad landing page](http://smartanswers.dev.gov.uk/marriage-abroad.txt)
* [Marriage abroad question page](http://smart-answers.dev.gov.uk/marriage-abroad/y.txt)
* [Marriage abroad outcome page](http://smartanswers.dev.gov.uk/marriage-abroad/y/afghanistan/uk/partner_other/opposite_sex.txt)

## In Integration environment

**Only outcomes pages can be rendered as Govspeak in Integration**. There's a [Trello card about this inconsistency](https://trello.com/c/qd5C7qDn/165-allow-landing-pages-to-be-rendered-as-govspeak-in-integration).
**It's not currently possible to access the Govspeak version of landing pages in the Integration environment.** There's a [Trello card about this inconsistency](https://trello.com/c/qd5C7qDn/165-allow-landing-pages-to-be-rendered-as-govspeak-in-integration).

* [Marriage abroad question page](https://www-origin.integration.publishing.service.gov.uk/marriage-abroad/y.txt)
* [Marriage abroad outcome page](https://www-origin.integration.publishing.service.gov.uk/marriage-abroad/y/afghanistan/uk/partner_other/opposite_sex.txt)
4 changes: 2 additions & 2 deletions lib/smart_answer_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def path_to_outputs_for_flow
artefacts_path.join(@flow_name)
end

def save_output(responses, response, extension: 'txt')
filename = "#{responses.pop}.#{extension}"
def save_output(responses, response)
filename = "#{responses.pop}.txt"
path_to_output_directory = path_to_outputs_for_flow.join(*responses)
FileUtils.mkdir_p(path_to_output_directory)
path_to_output_file = path_to_output_directory.join(filename)
Expand Down
134 changes: 0 additions & 134 deletions test/artefacts/additional-commodity-code/0.html

This file was deleted.

17 changes: 17 additions & 0 deletions test/artefacts/additional-commodity-code/0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
How much sucrose, invert sugar or isoglucose does the product contain?



The values represent % by weight

* 0: 0 - 4.99
* 5: 5 - 29.99
* 30: 30 - 49.99
* 50: 50 - 69.99
* 70: 70 or more






Loading

0 comments on commit 1989f6f

Please sign in to comment.