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
dc79eb54
Unverified
Commit
dc79eb54
authored
Jun 19, 2020
by
Benjamin Wheeler
Committed by
GitHub
Jun 19, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3974 from benjiwheeler/move-to-country-data-lib
move country name lookup to library
parents
7b76c195
d388eef5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
7 deletions
+20
-7
src/components/registration/steps.jsx
src/components/registration/steps.jsx
+2
-2
src/lib/country-data.js
src/lib/country-data.js
+5
-1
test/unit/lib/country-data.test.js
test/unit/lib/country-data.test.js
+13
-4
No files found.
src/components/registration/steps.jsx
View file @
dc79eb54
...
...
@@ -456,7 +456,7 @@ class DemographicsStep extends React.Component {
// look up country name using user's country code selection ('us' -> 'United States')
getCountryName
(
values
)
{
if
(
values
.
countryCode
)
{
const
countryInfo
=
countryData
.
lookupCountry
Info
(
values
.
countryCode
);
const
countryInfo
=
countryData
.
lookupCountry
ByCode
(
values
.
countryCode
);
if
(
countryInfo
)
{
return
countryInfo
.
name
;
}
...
...
@@ -466,7 +466,7 @@ class DemographicsStep extends React.Component {
// look up country code from country label ('United States' -> 'us')
// if `countryName` is not found, including if it's null or undefined, then this function will return undefined.
getCountryCode
(
countryName
)
{
const
country
=
countryData
.
countryInfo
.
find
(
countryItem
=>
countryItem
.
name
===
countryName
);
const
country
=
countryData
.
lookupCountryByName
(
countryName
);
return
country
&&
country
.
code
;
}
handleValidSubmit
(
formData
)
{
...
...
src/lib/country-data.js
View file @
dc79eb54
...
...
@@ -1036,10 +1036,14 @@ const countryOptions = module.exports.countryOptions = (startingCountryInfo, val
))
);
module
.
exports
.
lookupCountry
Info
=
countryCode
=>
(
module
.
exports
.
lookupCountry
ByCode
=
countryCode
=>
(
countryInfo
.
find
(
country
=>
country
.
code
===
countryCode
)
);
module
.
exports
.
lookupCountryByName
=
countryName
=>
(
countryInfo
.
find
(
country
=>
country
.
name
===
countryName
)
);
/**
* Function dupeCommonCountries():
* takes startingCountryInfo, and duplicates any number of its country labels
...
...
test/unit/lib/country-data.test.js
View file @
dc79eb54
const
{
countryInfo
,
countryOptions
,
lookupCountryInfo
,
lookupCountryByCode
,
lookupCountryByName
,
dupeCommonCountries
,
registrationCountryCodeOptions
,
registrationCountryNameOptions
,
...
...
@@ -45,9 +46,17 @@ describe('unit test lib/country-data.js', () => {
expect
(
szInfo
.
label
).
toEqual
(
'
Eswatini
'
);
});
test
(
'
lookupCountryInfo() will find country info
'
,
()
=>
{
expect
(
typeof
lookupCountryInfo
).
toBe
(
'
function
'
);
const
eswatiniInfo
=
lookupCountryInfo
(
'
sz
'
);
test
(
'
lookupCountryByCode() will find country info
'
,
()
=>
{
expect
(
typeof
lookupCountryByCode
).
toBe
(
'
function
'
);
const
eswatiniInfo
=
lookupCountryByCode
(
'
sz
'
);
expect
(
eswatiniInfo
.
name
).
toEqual
(
'
Swaziland
'
);
expect
(
eswatiniInfo
.
display
).
toEqual
(
'
Eswatini
'
);
expect
(
eswatiniInfo
.
code
).
toEqual
(
'
sz
'
);
});
test
(
'
lookupCountryByName() will find country info
'
,
()
=>
{
expect
(
typeof
lookupCountryByName
).
toBe
(
'
function
'
);
const
eswatiniInfo
=
lookupCountryByName
(
'
Swaziland
'
);
expect
(
eswatiniInfo
.
name
).
toEqual
(
'
Swaziland
'
);
expect
(
eswatiniInfo
.
display
).
toEqual
(
'
Eswatini
'
);
expect
(
eswatiniInfo
.
code
).
toEqual
(
'
sz
'
);
...
...
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