From a936f7f1d4eb813ce2882dddffc57080783c5ae4 Mon Sep 17 00:00:00 2001 From: davidtrussler Date: Wed, 8 May 2024 11:53:47 +0100 Subject: [PATCH] Add new table to render publications to publications view --- .../javascripts/modules/publications-table.js | 48 ++++ app/assets/stylesheets/application.scss | 1 + .../stylesheets/publications-table.scss | 82 ++++++ app/helpers/publications_table_helper.rb | 43 +++ app/presenters/filtered_editions_presenter.rb | 8 +- app/views/root/_claim_2i.html.erb | 7 + app/views/root/_table.html.erb | 55 ++++ app/views/root/index.html.erb | 2 +- .../spec/publications_table.spec.js | 170 ++++++++++++ test/functional/root_controller_test.rb | 8 +- test/support/factories.rb | 12 +- .../admin/publications_table_helper_test.rb | 259 ++++++++++++++++++ .../filtered_editions_presenter_test.rb | 13 +- 13 files changed, 699 insertions(+), 9 deletions(-) create mode 100644 app/assets/javascripts/modules/publications-table.js create mode 100644 app/assets/stylesheets/publications-table.scss create mode 100644 app/helpers/publications_table_helper.rb create mode 100644 app/views/root/_claim_2i.html.erb create mode 100644 app/views/root/_table.html.erb create mode 100644 spec/javascripts/spec/publications_table.spec.js create mode 100644 test/unit/helpers/admin/publications_table_helper_test.rb diff --git a/app/assets/javascripts/modules/publications-table.js b/app/assets/javascripts/modules/publications-table.js new file mode 100644 index 000000000..448e4de88 --- /dev/null +++ b/app/assets/javascripts/modules/publications-table.js @@ -0,0 +1,48 @@ +window.GOVUK = window.GOVUK || {} +window.GOVUK.Modules = window.GOVUK.Modules || {}; + +(function (Modules) { + function PublicationsTable ($module) { + this.$module = $module + this.details = this.$module.querySelectorAll('.govuk-details') + this.openDetailsCount = 0 + this.numDetails = this.details.length + } + + PublicationsTable.prototype.init = function () { + // Add Expand/Contract link to DOM + this.addExpandlink() + + // Add Event listener for Expand All button + this.$module.querySelector('.publications-table__heading a').addEventListener('click', this.toggleDetails.bind(this)) + } + + // Add Expand/Contract link to DOM + PublicationsTable.prototype.addExpandlink = function () { + var expandLink = document.createElement('a') + expandLink.classList.add('govuk-link', 'publications-table--expand-link') + expandLink.textContent = 'Expand all' + this.$module.querySelector('.publications-table__heading').append(expandLink) + } + + // Toggles the "More details" sections + PublicationsTable.prototype.toggleDetails = function (e) { + if (this.openDetailsCount < this.numDetails) { + this.details.forEach(function (section) { + section.setAttribute('open', true) + }) + + this.openDetailsCount = this.numDetails + e.target.textContent = 'Collapse all' + } else if (this.openDetailsCount === this.numDetails) { + this.details.forEach(function (section) { + section.removeAttribute('open') + }) + + this.openDetailsCount = 0 + e.target.textContent = 'Expand all' + } + } + + Modules.PublicationsTable = PublicationsTable +})(window.GOVUK.Modules) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 0226259a6..7616d273a 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -30,3 +30,4 @@ $govuk-page-width: 1140px; @import "downtimes"; @import "summary-card"; @import "popular_links"; +@import "publications-table"; diff --git a/app/assets/stylesheets/publications-table.scss b/app/assets/stylesheets/publications-table.scss new file mode 100644 index 000000000..2685bf66a --- /dev/null +++ b/app/assets/stylesheets/publications-table.scss @@ -0,0 +1,82 @@ +.publications-table { + position: relative; + + &--expand-link { + float: right; + font-size: 1.1875rem; + } + + .govuk-tag { + &--amends_needed { + @extend .govuk-tag--red; // stylelint-disable-line scss/at-extend-no-missing-placeholder + } + + &--archived { + @extend .govuk-tag--blue; // stylelint-disable-line scss/at-extend-no-missing-placeholder + } + + &--draft { + @extend .govuk-tag--yellow; // stylelint-disable-line scss/at-extend-no-missing-placeholder + } + + &--fact_check { + @extend .govuk-tag--purple; // stylelint-disable-line scss/at-extend-no-missing-placeholder + } + + &--fact_check_received { + @extend .govuk-tag--pink; // stylelint-disable-line scss/at-extend-no-missing-placeholder + } + + &--ready { + @extend .govuk-tag--green; // stylelint-disable-line scss/at-extend-no-missing-placeholder + } + + &--scheduled_for_publishing { + @extend .govuk-tag--turquoise; // stylelint-disable-line scss/at-extend-no-missing-placeholder + } + + &--published { + @extend .govuk-tag--orange; // stylelint-disable-line scss/at-extend-no-missing-placeholder + } + + &--in_review { + @extend .govuk-tag--grey; // stylelint-disable-line scss/at-extend-no-missing-placeholder + } + } + + .govuk-table { + border-top: 2px solid $govuk-text-colour; + + .govuk-table__header { + white-space: nowrap; + } + + .govuk-table__cell__updated { + white-space: nowrap; + } + } + + .govuk-details { + margin-top: govuk-spacing(2); + } + + .govuk-summary-list { + width: auto; + } + + .govuk-details__summary { + &::before { + color: $govuk-text-colour; + } + } + + .govuk-details__summary-text { + color: $govuk-text-colour; + } + + .govuk-details__text { + dd { + word-break: break-word; + } + } +} diff --git a/app/helpers/publications_table_helper.rb b/app/helpers/publications_table_helper.rb new file mode 100644 index 000000000..5e0e1e7b3 --- /dev/null +++ b/app/helpers/publications_table_helper.rb @@ -0,0 +1,43 @@ +module PublicationsTableHelper + def reviewer(publication, current_user) + if publication.state == "in_review" + if publication.reviewer.present? + publication.reviewer + elsif current_user != publication.assigned_to && current_user.has_editor_permissions?(publication) + render partial: "root/claim_2i", locals: { publication:, current_user: } + end + end + end + + def edition_number(publication) + if (publication.state == "published" || publication.state == "archived") && publication.subsequent_siblings.first.present? + sanitize("#{publication.version_number} - #{link_to("##{publication.subsequent_siblings.first.version_number} in #{publication.subsequent_siblings.first.state.humanize.downcase}", edition_path(publication.subsequent_siblings.first), class: 'link-inherit')}") + else + publication.version_number.to_s + end + end + + def format(publication) + publication.format.underscore.humanize + end + + def important_note(publication) + publication.important_note.comment if publication.important_note.present? + end + + def awaiting_review(publication) + time_ago_in_words(publication.review_requested_at) if publication.state == "in_review" + end + + def sent_out(publication) + publication.last_fact_checked_at.to_date.to_fs(:govuk_date_short) if publication.state == "fact_check" + end + + def scheduled(publication) + publication.publish_at.to_fs(:govuk_date_short) if publication.publish_at.present? + end + + def published_by(publication) + publication.publisher.presence + end +end diff --git a/app/presenters/filtered_editions_presenter.rb b/app/presenters/filtered_editions_presenter.rb index 21540c217..c8540e9a8 100644 --- a/app/presenters/filtered_editions_presenter.rb +++ b/app/presenters/filtered_editions_presenter.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class FilteredEditionsPresenter + ITEMS_PER_PAGE = 20 + def initialize(states_filter: [], assigned_to_filter: nil, format_filter: nil, title_filter: nil) @states_filter = states_filter || [] @assigned_to_filter = assigned_to_filter @@ -16,7 +18,11 @@ def editions result = editions_by_format result = apply_states_filter(result) result = apply_assigned_to_filter(result) - apply_title_filter(result) + result = apply_title_filter(result) + result = result.where.not(_type: "PopularLinksEdition") + # Sets a temporary limit of one page and twenty items + # Pagination to follow + result.page(1).per(ITEMS_PER_PAGE) end private diff --git a/app/views/root/_claim_2i.html.erb b/app/views/root/_claim_2i.html.erb new file mode 100644 index 000000000..702a12e7c --- /dev/null +++ b/app/views/root/_claim_2i.html.erb @@ -0,0 +1,7 @@ +<%= form_for :edition, url: review_edition_path(publication._id), method: :put do |f| %> + <%= f.hidden_field :reviewer, value: current_user.name %> + + <%= render "govuk_publishing_components/components/button", { + text: "Claim 2i", + } %> +<% end %> diff --git a/app/views/root/_table.html.erb b/app/views/root/_table.html.erb new file mode 100644 index 000000000..a50425ea7 --- /dev/null +++ b/app/views/root/_table.html.erb @@ -0,0 +1,55 @@ +
+

<%= @presenter.editions.length %> document(s)

+ + <%= render "govuk_publishing_components/components/table", { + head: [ + { + text: "Title", + }, + { + text: "Updated", + }, + { + text: "Assigned to", + }, + { + text: "Status", + }, + ], + rows: @presenter.editions.map do | publication | + [ + { + text: + sanitize("

#{publication.title}

") + + (render "govuk_publishing_components/components/details", { + title: "More details", + } do + render "govuk_publishing_components/components/summary_list", { + items: [ + {field: "Edition", value: edition_number(publication)}, + {field: "Format", value: format(publication)}, + *([{field: "Important Note", value: important_note(publication)}] if important_note(publication)), + *([{field: "Awaiting review", value: awaiting_review(publication)}] if awaiting_review(publication)), + *([{field: "2i reviewer", value: reviewer(publication, current_user)}] if reviewer(publication, current_user)), + *([{field: "Sent Out", value: sent_out(publication)}] if sent_out(publication)), + *([{field: "Scheduled", value: scheduled(publication)}] if scheduled(publication)), + *([{field: "Published by", value: published_by(publication)}] if published_by(publication)), + ], + borderless: true, + } + end + ), + }, + { + text: sanitize("#{publication.updated_at.to_date.to_fs(:govuk_date_short)}"), + }, + { + text: publication.assignee, + }, + { + text: sanitize("#{publication.state.humanize}"), + }, + ] + end, + } %> +
diff --git a/app/views/root/index.html.erb b/app/views/root/index.html.erb index 1bc5c7c77..b5d2488a5 100644 --- a/app/views/root/index.html.erb +++ b/app/views/root/index.html.erb @@ -20,5 +20,5 @@ <% end %>
-

<%= @presenter.editions.count %> document(s)

+ <%= render :partial => "table" %>
diff --git a/spec/javascripts/spec/publications_table.spec.js b/spec/javascripts/spec/publications_table.spec.js new file mode 100644 index 000000000..691d42c6d --- /dev/null +++ b/spec/javascripts/spec/publications_table.spec.js @@ -0,0 +1,170 @@ +window.GOVUK = window.GOVUK || {} +window.GOVUK.Modules = window.GOVUK.Modules || {} + +describe('Publications Table component', function () { + 'use strict' + + var module, publicationsTable + + beforeEach(function () { + var moduleHtml = + `

20 documents

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TitleUpdatedAssigned toStatus
+

Get an even faster decision on your visa or settlement application

+
+ + More details + +
+
12 Dec 2023Keir StarmerDraft
+

Test Smart Answer

+
+ More details +
+
11 Jul 2024Rishi SunakFact check
+

Gwneud cais i bleidleisio drwy’r post

+
+ More details +
+
10 Jul 2024Liz TrussAmends needed
` + + module = document.createElement('div') + module.innerHTML = moduleHtml + document.body.appendChild(module) + + publicationsTable = new window.GOVUK.Modules.PublicationsTable(module) + publicationsTable.init() + }) + + afterEach(function () { + document.body.removeChild(module) + }) + + describe('When initialised', function () { + it('should have an "Expand/Collapse All" button', function () { + var heading = module.querySelector('p.publications-table__heading') + + expect(heading.querySelector('a')).not.toBeNull() + expect(heading.querySelector('a').classList).toContain('publications-table--expand-link') + expect(heading.querySelector('a').textContent).toBe('Expand all') + }) + + it('all "More details" sections should be closed', function () { + var detailsSections = module.querySelectorAll('details') + + expect(detailsSections[0].getAttribute('open')).not.toBe(true) + expect(detailsSections[1].getAttribute('open')).not.toBe(true) + expect(detailsSections[2].getAttribute('open')).not.toBe(true) + }) + }) + + describe('The Expand/Contract all link', function () { + var expandContractLink, detailsSections, clickEvent + + beforeEach(function () { + expandContractLink = module.querySelector('p.publications-table__heading a') + detailsSections = module.querySelectorAll('details') + clickEvent = new Event('click') + }) + + it('should be labelled "Expand all" when all of the "More details" sections are closed', function () { + detailsSections[0].open = false + detailsSections[1].open = false + detailsSections[2].open = false + publicationsTable.openDetailsCount = 0 + + expect(expandContractLink.textContent).toBe('Expand all') + }) + + it('should be labelled "Expand all" when some of the "More details" sections are closed', function () { + detailsSections[0].open = false + detailsSections[1].open = true + detailsSections[2].open = true + publicationsTable.openDetailsCount = 2 + + expect(expandContractLink.textContent).toBe('Expand all') + }) + + it('should open all the "More details" sections when all of them are closed', function () { + detailsSections[0].open = false + detailsSections[1].open = false + detailsSections[2].open = false + publicationsTable.openDetailsCount = 0 + + expandContractLink.dispatchEvent(clickEvent) + + expect(publicationsTable.openDetailsCount).toBe(3) + expect(detailsSections[0].open).toBe(true) + expect(detailsSections[1].open).toBe(true) + expect(detailsSections[2].open).toBe(true) + }) + + it('should open all the "More details" sections when some of them are closed', function () { + detailsSections[0].open = false + detailsSections[1].open = true + detailsSections[2].open = true + publicationsTable.openDetailsCount = 2 + + expandContractLink.dispatchEvent(clickEvent) + + expect(publicationsTable.openDetailsCount).toBe(3) + expect(detailsSections[0].open).toBe(true) + expect(detailsSections[1].open).toBe(true) + expect(detailsSections[2].open).toBe(true) + }) + + it('should be labelled "Collapse all" when all of the "More details" sections are open', function () { + detailsSections[0].open = false + detailsSections[1].open = false + detailsSections[2].open = false + publicationsTable.openDetailsCount = 0 + + expandContractLink.dispatchEvent(clickEvent) + + expect(expandContractLink.textContent).toBe('Collapse all') + }) + + it('should close all the "More details" sections when they are all open', function () { + detailsSections[0].open = true + detailsSections[1].open = true + detailsSections[2].open = true + publicationsTable.openDetailsCount = 3 + + expandContractLink.dispatchEvent(clickEvent) + + expect(publicationsTable.openDetailsCount).toBe(0) + expect(detailsSections[0].open).toBe(false) + expect(detailsSections[1].open).toBe(false) + expect(detailsSections[2].open).toBe(false) + }) + }) +}) diff --git a/test/functional/root_controller_test.rb b/test/functional/root_controller_test.rb index 6657980dc..cb20d6fb5 100644 --- a/test/functional/root_controller_test.rb +++ b/test/functional/root_controller_test.rb @@ -20,7 +20,7 @@ class RootControllerTest < ActionController::TestCase get :index, params: { states_filter: %w[draft] } assert_response :ok - assert_select "h2", "1 document(s)" + assert_select "p.publications-table__heading", "1 document(s)" end should "filter publications by assignee" do @@ -30,7 +30,7 @@ class RootControllerTest < ActionController::TestCase get :index, params: { assignee_filter: [anna.id] } assert_response :ok - assert_select "h2", "1 document(s)" + assert_select "p.publications-table__heading", "1 document(s)" end should "filter publications by format" do @@ -40,7 +40,7 @@ class RootControllerTest < ActionController::TestCase get :index, params: { format_filter: "guide" } assert_response :ok - assert_select "h2", "1 document(s)" + assert_select "p.publications-table__heading", "1 document(s)" end should "filter publications by title text" do @@ -50,7 +50,7 @@ class RootControllerTest < ActionController::TestCase get :index, params: { title_filter: "zombie" } assert_response :ok - assert_select "h2", "1 document(s)" + assert_select "p.publications-table__heading", "1 document(s)" end should "ignore unrecognised filter states" do diff --git a/test/support/factories.rb b/test/support/factories.rb index bfc39a784..81e9df794 100644 --- a/test/support/factories.rb +++ b/test/support/factories.rb @@ -162,6 +162,11 @@ end factory :help_page_edition, traits: [:with_body], parent: :edition, class: "HelpPageEdition" do + sequence(:slug) { |n| "help/slug-#{n}" } + panopticon_id do + a = create(:artefact, kind: kind_for_artefact, slug:) + a.id + end end factory :campaign_edition, traits: [:with_body], parent: :edition, class: "CampaignEdition" do @@ -242,7 +247,12 @@ factory :devolved_administration_availability factory :local_transaction_edition, parent: :edition, class: "LocalTransactionEdition" do - sequence(:lgsl_code) { |nlgsl| nlgsl } + lgsl_code do + local_service = FactoryBot.create(:local_service) + local_service.lgsl_code + end + + lgil_code { "1" } introduction { "Test introduction" } more_information { "This is more information" } need_to_know { "This service is only available in England and Wales" } diff --git a/test/unit/helpers/admin/publications_table_helper_test.rb b/test/unit/helpers/admin/publications_table_helper_test.rb new file mode 100644 index 000000000..44be3f879 --- /dev/null +++ b/test/unit/helpers/admin/publications_table_helper_test.rb @@ -0,0 +1,259 @@ +require "test_helper" + +class PublicationsTableHelperTest < ActionView::TestCase + include PublicationsTableHelper + + context "#edition_number" do + should "return the edition number for an edition that is not archived or published " do + edition = FactoryBot.create( + :edition, + state: "draft", + version_number: 1, + ) + + assert_equal "1", edition_number(edition) + end + + should "return the edition number text for a published edition where a newer edition has been created" do + artefact = FactoryBot.create(:artefact) + published_edition = FactoryBot.create( + :edition, + panopticon_id: artefact.id, + state: "published", + version_number: 1, + sibling_in_progress: 2, + ) + FactoryBot.create( + :edition, + panopticon_id: artefact.id, + state: "draft", + version_number: 2, + ) + + edition_number_text = edition_number(published_edition) + + assert_match "1 - ", edition_number_text + assert_match "#2 in draft", edition_number_text + end + + should "return the edition number text for an archived edition where a newer edition has been created" do + artefact = FactoryBot.create(:artefact) + archived_edition = FactoryBot.create( + :edition, + panopticon_id: artefact.id, + state: "archived", + version_number: 2, + sibling_in_progress: 3, + ) + FactoryBot.create( + :edition, + panopticon_id: artefact.id, + state: "in_review", + review_requested_at: "2024-07-12 11:25:35.297 UTC", + version_number: 3, + ) + + edition_number_text = edition_number(archived_edition) + + assert_match "2 - ", edition_number_text + assert_match "#3 in in review", edition_number_text + end + end + + context "#important_note" do + should "return the important note text for an edition" do + user = FactoryBot.create(:user, name: "Keir Starmer") + 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_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 an edition in review" do + today = Date.parse("2024-08-02") + + Timecop.freeze(today) do + edition_draft = FactoryBot.create( + :edition, + state: "draft", + ) + + edition_in_review = FactoryBot.create( + :edition, + state: "in_review", + review_requested_at: "2024-07-12", + ) + + 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 an edition that is scheduled for publishing" do + today = Date.parse("2024-08-02") + + Timecop.freeze(today) do + 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_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 a published edition" do + today = Date.parse("2024-08-02") + + Timecop.freeze(today) do + edition_scheduled_for_publishing = FactoryBot.create( + :edition, + state: "scheduled_for_publishing", + publish_at: "2024-09-21", + ) + + edition_published = FactoryBot.create( + :edition, + state: "published", + publisher: "Keir Starmer", + ) + + assert_nil published_by(edition_scheduled_for_publishing) + assert_equal "Keir Starmer", published_by(edition_published) + end + end + end + + context "#reviewer" do + 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", + review_requested_at: "2024-07-12", + reviewer: "Rishi Sunak", + ) + + assert_equal "Rishi Sunak", reviewer(edition, current_user) + end + + 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, + ) + + assert_nil reviewer(edition, current_user) + end + + 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", + ) + + assert_includes reviewer(edition, current_user), '' + end + + 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( + :edition, + state: "in_review", + review_requested_at: "2024-07-12", + assigned_to_id: "66911dbf2c88ee0001d8af62", + ) + + assert_nil reviewer(edition, current_user) + end + end + + 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) + edition_licence = FactoryBot.create(:licence_edition) + edition_local_transaction = FactoryBot.create(:local_transaction_edition) + 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 + + context "#sent_out" do + should "return the correct text for an edition in Fact Check" do + today = Date.parse("2024-08-02") + edition = FactoryBot.create( + :edition, + state: "fact_check", + ) + + Timecop.freeze(today) do + send_fact_check_action = Action.new( + request_type: "send_fact_check", + ) + edition.stubs(:actions).returns([send_fact_check_action]) + end + + assert_equal "2 Aug 2024", sent_out(edition) + end + + should "return nil for an edition not in Fact Check" do + edition = FactoryBot.create( + :edition, + state: "draft", + ) + + assert_nil sent_out(edition) + end + end +end diff --git a/test/unit/presenters/filtered_editions_presenter_test.rb b/test/unit/presenters/filtered_editions_presenter_test.rb index 28cfdef27..5eefb21e5 100644 --- a/test/unit/presenters/filtered_editions_presenter_test.rb +++ b/test/unit/presenters/filtered_editions_presenter_test.rb @@ -60,7 +60,7 @@ class FilteredEditionsPresenterTest < ActiveSupport::TestCase guide = FactoryBot.create(:guide_edition) FactoryBot.create(:completed_transaction_edition) - filtered_editions = FilteredEditionsPresenter.new(format_filter: "guide").editions + filtered_editions = FilteredEditionsPresenter.new(format_filter: "guide").editions.to_a assert_equal([guide], filtered_editions) end @@ -78,7 +78,16 @@ class FilteredEditionsPresenterTest < ActiveSupport::TestCase guide_fawkes = FactoryBot.create(:guide_edition, title: "Guide Fawkes") FactoryBot.create(:guide_edition, title: "Hitchhiker's Guide") - filtered_editions = FilteredEditionsPresenter.new(title_filter: "Fawkes").editions + filtered_editions = FilteredEditionsPresenter.new(title_filter: "Fawkes").editions.to_a + + assert_equal([guide_fawkes], filtered_editions) + end + + should "not return popular links" do + guide_fawkes = FactoryBot.create(:guide_edition) + FactoryBot.create(:popular_links) + + filtered_editions = FilteredEditionsPresenter.new.editions.to_a assert_equal([guide_fawkes], filtered_editions) end