diff --git a/app/views/admin/editionable_worldwide_organisations/_pages_diff.html.erb b/app/views/admin/editionable_worldwide_organisations/_pages_diff.html.erb new file mode 100644 index 00000000000..61ace4537f3 --- /dev/null +++ b/app/views/admin/editionable_worldwide_organisations/_pages_diff.html.erb @@ -0,0 +1,47 @@ +<% if @edition.pages.any? %> +
+ <%= render "govuk_publishing_components/components/heading", { + text: "Pages", + margin_bottom: 3, + font_size: "xl", + } %> +
+ + <% @edition.pages.each do |page| %> + <% previous_page = @audit_trail_entry.pages.find_by(corporate_information_page_type_id: page.corporate_information_page_type_id) %> + +
+
+ <%= render "govuk_publishing_components/components/heading", { + text: page.corporate_information_page_type&.title(@edition), + margin_bottom: 3, + font_size: "l", + } %> +
+ +
+ <%= render "govuk_publishing_components/components/heading", { + text: "Summary", + margin_bottom: 3, + font_size: "m", + } %> +
+ +
+ <%= diff_html(previous_page.try(:summary), page.summary) %> +
+ +
+ <%= render "govuk_publishing_components/components/heading", { + text: "Body", + margin_bottom: 3, + font_size: "m", + } %> +
+ +
+ <%= diff_html(previous_page.try(:body), page.body) %> +
+
+ <% end %> +<% end %> diff --git a/app/views/admin/editions/diff.html.erb b/app/views/admin/editions/diff.html.erb index 4a6c895c30f..97677f463d6 100644 --- a/app/views/admin/editions/diff.html.erb +++ b/app/views/admin/editions/diff.html.erb @@ -11,7 +11,11 @@
-

This page shows changes to the title, summary and body in this edition. It does not show changes to attachments or associations.

+ <% if @edition.is_a?(EditionableWorldwideOrganisation) %> +

This page shows changes to the title, summary, body, and pages in this edition. It does not show changes to attachments.

+ <% else %> +

This page shows changes to the title, summary and body in this edition. It does not show changes to attachments or associations.

+ <% end %>
<%= render "govuk_publishing_components/components/heading", { @@ -45,5 +49,9 @@ <%= diff_html(@audit_trail_entry.body, @edition.body) %>
+ + <% if @edition.is_a?(EditionableWorldwideOrganisation) %> + <%= render "admin/editionable_worldwide_organisations/pages_diff" %> + <% end %>
diff --git a/features/editionable-worldwide-organisations.feature b/features/editionable-worldwide-organisations.feature index ee16984d367..4a2e33c8be0 100644 --- a/features/editionable-worldwide-organisations.feature +++ b/features/editionable-worldwide-organisations.feature @@ -145,6 +145,22 @@ Feature: Editionable worldwide organisations And I visit the "Pages" tab Then I should see that the translated page with body "French Body" is gone + Scenario: Viewing audit history for the worldwide organisation and associated pages + Given a published editionable worldwide organisation "Test Worldwide Organisation" with a "Personal information charter" page + When I create a new edition of the "Test Worldwide Organisation" worldwide organisation + And I visit the pages tab for the worldwide organisation + And I click the "Edit" link for the "Personal information charter" page + And I correctly fill out the worldwide organisation page fields for a "Personal information charter" with: + | Summary | Some updated summary | + | Body (required) | Some updated body | + And I click the link to create a new page + And I correctly fill out the worldwide organisation page fields for a "Complaints procedure" with: + | Summary | An interesting summary | + | Body (required) | An interesting body | + Then The audit history for the pages should be displayed on the document history page with: + | Personal information charter | Some summary | Some updated summary | Some body | Some updated body | + | Complaints procedure | | An interesting summary | | An interesting body | + @javascript Scenario: Reordering home page offices for a worldwide organisation Given An editionable worldwide organisation "Test Worldwide Organisation" with home page offices "Home page office 1" and "Home page office 2" diff --git a/features/step_definitions/editionable_worldwide_organisation_steps.rb b/features/step_definitions/editionable_worldwide_organisation_steps.rb index c7fba0b8368..39bee638b86 100644 --- a/features/step_definitions/editionable_worldwide_organisation_steps.rb +++ b/features/step_definitions/editionable_worldwide_organisation_steps.rb @@ -41,6 +41,11 @@ create(:worldwide_organisation_page, edition: worldwide_organisation, corporate_information_page_type: CorporateInformationPageType.find(type.parameterize)) end +Given(/^a published editionable worldwide organisation "([^"]*)" with a "([^"]*)" page$/) do |title, type| + worldwide_organisation = create(:published_editionable_worldwide_organisation, title:) + create(:worldwide_organisation_page, edition: worldwide_organisation, corporate_information_page_type: CorporateInformationPageType.find(type.parameterize)) +end + Given(/^a role "([^"]*)" exists$/) do |name| create(:role, name:) end @@ -49,6 +54,12 @@ create(:social_media_service, name:) end +When(/^I create a new edition of the "([^"]*)" worldwide organisation$/) do |name| + worldwide_organisation = EditionableWorldwideOrganisation.latest_edition.find_by!(title: name) + visit admin_edition_path(worldwide_organisation) + click_button "Create new edition" +end + When(/^I choose "([^"]*)" to be the main office for the editionable worldwide organisation$/) do |contact_title| WorldwideOffice.joins(contact: :translations).where(contact_translations: { title: contact_title }).first visit admin_editionable_worldwide_organisation_path(EditionableWorldwideOrganisation.last) @@ -352,3 +363,25 @@ Then(/^The "(.*?)" attachment should have uploaded successfully$/) do |attachment_title| expect(page).to have_content("Attachment '#{attachment_title}' uploaded") end + +Then(/^The audit history for the pages should be displayed on the document history page with:$/) do |table| + visit admin_editionable_worldwide_organisation_path(EditionableWorldwideOrganisation.last) + click_link("See what’s changed") + expect(page).to have_text("This page shows changes to the title, summary, body, and pages in this edition. It does not show changes to attachments.") + + page_histories = page.all(".app-view-audit-trail__page-comparison") + expect(page_histories.count).to be table.raw.count + + table.raw.each_with_index do |row, index| + page = page_histories[index] + page_title, previous_summary, new_summary, previous_body, new_body = row + + expect(page).to have_text(page_title) + + expect(page).to have_selector("del", text: previous_summary) if previous_summary.present? + expect(page).to have_selector("ins", text: new_summary) + + expect(page).to have_selector("del", text: previous_body) if previous_body.present? + expect(page).to have_selector("ins", text: new_body) + end +end