Skip to content

Commit

Permalink
Merge pull request #772 from Financial-Times/accommodate-units-of-day…
Browse files Browse the repository at this point in the history
…s-for-term-display-name

Accommodate units of days for term display name in PaymentTerm component
  • Loading branch information
andygout committed Dec 1, 2023
2 parents 028fb82 + 547ec8f commit 816f643
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 19 deletions.
3 changes: 2 additions & 1 deletion components/payment-term.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ export function PaymentTerm({
/**
* returns period converted to time if found
* otherwise returns empty string to avoid show information not mapped
* @param {string} period (expressed in IS0 8601 duration format): PxY (yearly), PxM (montly), or PxW, where x is the amount of years/months/weeks
* @param {string} period (expressed in IS0 8601 duration format): PxY (yearly), PxM (montly), PxW (weekly), of PxD (daily), where x is the amount of years/months/weeks/days
* @returns {string}
*/
const getTimeFromPeriod = (period) => {
const periodUnitCodeToWordMap = {
Y: 'years',
M: 'months',
W: 'weeks',
D: 'days',
};

const periodUnitCode = period.substring(period.length - 1);
Expand Down
66 changes: 48 additions & 18 deletions components/payment-term.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,28 +185,58 @@ describe('PaymentTerm', () => {
});

describe('given isTermedSubscriptionTermType is true', () => {
const options = [
{
name: '8 weeks',
price: '£19.00',
amount: '19.00',
value: 'P8W',
},
];
const wrapper = shallow(
<PaymentTerm options={options} isTermedSubscriptionTermType={true} />
);

it('renders subscription term as title', () => {
expect(wrapper.find('.ncf__payment-term__title').text()).toMatch(
'8 weeks'
describe('options include duration expressed in weeks', () => {
const options = [
{
price: '£19.00',
amount: '19.00',
value: 'P8W',
},
];
const wrapper = shallow(
<PaymentTerm options={options} isTermedSubscriptionTermType={true} />
);

it('renders subscription term as title', () => {
expect(wrapper.find('.ncf__payment-term__title').text()).toMatch(
'8 weeks'
);
});

it('renders description text that reflects that the termed subscription requires a single payment that expresses the per duration cost for shorter durations', () => {
expect(
wrapper.find('.ncf__payment-term__description').text()
).toContain(
'Single £19.00 paymentThat’s equivalent to GBP9.50 per month'
);
});
});

it('renders description text that reflects that the termed subscription requires a single payment that expresses the per duration cost for shorter durations', () => {
expect(wrapper.find('.ncf__payment-term__description').text()).toContain(
'Single £19.00 paymentThat’s equivalent to GBP9.50 per month'
describe('options include duration expressed in days', () => {
const options = [
{
price: '£30.00',
amount: '30.00',
value: 'P90D',
},
];
const wrapper = shallow(
<PaymentTerm options={options} isTermedSubscriptionTermType={true} />
);

it('renders subscription term as title', () => {
expect(wrapper.find('.ncf__payment-term__title').text()).toMatch(
'90 days'
);
});

it('renders description text that reflects that the termed subscription requires a single payment that expresses the per duration cost for shorter durations', () => {
expect(
wrapper.find('.ncf__payment-term__description').text()
).toContain(
'Single £30.00 paymentThat’s equivalent to GBP10.00 per month'
);
});
});
});

Expand Down

0 comments on commit 816f643

Please sign in to comment.