Commit dd3e1c9f authored by Ben Wheeler's avatar Ben Wheeler

update country data test

parent 7b69935d
...@@ -3,7 +3,8 @@ const { ...@@ -3,7 +3,8 @@ const {
countryOptions, countryOptions,
lookupCountryInfo, lookupCountryInfo,
dupeCommonCountries, dupeCommonCountries,
registrationCountryOptions, registrationCountryCodeOptions,
registrationCountryNameOptions,
subdivisionOptions subdivisionOptions
} = require('../../../src/lib/country-data'); } = require('../../../src/lib/country-data');
...@@ -74,32 +75,41 @@ describe('unit test lib/country-data.js', () => { ...@@ -74,32 +75,41 @@ describe('unit test lib/country-data.js', () => {
expect(ukItems.length).toEqual(2); expect(ukItems.length).toEqual(2);
}); });
test('registrationCountryOptions object uses country names for both option label and option value', () => { test('registrationCountryNameOptions object uses country names for both option label and option value', () => {
expect(typeof registrationCountryOptions).toBe('object'); expect(typeof registrationCountryNameOptions).toBe('object');
// test that there is one option with label and value === 'Brazil' // test that there is one option with label and value === 'Brazil'
const brazilOptions = registrationCountryOptions.reduce((acc, thisCountry) => ( const brazilOptions = registrationCountryNameOptions.reduce((acc, thisCountry) => (
(thisCountry.value === 'Brazil' && thisCountry.label === 'Brazil') ? [...acc, thisCountry] : acc (thisCountry.value === 'Brazil' && thisCountry.label === 'Brazil') ? [...acc, thisCountry] : acc
), []); ), []);
expect(brazilOptions.length).toEqual(1); expect(brazilOptions.length).toEqual(1);
}); });
test('registrationCountryOptions object places USA and UK at start, with display name versions', () => { test('registrationCountryCodeOptions object uses country codes for option value', () => {
expect(typeof registrationCountryOptions).toBe('object'); expect(typeof registrationCountryCodeOptions).toBe('object');
// test that there is one option with label and value === 'Brazil'
const brazilOptions = registrationCountryCodeOptions.reduce((acc, thisCountry) => (
(thisCountry.value === 'br' && thisCountry.label === 'Brazil') ? [...acc, thisCountry] : acc
), []);
expect(brazilOptions.length).toEqual(1);
});
test('registrationCountryNameOptions object places USA and UK at start, with display name versions', () => {
expect(typeof registrationCountryNameOptions).toBe('object');
const numCountries = countryInfo.length; const numCountries = countryInfo.length;
// test that the two entries have been added to the start of the array, and that // test that the two entries have been added to the start of the array, and that
// the name of the USA includes "America" // the name of the USA includes "America"
expect(registrationCountryOptions.length).toEqual(numCountries + 2); expect(registrationCountryNameOptions.length).toEqual(numCountries + 2);
expect(registrationCountryOptions[0]).toEqual({value: 'United States', label: 'United States of America'}); expect(registrationCountryNameOptions[0]).toEqual({value: 'United States', label: 'United States of America'});
expect(registrationCountryOptions[1]).toEqual({value: 'United Kingdom', label: 'United Kingdom'}); expect(registrationCountryNameOptions[1]).toEqual({value: 'United Kingdom', label: 'United Kingdom'});
// test that there are now two entries for USA // test that there are now two entries for USA
const usaOptions = registrationCountryOptions.reduce((acc, thisCountry) => ( const usaOptions = registrationCountryNameOptions.reduce((acc, thisCountry) => (
thisCountry.value === 'United States' ? [...acc, thisCountry] : acc thisCountry.value === 'United States' ? [...acc, thisCountry] : acc
), []); ), []);
expect(usaOptions.length).toEqual(2); expect(usaOptions.length).toEqual(2);
// test that there are now two entries for UK // test that there are now two entries for UK
const ukOptions = registrationCountryOptions.reduce((acc, thisCountry) => ( const ukOptions = registrationCountryNameOptions.reduce((acc, thisCountry) => (
thisCountry.value === 'United Kingdom' ? [...acc, thisCountry] : acc thisCountry.value === 'United Kingdom' ? [...acc, thisCountry] : acc
), []); ), []);
expect(ukOptions.length).toEqual(2); expect(ukOptions.length).toEqual(2);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment