From 64a23d1f7f0de5a1c19732cef968ce348d7dfd2b Mon Sep 17 00:00:00 2001 From: Becky Ransome <91424856+Beckyrose200@users.noreply.github.com> Date: Tue, 30 Apr 2024 11:43:51 +0100 Subject: [PATCH] Add charge reference links to licence review page (#936) This PR is an enhancement to the licence review page for two-part tariff bill runs. It is adding a dynamic link to the charge references being displayed. The link will display 1 of two pieces of text depending on if the charge reference has either an aggregate value or a charge adjustment factor. If it does it will display 'Change details' and if it doesn't then 'view details'. --- .../review-licence.presenter.js | 11 +++++ app/views/bill-runs/review-licence.njk | 8 +++ .../review-licence.presenter.test.js | 49 +++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/app/presenters/bill-runs/two-part-tariff/review-licence.presenter.js b/app/presenters/bill-runs/two-part-tariff/review-licence.presenter.js index e0a31a06e6..6642e02255 100644 --- a/app/presenters/bill-runs/two-part-tariff/review-licence.presenter.js +++ b/app/presenters/bill-runs/two-part-tariff/review-licence.presenter.js @@ -112,6 +112,7 @@ function _chargeReferenceDetails (reviewChargeVersion, chargePeriod) { chargeCategory: `Charge reference ${reviewChargeReference.chargeReference.chargeCategory.reference}`, chargeDescription: reviewChargeReference.chargeReference.chargeCategory.shortDescription, totalBillableReturns: _totalBillableReturns(reviewChargeReference), + chargeReferenceLink: _chargeReferenceLink(reviewChargeReference), chargeElements: _chargeElementDetails(reviewChargeReference, chargePeriod) }) }) @@ -119,6 +120,16 @@ function _chargeReferenceDetails (reviewChargeVersion, chargePeriod) { return chargeReference } +function _chargeReferenceLink (reviewChargeReference) { + const { chargeAdjustment, aggregate } = reviewChargeReference + + if (chargeAdjustment !== 1 || aggregate !== 1) { + return { linkName: 'Change details' } + } + + return { linkName: 'View details' } +} + function _contactName (billingAccount) { const contact = billingAccount.billingAccountAddresses[0].contact diff --git a/app/views/bill-runs/review-licence.njk b/app/views/bill-runs/review-licence.njk index b9f950b614..bcc07296b9 100644 --- a/app/views/bill-runs/review-licence.njk +++ b/app/views/bill-runs/review-licence.njk @@ -352,6 +352,14 @@ value: { text: chargeReference.totalBillableReturns, attributes: { 'data-test': 'total-billable-returns' } + }, + actions: { + items: [ + { + href: "#", + text: chargeReference.chargeReferenceLink.linkName + } + ] } } %} diff --git a/test/presenters/bill-runs/two-part-tariff/review-licence.presenter.test.js b/test/presenters/bill-runs/two-part-tariff/review-licence.presenter.test.js index ed03853c78..1247ae9ae0 100644 --- a/test/presenters/bill-runs/two-part-tariff/review-licence.presenter.test.js +++ b/test/presenters/bill-runs/two-part-tariff/review-licence.presenter.test.js @@ -85,6 +85,7 @@ describe('Review Licence presenter', () => { chargeCategory: 'Charge reference 4.6.7', chargeDescription: 'High loss, non-tidal, greater than 15 up to and including 50 ML/yr', totalBillableReturns: '0 ML / 200 ML', + chargeReferenceLink: { linkName: 'View details' }, chargeElements: [ { elementNumber: 'Element 1 of 1', @@ -181,6 +182,53 @@ describe('Review Licence presenter', () => { }) }) }) + + describe("the 'adjustment' property's", () => { + describe('when a review charge reference has an aggregate', () => { + beforeEach(() => { + licence[0].reviewChargeVersions[0].reviewChargeReferences[0].aggregate = 0.5 + }) + + it("changes the chargeReferenceLink to 'Change details'", () => { + const result = ReviewLicencePresenter.go(billRun, licence) + + expect(result.chargeData[0].chargeReferences[0].chargeReferenceLink.linkName).to.equal('Change details') + }) + }) + + describe('when a review charge reference has a charge factor adjustment', () => { + beforeEach(() => { + licence[0].reviewChargeVersions[0].reviewChargeReferences[0].chargeAdjustment = 0.5 + }) + + it("changes the chargeReferenceLink to 'Change details'", () => { + const result = ReviewLicencePresenter.go(billRun, licence) + + expect(result.chargeData[0].chargeReferences[0].chargeReferenceLink.linkName).to.equal('Change details') + }) + }) + + describe('when a review charge reference has an aggregate and charge factor adjustment', () => { + beforeEach(() => { + licence[0].reviewChargeVersions[0].reviewChargeReferences[0].aggregate = 0.5 + licence[0].reviewChargeVersions[0].reviewChargeReferences[0].chargeAdjustment = 0.5 + }) + + it("changes the chargeReferenceLink to 'Change details'", () => { + const result = ReviewLicencePresenter.go(billRun, licence) + + expect(result.chargeData[0].chargeReferences[0].chargeReferenceLink.linkName).to.equal('Change details') + }) + }) + + describe('when a review charge reference does not have an aggregate or charge factor adjustment', () => { + it("changes the chargeReferenceLink to 'View details'", () => { + const result = ReviewLicencePresenter.go(billRun, licence) + + expect(result.chargeData[0].chargeReferences[0].chargeReferenceLink.linkName).to.equal('View details') + }) + }) + }) }) }) @@ -274,6 +322,7 @@ function _licenceData () { reviewChargeVersionId: 'bd16e7b0-c2a3-4258-b873-b965fd74cdf5', chargeReferenceId: '82ce8695-5841-41b0-a1e7-d016407adad4', aggregate: 1, + chargeAdjustment: 1, createdAt: new Date('2024-03-18'), updatedAt: new Date('2024-03-18'), chargeReference: {