UNPKG

@financial-times/n-conversion-forms

Version:

Containing jsx components and styles for forms included on Accounts and Acquisition apps (next-signup, next-profile, next-retention, etc).

176 lines (161 loc) 3.63 kB
const { getDurationFromISO8601Value, is52WeeksOrLonger, is90DaysOrLonger, } = require('./duration-helpers'); describe('Duration Utils', () => { describe('getDurationFromISO8601Value', () => { describe('plural units', () => { const PLURAL_UNITS = [ { input: 'P3Y', expectation: '3 years', }, { input: 'P26M', expectation: '26 months', }, { input: 'P2Y', expectation: '2 years', }, { input: 'P13M', expectation: '13 months', }, { input: 'P52W', expectation: '52 weeks', }, { input: 'P6M', expectation: '6 months', }, { input: 'P13W', expectation: '13 weeks', }, { input: 'P3M', expectation: '3 months', }, { input: 'P8W', expectation: '8 weeks', }, ]; PLURAL_UNITS.forEach(({ input, expectation }) => { it(`returns "${expectation}" for ${input}`, () => { expect(getDurationFromISO8601Value({ iso8601Value: input })).toBe( expectation ); }); }); }); describe('singular units', () => { describe('excludeAmountWhenSingular is true', () => { const SINGULAR_UNITS = [ { input: 'P1Y', expectation: 'year', }, { input: 'P1M', expectation: 'month', }, ]; SINGULAR_UNITS.forEach(({ input, expectation }) => { it(`returns "${expectation}" for ${input}`, () => { expect( getDurationFromISO8601Value({ iso8601Value: input, excludeAmountWhenSingular: true, }) ).toBe(expectation); }); }); }); describe('excludeAmountWhenSingular is false', () => { const SINGULAR_UNITS = [ { input: 'P1Y', expectation: '1 year', }, { input: 'P1M', expectation: '1 month', }, ]; SINGULAR_UNITS.forEach(({ input, expectation }) => { it(`returns "${expectation}" for ${input}`, () => { expect( getDurationFromISO8601Value({ iso8601Value: input, excludeAmountWhenSingular: false, }) ).toBe(expectation); }); }); }); }); }); describe('is52WeeksOrLonger', () => { describe('returns true for durations >= 52 weeks', () => { const DURATIONS_OF_52_WEEKS_OR_MORE = [ 'P3Y', 'P26M', 'P2Y', 'P13M', 'P1Y', 'P52W', ]; DURATIONS_OF_52_WEEKS_OR_MORE.forEach((duration) => { it(`returns true for ${duration}`, () => { expect(is52WeeksOrLonger(duration)).toBe(true); }); }); }); describe('returns false for durations < 52 weeks', () => { const DURATIONS_OF_LESS_THAN_52_WEEKS = [ 'P8W', 'P1M', 'P3M', 'P13W', 'P6M', ]; DURATIONS_OF_LESS_THAN_52_WEEKS.forEach((duration) => { it(`returns false for ${duration}`, () => { expect(is52WeeksOrLonger(duration)).toBe(false); }); }); }); }); describe('is90DaysOrLonger', () => { describe('returns true for durations >= 90 days', () => { const DURATIONS_OF_90_DAYS_OR_MORE = [ 'P3Y', 'P26M', 'P2Y', 'P13M', 'P1Y', 'P52W', 'P6M', 'P13W', 'P3M', ]; DURATIONS_OF_90_DAYS_OR_MORE.forEach((duration) => { it(`returns true for ${duration}`, () => { expect(is90DaysOrLonger(duration)).toBe(true); }); }); }); describe('returns false for durations < 90 days', () => { const DURATIONS_OF_LESS_THAN_90_DAYS = ['P8W', 'P1M']; DURATIONS_OF_LESS_THAN_90_DAYS.forEach((duration) => { it(`returns false for ${duration}`, () => { expect(is90DaysOrLonger(duration)).toBe(false); }); }); }); }); });