Comments (20)
@oh3vci Did you try locale props with 'kr-KR' or other timezones when you test? Did it work as like 'μ', 'ν'...?
from dooboo-ui-legacy.
@0916dhkim Cool. We can use snapshot test again for DatePicker.
from dooboo-ui-legacy.
@oh3vci Did you try locale props with 'kr-KR' or other timezones when you test? Did it work as like 'μ', 'ν'...?
Isn't it 'ko-KR', not 'kr-KR'?
@JeffGuKang I tried setting
locale
props toko-KR
in storybook. Korean characters show up correctly on web, but it does not work on Android. The same thing happens forlocale="es-ES"
.I guess it seems to be another bug of android or storybook. it works well in iOS.
Maybe, this is related issue in android.
from dooboo-ui-legacy.
@oh3vci It is working well now with #351. π
from dooboo-ui-legacy.
I think it will be solved by mocking as like
jest
.spyOn(Date, 'now')
.mockImplementation(() => new Date('2020-09-01').valueOf())
from dooboo-ui-legacy.
Because date values are used a lot in test cases, I set a standard date instead of using spyOn.
from dooboo-ui-legacy.
@oh3vci It is not solved yet. Snapshots change everyday.
from dooboo-ui-legacy.
spyOn
is not working with Date
.
Related issues:
I finally mocked global.Date
through
const standardDate = new Date('2020-09-01');
const _Date = Date;
// @ts-ignore
global.Date = jest.fn(() => standardDate);
global.Date.UTC = _Date.UTC;
global.Date.parse = _Date.parse;
global.Date.now = _Date.now;
But I couldn't mocking toLocaleString
.
Already tried
- jest.spyOn
const localeOption = {
year: '2-digit',
month: '2-digit',
day: '2-digit',
};
const dateSpy = jest.spyOn(global.Date.prototype, 'toLocaleString')
.mockImplementation(() => new Date().toLocaleString('UTC', localeOption));
- installing full-icu for node 12 and earlier: not working
from dooboo-ui-legacy.
I think it's good to exclude snapshots from the Datepicker test.
from dooboo-ui-legacy.
@JeffGuKang How about we add today
as a props for DatePicker
? That would eliminate the need for mocking global.Date
, and also allow us to use snapshot testing.
from dooboo-ui-legacy.
@JeffGuKang How about we add
today
as a props forDatePicker
? That would eliminate the need for mockingglobal.Date
, and also allow us to use snapshot testing.
But I couldn't control locale
in dooboo-ui node environment for testing.
It seems to be dependent on the user's OS.
For example,
Weekdays would be 'Mon', 'Tue'... in en-EN
. But in Korean OS, this appears to be 'μ', 'ν'...
And we cannot control locale manually as I said dooboolab-community/dooboo-ui#337 (comment).
from dooboo-ui-legacy.
We can except validation from specific area of snapshots through matcher
. It can be the one of the solutions.
from dooboo-ui-legacy.
@JeffGuKang I suggest we use react-intl
package for internationalization instead of toLocaleString
and add today
props to DatePicker
component. react-intl
(from FormatJS) allows developers to wrap components with IntlProvider
, so we can provide { locale: 'en' }
for testing and provide user-specific locale for production.
Here's the relevant documentation : https://formatjs.io/docs/guides/testing#jest
Excerpt:
import React from 'react'
import renderer from 'react-test-renderer'
import {IntlProvider} from 'react-intl'
const createComponentWithIntl = (children, props = {locale: 'en'}) => {
return renderer.create(<IntlProvider {...props}>{children}</IntlProvider>)
}
export default createComponentWithIntl
import React from 'react'
import createComponentWithIntl from '../../utils/createComponentWithIntl'
import AppMain from '../AppMain'
test('app main should be rendered', () => {
const component = createComponentWithIntl(<AppMain />)
let tree = component.toJSON()
expect(tree).toMatchSnapshot()
tree.props.onClick()
tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
from dooboo-ui-legacy.
As adding locale prop to component, I implemented already this approach without react-intl
. Can you check this? #347
from dooboo-ui-legacy.
@oh3vci It looks good to me. So I guess we just need to test DatePicker
with locale
and today
props defined.
BTW do we have any timezone related issue with DatePicker
snapshot testing?
from dooboo-ui-legacy.
I think timezone issue is already solved problem,
because I set en to the value of the locale prop that is the locale parameter of toLocaleString method in test code.
So the test snapshot will no longer be affected by the OS.
from dooboo-ui-legacy.
@JeffGuKang I tried setting locale
props to ko-KR
in storybook. Korean characters show up correctly on web, but it does not work on Android. The same thing happens for locale="es-ES"
.
from dooboo-ui-legacy.
@oh3vci Did you try locale props with 'kr-KR' or other timezones when you test? Did it work as like 'μ', 'ν'...?
Isn't it 'ko-KR', not 'kr-KR'?
@JeffGuKang I tried setting
locale
props toko-KR
in storybook. Korean characters show up correctly on web, but it does not work on Android. The same thing happens forlocale="es-ES"
.
I guess it seems to be another bug of android or storybook. it works well in iOS.
from dooboo-ui-legacy.
@oh3vci How about testing environment? Testing is not work as expectation with locale control or mocking.
from dooboo-ui-legacy.
@JeffGuKang locale
props works inside jest.
I tested this first,
<DatePicker selectedDate={standardDate} locale={'ko-KR'} />
then this,
<DatePicker selectedDate={standardDate} locale={'en-US'} />
Here's the snapshot diff:
- Snapshot - 7
+ Received + 7
@@ -247,11 +247,11 @@
"color": "#ff424c",
},
]
}
>
- μΌ
+ S
</Text>
</View>
<View
style={
Array [
@@ -279,11 +279,11 @@
"color": "#565656",
},
]
}
>
- μ
+ M
</Text>
</View>
<View
style={
Array [
@@ -311,11 +311,11 @@
"color": "#565656",
},
]
}
>
- ν
+ T
</Text>
</View>
<View
style={
Array [
@@ -343,11 +343,11 @@
"color": "#565656",
},
]
}
>
- μ
+ W
</Text>
</View>
<View
style={
Array [
@@ -375,11 +375,11 @@
"color": "#565656",
},
]
}
>
- λͺ©
+ T
</Text>
</View>
<View
style={
Array [
@@ -407,11 +407,11 @@
"color": "#565656",
},
]
}
>
- κΈ
+ F
</Text>
</View>
<View
style={
Array [
@@ -439,11 +439,11 @@
"color": "#565656",
},
]
}
>
- ν
+ S
</Text>
</View>
</View>
<ScrollView
data={
from dooboo-ui-legacy.
Related Issues (20)
- Mistakes in the README : import instructions of Select HOT 9
- [Feature] How about adding duration prop to the LoadingIndicator component? HOT 5
- first PR test fail: `[error]Resource not accessible by integration` HOT 7
- Problem with snapshot testing environment of CalendarCarousel HOT 4
- Password character ellipsis issue.
- 'react-native-svg' module is not contained in the library dependency HOT 3
- [Feature][DatePicker] HOT 6
- [Select] not working on Android HOT 6
- [Feature] Card HOT 1
- [Feature] PinchZoom
- Set storybook server that makes controllable iOS and Android stories on the webbrowser HOT 2
- [Checkbox][Web] outline style glitch
- [Feature][DatePicker] Support web environment HOT 1
- [Question] How can I swipe down to close the PinchZoomSliderModal? HOT 3
- [Button] Documentation Is Outdated HOT 2
- [Select] is using react-native-svg module HOT 3
- [Badge] Custom size HOT 1
- [Rating] Customize image
- React Native SVG in components HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dooboo-ui-legacy.