-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This updates the `edition_actions` helper to accept an array of host_content_update events, filter by if they apply to the edition, then cast as an actionable item.
- Loading branch information
Showing
5 changed files
with
190 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,143 @@ | ||
require "legacy_integration_test_helper" | ||
|
||
class HostContentUpdateHistoryTest < LegacyJavascriptIntegrationTest | ||
setup do | ||
setup_users | ||
stub_linkables | ||
stub_holidays_used_by_fact_check | ||
end | ||
|
||
context "Viewing content update history" do | ||
setup do | ||
user1 = { | ||
"uid" => SecureRandom.uuid, | ||
"name" => "User 1", | ||
"email" => "[email protected]", | ||
} | ||
|
||
user2 = { | ||
"uid" => SecureRandom.uuid, | ||
"name" => "User 2", | ||
"email" => "[email protected]", | ||
} | ||
|
||
@host_content_update_events = [] | ||
|
||
@out_of_scope_content_update_event = create_content_update_event( | ||
updated_by_user_uid: user1["uid"], | ||
) | ||
|
||
some_time_passes | ||
edition1 = FactoryBot.create(:answer_edition, slug: "test-slug") | ||
|
||
some_time_passes | ||
edition1.new_action(@author, Action::SEND_FACT_CHECK) | ||
|
||
some_time_passes | ||
edition1.new_action(@author, Action::RECEIVE_FACT_CHECK) | ||
|
||
some_time_passes | ||
edition1.new_action(@author, Action::PUBLISH) | ||
edition1.state = "published" | ||
edition1.save! | ||
|
||
some_time_passes | ||
@edition1_content_update_event = create_content_update_event( | ||
updated_by_user_uid: user1["uid"], | ||
) | ||
|
||
some_time_passes | ||
edition2 = edition1.build_clone | ||
edition2.save! | ||
|
||
some_time_passes | ||
edition2.new_action(@author, Action::SEND_FACT_CHECK) | ||
|
||
some_time_passes | ||
edition2.new_action(@author, Action::RECEIVE_FACT_CHECK) | ||
|
||
some_time_passes | ||
edition2.new_action(@author, Action::PUBLISH) | ||
edition1.state = "archived" | ||
edition1.save! | ||
edition2.state = "published" | ||
edition2.save! | ||
|
||
some_time_passes | ||
@edition2_content_update_event = create_content_update_event( | ||
updated_by_user_uid: user2["uid"], | ||
) | ||
|
||
some_time_passes | ||
@edition2_content_update_event_1 = create_content_update_event( | ||
updated_by_user_uid: user1["uid"], | ||
) | ||
|
||
some_time_passes | ||
@edition3 = edition2.build_clone(GuideEdition) | ||
@edition3.save! | ||
|
||
@edition3.new_action(@author, Action::NEW_VERSION) | ||
|
||
all_events = [ | ||
@out_of_scope_content_update_event, | ||
@edition1_content_update_event, | ||
@edition2_content_update_event, | ||
@edition2_content_update_event_1, | ||
] | ||
|
||
stub_events_for_all_content_ids(events: all_events) | ||
stub_users_from_signon_api([user1["uid"], user2["uid"]], [user1, user2]) | ||
end | ||
|
||
should "show host content update actions" do | ||
visit_edition @edition3 | ||
click_on "History and notes" | ||
|
||
assert page.has_no_content?("Content block updated") | ||
assert page.has_no_content?("Email address updated") | ||
|
||
click_on "Edition 2" | ||
within "#version2" do | ||
within page.all(".action-content-block-updated")[0] do | ||
assert page.has_content?(Time.zone.parse(@edition2_content_update_event_1["created_at"]).to_fs(:govuk_date)) | ||
assert page.has_content?("Content block updated by User 1") | ||
assert page.has_content?("Email address updated") | ||
end | ||
|
||
within page.all(".action-content-block-updated")[1] do | ||
assert page.has_content?(Time.zone.parse(@edition2_content_update_event["created_at"]).to_fs(:govuk_date)) | ||
assert page.has_content?("Content block updated by User 2") | ||
assert page.has_content?("Email address updated") | ||
end | ||
end | ||
|
||
click_on "Edition 1" | ||
within "#version1" do | ||
within ".action-content-block-updated" do | ||
assert page.has_content?(Time.zone.parse(@edition1_content_update_event["created_at"]).to_fs(:govuk_date)) | ||
assert page.has_content?("Content block updated by User 1") | ||
assert page.has_content?("Email address updated") | ||
end | ||
end | ||
end | ||
end | ||
|
||
def some_time_passes | ||
travel_to rand(1.hour..1.week).from_now | ||
end | ||
|
||
def create_content_update_event(updated_by_user_uid:) | ||
{ | ||
"created_at" => Time.zone.now.to_s, | ||
"payload" => { | ||
"source_block" => { | ||
"updated_by_user_uid" => updated_by_user_uid, | ||
"content_id" => SecureRandom.uuid, | ||
"title" => "Some content", | ||
"document_type" => "content_block_email_address", | ||
}, | ||
}, | ||
} | ||
end | ||
end |
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