Skip to content

Commit c69fb58

Browse files
authored
CDPTKAN-639: Add acceptance tests for the pre check questionnaire (#2899)
* Added four scenarios covering major questionnaire flows * Cleanup and Refactor * Replace Admin credentials keys - ACCEPTANCE_TESTS_USER -> ACCEPTANCE_TESTS_ADMIN_USER - ACCEPTANCE_TESTS_PASSWORD -> ACCEPTANCE_TESTS_ADMIN_PASSWORD * Add ACCEPTANCE_TESTS_ADMIN_USER to list of admins * Run acceptance tests at build stage * Update config.yml * Revert "Run acceptance tests at build stage" This reverts commit c51b4f9.
1 parent c1e7da7 commit c69fb58

7 files changed

Lines changed: 195 additions & 42 deletions

File tree

.circleci/config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
steps:
7777
- checkout
7878
- ruby/install-deps
79-
- run: bundle exec brakeman -q --no-pager -i brakeman.ignore
79+
- run: bundle exec brakeman -q --no-pager -i brakeman.ignore --except EOLRuby
8080
- slack/status: *slack_status
8181
rspec_test:
8282
docker: &test_image
@@ -318,8 +318,8 @@ jobs:
318318
command: |
319319
EDITOR_APP=https://fb-editor-test.apps.live.cloud-platform.service.justice.gov.uk
320320
echo 'export ACCEPTANCE_TESTS_EDITOR_APP=$EDITOR_APP' >> $BASH_ENV
321-
echo 'export ACCEPTANCE_TESTS_USER=$ACCEPTANCE_TESTS_USER' >> $BASH_ENV
322-
echo 'export ACCEPTANCE_TESTS_PASSWORD=$ACCEPTANCE_TESTS_PASSWORD' >> $BASH_ENV
321+
echo 'export ACCEPTANCE_TESTS_ADMIN_USER=$ACCEPTANCE_TESTS_USER' >> $BASH_ENV
322+
echo 'export ACCEPTANCE_TESTS_ADMIN_PASSWORD=$ACCEPTANCE_TESTS_PASSWORD' >> $BASH_ENV
323323
echo 'export CI_MODE=true' >> $BASH_ENV
324324
echo 'export SITEPRISM_DSL_VALIDATION_DISABLED=true' >> $BASH_ENV
325325
source $BASH_ENV
@@ -353,8 +353,8 @@ jobs:
353353
command: |
354354
EDITOR_APP=https://${CIRCLE_BRANCH}.apps.live.cloud-platform.service.justice.gov.uk
355355
echo 'export ACCEPTANCE_TESTS_EDITOR_APP=$EDITOR_APP' >> $BASH_ENV
356-
echo 'export ACCEPTANCE_TESTS_USER=$ACCEPTANCE_TESTS_USER' >> $BASH_ENV
357-
echo 'export ACCEPTANCE_TESTS_PASSWORD=$ACCEPTANCE_TESTS_PASSWORD' >> $BASH_ENV
356+
echo 'export ACCEPTANCE_TESTS_ADMIN_USER=$ACCEPTANCE_TESTS_USER' >> $BASH_ENV
357+
echo 'export ACCEPTANCE_TESTS_ADMIN_PASSWORD=$ACCEPTANCE_TESTS_PASSWORD' >> $BASH_ENV
358358
echo 'export CI_MODE=true' >> $BASH_ENV
359359
echo 'export SITEPRISM_DSL_VALIDATION_DISABLED=true' >> $BASH_ENV
360360
source $BASH_ENV

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ copy-testable-branch-env-vars-ci:
3939

4040
.PHONY: add-env-vars-ci
4141
add-env-vars-ci:
42-
echo "ACCEPTANCE_TESTS_USER=${ACCEPTANCE_TESTS_USER}" >> .env.acceptance_tests
43-
echo "ACCEPTANCE_TESTS_PASSWORD=${ACCEPTANCE_TESTS_PASSWORD}" >> .env.acceptance_tests
42+
echo "ACCEPTANCE_TESTS_ADMIN_USER=${ACCEPTANCE_TESTS_ADMIN_USER}" >> .env.acceptance_tests
43+
echo "ACCEPTANCE_TESTS_ADMIN_PASSWORD=${ACCEPTANCE_TESTS_ADMIN_PASSWORD}" >> .env.acceptance_tests
4444

4545
.PHONY: setup-ci
4646
setup-ci:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ This is already added on CircleCI but in case you want to run on your local
113113
machine to point to the test environment you need to run:
114114

115115
```
116-
export ACCEPTANCE_TESTS_USER='my-user'
117-
export ACCEPTANCE_TESTS_PASSWORD='my-password'
116+
export ACCEPTANCE_TESTS_ADMIN_USER='my-user'
117+
export ACCEPTANCE_TESTS_ADMIN_PASSWORD='my-password'
118118
make acceptance-ci -s
119119
```
120120

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
require_relative '../spec_helper'
2+
3+
feature 'Questionnaire' do
4+
let(:editor) { EditorApp.new }
5+
6+
scenario 'Building a form and ruling out GOV.UK Forms' do
7+
given_I_am_logged_in(admin: false)
8+
click_link I18n.t('services.create')
9+
10+
# get_started
11+
expect(page).to have_content(I18n.t('questionnaire.get_started_form.heading'))
12+
choose I18n.t('activemodel.attributes.questionnaire/get_started_form/new_form_reason.building'), allow_label_click: true
13+
click_button I18n.t('dialogs.button_continue')
14+
15+
# gov_forms
16+
expect(page).to have_content(I18n.t('questionnaire.gov_forms_form.heading'))
17+
choose I18n.t('activemodel.attributes.questionnaire/gov_forms/govuk_forms_ruled_out.true'), allow_label_click: true
18+
click_button I18n.t('dialogs.button_continue')
19+
20+
# form_features
21+
expect(page).to have_content(I18n.t('questionnaire.form_features_form.heading'))
22+
check I18n.t('activemodel.attributes.questionnaire/form_features_form/required_moj_forms_features.multiple_questions'), allow_label_click: true
23+
fill_in I18n.t('questionnaire.form_features_form.label.text'), with: 'Because I want to use MoJ Forms'
24+
click_button I18n.t('dialogs.button_continue')
25+
26+
# new_form
27+
expect(page).to have_content(I18n.t('questionnaire.new_form_form.heading'))
28+
choose I18n.t('activemodel.attributes.questionnaire/new_form_form/estimated_page_count.under_20'), allow_label_click: true
29+
choose I18n.t('activemodel.attributes.questionnaire/new_form_form/estimated_first_year_submissions_count.under_10000'), allow_label_click: true
30+
choose I18n.t('activemodel.attributes.questionnaire/new_form_form/submission_delivery_method.email'), allow_label_click: true
31+
click_button I18n.t('dialogs.button_continue')
32+
33+
# requirements
34+
expect(page).to have_content(I18n.t('questionnaire.requirements.heading'))
35+
click_link I18n.t('dialogs.button_continue')
36+
37+
# services/new
38+
expect(page).to have_content(I18n.t('activemodel.attributes.service_creation.service_name'))
39+
end
40+
41+
scenario 'Building a form and NOT ruling out GOV.UK Forms but continuing anyway' do
42+
given_I_am_logged_in(admin: false)
43+
click_link I18n.t('services.create')
44+
45+
# get_started
46+
choose I18n.t('activemodel.attributes.questionnaire/get_started_form/new_form_reason.building'), allow_label_click: true
47+
click_button I18n.t('dialogs.button_continue')
48+
49+
# gov_forms
50+
choose I18n.t('activemodel.attributes.questionnaire/gov_forms/govuk_forms_ruled_out.false'), allow_label_click: true
51+
click_button I18n.t('dialogs.button_continue')
52+
53+
# continue
54+
expect(page).to have_content(I18n.t('questionnaire.continue_form.heading'))
55+
choose I18n.t('activemodel.attributes.questionnaire/continue_form/continue_with_moj_forms.true'), allow_label_click: true
56+
click_button I18n.t('dialogs.button_continue')
57+
58+
# new_form
59+
expect(page).to have_content(I18n.t('questionnaire.new_form_form.heading'))
60+
choose I18n.t('activemodel.attributes.questionnaire/new_form_form/estimated_page_count.under_20'), allow_label_click: true
61+
choose I18n.t('activemodel.attributes.questionnaire/new_form_form/estimated_first_year_submissions_count.under_10000'), allow_label_click: true
62+
choose I18n.t('activemodel.attributes.questionnaire/new_form_form/submission_delivery_method.email'), allow_label_click: true
63+
click_button I18n.t('dialogs.button_continue')
64+
65+
# requirements
66+
expect(page).to have_content(I18n.t('questionnaire.requirements.heading'))
67+
click_link I18n.t('dialogs.button_continue')
68+
69+
# services/new
70+
expect(page).to have_content(I18n.t('activemodel.attributes.service_creation.service_name'))
71+
end
72+
73+
scenario 'Just experimenting' do
74+
given_I_am_logged_in(admin: false)
75+
click_link I18n.t('services.create')
76+
77+
# get_started
78+
choose I18n.t('activemodel.attributes.questionnaire/get_started_form/new_form_reason.experiment'), allow_label_click: true
79+
click_button I18n.t('dialogs.button_continue')
80+
81+
# great_choice
82+
expect(page).to have_content(I18n.t('questionnaire.great_choice.heading'))
83+
click_link I18n.t('dialogs.button_continue')
84+
85+
# services/new
86+
expect(page).to have_content(I18n.t('activemodel.attributes.service_creation.service_name'))
87+
end
88+
89+
scenario 'Building a form and NOT ruling out GOV.UK Forms and NOT continuing' do
90+
given_I_am_logged_in(admin: false)
91+
click_link I18n.t('services.create')
92+
93+
# get_started
94+
choose I18n.t('activemodel.attributes.questionnaire/get_started_form/new_form_reason.building'), allow_label_click: true
95+
click_button I18n.t('dialogs.button_continue')
96+
97+
# gov_forms
98+
choose I18n.t('activemodel.attributes.questionnaire/gov_forms/govuk_forms_ruled_out.false'), allow_label_click: true
99+
click_button I18n.t('dialogs.button_continue')
100+
101+
# continue
102+
choose I18n.t('activemodel.attributes.questionnaire/continue_form/continue_with_moj_forms.false'), allow_label_click: true
103+
click_button I18n.t('dialogs.button_continue')
104+
105+
# exit
106+
expect(page).to have_content(I18n.t('questionnaire.exit.heading'))
107+
click_link I18n.t('dialogs.link_back_to_your_forms')
108+
109+
# services index
110+
expect(page).to have_content(I18n.t('services.heading'))
111+
end
112+
end

acceptance/pages/editor_app.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
class EditorApp < SitePrism::Page
77
extend DataContentId
88

9-
if ENV['ACCEPTANCE_TESTS_USER'] && ENV['ACCEPTANCE_TESTS_PASSWORD']
10-
set_url sprintf(ENV['ACCEPTANCE_TESTS_EDITOR_APP'], user: ENV['ACCEPTANCE_TESTS_USER'], password: ENV['ACCEPTANCE_TESTS_PASSWORD'])
9+
if ENV['ACCEPTANCE_TESTS_ADMIN_USER'] && ENV['ACCEPTANCE_TESTS_ADMIN_PASSWORD']
10+
set_url sprintf(ENV['ACCEPTANCE_TESTS_EDITOR_APP'], user: ENV['ACCEPTANCE_TESTS_ADMIN_USER'], password: ENV['ACCEPTANCE_TESTS_ADMIN_PASSWORD'])
1111
else
1212
set_url ENV['ACCEPTANCE_TESTS_EDITOR_APP']
1313
end

acceptance/support/common_steps.rb

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,74 @@ module CommonSteps
1313
I18n.t('warnings.pages_flow.both_pages')
1414
].freeze
1515

16-
def given_I_am_logged_in
16+
CREDENTIALS = {
17+
admin: {
18+
form_email: 'fb-acceptance-tests@digital.justice.gov.uk',
19+
ci_email_env: 'ACCEPTANCE_TESTS_ADMIN_USER',
20+
ci_password_env: 'ACCEPTANCE_TESTS_ADMIN_PASSWORD'
21+
},
22+
user: {
23+
form_email: 'fb-acceptance-tests-standard@digital.justice.gov.uk',
24+
ci_email_env: 'ACCEPTANCE_TESTS_STANDARD_USER',
25+
ci_password_env: 'ACCEPTANCE_TESTS_STANDARD_PASSWORD'
26+
}
27+
}.freeze
28+
29+
def given_I_am_logged_in(admin: true)
1730
editor.load
18-
page.find(:css, '#main-content', visible: true)
31+
page.find('#main-content', visible: true)
1932
editor.sign_in_button.click
2033

21-
if ENV['CI_MODE'].present?
22-
expect(page).to have_content('Please select the log in option that matches your work email')
23-
24-
# Executing javascript directly as the fields and button are hidden on the
25-
# login page for the moment
26-
editor.execute_script(
27-
"document.getElementById('email').value = '#{ENV['ACCEPTANCE_TESTS_USER']}'"
28-
)
29-
editor.execute_script(
30-
"document.getElementById('password').value = '#{ENV['ACCEPTANCE_TESTS_PASSWORD']}'"
31-
)
32-
editor.execute_script(
33-
"document.getElementById('btn-login').click()"
34-
)
35-
else
36-
editor.sign_in_email_field.set('fb-acceptance-tests@digital.justice.gov.uk')
37-
editor.sign_in_submit.click
38-
end
34+
creds = credentials(admin)
35+
36+
ci_mode? ? login_via_ci(creds) : login_via_form(creds)
37+
38+
verify_logged_in(admin)
39+
end
40+
41+
def credentials(admin)
42+
admin ? CREDENTIALS[:admin] : CREDENTIALS[:user]
43+
end
44+
45+
def ci_mode?
46+
ENV['CI_MODE'].present?
47+
end
48+
49+
def login_via_ci(creds)
50+
expect(page).to have_content('Please select the log in option that matches your work email')
51+
52+
# Executing javascript directly as the fields and button are hidden on the
53+
# login page for the moment
54+
editor.execute_script(
55+
"document.getElementById('email').value = '#{ENV[creds[:ci_email_env]]}'"
56+
)
57+
editor.execute_script(
58+
"document.getElementById('password').value = '#{ENV[creds[:ci_password_env]]}'"
59+
)
60+
editor.execute_script(
61+
"document.getElementById('btn-login').click()"
62+
)
63+
end
64+
65+
def login_via_form(creds)
66+
editor.sign_in_email_field.set(creds[:form_email])
67+
editor.sign_in_submit.click
68+
end
69+
70+
def verify_logged_in(admin)
71+
admin ? user_sees_create_new_form_button : user_sees_create_new_form_link
72+
end
73+
74+
def user_sees_create_new_form_button
3975
page.find('button.DialogActivator.govuk-button.fb-govuk-button', visible: true)
4076
expect(page).to have_content(I18n.t('services.create'))
4177
end
4278

79+
def user_sees_create_new_form_link
80+
page.find('a.govuk-button.fb-govuk-button', visible: true)
81+
expect(page).to have_content(I18n.t('services.create'))
82+
end
83+
4384
def given_I_have_a_service(service = service_name)
4485
editor.load
4586
page.find(:css, '#main-content', visible: true)

config/initializers/moj_forms_team.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
MOJ_FORMS_ADMIN = %w[
2-
fb-acceptance-tests@digital.justice.gov.uk
3-
mark.jefferson@digital.justice.gov.uk
4-
deepika.patel@digital.justice.gov.uk
5-
Deepika.Patel@justice.gov.uk
6-
Rhian.Townsend@justice.gov.uk
7-
Mark.Jefferson1@justice.gov.uk
8-
Edwin.Bajomo@justice.gov.uk
9-
andrew.altwasser@digital.justice.gov.uk
10-
Andrew.Altwasser@justice.gov.uk
11-
].freeze
1+
MOJ_FORMS_ADMIN = [
2+
ENV['ACCEPTANCE_TESTS_ADMIN_USER'],
3+
'mark.jefferson@digital.justice.gov.uk',
4+
'deepika.patel@digital.justice.gov.uk',
5+
'Deepika.Patel@justice.gov.uk',
6+
'Rhian.Townsend@justice.gov.uk',
7+
'Mark.Jefferson1@justice.gov.uk',
8+
'Edwin.Bajomo@justice.gov.uk',
9+
'andrew.altwasser@digital.justice.gov.uk',
10+
'Andrew.Altwasser@justice.gov.uk'
11+
].compact.freeze
1212

1313
MOJ_FORMS_DEVS = %w[
1414
matt.tei@digital.justice.gov.uk

0 commit comments

Comments
 (0)