-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #374 from alphagov/refactor-feature-specs
Refactor audit feature specs
- Loading branch information
Showing
7 changed files
with
388 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,168 +1,205 @@ | ||
RSpec.feature "Auditing a content item", type: :feature do | ||
let!(:content_item) do | ||
create( | ||
:content_item, | ||
title: "Flooding", | ||
description: "All about flooding.", | ||
base_path: "/flooding", | ||
publishing_app: "whitehall", | ||
) | ||
RSpec.feature 'Auditing a content item', type: :feature do | ||
scenario 'information about the published content is available' do | ||
given_i_am_auditing_a_content_item | ||
then_the_title_is_shown_linking_to_the_published_content | ||
and_the_description_is_shown | ||
end | ||
|
||
let!(:my_organisation) do | ||
create( | ||
:organisation, | ||
title: "YA Authors", | ||
) | ||
scenario 'information about the assignee is available' do | ||
given_i_am_auditing_a_content_item | ||
then_the_name_of_the_assignee_is_shown | ||
end | ||
|
||
let!(:me) do | ||
create( | ||
:user, | ||
name: "Garth Nix", | ||
organisation: my_organisation, | ||
) | ||
scenario 'all questions must be answered' do | ||
given_i_am_auditing_a_content_item | ||
then_i_am_prompted_to_consider_if_it_needs_to_change | ||
when_i_answer_some_of_the_questions | ||
then_an_error_message_is_shown | ||
end | ||
|
||
def answer_question(question, answer) | ||
find('p', text: question) | ||
.first(:xpath, '..//..') | ||
.choose(answer) | ||
scenario 'answers are remembered' do | ||
given_i_am_auditing_a_content_item | ||
when_i_answer_all_of_the_questions | ||
then_a_success_message_is_shown | ||
and_my_answers_to_the_questions_are_remembered | ||
end | ||
|
||
def expect_answer(question, answer) | ||
label_element = find('p', text: question) | ||
.first(:xpath, "..//..//input[@type='radio'][@checked='checked']//..") | ||
|
||
expect(label_element).to have_content(answer) | ||
scenario 'clicking on yes and no buttons for redundant/similar content questions', js: true do | ||
given_i_am_auditing_a_content_item | ||
then_i_am_prompted_to_specify_redirect_urls_if_the_content_should_be_removed | ||
end | ||
|
||
scenario "auditing a content item" do | ||
visit content_item_audit_path(content_item) | ||
|
||
expect(page).to_not have_selector(".nav") | ||
|
||
expect(page).to have_link("Flooding", href: "https://gov.uk/flooding") | ||
expect(page).to have_content("All about flooding.") | ||
|
||
expect(page).to have_content("Do these things need to change?") | ||
scenario 'filling in and saving questions for redundant content', js: true do | ||
given_i_am_auditing_a_content_item | ||
when_i_specify_urls | ||
then_the_urls_i_specified_are_shown | ||
when_i_specify_that_the_content_is_relevant | ||
then_the_urls_i_previously_specified_are_discarded | ||
end | ||
|
||
answer_question "Title", "No" | ||
answer_question "Summary", "Yes" | ||
answer_question "Page detail", "No" | ||
fill_in "Notes", with: "something" | ||
private | ||
|
||
click_on "Save and continue" | ||
expect(page).to have_content("Please answer all the questions.") | ||
def given_i_am_auditing_a_content_item | ||
organisation = create(:organisation, title: 'YA Authors') | ||
user = create(:user, name: 'Garth Nix', organisation: organisation) | ||
|
||
answer_question "Attachments", "Yes" | ||
answer_question "Content type", "No" | ||
answer_question "Is the content out of date?", "Yes" | ||
content_item = create( | ||
:content_item, | ||
allocated_to: user, | ||
title: 'Flooding', | ||
description: 'All about flooding.', | ||
base_path: '/flooding', | ||
publishing_app: 'whitehall', | ||
) | ||
|
||
answer_question "Should the content be removed?", "Yes" | ||
expect(page).to have_content("Where should users be redirected to? (optional)") | ||
fill_in "Where should users be redirected to? (optional)", with: "http://www.example.com" | ||
@audit_content_item = ContentAuditTool.new.audit_content_item | ||
@audit_content_item.load(content_id: content_item.content_id) | ||
end | ||
|
||
answer_question "Is this content very similar to other pages?", "Yes" | ||
fill_in "URLs of similar pages", with: "something" | ||
def then_i_am_prompted_to_consider_if_it_needs_to_change | ||
expect(@audit_content_item) | ||
.to have_questions_title(text: 'Do these things need to change?') | ||
end | ||
|
||
click_on "Save and continue" | ||
expect(page).to have_content("Audit saved — no items remaining.") | ||
def then_the_name_of_the_assignee_is_shown | ||
expect(@audit_content_item.metadata) | ||
.to have_assigned_to(text: 'Garth Nix YA Authors') | ||
end | ||
|
||
expect_answer "Title", "No" | ||
expect_answer "Summary", "Yes" | ||
expect_answer "Page detail", "No" | ||
expect_answer "Attachments", "Yes" | ||
expect_answer "Content type", "No" | ||
expect_answer "Is the content out of date?", "Yes" | ||
expect_answer "Should the content be removed?", "Yes" | ||
expect(find_field("Where should users be redirected to? (optional)").value).to eq("http://www.example.com") | ||
expect_answer "Is this content very similar to other pages?", "Yes" | ||
expect(find_field("URLs of similar pages").value).to eq("something") | ||
expect(find_field("Notes").value).to eq("something") | ||
def when_i_answer_some_of_the_questions | ||
@audit_content_item.audit_form do |form| | ||
form.title.choose 'No' | ||
form.summary.choose 'Yes' | ||
form.page_detail.choose 'No' | ||
form.notes.set 'something' | ||
form.save_and_continue.click | ||
end | ||
end | ||
|
||
answer_question "Attachments", "Yes" | ||
answer_question "Content type", "No" | ||
answer_question "Is the content out of date?", "Yes" | ||
def when_i_answer_all_of_the_questions | ||
@audit_content_item.audit_form do |form| | ||
form.title.choose 'No' | ||
form.summary.choose 'Yes' | ||
form.page_detail.choose 'No' | ||
form.attachments.choose 'Yes' | ||
form.content_type.choose 'No' | ||
form.content_out_of_date.choose 'Yes' | ||
form.content_should_be_removed.choose 'Yes' | ||
expect(form).to have_redirect_urls | ||
form.redirect_urls.set 'https://example.com/redirect' | ||
form.content_similar.choose 'Yes' | ||
expect(form).to have_similar_urls | ||
form.similar_urls.set 'https://example.com/similar' | ||
form.notes.set 'something' | ||
form.save_and_continue.click | ||
end | ||
end | ||
|
||
click_on "Save and continue" | ||
expect(page).to have_content("Audit saved — no items remaining.") | ||
def when_i_specify_that_the_content_is_relevant | ||
@audit_content_item.audit_form do |form| | ||
form.content_should_be_removed.choose 'No' | ||
form.content_similar.choose 'No' | ||
|
||
expect_answer "Title", "No" | ||
expect_answer "Summary", "Yes" | ||
expect_answer "Page detail", "No" | ||
expect_answer "Attachments", "Yes" | ||
expect_answer "Content type", "No" | ||
expect_answer "Is the content out of date?", "Yes" | ||
form.save_and_continue.click | ||
end | ||
end | ||
|
||
scenario "clicking on yes and no buttons for redundant/similar content questions", js: true do | ||
visit content_item_audit_path(content_item) | ||
|
||
expect(page).to have_no_content("Where should users be redirected to? (optional)") | ||
expect(page).to have_no_content("URLs of similar pages") | ||
def when_i_specify_urls | ||
@audit_content_item.audit_form do |form| | ||
form.title.choose 'No' | ||
form.summary.choose 'Yes' | ||
form.page_detail.choose 'No' | ||
form.notes.set 'something' | ||
form.attachments.choose 'Yes' | ||
form.content_type.choose 'No' | ||
form.content_out_of_date.choose 'Yes' | ||
form.content_should_be_removed.choose 'Yes' | ||
form.redirect_urls.set 'https://example.com/redirect' | ||
form.content_similar.choose 'Yes' | ||
form.similar_urls.set 'https://example.com/similar' | ||
|
||
form.save_and_continue.click | ||
end | ||
end | ||
|
||
answer_question "Should the content be removed?", "Yes" | ||
expect(page).to have_content("Where should users be redirected to? (optional)") | ||
def then_a_success_message_is_shown | ||
expect(@audit_content_item) | ||
.to have_success_message(text: 'Audit saved — no items remaining.') | ||
end | ||
|
||
answer_question "Should the content be removed?", "No" | ||
expect(page).to have_no_content("Where should users be redirected to? (optional)") | ||
def then_an_error_message_is_shown | ||
expect(@audit_content_item) | ||
.to have_error_message(text: 'Please answer all the questions.') | ||
end | ||
|
||
answer_question "Is this content very similar to other pages?", "Yes" | ||
expect(page).to have_content("URLs of similar pages") | ||
def then_the_title_is_shown_linking_to_the_published_content | ||
expect(@audit_content_item.content_item_title) | ||
.to have_link('Flooding', href: 'https://gov.uk/flooding') | ||
end | ||
|
||
answer_question "Is this content very similar to other pages?", "No" | ||
expect(page).to have_no_content("URLs of similar pages") | ||
def and_the_description_is_shown | ||
expect(@audit_content_item) | ||
.to have_content_item_description(text: 'All about flooding.') | ||
end | ||
|
||
scenario "filling in and saving questions for redundant content", js: true do | ||
visit content_item_audit_path(content_item) | ||
def and_my_answers_to_the_questions_are_remembered | ||
@audit_content_item.audit_form do |form| | ||
expect(form.title).to have_checked_field('No') | ||
expect(form.summary).to have_checked_field('Yes') | ||
expect(form.page_detail).to have_checked_field('No') | ||
expect(form.attachments).to have_checked_field('Yes') | ||
expect(form.content_type).to have_checked_field('No') | ||
expect(form.content_out_of_date).to have_checked_field('Yes') | ||
expect(form.content_should_be_removed).to have_checked_field('Yes') | ||
expect(form).to have_redirect_urls(text: 'https://example.com/redirect') | ||
expect(form.content_similar).to have_checked_field('Yes') | ||
expect(form).to have_similar_urls(text: 'https://example.com/similar') | ||
expect(form).to have_notes(text: 'something') | ||
end | ||
end | ||
|
||
answer_question "Title", "No" | ||
answer_question "Summary", "Yes" | ||
answer_question "Page detail", "No" | ||
fill_in "Notes", with: "something" | ||
answer_question "Attachments", "Yes" | ||
answer_question "Content type", "No" | ||
answer_question "Is the content out of date?", "Yes" | ||
answer_question "Should the content be removed?", "Yes" | ||
fill_in "Where should users be redirected to? (optional)", with: "http://www.example.com" | ||
answer_question "Is this content very similar to other pages?", "Yes" | ||
fill_in "URLs of similar pages", with: "http://www.example.com" | ||
def then_i_am_prompted_to_specify_redirect_urls_if_the_content_should_be_removed | ||
@audit_content_item.audit_form do |form| | ||
expect(form).to have_no_redirect_urls | ||
expect(form).to have_no_similar_urls | ||
|
||
click_on "Save" | ||
form.content_should_be_removed.choose 'Yes' | ||
expect(form).to have_redirect_urls | ||
|
||
expect(page).to have_content("Where should users be redirected to? (optional)") | ||
expect(find_field("Where should users be redirected to? (optional)").value).to eq("http://www.example.com") | ||
expect(page).to have_content("URLs of similar pages") | ||
expect(find_field("URLs of similar pages").value).to eq("http://www.example.com") | ||
form.content_should_be_removed.choose 'No' | ||
expect(form).to have_no_redirect_urls | ||
|
||
answer_question "Should the content be removed?", "No" | ||
answer_question "Is this content very similar to other pages?", "No" | ||
click_on "Save" | ||
form.content_similar.choose 'Yes' | ||
expect(form).to have_similar_urls | ||
|
||
expect(page).to have_no_content('Where should users be redirected to? (optional)') | ||
expect(page).to have_no_content("URLs of similar pages") | ||
form.content_similar.choose 'No' | ||
expect(form).to have_no_similar_urls | ||
end | ||
end | ||
|
||
answer_question "Should the content be removed?", "Yes" | ||
answer_question "Is this content very similar to other pages?", "Yes" | ||
expect(find_field("Where should users be redirected to? (optional)").value).to eq("") | ||
expect(find_field("URLs of similar pages").value).to eq("") | ||
end | ||
def then_the_urls_i_specified_are_shown | ||
@audit_content_item.audit_form do |form| | ||
form.wait_for_redirect_urls | ||
form.wait_for_similar_urls | ||
|
||
context "a content item is assigned to me" do | ||
let!(:sabriel) do | ||
create( | ||
:content_item, | ||
allocated_to: me, | ||
) | ||
expect(form).to have_redirect_urls(text: 'https://example.com/redirect') | ||
expect(form).to have_similar_urls(text: 'https://example.com/similar') | ||
end | ||
end | ||
|
||
def then_the_urls_i_previously_specified_are_discarded | ||
@audit_content_item.audit_form do |form| | ||
form.wait_for_redirect_urls | ||
form.wait_for_similar_urls | ||
|
||
expect(form).to have_no_redirect_urls | ||
expect(form).to have_no_similar_urls | ||
|
||
scenario "my name and organisation are shown on the content item" do | ||
visit content_item_audit_path(sabriel) | ||
form.content_should_be_removed.choose 'Yes' | ||
form.content_similar.choose 'Yes' | ||
|
||
expect(page).to have_content("Garth Nix") | ||
expect(page).to have_content("YA Authors") | ||
expect(form).to have_redirect_urls(text: '') | ||
expect(form).to have_similar_urls(text: '') | ||
end | ||
end | ||
end |
Oops, something went wrong.