Skip to content

Commit

Permalink
Merge pull request #8973 from alphagov/worldwide-organisation-pages-a…
Browse files Browse the repository at this point in the history
…udit

Add audit history for worldwide organisation pages
  • Loading branch information
brucebolt authored Apr 22, 2024
2 parents 578aa90 + 9003800 commit d2612c1
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<% if @edition.pages.any? %>
<div class="govuk-!-margin-bottom-5">
<%= render "govuk_publishing_components/components/heading", {
text: "Pages",
margin_bottom: 3,
font_size: "xl",
} %>
</div>

<% @edition.pages.each do |page| %>
<% previous_page = @audit_trail_entry.pages.find_by(corporate_information_page_type_id: page.corporate_information_page_type_id) %>

<div class="app-view-audit-trail__page-comparison">
<div class="govuk-!-margin-bottom-5">
<%= render "govuk_publishing_components/components/heading", {
text: page.corporate_information_page_type&.title(@edition),
margin_bottom: 3,
font_size: "l",
} %>
</div>

<div class="govuk-!-margin-bottom-5">
<%= render "govuk_publishing_components/components/heading", {
text: "Summary",
margin_bottom: 3,
font_size: "m",
} %>
</div>

<div class="govuk-body app-view-audit-trail__history-comparison">
<%= diff_html(previous_page.try(:summary), page.summary) %>
</div>

<div class="govuk-!-margin-bottom-5">
<%= render "govuk_publishing_components/components/heading", {
text: "Body",
margin_bottom: 3,
font_size: "m",
} %>
</div>

<div class="govuk-body app-view-audit-trail__history-comparison">
<%= diff_html(previous_page.try(:body), page.body) %>
</div>
</div>
<% end %>
<% end %>
10 changes: 9 additions & 1 deletion app/views/admin/editions/diff.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">

<p class="govuk-body">This page shows changes to the title, summary and body in this edition. It does not show changes to attachments or associations.</p>
<% if @edition.is_a?(EditionableWorldwideOrganisation) %>
<p class="govuk-body">This page shows changes to the title, summary, body, and pages in this edition. It does not show changes to attachments.</p>
<% else %>
<p class="govuk-body">This page shows changes to the title, summary and body in this edition. It does not show changes to attachments or associations.</p>
<% end %>

<div class="govuk-!-margin-bottom-5">
<%= render "govuk_publishing_components/components/heading", {
Expand Down Expand Up @@ -45,5 +49,9 @@
<%= diff_html(@audit_trail_entry.body, @edition.body) %>
</div>
</div>

<% if @edition.is_a?(EditionableWorldwideOrganisation) %>
<%= render "admin/editionable_worldwide_organisations/pages_diff" %>
<% end %>
</div>
</div>
16 changes: 16 additions & 0 deletions features/editionable-worldwide-organisations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit d2612c1

Please sign in to comment.