diff --git a/app/presenters/notifications/setup/review.presenter.js b/app/presenters/notifications/setup/review.presenter.js index 17f3ce485c..c8e2fb33b2 100644 --- a/app/presenters/notifications/setup/review.presenter.js +++ b/app/presenters/notifications/setup/review.presenter.js @@ -13,13 +13,14 @@ const { titleCase } = require('../../base.presenter.js') * * @param {object[]} recipients - List of recipient objects, each containing recipient details like email or name. * @param {number|string} page - The currently selected page + * @param {object} pagination - * * @returns {object} - The data formatted for the view template */ -function go(recipients, page) { +function go(recipients, page, pagination) { return { defaultPageSize, - pageTitle: 'Send returns invitations', + pageTitle: _pageTitle(page, pagination), recipients: _recipients(recipients, page), recipientsAmount: recipients.length } @@ -54,6 +55,14 @@ function _licences(licences) { return licences.split(',') } +function _pageTitle(page, pagination) { + if (pagination.numberOfPages > 1) { + return `Send returns invitations (page ${page} of ${pagination.numberOfPages})` + } + + return 'Send returns invitations' +} + /** * Due to the complexity of the query to get the recipients data, we handle pagination in the presenter. * diff --git a/app/services/notifications/setup/review.service.js b/app/services/notifications/setup/review.service.js index 5bd97f9b24..4a69e16fc3 100644 --- a/app/services/notifications/setup/review.service.js +++ b/app/services/notifications/setup/review.service.js @@ -31,14 +31,14 @@ async function go(sessionId, page = 1) { const dedupeRecipients = DedupeRecipientsService.go(recipients) - const formattedData = ReviewPresenter.go(dedupeRecipients, page) - const pagination = PaginatorPresenter.go( - formattedData.recipientsAmount, + dedupeRecipients.length, Number(page), `/system/notifications/setup/${sessionId}/review` ) + const formattedData = ReviewPresenter.go(dedupeRecipients, page, pagination) + return { activeNavBar: 'manage', ...formattedData, diff --git a/app/views/notifications/setup/review.njk b/app/views/notifications/setup/review.njk index ac545fac49..512f602273 100644 --- a/app/views/notifications/setup/review.njk +++ b/app/views/notifications/setup/review.njk @@ -47,7 +47,7 @@ {% block content %}
Returns invitations are ready to send.
diff --git a/test/presenters/notifications/setup/review.presenter.test.js b/test/presenters/notifications/setup/review.presenter.test.js index b2280ee918..0122d2f642 100644 --- a/test/presenters/notifications/setup/review.presenter.test.js +++ b/test/presenters/notifications/setup/review.presenter.test.js @@ -14,20 +14,24 @@ const RecipientsFixture = require('../../../fixtures/recipients.fixtures.js') const ReviewPresenter = require('../../../../app/presenters/notifications/setup/review.presenter.js') describe('Notifications Setup - Review presenter', () => { - let testRecipients - let testInput let page + let pagination + let testInput + let testRecipients beforeEach(() => { + page = 1 + pagination = { + numberOfPages: 1 + } + testRecipients = RecipientsFixture.recipients() testInput = Object.values(testRecipients) - - page = 1 }) describe('when provided with "recipients"', () => { it('correctly presents the data', () => { - const result = ReviewPresenter.go(testInput, page) + const result = ReviewPresenter.go(testInput, page, pagination) expect(result).to.equal({ defaultPageSize: 25, @@ -66,7 +70,7 @@ describe('Notifications Setup - Review presenter', () => { describe('the "recipients" property', () => { describe('format all recipient types', () => { it('should return the formatted recipients', () => { - const result = ReviewPresenter.go(testInput, page) + const result = ReviewPresenter.go(testInput, page, pagination) expect(result.recipients).to.equal([ { @@ -100,7 +104,7 @@ describe('Notifications Setup - Review presenter', () => { describe('the "contact" property', () => { describe('when the contact is an email', () => { it('should return the email address', () => { - const result = ReviewPresenter.go(testInput, page) + const result = ReviewPresenter.go(testInput, page, pagination) const testRecipient = result.recipients.find((recipient) => recipient.licences.includes(testRecipients.primaryUser.all_licences) @@ -116,7 +120,7 @@ describe('Notifications Setup - Review presenter', () => { describe('when the contact is an address', () => { it('should convert the contact into an array', () => { - const result = ReviewPresenter.go(testInput, page) + const result = ReviewPresenter.go(testInput, page, pagination) const testRecipient = result.recipients.find((recipient) => recipient.licences.includes(testRecipients.licenceHolder.all_licences) @@ -134,7 +138,7 @@ describe('Notifications Setup - Review presenter', () => { describe('the "licences" property', () => { describe('when the recipient has a single licence number', () => { it('should return licence numbers as an array', () => { - const result = ReviewPresenter.go(testInput, page) + const result = ReviewPresenter.go(testInput, page, pagination) const testRecipient = result.recipients.find((recipient) => recipient.licences.includes(testRecipients.licenceHolder.all_licences) @@ -146,7 +150,7 @@ describe('Notifications Setup - Review presenter', () => { describe('when the recipient has multiple licence numbers', () => { it('should return licence numbers as an array', () => { - const result = ReviewPresenter.go(testInput, page) + const result = ReviewPresenter.go(testInput, page, pagination) const testRecipient = result.recipients.find( (recipient) => @@ -164,7 +168,7 @@ describe('Notifications Setup - Review presenter', () => { describe('and there are <= 25 recipients ', () => { it('returns all the recipients', () => { - const result = ReviewPresenter.go(testInput, page) + const result = ReviewPresenter.go(testInput, page, pagination) expect(result.recipients.length).to.equal(testInput.length) }) @@ -173,21 +177,41 @@ describe('Notifications Setup - Review presenter', () => { describe('and there are >= 25 recipients', () => { beforeEach(() => { testInput = [...testInput, ...testInput, ...testInput, ...testInput, ...testInput, ...testInput] + + pagination = { + numberOfPages: 2 + } }) describe('and the page is 1', () => { it('returns the first 25 recipients', () => { - const result = ReviewPresenter.go(testInput, page) + const result = ReviewPresenter.go(testInput, page, pagination) expect(result.recipients.length).to.equal(25) }) - describe('and there is more than one page', () => { - it('returns the remaining recipients', () => { - const result = ReviewPresenter.go(testInput, '2') + it('returns the updated "pageTitle"', () => { + const result = ReviewPresenter.go(testInput, page, pagination) - expect(result.recipients.length).to.equal(5) - }) + expect(result.pageTitle).to.equal('Send returns invitations (page 1 of 2)') + }) + }) + + describe('and there is more than one page', () => { + beforeEach(() => { + page = '2' + }) + + it('returns the remaining recipients', () => { + const result = ReviewPresenter.go(testInput, page, pagination) + + expect(result.recipients.length).to.equal(5) + }) + + it('returns the updated "pageTitle"', () => { + const result = ReviewPresenter.go(testInput, page, pagination) + + expect(result.pageTitle).to.equal('Send returns invitations (page 2 of 2)') }) }) })