mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-22 15:17:53 -05:00
update country data test
This commit is contained in:
parent
7b69935d50
commit
dd3e1c9f28
1 changed files with 21 additions and 11 deletions
|
@ -3,7 +3,8 @@ const {
|
|||
countryOptions,
|
||||
lookupCountryInfo,
|
||||
dupeCommonCountries,
|
||||
registrationCountryOptions,
|
||||
registrationCountryCodeOptions,
|
||||
registrationCountryNameOptions,
|
||||
subdivisionOptions
|
||||
} = require('../../../src/lib/country-data');
|
||||
|
||||
|
@ -74,32 +75,41 @@ describe('unit test lib/country-data.js', () => {
|
|||
expect(ukItems.length).toEqual(2);
|
||||
});
|
||||
|
||||
test('registrationCountryOptions object uses country names for both option label and option value', () => {
|
||||
expect(typeof registrationCountryOptions).toBe('object');
|
||||
test('registrationCountryNameOptions object uses country names for both option label and option value', () => {
|
||||
expect(typeof registrationCountryNameOptions).toBe('object');
|
||||
// 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
|
||||
), []);
|
||||
expect(brazilOptions.length).toEqual(1);
|
||||
});
|
||||
|
||||
test('registrationCountryOptions object places USA and UK at start, with display name versions', () => {
|
||||
expect(typeof registrationCountryOptions).toBe('object');
|
||||
test('registrationCountryCodeOptions object uses country codes for option value', () => {
|
||||
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;
|
||||
|
||||
// test that the two entries have been added to the start of the array, and that
|
||||
// the name of the USA includes "America"
|
||||
expect(registrationCountryOptions.length).toEqual(numCountries + 2);
|
||||
expect(registrationCountryOptions[0]).toEqual({value: 'United States', label: 'United States of America'});
|
||||
expect(registrationCountryOptions[1]).toEqual({value: 'United Kingdom', label: 'United Kingdom'});
|
||||
expect(registrationCountryNameOptions.length).toEqual(numCountries + 2);
|
||||
expect(registrationCountryNameOptions[0]).toEqual({value: 'United States', label: 'United States of America'});
|
||||
expect(registrationCountryNameOptions[1]).toEqual({value: 'United Kingdom', label: 'United Kingdom'});
|
||||
|
||||
// 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
|
||||
), []);
|
||||
expect(usaOptions.length).toEqual(2);
|
||||
// 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
|
||||
), []);
|
||||
expect(ukOptions.length).toEqual(2);
|
||||
|
|
Loading…
Reference in a new issue