Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Present social media accounts #9731

Draft
wants to merge 4 commits into
base: present-summary-ete
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/editionable_topical_event.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class EditionableTopicalEvent < Edition
include Edition::SocialMediaAccounts

def display_type_key
"editionable_topical_event"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,22 @@ def links
{}
end

private

def details
{}
{}.tap do |details|
details[:social_media_links] = social_media_links
end
end

def social_media_links
item.social_media_accounts.map do |social_media_account|
{
href: social_media_account.url,
service_type: social_media_account.service_name.parameterize,
title: social_media_account.display_name,
}
end
end
end
end
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ en:
edition:
one: Edition
other: Editions
editionable_topical_event:
one: Topical event
other: Topical events
edition_with_appointment:
one: Edition with appointment
other: Editions with appointment
Expand Down
20 changes: 20 additions & 0 deletions features/editionable-topical-events.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Feature: Topical events
Scenario Outline: Adding a social media account to an editionable topical event
Given a social media service "Facebook" exists
Given a topical event called "Test editionable topical event" with summary "A topical event" and description "A topical event"
And I edit the editionable topical event "Test editionable topical event" adding the social media service of "Facebook" with title "Our Facebook page" at URL "https://www.social.gov.uk"
Then I should see the "Our Facebook page" social media site has been assigned to the editionable topical event "Test editionable topical event"

Scenario Outline: Editing a social media account to an editionable topical event
Given a social media service "Facebook" exists
Given a topical event called "Test editionable topical event" with summary "A topical event" and description "A topical event"
And I edit the editionable topical event "Test editionable topical event" adding the social media service of "Facebook" with title "Our Facebook page" at URL "https://www.social.gov.uk"
And I edit the editionable topical event "Test editionable topical event" changing the social media account with title "Our Facebook page" to "Our new Facebook page"
Then I should see the "Our new Facebook page" social media site has been assigned to the editionable topical event "Test editionable topical event"

Scenario Outline: Deleting a social media account assigned to an editionable topical event
Given a social media service "Facebook" exists
Given a topical event called "Test editionable topical event" with summary "A topical event" and description "A topical event"
And I edit the editionable topical event "Test editionable topical event" adding the social media service of "Facebook" with title "Our Facebook page" at URL "https://www.social.gov.uk"
And I edit the editionable topical event "Test editionable topical event" deleting the social media account with title "Our Facebook page"
Then I should see the editionable topical event "Test editionable topical event" has no social media accounts
34 changes: 34 additions & 0 deletions features/step_definitions/editionable_topical_events_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
And(/^I edit the topical event "([^"]*)" adding the social media service of "([^"]*)" with title "([^"]*)" at URL "([^"]*)"$/) do |title, social_media_service_name, social_media_title, social_media_url|
begin_editing_document(title)
click_link "Social media accounts"
click_link "Add new social media account"
select social_media_service_name, from: "Service (required)"
fill_in "URL (required)", with: social_media_url
fill_in "Title", with: social_media_title
click_button "Save"
end

And(/^I edit the topical event "([^"]*)" changing the social media account with title "([^"]*)" to "([^"]*)"$/) do |title, _old_social_media_title, new_social_media_title|
begin_editing_document(title)
click_link "Social media accounts"
click_link "Edit"
fill_in "Title", with: new_social_media_title
click_button "Save"
end

And(/^I edit the topical event "([^"]*)" deleting the social media account with title "([^"]*)"$/) do |title, _social_media_title|
begin_editing_document(title)
click_link "Social media accounts"
click_link "Delete"
click_button "Delete"
end

Then(/^I should see the "([^"]*)" social media site has been assigned to the topical event "([^"]*)"$/) do |social_media_title, title|
@topical_event = EditionableTopicalEvent.find_by(title:)
expect(@topical_event.social_media_accounts.first.title).to eq(social_media_title)
end

Then(/^I should see the topical event "([^"]*)" has no social media accounts$/) do |title|
@topical_event = EditionableTopicalEvent.find_by(title:)
expect(@topical_event.social_media_accounts).to be_empty
end
8 changes: 8 additions & 0 deletions features/support/document_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ def begin_drafting_worldwide_organisation(options)
fill_in_worldwide_organisation_fields(**options.slice(:world_location))
end

def begin_drafting_editionable_topical_event(options)
begin_drafting_document options.merge(type: "editionable_topical_event")

fill_in_editionable_topical_event_fields(**options.slice(:topical_event))
end

def pdf_attachment
Rails.root.join("features/fixtures/attachment.pdf")
end
Expand All @@ -131,6 +137,8 @@ def fill_in_worldwide_organisation_fields(world_location: "United Kingdom")
fill_in "Logo formatted name", with: "Logo\r\nformatted\r\nname\r\n"
end

def fill_in_editionable_topical_event_fields; end

def fill_in_news_article_fields(first_published: "2010-01-01", announcement_type: "News story")
select announcement_type, from: "News article type"
checkbox_label = "This document has previously been published on another website"
Expand Down
6 changes: 6 additions & 0 deletions test/factories/editionable_topical_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
end

factory :draft_editionable_topical_event, parent: :editionable_topical_event, traits: [:draft]

trait(:with_social_media_account) do
after :create do |organisation, _evaluator|
create(:social_media_account, socialable: organisation, social_media_service: create(:social_media_service, name: "Blog"))
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@ def present(...)
end

test "presents a Topical Event ready for adding to the publishing API" do
topical_event = create(:editionable_topical_event)
topical_event = create(:editionable_topical_event,
:with_social_media_account)

public_path = topical_event.public_path

expected_details = {
social_media_links: [
{
href: topical_event.social_media_accounts.first.url,
service_type: topical_event.social_media_accounts.first.service_name.parameterize,
title: topical_event.social_media_accounts.first.display_name,
},
],
}

expected_hash = {
base_path: public_path,
title: topical_event.title,
Expand All @@ -22,7 +33,7 @@ def present(...)
public_updated_at: topical_event.updated_at,
routes: [{ path: public_path, type: "exact" }],
redirects: [],
details: {},
details: expected_details,
update_type: "major",
}

Expand Down
Loading