Skip to content

Commit

Permalink
Update helper tests
Browse files Browse the repository at this point in the history
- Update `important_note` test for scenario where there is no important note
- Update `awaiting_review` test for scenario where edition is not in review
- Update `scheduled` test for scenario where the edition is not scheduled for publishing
- Update title for `scheduled` test
- Update `published_by` test for when edition is not scheduled for publication
- Update title for `published_by` test
- reviewer test
  - Add case for edition not in review
  - Add case for user without editor permissions
  - Update some titles for `reviewer` test
  - Remove some unecessary values from user and edition
  - Add all cases for `format` test
  • Loading branch information
davidtrussler committed Aug 20, 2024
1 parent 48def3c commit cb20a56
Showing 1 changed file with 87 additions and 26 deletions.
113 changes: 87 additions & 26 deletions test/unit/helpers/admin/publications_table_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,61 +63,91 @@ class PublicationsTableHelperTest < ActionView::TestCase
context "#important_note" do
should "return the important note text for an edition" do
user = FactoryBot.create(:user, name: "Keir Starmer")
edition = FactoryBot.create(:edition)
user.record_note(edition, "This is an important note", Action::IMPORTANT_NOTE)
edition_without_important_note = FactoryBot.create(:edition)
edition_with_important_note = FactoryBot.create(:edition)
user.record_note(edition_with_important_note, "This is an important note", Action::IMPORTANT_NOTE)

assert_equal "This is an important note", important_note(edition)
assert_nil important_note(edition_without_important_note)
assert_equal "This is an important note", important_note(edition_with_important_note)
end
end

context "#awaiting_review" do
should "return the correct text for the 'Awaiting review' field for an edition in review" do
should "return the correct text for an edition in review" do
today = Date.parse("2024-08-02")

Timecop.freeze(today) do
edition = FactoryBot.create(
edition_draft = FactoryBot.create(
:edition,
state: "draft",
)

edition_in_review = FactoryBot.create(
:edition,
state: "in_review",
review_requested_at: "2024-07-12",
)

assert_equal "21 days", awaiting_review(edition)
assert_nil awaiting_review(edition_draft)
assert_equal "21 days", awaiting_review(edition_in_review)
end
end
end

context "#scheduled" do
should "return the correct text for the 'Scheduled' field for an edition in 'Scheduled for publishing'" do
should "return the correct text for an edition that is scheduled for publishing" do
today = Date.parse("2024-08-02")

Timecop.freeze(today) do
edition = FactoryBot.create(
edition_published = FactoryBot.create(
:edition,
state: "published",
)

edition_scheduled_for_publishing = FactoryBot.create(
:edition,
state: "scheduled_for_publishing",
publish_at: "2024-08-21 10:04:50.119 UTC",
)

assert_equal "11:04am, 21 Aug 2024", scheduled(edition)
assert_nil scheduled(edition_published)
assert_equal "11:04am, 21 Aug 2024", scheduled(edition_scheduled_for_publishing)
end
end
end

context "#published_by" do
should "return the correct text for the 'Published by' field for an edition in 'Published'" do
edition = FactoryBot.create(
should "return the correct text for a ;published edition" do
edition_scheduled_for_publishing = FactoryBot.create(
:edition,
state: "scheduled_for_publishing",
publish_at: "2024-08-21 10:04:50.119 UTC",
)

edition_published = FactoryBot.create(
:edition,
state: "published",
publisher: "Keir Starmer",
)

assert_equal "Keir Starmer", published_by(edition)
assert_nil published_by(edition_scheduled_for_publishing)
assert_equal "Keir Starmer", published_by(edition_published)
end
end

# TODO: Remove some unecessary values from current_user & edition
context "#reviewer" do
should "return the correct text for the '2i reviewer' field for an edition in 'In review' that is claimed by a 2i reviewer" do
current_user = FactoryBot.create(:user, name: "Liz Truss", permissions: %w[signin govuk_editor skip_review])
should "return the correct text for the '2i reviewer' field for an edition that is not in review" do
current_user = FactoryBot.create(:user, name: "Liz Truss", permissions: %w[govuk_editor])
edition = FactoryBot.create(
:edition,
state: "draft",
)

assert_nil reviewer(edition, current_user)
end

should "return an edition's reviewer when there is one" do
current_user = FactoryBot.create(:user, name: "Boris Johnson", permissions: %w[govuk_editor])
edition = FactoryBot.create(
:edition,
state: "in_review",
Expand All @@ -128,40 +158,71 @@ class PublicationsTableHelperTest < ActionView::TestCase
assert_equal "Rishi Sunak", reviewer(edition, current_user)
end

should "return the correct text for the '2i reviewer' field for an edition in 'In review' that is assigned to the current user and not claimed by a 2i reviewer" do
current_user = FactoryBot.create(:user, name: "Boris Johnson", permissions: %w[signin govuk_editor skip_review])
should "return nil when an edition assigned to the current user is in review and has not yet been claimed" do
current_user = FactoryBot.create(:user, name: "Theresa May", permissions: %w[govuk_editor])
edition = FactoryBot.create(
:edition,
state: "in_review",
review_requested_at: "2024-07-12",
assigned_to_id: current_user.id,
reviewer: nil,
)

assert_nil reviewer(edition, current_user)
end

should "return the correct text for the '2i reviewer' field for an edition in 'In review' that is not assigned to the current user and not claimed by a 2i reviewer" do
current_user = FactoryBot.create(:user, name: "Theresa May", permissions: %w[signin govuk_editor skip_review])
should "return a form for claiming a review when an edition assigned to another user is in review and has not been claimed and the current user may do so" do
current_user = FactoryBot.create(:user, name: "David Cameron", permissions: %w[govuk_editor])
edition = FactoryBot.create(
:edition,
state: "in_review",
review_requested_at: "2024-07-12",
assigned_to_id: "66911dbf2c88ee0001d8af62",
reviewer: nil,
)

assert_includes reviewer(edition, current_user), '<button class="gem-c-button govuk-button" type="submit">Claim 2i</button>'
end
end

context "#format" do
should "return the correct value for the format" do
should "return nil when an edition assigned to another user is in review and has not been claimed and the current user may not do so" do
current_user = FactoryBot.create(:user, name: "Gordon Brown")
edition = FactoryBot.create(
:transaction_edition,
:edition,
state: "in_review",
review_requested_at: "2024-07-12",
assigned_to_id: "66911dbf2c88ee0001d8af62",
)

assert_equal "Transaction", format(edition)
assert_nil reviewer(edition, current_user)
end
end

# TODO: How to create help_page and local_transaction editions?
context "#format" do
should "return the correct value for the format" do
edition_answer = FactoryBot.create(:answer_edition)
edition_campaign = FactoryBot.create(:campaign_edition)
edition_completed_transaction = FactoryBot.create(:completed_transaction_edition)
edition_guide = FactoryBot.create(:guide_edition)
# edition_help_page = FactoryBot.create(:help_page_edition, slug: "help/me-if-you-can")
edition_licence = FactoryBot.create(:licence_edition)
# edition_local_transaction = FactoryBot.create(:local_transaction_edition, lgsl_code: "368")
edition_place = FactoryBot.create(:place_edition)
edition_programme = FactoryBot.create(:programme_edition)
edition_simple_smart_answer = FactoryBot.create(:simple_smart_answer_edition)
edition_transaction = FactoryBot.create(:transaction_edition)
edition_video = FactoryBot.create(:video_edition)

assert_equal "Answer", format(edition_answer)
assert_equal "Campaign", format(edition_campaign)
assert_equal "Completed transaction", format(edition_completed_transaction)
assert_equal "Guide", format(edition_guide)
# assert_equal "Help page", format(edition_help_page)
assert_equal "Licence", format(edition_licence)
# assert_equal "Local transaction", format(edition_local_transaction)
assert_equal "Place", format(edition_place)
assert_equal "Programme", format(edition_programme)
assert_equal "Simple smart answer", format(edition_simple_smart_answer)
assert_equal "Transaction", format(edition_transaction)
assert_equal "Video", format(edition_video)
end
end

Expand Down

0 comments on commit cb20a56

Please sign in to comment.