Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scratch-www
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
scratch-www
Commits
2182853d
Unverified
Commit
2182853d
authored
Nov 05, 2019
by
Benjamin Wheeler
Committed by
GitHub
Nov 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Revert "fixed country options to use full country name string as option value""
parent
1f4aabd9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
14 deletions
+25
-14
src/lib/country-data.js
src/lib/country-data.js
+12
-10
test/unit/lib/country-data.test.js
test/unit/lib/country-data.test.js
+13
-4
No files found.
src/lib/country-data.js
View file @
2182853d
...
...
@@ -1060,23 +1060,25 @@ const dupeCommonCountries = module.exports.dupeCommonCountries = (startingCountr
/*
* registrationCountryOptions is the result of taking the standard countryInfo,
* and duplicating 'United States of America' and 'United Kingdom' at the top of the list.
* setting a 'value' key and a 'label' key both to the country data's 'name' value,
* but using the 'display' value for 'label' instead of 'name' if 'display' exists;
* then duplicating 'United States of America' and 'United Kingdom' at the top of the list.
* The result is an array like:
* [
* {
code: 'us', name: 'United States', display
: 'United States of America'},
* {
code: 'gb', name
: 'United Kingdom'},
* {
code: 'af', name
: 'Afghanistan'},
* {
value: 'United States', label
: 'United States of America'},
* {
value: 'United Kingdom', label
: 'United Kingdom'},
* {
value: 'Afghanistan', label
: 'Afghanistan'},
* ...
* {
code: 'ae', name
: 'United Arab Emirates'},
* {
code: 'us', name: 'United States', display
: 'United States of America'},
* {
code: 'gb', name
: 'United Kingdom'},
* {
code: 'uz', name
: 'Uzbekistan'},
* {
value: 'United Arab Emirates', label
: 'United Arab Emirates'},
* {
value: 'United States', label
: 'United States of America'},
* {
value: 'United Kingdom', label
: 'United Kingdom'},
* {
value: 'Uzbekistan', label
: 'Uzbekistan'},
* ...
* {
code: 'zm', name
: 'Zimbabwe'}
* {
value: 'Zimbabwe', label
: 'Zimbabwe'}
* ]
*/
module
.
exports
.
registrationCountryOptions
=
countryOptions
(
dupeCommonCountries
(
countryInfo
,
[
'
us
'
,
'
gb
'
]),
'
cod
e
'
);
countryOptions
(
dupeCommonCountries
(
countryInfo
,
[
'
us
'
,
'
gb
'
]),
'
nam
e
'
);
/* subdivisionOptions uses iso-3166 data to produce an array like:
* [
...
...
test/unit/lib/country-data.test.js
View file @
2182853d
...
...
@@ -74,6 +74,15 @@ 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 that there is one option with label and value === 'Brazil'
const
brazilOptions
=
registrationCountryOptions
.
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
'
);
const
numCountries
=
countryInfo
.
length
;
...
...
@@ -81,17 +90,17 @@ describe('unit test lib/country-data.js', () => {
// 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
:
'
u
s
'
,
label
:
'
United States of America
'
});
expect
(
registrationCountryOptions
[
1
]).
toEqual
({
value
:
'
gb
'
,
label
:
'
United Kingdom
'
});
expect
(
registrationCountryOptions
[
0
]).
toEqual
({
value
:
'
United State
s
'
,
label
:
'
United States of America
'
});
expect
(
registrationCountryOptions
[
1
]).
toEqual
({
value
:
'
United Kingdom
'
,
label
:
'
United Kingdom
'
});
// test that there are now two entries for USA
const
usaOptions
=
registrationCountryOptions
.
reduce
((
acc
,
thisCountry
)
=>
(
thisCountry
.
value
===
'
u
s
'
?
[...
acc
,
thisCountry
]
:
acc
thisCountry
.
value
===
'
United State
s
'
?
[...
acc
,
thisCountry
]
:
acc
),
[]);
expect
(
usaOptions
.
length
).
toEqual
(
2
);
// test that there are now two entries for UK
const
ukOptions
=
registrationCountryOptions
.
reduce
((
acc
,
thisCountry
)
=>
(
thisCountry
.
value
===
'
gb
'
?
[...
acc
,
thisCountry
]
:
acc
thisCountry
.
value
===
'
United Kingdom
'
?
[...
acc
,
thisCountry
]
:
acc
),
[]);
expect
(
ukOptions
.
length
).
toEqual
(
2
);
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment