From 5f1bdd7cfbe28f3792d1e0378aff2098f2b902e6 Mon Sep 17 00:00:00 2001 From: pezholio Date: Thu, 23 Jan 2025 11:12:16 +0000 Subject: [PATCH 1/2] Refactor steps This organises the Cucumber steps into more logical files to make them easier to keep track of. --- .../step_definitions/back_link_steps.rb | 33 ++ .../content_block_manager_steps.rb | 516 +----------------- .../dependent_content_steps.rb | 61 +++ .../step_definitions/embed_code_steps.rb | 20 + .../step_definitions/error_message_steps.rb | 30 + .../features/step_definitions/filter_steps.rb | 29 + .../step_definitions/form_step_steps.rb | 17 + .../step_definitions/navigation_steps.rb | 21 + .../step_definitions/preview_steps.rb | 59 ++ .../step_definitions/schedule_steps.rb | 61 +++ .../features/step_definitions/schema_steps.rb | 31 ++ .../step_definitions/sidekiq_steps.rb | 9 + .../step_definitions/timeline_steps.rb | 18 + .../features/step_definitions/user_steps.rb | 24 + .../features/support/form_step_helpers.rb | 38 ++ .../features/support/helpers.rb | 53 ++ 16 files changed, 505 insertions(+), 515 deletions(-) create mode 100644 lib/engines/content_block_manager/features/step_definitions/back_link_steps.rb create mode 100644 lib/engines/content_block_manager/features/step_definitions/dependent_content_steps.rb create mode 100644 lib/engines/content_block_manager/features/step_definitions/embed_code_steps.rb create mode 100644 lib/engines/content_block_manager/features/step_definitions/error_message_steps.rb create mode 100644 lib/engines/content_block_manager/features/step_definitions/filter_steps.rb create mode 100644 lib/engines/content_block_manager/features/step_definitions/form_step_steps.rb create mode 100644 lib/engines/content_block_manager/features/step_definitions/navigation_steps.rb create mode 100644 lib/engines/content_block_manager/features/step_definitions/preview_steps.rb create mode 100644 lib/engines/content_block_manager/features/step_definitions/schedule_steps.rb create mode 100644 lib/engines/content_block_manager/features/step_definitions/schema_steps.rb create mode 100644 lib/engines/content_block_manager/features/step_definitions/sidekiq_steps.rb create mode 100644 lib/engines/content_block_manager/features/step_definitions/timeline_steps.rb create mode 100644 lib/engines/content_block_manager/features/step_definitions/user_steps.rb create mode 100644 lib/engines/content_block_manager/features/support/form_step_helpers.rb create mode 100644 lib/engines/content_block_manager/features/support/helpers.rb diff --git a/lib/engines/content_block_manager/features/step_definitions/back_link_steps.rb b/lib/engines/content_block_manager/features/step_definitions/back_link_steps.rb new file mode 100644 index 00000000000..d3c54878742 --- /dev/null +++ b/lib/engines/content_block_manager/features/step_definitions/back_link_steps.rb @@ -0,0 +1,33 @@ +Then("I should see a back link to the select schema page") do + expect(page).to have_link("Back", href: content_block_manager.new_content_block_manager_content_block_document_path) +end + +Then("I should see a back link to the document page") do + expect(page).to have_link( + "Back", + href: content_block_manager.content_block_manager_content_block_document_path(@content_block.document), + ) +end + +Then("I should see a back link to the show page") do + match_data = URI.parse(page.current_url).path.match(%r{content-block-editions/(\d+)/edit$}) + id = match_data[1] unless match_data.nil? + expect(id).not_to be_nil, "Could not find an existing content block edition ID in the URL" + expect(page).to have_link("Back", href: content_block_manager.content_block_manager_content_block_edition_path(id)) +end + +Then(/^I should see a back link to the "([^"]*)" step$/) do |step| + link = if step == "edit" + content_block_manager.new_content_block_manager_content_block_document_edition_path(@content_block.document) + else + content_block_manager.content_block_manager_content_block_workflow_path( + @content_block.document.editions.last, + step:, + ) + end + expect(page).to have_link("Back", href: link) +end + +Then("I should see a back link to the document list page") do + expect(page).to have_link("Back", href: content_block_manager.content_block_manager_content_block_documents_path) +end diff --git a/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb b/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb index 292f4b3571b..eeb625176f8 100644 --- a/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb +++ b/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb @@ -1,5 +1,5 @@ require_relative "../support/stubs" -require_relative "../support/dependent_content" +require_relative "../support/helpers" # Suppress noisy Sidekiq logging in the test output Sidekiq.configure_client do |cfg| @@ -10,25 +10,6 @@ Whitehall.stubs(:integration_or_staging?).returns(true) end -Given("a schema {string} exists with the following fields:") do |block_type, table| - fields = table.hashes - @schemas ||= {} - body = { - "type" => "object", - "required" => fields.select { |f| f["required"] == "true" }.map { |f| f["field"] }, - "additionalProperties" => false, - "properties" => fields.map { |f| - [f["field"], { "type" => f["type"], "format" => f["format"] }] - }.to_h, - } - @schemas[block_type] = build(:content_block_schema, block_type:, body:) - ContentBlockManager::ContentBlock::Schema.stubs(:all).returns(@schemas.values) -end - -When("I access the create object page") do - visit content_block_manager.new_content_block_manager_content_block_edition_path -end - When("I click to create an object") do click_link "Create content block" end @@ -49,49 +30,10 @@ click_button "View results" end -Then("I should see all the schemas listed") do - @schemas.values.each do |schema| - expect(page).to have_content(schema.name) - end -end - -When("I click on the {string} schema") do |schema_id| - @schema = @schemas[schema_id] - ContentBlockManager::ContentBlock::Schema.expects(:find_by_block_type).with(schema_id).at_least_once.returns(@schema) - choose @schema.name - click_save_and_continue -end - -Then("I should see a form for the schema") do - expect(page).to have_content(@schema.name) -end - -Then("I should see a back link to the document list page") do - expect(page).to have_link("Back", href: content_block_manager.content_block_manager_content_block_documents_path) -end - Then("I should see a Cancel button to the document list page") do expect(page).to have_link("Cancel", href: content_block_manager.content_block_manager_content_block_documents_path) end -Then("I should see a back link to the select schema page") do - expect(page).to have_link("Back", href: content_block_manager.new_content_block_manager_content_block_document_path) -end - -Then("I should see a back link to the document page") do - expect(page).to have_link( - "Back", - href: content_block_manager.content_block_manager_content_block_document_path(@content_block.document), - ) -end - -Then("I should see a back link to the show page") do - match_data = URI.parse(page.current_url).path.match(%r{content-block-editions/(\d+)/edit$}) - id = match_data[1] unless match_data.nil? - expect(id).not_to be_nil, "Could not find an existing content block edition ID in the URL" - expect(page).to have_link("Back", href: content_block_manager.content_block_manager_content_block_edition_path(id)) -end - When("I complete the form with the following fields:") do |table| fields = table.hashes.first @title = fields.delete("title") @@ -153,13 +95,6 @@ has_support_button end -def has_support_button - expect(page).to have_link( - "Raise a support request", - href: Whitehall.support_url, - ) -end - And("I should be taken to the confirmation page for a new block") do content_block = ContentBlockManager::ContentBlock::Edition.last @@ -275,19 +210,6 @@ def has_support_button @content_blocks.push(@content_block) end -When("I visit the page for the content block") do - visit content_block_manager.content_block_manager_content_block_edition_path(@content_block) -end - -When("I visit the Content Block Manager home page") do - visit content_block_manager.content_block_manager_root_path -end - -When("I visit a block's content ID endpoint") do - block = ContentBlockManager::ContentBlock::Document.last - visit content_block_manager.content_block_manager_content_block_content_id_path(block.content_id) -end - Then("I am taken back to Content Block Manager home page") do assert_equal current_path, content_block_manager.content_block_manager_root_path end @@ -315,10 +237,6 @@ def has_support_button end end -Then("'all organisations' is already selected as a filter") do - expect(page).to have_field("Lead organisation", with: "") -end - Then("I should see the details for all documents from my organisation") do ContentBlockManager::ContentBlock::Document.with_lead_organisation(@user.organisation.id).each do |document| should_show_summary_card_for_email_address_content_block( @@ -384,99 +302,6 @@ def has_support_button assert_equal "Changed title", edition.title end -def should_show_summary_card_for_email_address_content_block(document_title, email_address) - expect(page).to have_selector(".govuk-summary-list__key", text: "Title") - expect(page).to have_selector(".govuk-summary-list__value", text: document_title) - expect(page).to have_selector(".govuk-summary-list__key", text: "Email address") - expect(page).to have_selector(".govuk-summary-list__value", text: email_address) -end - -def should_show_summary_list_for_email_address_content_block(document_title, email_address, organisation, instructions_to_publishers = nil) - expect(page).to have_selector(".govuk-summary-list__key", text: "Title") - expect(page).to have_selector(".govuk-summary-list__value", text: document_title) - expect(page).to have_selector(".govuk-summary-list__actions", text: "Edit") - expect(page).to have_selector(".govuk-summary-list__key", text: "Email address") - expect(page).to have_selector(".govuk-summary-list__value", text: email_address) - expect(page).to have_selector(".govuk-summary-list__key", text: "Lead organisation") - expect(page).to have_selector(".govuk-summary-list__value", text: organisation) - if instructions_to_publishers - expect(page).to have_selector(".govuk-summary-list__key", text: "Instructions to publishers") - expect(page).to have_selector(".govuk-summary-list__value", text: instructions_to_publishers) - end - expect(page).to have_selector(".govuk-summary-list__key", text: "Status") - expect(page).to have_selector(".govuk-summary-list__value", text: @user.name) -end - -def should_show_edit_form_for_email_address_content_block(document_title, email_address) - expect(page).to have_content(I18n.t("content_block_edition.update.title", block_type: "email address")) - expect(page).to have_field("Title", with: document_title) - expect(page).to have_field("Email address", with: email_address) - expect(page).to have_content("Save and continue") - expect(page).to have_content("Cancel") -end - -Then("I should see errors for the required fields") do - assert_text "Title cannot be blank", minimum: 2 - - required_fields = @schema.body["required"] - required_fields.each do |required_field| - assert_text "#{ContentBlockManager::ContentBlock::Edition.human_attribute_name("details_#{required_field}")} cannot be blank", minimum: 2 - end - assert_text "Lead organisation cannot be blank", minimum: 2 -end - -Then("I see the errors prompting me to provide a date and time") do - assert_text "Scheduled publication date and time cannot be blank", minimum: 2 -end - -Then("I see the errors informing me the date is invalid") do - assert_text I18n.t("activerecord.errors.models.content_block_manager/content_block/edition.attributes.scheduled_publication.time.blank"), minimum: 2 -end - -Then("I should see an error message telling me that schedule publishing cannot be blank") do - assert_text I18n.t("activerecord.errors.models.content_block_manager/content_block/edition.attributes.schedule_publishing.blank"), minimum: 2 -end - -Then("I see the errors informing me the date must be in the future") do - assert_text I18n.t("activerecord.errors.models.content_block_manager/content_block/edition.attributes.scheduled_publication.future_date"), minimum: 2 -end - -Then("I should see a message that the field is an invalid {string}") do |format| - assert_text I18n.t("activerecord.errors.models.content_block_manager/content_block/edition.invalid", attribute: format) -end - -Then("I should see a message that I need to confirm the details are correct") do - assert_text I18n.t("content_block_edition.review_page.errors.confirm"), minimum: 2 -end - -Then("I should see a message that the filter dates are invalid") do - expect(page).to have_selector("a[href='#last_updated_from_3i']"), text: "Last updated from is not a valid date" - expect(page).to have_selector("a[href='#last_updated_to_3i']"), text: "Last updated to is not a valid date" -end - -Then("I should see a permissions error") do - assert_text "Permissions error" -end - -Then("I should see the created event on the timeline") do - expect(page).to have_selector(".timeline__title", text: "Email address created") - expect(page).to have_selector(".timeline__byline", text: "by #{@user.name}") -end - -Then(/^I should see ([^"]*) publish events on the timeline$/) do |count| - expect(page).to have_selector(".timeline__title", text: "Email address published", count:) -end - -Then("I should see the publish event on the timeline") do - expect(page).to have_selector(".timeline__title", text: "Email address published") - expect(page).to have_selector(".timeline__byline", text: "by Scheduled Publishing Robot") -end - -Then("I should see the scheduled event on the timeline") do - expect(page).to have_selector(".timeline__title", text: "Email address scheduled") - expect(page).to have_selector(".timeline__byline", text: "by #{@user.name}") -end - Then("I am asked to review my answers") do assert_text "Review email address" end @@ -498,129 +323,6 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_ click_on "Publish" end -When(/^dependent content exists for a content block$/) do - host_editor_id = SecureRandom.uuid - @dependent_content = 10.times.map do |i| - { - "title" => "Content #{i}", - "document_type" => "document", - "base_path" => "/host-content-path-#{i}", - "content_id" => SecureRandom.uuid, - "last_edited_by_editor_id" => host_editor_id, - "last_edited_at" => 2.days.ago.to_s, - "host_content_id" => "abc12345", - "instances" => 1, - "primary_publishing_organisation" => { - "content_id" => SecureRandom.uuid, - "title" => "Organisation #{i}", - "base_path" => "/organisation/#{i}", - }, - } - end - - @rollup = build(:rollup).to_h - - stub_publishing_api_has_embedded_content_for_any_content_id( - results: @dependent_content, - total: @dependent_content.length, - order: ContentBlockManager::HostContentItem::DEFAULT_ORDER, - rollup: @rollup, - ) - - stub_publishing_api_has_embedded_content_details(@dependent_content.first) - - @host_content_editor = build(:signon_user, uid: host_editor_id) - - stub_request(:get, "#{Plek.find('signon', external: true)}/api/users") - .with(query: { uuids: [host_editor_id] }) - .to_return(body: [@host_content_editor].to_json) -end - -Then(/^I should see the dependent content listed$/) do - assert_text "List of locations" - - @dependent_content.each do |item| - assert_text item["title"] - break if item == @dependent_content.last - end - - expect(page).to have_link(@host_content_editor.name, href: content_block_manager.content_block_manager_user_path(@host_content_editor.uid)) -end - -Then(/^I (should )?see the rollup data for the dependent content$/) do |_should| - should_show_rollup_data -end - -Then(/^I should see an error prompting me to choose an object type$/) do - assert_text I18n.t("activerecord.errors.models.content_block_manager/content_block/document.attributes.block_type.blank") -end - -And("the host documents link to the draft content store") do - @dependent_content.each do |item| - expect(page).to have_selector("a.govuk-link[href='#{Plek.external_url_for('draft-origin') + item['base_path']}']", text: item["title"]) - end -end - -When("I click on the first host document") do - @current_host_document = @dependent_content.first - stub_request( - :get, - "#{Plek.find('publishing-api')}/v2/content/#{@current_host_document['host_content_id']}", - ).to_return( - status: 200, - body: { - details: { - body: "

title

", - }, - title: @current_host_document["title"], - document_type: "news_story", - base_path: @current_host_document["base_path"], - publishing_app: "test", - }.to_json, - ) - - stub_request( - :get, - Plek.website_root + @current_host_document["base_path"], - ).to_return( - status: 200, - body: "

#{@current_host_document['title']}

iframe preview Link to other page

#{@content_block.render}", - ) - - stub_request( - :get, - "#{Plek.website_root}/other-page", - ).to_return( - status: 200, - body: "

#{@current_host_document['title']}

other page

#{@content_block.render}", - ) - - click_on @current_host_document["title"] -end - -Then("the preview page opens in a new tab") do - page.switch_to_window(page.windows.last) - assert_text "Preview email address" - assert_text "Instances: 1" - assert_text "Email address: #{@email_address}" - within_frame "preview" do - assert_text @current_host_document["title"] - end -end - -When("I click on a link within the frame") do - within_frame "preview" do - click_on "Link to other page" - end -end - -Then("I should see the content of the linked page") do - within_frame "preview" do - assert_text "other page" - assert_text @email_address - end -end - When(/^I save and continue$/) do click_save_and_continue end @@ -639,11 +341,6 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_ select organisation, from: "lead_organisation" end -When("I revisit the edit page") do - @content_block = @content_block.document.latest_edition - visit_edit_page -end - When("I make the changes") do change_details click_save_and_continue @@ -658,76 +355,12 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_ click_save_and_continue end -When("I choose to schedule the change") do - choose "Schedule the edit for the future" -end - -And(/^I schedule the change for (\d+) days in the future$/) do |number_of_days| - choose "Schedule the edit for the future" - @future_date = number_of_days.days.since(Time.zone.now) - @is_scheduled = true - fill_in_date_and_time_field(@future_date) - - click_on "Save and continue" -end - When("one of the content blocks was updated 2 days ago") do content_block_document = ContentBlockManager::ContentBlock::Document.all.last content_block_document.latest_edition.updated_at = 2.days.before(Time.zone.now) content_block_document.latest_edition.save! end -When("I add a filter for blocks updated two days ago") do - date = 2.days.before(Time.zone.now) - - fill_in "last_updated_from_1i", with: date.year - fill_in "last_updated_from_2i", with: date.month - fill_in "last_updated_from_3i", with: date.day - - fill_in "last_updated_to_1i", with: date.year - fill_in "last_updated_to_2i", with: date.month - fill_in "last_updated_to_3i", with: date.day -end - -When("I input invalid dates to filter by") do - fill_in "last_updated_from_1i", with: "1" - fill_in "last_updated_from_2i", with: "34" - fill_in "last_updated_from_3i", with: "56" - - fill_in "last_updated_to_1i", with: "1" - fill_in "last_updated_to_2i", with: "67" - fill_in "last_updated_to_3i", with: "56" -end - -When("I enter an invalid date") do - fill_in "Year", with: "01" -end - -When("I enter a date in the past") do - past_date = 7.days.before(Time.zone.now).to_date - fill_in_date_and_time_field(past_date) -end - -When("I enter the keyword {string}") do |keyword| - fill_in "Keyword", with: keyword -end - -Then("the edition should have been scheduled successfully") do - @schema = @schemas[@content_block.document.block_type] - assert_text "#{@schema.name} scheduled successfully" -end - -And("the block is scheduled and published") do - @is_scheduled = true - create(:scheduled_publishing_robot) - near_future_date = 1.minute.from_now - fill_in_date_and_time_field(near_future_date) - - Sidekiq::Testing.inline! do - click_on "Save and continue" - end -end - Then("the published state of the object should be shown") do visit content_block_manager.content_block_manager_content_block_document_path(@content_block.document) expect(page).to have_selector(".govuk-summary-list__key", text: "Status") @@ -739,10 +372,6 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_ expect(page).to have_selector(".govuk-summary-list__value", text: I18n.l(@future_date, format: :long_ordinal).squish) end -Then("I should see a warning telling me there is a scheduled change") do - assert_text "There is currently a change scheduled" -end - When("I continue after reviewing the links") do click_save_and_continue end @@ -753,22 +382,6 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_ click_save_and_continue end -def visit_edit_page - visit content_block_manager.new_content_block_manager_content_block_document_edition_path(@content_block.document) -end - -def change_details - fill_in "Title", with: "Changed title" - fill_in "Email address", with: "changed@example.com" - select "Ministry of Example", from: "content_block_manager_content_block_edition_lead_organisation" - fill_in "Instructions to publishers", with: "new context information" - click_save_and_continue -end - -def click_save_and_continue - click_on "Save and continue" -end - Then(/^I should see the object store's title in the header$/) do expect(page).to have_selector(".govuk-header__product-name", text: "Content Block Manager") end @@ -802,134 +415,7 @@ def click_save_and_continue expect(page).to have_content("Content Block Manager") end -When("I click to copy the embed code") do - find("a", text: "Copy code").click - has_text?("Code copied") - @embed_code = @content_block.document.embed_code -end - -When("I click to copy the embed code for the content block {string}") do |content_block_name| - within(".govuk-summary-card", text: content_block_name) do - find("a", text: "Copy code").click - has_text?("Code copied") - edition = ContentBlockManager::ContentBlock::Edition.find_by(title: content_block_name) - @embed_code = edition.document.embed_code - end -end - -Then("the embed code should be copied to my clipboard") do - page.driver.browser.execute_cdp("Browser.grantPermissions", origin: page.server_url, permissions: %w[clipboardReadWrite]) - clip_text = page.evaluate_async_script("navigator.clipboard.readText().then(arguments[0])") - expect(clip_text).to eq(@embed_code) -end - -When("I click to edit the schedule") do - find("a", text: "Edit schedule").click -end - -Then(/^there should only be one job scheduled$/) do - jobs = Sidekiq::ScheduledSet.new.select { |job| job.item["class"] == ContentBlockManager::SchedulePublishingWorker.to_s } - expect(jobs.count).to eq(1) -end - -Then(/^there should be no jobs scheduled$/) do - jobs = Sidekiq::ScheduledSet.new.select { |job| job.item["class"] == ContentBlockManager::SchedulePublishingWorker.to_s } - expect(jobs.count).to eq(0) -end - -Given("A user exists with uuid {string}") do |uuid| - @user_from_signon = build( - :signon_user, - uid: uuid, - name: "John Doe", - email: "john@doe.com", - organisation: build(:signon_user_organisation, content_id: "456", name: "User's Org", slug: "users-org"), - ) - - stub_request(:get, "#{Plek.find('signon', external: true)}/api/users") - .with(query: { uuids: [uuid] }) - .to_return(body: [@user_from_signon].to_json) -end - -When("I visit the user page for uuid {string}") do |uuid| - visit content_block_manager.content_block_manager_user_path(uuid) -end - -Then("I should see the details for that user") do - expect(page).to have_selector("h1", text: @user_from_signon.name) - expect(page).to have_selector(".govuk-summary-list__value", text: @user_from_signon.name) - expect(page).to have_selector(".govuk-summary-list__value", text: @user_from_signon.email) - expect(page).to have_selector(".govuk-summary-list__value", text: @user_from_signon.organisation.name) -end - -Then(/^I should be on the "([^"]*)" step$/) do |step| - case step - when "edit" - should_show_edit_form - when "review_links" - should_show_dependent_content - should_show_rollup_data - when "schedule_publishing" - should_show_publish_form - when "review" - should_be_on_review_step - when "change_note" - should_be_on_change_note_step - end -end - -Then(/^I should see a back link to the "([^"]*)" step$/) do |step| - link = if step == "edit" - content_block_manager.new_content_block_manager_content_block_document_edition_path(@content_block.document) - else - content_block_manager.content_block_manager_content_block_workflow_path( - @content_block.document.editions.last, - step:, - ) - end - expect(page).to have_link("Back", href: link) -end - When(/^I add an internal note$/) do fill_in "Describe the change for internal users", with: "Some internal note goes here" click_save_and_continue end - -def should_show_edit_form - should_show_edit_form_for_email_address_content_block( - @content_block.document.title, - @email_address, - ) -end - -def should_show_dependent_content - expect(page).to have_selector("h1", text: "Preview email address") - - @dependent_content.each do |item| - assert_text item["title"] - break if item == @dependent_content.last - end -end - -def should_show_rollup_data - @rollup.keys.each do |k| - within ".rollup-details__rollup-metric.#{k}" do - assert_text k.to_s.titleize - within ".gem-c-glance-metric__figure" do - assert_text @rollup[k] - end - end - end -end - -def should_show_publish_form - assert_text "Select publish date" -end - -def should_be_on_review_step - assert_text "Review email address" -end - -def should_be_on_change_note_step - assert_text "Do users have to know the content has changed?" -end diff --git a/lib/engines/content_block_manager/features/step_definitions/dependent_content_steps.rb b/lib/engines/content_block_manager/features/step_definitions/dependent_content_steps.rb new file mode 100644 index 00000000000..153c88cd49a --- /dev/null +++ b/lib/engines/content_block_manager/features/step_definitions/dependent_content_steps.rb @@ -0,0 +1,61 @@ +require_relative "../support/dependent_content" +require_relative "../support/helpers" + +Then(/^I should see the dependent content listed$/) do + assert_text "List of locations" + + @dependent_content.each do |item| + assert_text item["title"] + break if item == @dependent_content.last + end + + expect(page).to have_link(@host_content_editor.name, href: content_block_manager.content_block_manager_user_path(@host_content_editor.uid)) +end + +Then(/^I (should )?see the rollup data for the dependent content$/) do |_should| + should_show_rollup_data +end + +When(/^dependent content exists for a content block$/) do + host_editor_id = SecureRandom.uuid + @dependent_content = 10.times.map do |i| + { + "title" => "Content #{i}", + "document_type" => "document", + "base_path" => "/host-content-path-#{i}", + "content_id" => SecureRandom.uuid, + "last_edited_by_editor_id" => host_editor_id, + "last_edited_at" => 2.days.ago.to_s, + "host_content_id" => "abc12345", + "instances" => 1, + "primary_publishing_organisation" => { + "content_id" => SecureRandom.uuid, + "title" => "Organisation #{i}", + "base_path" => "/organisation/#{i}", + }, + } + end + + @rollup = build(:rollup).to_h + + stub_publishing_api_has_embedded_content_for_any_content_id( + results: @dependent_content, + total: @dependent_content.length, + order: ContentBlockManager::HostContentItem::DEFAULT_ORDER, + rollup: @rollup, + ) + + stub_publishing_api_has_embedded_content_details(@dependent_content.first) + + @host_content_editor = build(:signon_user, uid: host_editor_id) + + stub_request(:get, "#{Plek.find('signon', external: true)}/api/users") + .with(query: { uuids: [host_editor_id] }) + .to_return(body: [@host_content_editor].to_json) +end + +And("the host documents link to the draft content store") do + @dependent_content.each do |item| + expect(page).to have_selector("a.govuk-link[href='#{Plek.external_url_for('draft-origin') + item['base_path']}']", text: item["title"]) + end +end diff --git a/lib/engines/content_block_manager/features/step_definitions/embed_code_steps.rb b/lib/engines/content_block_manager/features/step_definitions/embed_code_steps.rb new file mode 100644 index 00000000000..868a53e3056 --- /dev/null +++ b/lib/engines/content_block_manager/features/step_definitions/embed_code_steps.rb @@ -0,0 +1,20 @@ +When("I click to copy the embed code") do + find("a", text: "Copy code").click + has_text?("Code copied") + @embed_code = @content_block.document.embed_code +end + +When("I click to copy the embed code for the content block {string}") do |content_block_name| + within(".govuk-summary-card", text: content_block_name) do + find("a", text: "Copy code").click + has_text?("Code copied") + edition = ContentBlockManager::ContentBlock::Edition.find_by(title: content_block_name) + @embed_code = edition.document.embed_code + end +end + +Then("the embed code should be copied to my clipboard") do + page.driver.browser.execute_cdp("Browser.grantPermissions", origin: page.server_url, permissions: %w[clipboardReadWrite]) + clip_text = page.evaluate_async_script("navigator.clipboard.readText().then(arguments[0])") + expect(clip_text).to eq(@embed_code) +end diff --git a/lib/engines/content_block_manager/features/step_definitions/error_message_steps.rb b/lib/engines/content_block_manager/features/step_definitions/error_message_steps.rb new file mode 100644 index 00000000000..47c65104204 --- /dev/null +++ b/lib/engines/content_block_manager/features/step_definitions/error_message_steps.rb @@ -0,0 +1,30 @@ +Then("I should see a message that the field is an invalid {string}") do |format| + assert_text I18n.t("activerecord.errors.models.content_block_manager/content_block/edition.invalid", attribute: format) +end + +Then("I should see a message that I need to confirm the details are correct") do + assert_text I18n.t("content_block_edition.review_page.errors.confirm"), minimum: 2 +end + +Then("I should see a permissions error") do + assert_text "Permissions error" +end + +Then(/^I should see an error prompting me to choose an object type$/) do + assert_text I18n.t("activerecord.errors.models.content_block_manager/content_block/document.attributes.block_type.blank") +end + +Then("I should see errors for the required fields") do + assert_text "Title cannot be blank", minimum: 2 + + required_fields = @schema.body["required"] + required_fields.each do |required_field| + assert_text "#{ContentBlockManager::ContentBlock::Edition.human_attribute_name("details_#{required_field}")} cannot be blank", minimum: 2 + end + assert_text "Lead organisation cannot be blank", minimum: 2 +end + +Then("I should see a message that the filter dates are invalid") do + expect(page).to have_selector("a[href='#last_updated_from_3i']"), text: "Last updated from is not a valid date" + expect(page).to have_selector("a[href='#last_updated_to_3i']"), text: "Last updated to is not a valid date" +end diff --git a/lib/engines/content_block_manager/features/step_definitions/filter_steps.rb b/lib/engines/content_block_manager/features/step_definitions/filter_steps.rb new file mode 100644 index 00000000000..24de9b87db6 --- /dev/null +++ b/lib/engines/content_block_manager/features/step_definitions/filter_steps.rb @@ -0,0 +1,29 @@ +When("I add a filter for blocks updated two days ago") do + date = 2.days.before(Time.zone.now) + + fill_in "last_updated_from_1i", with: date.year + fill_in "last_updated_from_2i", with: date.month + fill_in "last_updated_from_3i", with: date.day + + fill_in "last_updated_to_1i", with: date.year + fill_in "last_updated_to_2i", with: date.month + fill_in "last_updated_to_3i", with: date.day +end + +When("I input invalid dates to filter by") do + fill_in "last_updated_from_1i", with: "1" + fill_in "last_updated_from_2i", with: "34" + fill_in "last_updated_from_3i", with: "56" + + fill_in "last_updated_to_1i", with: "1" + fill_in "last_updated_to_2i", with: "67" + fill_in "last_updated_to_3i", with: "56" +end + +Then("'all organisations' is already selected as a filter") do + expect(page).to have_field("Lead organisation", with: "") +end + +When("I enter the keyword {string}") do |keyword| + fill_in "Keyword", with: keyword +end diff --git a/lib/engines/content_block_manager/features/step_definitions/form_step_steps.rb b/lib/engines/content_block_manager/features/step_definitions/form_step_steps.rb new file mode 100644 index 00000000000..b0f11aa2d58 --- /dev/null +++ b/lib/engines/content_block_manager/features/step_definitions/form_step_steps.rb @@ -0,0 +1,17 @@ +require_relative "../support/form_step_helpers" + +Then(/^I should be on the "([^"]*)" step$/) do |step| + case step + when "edit" + should_show_edit_form + when "review_links" + should_show_dependent_content + should_show_rollup_data + when "schedule_publishing" + should_show_publish_form + when "review" + should_be_on_review_step + when "change_note" + should_be_on_change_note_step + end +end diff --git a/lib/engines/content_block_manager/features/step_definitions/navigation_steps.rb b/lib/engines/content_block_manager/features/step_definitions/navigation_steps.rb new file mode 100644 index 00000000000..6be30621d28 --- /dev/null +++ b/lib/engines/content_block_manager/features/step_definitions/navigation_steps.rb @@ -0,0 +1,21 @@ +When("I access the create object page") do + visit content_block_manager.new_content_block_manager_content_block_edition_path +end + +When("I visit the page for the content block") do + visit content_block_manager.content_block_manager_content_block_edition_path(@content_block) +end + +When("I visit the Content Block Manager home page") do + visit content_block_manager.content_block_manager_root_path +end + +When("I visit a block's content ID endpoint") do + block = ContentBlockManager::ContentBlock::Document.last + visit content_block_manager.content_block_manager_content_block_content_id_path(block.content_id) +end + +When("I revisit the edit page") do + @content_block = @content_block.document.latest_edition + visit_edit_page +end diff --git a/lib/engines/content_block_manager/features/step_definitions/preview_steps.rb b/lib/engines/content_block_manager/features/step_definitions/preview_steps.rb new file mode 100644 index 00000000000..ade8255eead --- /dev/null +++ b/lib/engines/content_block_manager/features/step_definitions/preview_steps.rb @@ -0,0 +1,59 @@ +When("I click on the first host document") do + @current_host_document = @dependent_content.first + stub_request( + :get, + "#{Plek.find('publishing-api')}/v2/content/#{@current_host_document['host_content_id']}", + ).to_return( + status: 200, + body: { + details: { + body: "

title

", + }, + title: @current_host_document["title"], + document_type: "news_story", + base_path: @current_host_document["base_path"], + publishing_app: "test", + }.to_json, + ) + + stub_request( + :get, + Plek.website_root + @current_host_document["base_path"], + ).to_return( + status: 200, + body: "

#{@current_host_document['title']}

iframe preview Link to other page

#{@content_block.render}", + ) + + stub_request( + :get, + "#{Plek.website_root}/other-page", + ).to_return( + status: 200, + body: "

#{@current_host_document['title']}

other page

#{@content_block.render}", + ) + + click_on @current_host_document["title"] +end + +Then("the preview page opens in a new tab") do + page.switch_to_window(page.windows.last) + assert_text "Preview email address" + assert_text "Instances: 1" + assert_text "Email address: #{@email_address}" + within_frame "preview" do + assert_text @current_host_document["title"] + end +end + +When("I click on a link within the frame") do + within_frame "preview" do + click_on "Link to other page" + end +end + +Then("I should see the content of the linked page") do + within_frame "preview" do + assert_text "other page" + assert_text @email_address + end +end diff --git a/lib/engines/content_block_manager/features/step_definitions/schedule_steps.rb b/lib/engines/content_block_manager/features/step_definitions/schedule_steps.rb new file mode 100644 index 00000000000..91c651cabaf --- /dev/null +++ b/lib/engines/content_block_manager/features/step_definitions/schedule_steps.rb @@ -0,0 +1,61 @@ +Then("I see the errors prompting me to provide a date and time") do + assert_text "Scheduled publication date and time cannot be blank", minimum: 2 +end + +Then("I see the errors informing me the date is invalid") do + assert_text I18n.t("activerecord.errors.models.content_block_manager/content_block/edition.attributes.scheduled_publication.time.blank"), minimum: 2 +end + +Then("I should see an error message telling me that schedule publishing cannot be blank") do + assert_text I18n.t("activerecord.errors.models.content_block_manager/content_block/edition.attributes.schedule_publishing.blank"), minimum: 2 +end + +Then("I see the errors informing me the date must be in the future") do + assert_text I18n.t("activerecord.errors.models.content_block_manager/content_block/edition.attributes.scheduled_publication.future_date"), minimum: 2 +end + +When("I choose to schedule the change") do + choose "Schedule the edit for the future" +end + +And(/^I schedule the change for (\d+) days in the future$/) do |number_of_days| + choose "Schedule the edit for the future" + @future_date = number_of_days.days.since(Time.zone.now) + @is_scheduled = true + fill_in_date_and_time_field(@future_date) + + click_on "Save and continue" +end + +Then("the edition should have been scheduled successfully") do + @schema = @schemas[@content_block.document.block_type] + assert_text "#{@schema.name} scheduled successfully" +end + +And("the block is scheduled and published") do + @is_scheduled = true + create(:scheduled_publishing_robot) + near_future_date = 1.minute.from_now + fill_in_date_and_time_field(near_future_date) + + Sidekiq::Testing.inline! do + click_on "Save and continue" + end +end + +When("I click to edit the schedule") do + find("a", text: "Edit schedule").click +end + +When("I enter an invalid date") do + fill_in "Year", with: "01" +end + +When("I enter a date in the past") do + past_date = 7.days.before(Time.zone.now).to_date + fill_in_date_and_time_field(past_date) +end + +Then("I should see a warning telling me there is a scheduled change") do + assert_text "There is currently a change scheduled" +end diff --git a/lib/engines/content_block_manager/features/step_definitions/schema_steps.rb b/lib/engines/content_block_manager/features/step_definitions/schema_steps.rb new file mode 100644 index 00000000000..fc21b98e902 --- /dev/null +++ b/lib/engines/content_block_manager/features/step_definitions/schema_steps.rb @@ -0,0 +1,31 @@ +Given("a schema {string} exists with the following fields:") do |block_type, table| + fields = table.hashes + @schemas ||= {} + body = { + "type" => "object", + "required" => fields.select { |f| f["required"] == "true" }.map { |f| f["field"] }, + "additionalProperties" => false, + "properties" => fields.map { |f| + [f["field"], { "type" => f["type"], "format" => f["format"] }] + }.to_h, + } + @schemas[block_type] = build(:content_block_schema, block_type:, body:) + ContentBlockManager::ContentBlock::Schema.stubs(:all).returns(@schemas.values) +end + +When("I click on the {string} schema") do |schema_id| + @schema = @schemas[schema_id] + ContentBlockManager::ContentBlock::Schema.expects(:find_by_block_type).with(schema_id).at_least_once.returns(@schema) + choose @schema.name + click_save_and_continue +end + +Then("I should see a form for the schema") do + expect(page).to have_content(@schema.name) +end + +Then("I should see all the schemas listed") do + @schemas.values.each do |schema| + expect(page).to have_content(schema.name) + end +end diff --git a/lib/engines/content_block_manager/features/step_definitions/sidekiq_steps.rb b/lib/engines/content_block_manager/features/step_definitions/sidekiq_steps.rb new file mode 100644 index 00000000000..acc7ea3a5f9 --- /dev/null +++ b/lib/engines/content_block_manager/features/step_definitions/sidekiq_steps.rb @@ -0,0 +1,9 @@ +Then(/^there should only be one job scheduled$/) do + jobs = Sidekiq::ScheduledSet.new.select { |job| job.item["class"] == ContentBlockManager::SchedulePublishingWorker.to_s } + expect(jobs.count).to eq(1) +end + +Then(/^there should be no jobs scheduled$/) do + jobs = Sidekiq::ScheduledSet.new.select { |job| job.item["class"] == ContentBlockManager::SchedulePublishingWorker.to_s } + expect(jobs.count).to eq(0) +end diff --git a/lib/engines/content_block_manager/features/step_definitions/timeline_steps.rb b/lib/engines/content_block_manager/features/step_definitions/timeline_steps.rb new file mode 100644 index 00000000000..0092e0418c8 --- /dev/null +++ b/lib/engines/content_block_manager/features/step_definitions/timeline_steps.rb @@ -0,0 +1,18 @@ +Then("I should see the created event on the timeline") do + expect(page).to have_selector(".timeline__title", text: "Email address created") + expect(page).to have_selector(".timeline__byline", text: "by #{@user.name}") +end + +Then(/^I should see ([^"]*) publish events on the timeline$/) do |count| + expect(page).to have_selector(".timeline__title", text: "Email address published", count:) +end + +Then("I should see the publish event on the timeline") do + expect(page).to have_selector(".timeline__title", text: "Email address published") + expect(page).to have_selector(".timeline__byline", text: "by Scheduled Publishing Robot") +end + +Then("I should see the scheduled event on the timeline") do + expect(page).to have_selector(".timeline__title", text: "Email address scheduled") + expect(page).to have_selector(".timeline__byline", text: "by #{@user.name}") +end diff --git a/lib/engines/content_block_manager/features/step_definitions/user_steps.rb b/lib/engines/content_block_manager/features/step_definitions/user_steps.rb new file mode 100644 index 00000000000..69e910ee7da --- /dev/null +++ b/lib/engines/content_block_manager/features/step_definitions/user_steps.rb @@ -0,0 +1,24 @@ +Given("A user exists with uuid {string}") do |uuid| + @user_from_signon = build( + :signon_user, + uid: uuid, + name: "John Doe", + email: "john@doe.com", + organisation: build(:signon_user_organisation, content_id: "456", name: "User's Org", slug: "users-org"), + ) + + stub_request(:get, "#{Plek.find('signon', external: true)}/api/users") + .with(query: { uuids: [uuid] }) + .to_return(body: [@user_from_signon].to_json) +end + +When("I visit the user page for uuid {string}") do |uuid| + visit content_block_manager.content_block_manager_user_path(uuid) +end + +Then("I should see the details for that user") do + expect(page).to have_selector("h1", text: @user_from_signon.name) + expect(page).to have_selector(".govuk-summary-list__value", text: @user_from_signon.name) + expect(page).to have_selector(".govuk-summary-list__value", text: @user_from_signon.email) + expect(page).to have_selector(".govuk-summary-list__value", text: @user_from_signon.organisation.name) +end diff --git a/lib/engines/content_block_manager/features/support/form_step_helpers.rb b/lib/engines/content_block_manager/features/support/form_step_helpers.rb new file mode 100644 index 00000000000..33dd6fd1b71 --- /dev/null +++ b/lib/engines/content_block_manager/features/support/form_step_helpers.rb @@ -0,0 +1,38 @@ +def should_show_edit_form + should_show_edit_form_for_email_address_content_block( + @content_block.document.title, + @email_address, + ) +end + +def should_show_dependent_content + expect(page).to have_selector("h1", text: "Preview email address") + + @dependent_content.each do |item| + assert_text item["title"] + break if item == @dependent_content.last + end +end + +def should_show_rollup_data + @rollup.keys.each do |k| + within ".rollup-details__rollup-metric.#{k}" do + assert_text k.to_s.titleize + within ".gem-c-glance-metric__figure" do + assert_text @rollup[k] + end + end + end +end + +def should_show_publish_form + assert_text "Select publish date" +end + +def should_be_on_review_step + assert_text "Review email address" +end + +def should_be_on_change_note_step + assert_text "Do users have to know the content has changed?" +end diff --git a/lib/engines/content_block_manager/features/support/helpers.rb b/lib/engines/content_block_manager/features/support/helpers.rb new file mode 100644 index 00000000000..8e143ed9b43 --- /dev/null +++ b/lib/engines/content_block_manager/features/support/helpers.rb @@ -0,0 +1,53 @@ +def should_show_summary_card_for_email_address_content_block(document_title, email_address) + expect(page).to have_selector(".govuk-summary-list__key", text: "Title") + expect(page).to have_selector(".govuk-summary-list__value", text: document_title) + expect(page).to have_selector(".govuk-summary-list__key", text: "Email address") + expect(page).to have_selector(".govuk-summary-list__value", text: email_address) +end + +def should_show_summary_list_for_email_address_content_block(document_title, email_address, organisation, instructions_to_publishers = nil) + expect(page).to have_selector(".govuk-summary-list__key", text: "Title") + expect(page).to have_selector(".govuk-summary-list__value", text: document_title) + expect(page).to have_selector(".govuk-summary-list__actions", text: "Edit") + expect(page).to have_selector(".govuk-summary-list__key", text: "Email address") + expect(page).to have_selector(".govuk-summary-list__value", text: email_address) + expect(page).to have_selector(".govuk-summary-list__key", text: "Lead organisation") + expect(page).to have_selector(".govuk-summary-list__value", text: organisation) + if instructions_to_publishers + expect(page).to have_selector(".govuk-summary-list__key", text: "Instructions to publishers") + expect(page).to have_selector(".govuk-summary-list__value", text: instructions_to_publishers) + end + expect(page).to have_selector(".govuk-summary-list__key", text: "Status") + expect(page).to have_selector(".govuk-summary-list__value", text: @user.name) +end + +def should_show_edit_form_for_email_address_content_block(document_title, email_address) + expect(page).to have_content(I18n.t("content_block_edition.update.title", block_type: "email address")) + expect(page).to have_field("Title", with: document_title) + expect(page).to have_field("Email address", with: email_address) + expect(page).to have_content("Save and continue") + expect(page).to have_content("Cancel") +end + +def visit_edit_page + visit content_block_manager.new_content_block_manager_content_block_document_edition_path(@content_block.document) +end + +def change_details + fill_in "Title", with: "Changed title" + fill_in "Email address", with: "changed@example.com" + select "Ministry of Example", from: "content_block_manager_content_block_edition_lead_organisation" + fill_in "Instructions to publishers", with: "new context information" + click_save_and_continue +end + +def click_save_and_continue + click_on "Save and continue" +end + +def has_support_button + expect(page).to have_link( + "Raise a support request", + href: Whitehall.support_url, + ) +end From 398eb8c77c05460323a447e639d04265e537a5d0 Mon Sep 17 00:00:00 2001 From: pezholio Date: Thu, 23 Jan 2025 11:33:28 +0000 Subject: [PATCH 2/2] Group scheduling steps This makes some of the rescheduling-related steps a bit less verbose --- .../features/edit_object.feature | 6 +--- .../features/reschedule_object.feature | 30 +++------------- .../features/schedule_object.feature | 6 +--- .../content_block_manager_steps.rb | 17 +++------- .../step_definitions/schedule_steps.rb | 17 ++++++---- .../features/support/helpers.rb | 34 +++++++++++++++++++ 6 files changed, 56 insertions(+), 54 deletions(-) diff --git a/lib/engines/content_block_manager/features/edit_object.feature b/lib/engines/content_block_manager/features/edit_object.feature index ad9e0ff7375..26c23f6adfb 100644 --- a/lib/engines/content_block_manager/features/edit_object.feature +++ b/lib/engines/content_block_manager/features/edit_object.feature @@ -107,11 +107,7 @@ Feature: Edit a content object @enable-sidekiq-test-mode Scenario: GDS editor can override a previously scheduled object - When I am updating a content block - And I schedule the change for 7 days in the future - And I add an internal note - And I add a change note - When I review and confirm my answers are correct + Given I have scheduled a change for 7 days in the future When I revisit the edit page Then I should see a warning telling me there is a scheduled change When I make the changes diff --git a/lib/engines/content_block_manager/features/reschedule_object.feature b/lib/engines/content_block_manager/features/reschedule_object.feature index 5d5843b1569..b83ae0bc5e4 100644 --- a/lib/engines/content_block_manager/features/reschedule_object.feature +++ b/lib/engines/content_block_manager/features/reschedule_object.feature @@ -9,11 +9,7 @@ Feature: Schedule a content object @disable-sidekiq-test-mode Scenario: GDS Editor immediately publishes a scheduled content object - When I am updating a content block - And I schedule the change for 7 days in the future - And I add an internal note - And I add a change note - When I review and confirm my answers are correct + Given I have scheduled a change for 7 days in the future When I click to view the content block And I click to edit the schedule And I choose to publish the change now @@ -24,11 +20,7 @@ Feature: Schedule a content object @disable-sidekiq-test-mode Scenario: GDS Editor reschedules a content object - When I am updating a content block - And I schedule the change for 7 days in the future - And I add an internal note - And I add a change note - When I review and confirm my answers are correct + Given I have scheduled a change for 7 days in the future When I click to view the content block And I click to edit the schedule And I schedule the change for 5 days in the future @@ -39,11 +31,7 @@ Feature: Schedule a content object @disable-sidekiq-test-mode Scenario: GDS Editor tries to reschedule a content object without choosing to schedule - When I am updating a content block - And I schedule the change for 7 days in the future - And I add an internal note - And I add a change note - When I review and confirm my answers are correct + Given I have scheduled a change for 7 days in the future When I click to view the content block And I click to edit the schedule And I save and continue @@ -51,11 +39,7 @@ Feature: Schedule a content object @disable-sidekiq-test-mode Scenario: GDS editor cancels the rescheduling of an object - When I am updating a content block - And I schedule the change for 7 days in the future - And I add an internal note - And I add a change note - When I review and confirm my answers are correct + Given I have scheduled a change for 7 days in the future When I click to view the content block And I click to edit the schedule And I click the cancel link @@ -64,11 +48,7 @@ Feature: Schedule a content object @disable-sidekiq-test-mode Scenario: GDS editor cancels the rescheduling of an object on the confirmation page - When I am updating a content block - And I schedule the change for 7 days in the future - And I add an internal note - And I add a change note - When I review and confirm my answers are correct + Given I have scheduled a change for 7 days in the future When I click to view the content block And I click to edit the schedule And I schedule the change for 5 days in the future diff --git a/lib/engines/content_block_manager/features/schedule_object.feature b/lib/engines/content_block_manager/features/schedule_object.feature index a8bd7072442..89fd60da4a3 100644 --- a/lib/engines/content_block_manager/features/schedule_object.feature +++ b/lib/engines/content_block_manager/features/schedule_object.feature @@ -21,11 +21,7 @@ Feature: Schedule a content object @disable-sidekiq-test-mode Scenario: GDS Editor publishes a new version of a previously scheduled content object - When I am updating a content block - And I schedule the change for 7 days in the future - And I add an internal note - And I add a change note - When I review and confirm my answers are correct + Given I have scheduled a change for 7 days in the future When I am updating a content block And I choose to publish the change now And I save and continue diff --git a/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb b/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb index eeb625176f8..3dd045606c0 100644 --- a/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb +++ b/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb @@ -315,8 +315,7 @@ end When("I review and confirm my answers are correct") do - check "By creating this content block you are confirming that, to the best of your knowledge, the details you are providing are correct." - click_on @is_scheduled ? "Schedule" : "Publish" + review_and_confirm end When("I click publish without confirming my details") do @@ -347,12 +346,7 @@ end When("I am updating a content block") do - # go to the edit page for the block - visit content_block_manager.new_content_block_manager_content_block_document_edition_path(@content_block.document) - # fill in the new data - change_details - # accept changes - click_save_and_continue + update_content_block end When("one of the content blocks was updated 2 days ago") do @@ -377,9 +371,7 @@ end When(/^I add a change note$/) do - choose "Yes - information has been added, updated or removed" - fill_in "Describe the edit for users", with: "Some text" - click_save_and_continue + add_change_note end Then(/^I should see the object store's title in the header$/) do @@ -416,6 +408,5 @@ end When(/^I add an internal note$/) do - fill_in "Describe the change for internal users", with: "Some internal note goes here" - click_save_and_continue + add_internal_note end diff --git a/lib/engines/content_block_manager/features/step_definitions/schedule_steps.rb b/lib/engines/content_block_manager/features/step_definitions/schedule_steps.rb index 91c651cabaf..a81a43ba9ee 100644 --- a/lib/engines/content_block_manager/features/step_definitions/schedule_steps.rb +++ b/lib/engines/content_block_manager/features/step_definitions/schedule_steps.rb @@ -1,3 +1,5 @@ +require_relative "../support/helpers" + Then("I see the errors prompting me to provide a date and time") do assert_text "Scheduled publication date and time cannot be blank", minimum: 2 end @@ -19,12 +21,7 @@ end And(/^I schedule the change for (\d+) days in the future$/) do |number_of_days| - choose "Schedule the edit for the future" - @future_date = number_of_days.days.since(Time.zone.now) - @is_scheduled = true - fill_in_date_and_time_field(@future_date) - - click_on "Save and continue" + schedule_change(number_of_days) end Then("the edition should have been scheduled successfully") do @@ -59,3 +56,11 @@ Then("I should see a warning telling me there is a scheduled change") do assert_text "There is currently a change scheduled" end + +Given(/^I have scheduled a change for (\d+) days in the future$/) do |number_of_days| + update_content_block + schedule_change(number_of_days) + add_internal_note + add_change_note + review_and_confirm +end diff --git a/lib/engines/content_block_manager/features/support/helpers.rb b/lib/engines/content_block_manager/features/support/helpers.rb index 8e143ed9b43..0f2548f91b6 100644 --- a/lib/engines/content_block_manager/features/support/helpers.rb +++ b/lib/engines/content_block_manager/features/support/helpers.rb @@ -51,3 +51,37 @@ def has_support_button href: Whitehall.support_url, ) end + +def schedule_change(number_of_days) + choose "Schedule the edit for the future" + @future_date = number_of_days.days.since(Time.zone.now) + @is_scheduled = true + fill_in_date_and_time_field(@future_date) + + click_on "Save and continue" +end + +def update_content_block + # go to the edit page for the block + visit content_block_manager.new_content_block_manager_content_block_document_edition_path(@content_block.document) + # fill in the new data + change_details + # accept changes + click_save_and_continue +end + +def add_internal_note + fill_in "Describe the change for internal users", with: "Some internal note goes here" + click_save_and_continue +end + +def add_change_note + choose "Yes - information has been added, updated or removed" + fill_in "Describe the edit for users", with: "Some text" + click_save_and_continue +end + +def review_and_confirm + check "By creating this content block you are confirming that, to the best of your knowledge, the details you are providing are correct." + click_on @is_scheduled ? "Schedule" : "Publish" +end