Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

Commit

Permalink
test(rating): update test
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffGuKang authored and JongtaekChoi committed Nov 18, 2020
1 parent 06617f5 commit efc05bc
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 42 deletions.
11 changes: 5 additions & 6 deletions main/Rating/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import React, { useMemo } from 'react';
import { StyleProp, ViewStyle } from 'react-native';
import styled from 'styled-components/native';

interface CustomItem {
onComponent: React.ReactElement;
offComponent: React.ReactElement;
}
interface Props {
total: number;
value: number;
onChange?: (value: number) => void;
disabled?: boolean;
customItem?: CustomStar;
customItem?: CustomItem;
containerStyle?: StyleProp<ViewStyle>;
}

Expand All @@ -24,11 +28,6 @@ interface StarProps {
customItem?: CustomItem;
}

interface CustomItem {
onComponent: React.ReactElement;
offComponent: React.ReactElement;
}

const ContainerWrapper = styled.View<ContainerWrapperProps>`
width: ${({ total }): number => total * 30}px;
flex-direction: row;
Expand Down
28 changes: 26 additions & 2 deletions main/__tests__/Rating.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { Rating } from '../../main';
// Note: test renderer must be required after react-native.
import { TouchableOpacity } from 'react-native';
import { TouchableOpacity, View } from 'react-native';
import { Rating } from '../../main';
import renderer from 'react-test-renderer';

const defaultProps = {
Expand Down Expand Up @@ -69,5 +69,29 @@ describe('[Rating] render', () => {
expect(rendered).toMatchSnapshot();
expect(rendered).toBeTruthy();
});

it('should simulate customItem and containerStyle props', (): void => {
const rendered = renderer.create(
component({
...defaultProps,
customItem: {
onComponent: <View />,
offComponent: <View />,
},
containerStyle: {
width: 300,
},
testID: 'RATING_ID',
}),
);

rendered.update(component({ value: 3 }));
expect(rendered).toMatchSnapshot();
expect(rendered).toBeTruthy();

rendered.update(component({ disabled: true }));
expect(rendered).toMatchSnapshot();
expect(rendered).toBeTruthy();
});
});
});
152 changes: 118 additions & 34 deletions main/__tests__/__snapshots__/Rating.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,14 +1,114 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`[Rating] render [Rating] Interaction should simulate customItem and containerStyle props 1`] = `
<View
style={
Array [
Object {
"alignItems": "center",
"flexDirection": "row",
"justifyContent": "space-between",
"opacity": 1,
"width": "NaNpx",
},
]
}
>
<View
accessible={true}
focusable={true}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"opacity": 1,
}
}
>
<Image
resizeMode="contain"
source={
Object {
"testUri": "../../../main/__assets__/star_s.png",
}
}
style={
Array [
Object {
"height": 30,
"width": 30,
},
]
}
/>
</View>
</View>
`;

exports[`[Rating] render [Rating] Interaction should simulate customItem and containerStyle props 2`] = `
<View
disabled={true}
style={
Array [
Object {
"alignItems": "center",
"flexDirection": "row",
"justifyContent": "space-between",
"opacity": 0.5,
"width": "NaNpx",
},
]
}
>
<View
accessible={true}
focusable={true}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"opacity": 1,
}
}
>
<Image
resizeMode="contain"
source={
Object {
"testUri": "../../../main/__assets__/star_d.png",
}
}
style={
Array [
Object {
"height": 30,
"width": 30,
},
]
}
/>
</View>
</View>
`;

exports[`[Rating] render [Rating] Interaction should simulate props 1`] = `
<View
style={
Array [
Object {
"alignItems": "center",
"flexDirection": "row",
"height": 30,
"justifyContent": "center",
"justifyContent": "space-between",
"opacity": 1,
"width": "NaNpx",
},
Expand All @@ -27,9 +127,7 @@ exports[`[Rating] render [Rating] Interaction should simulate props 1`] = `
onStartShouldSetResponder={[Function]}
style={
Object {
"height": "100%",
"opacity": 1,
"width": 30,
}
}
>
Expand All @@ -43,8 +141,8 @@ exports[`[Rating] render [Rating] Interaction should simulate props 1`] = `
style={
Array [
Object {
"height": "100%",
"width": "100%",
"height": 30,
"width": 30,
},
]
}
Expand All @@ -61,8 +159,7 @@ exports[`[Rating] render [Rating] Interaction should simulate props 2`] = `
Object {
"alignItems": "center",
"flexDirection": "row",
"height": 30,
"justifyContent": "center",
"justifyContent": "space-between",
"opacity": 0.5,
"width": "NaNpx",
},
Expand All @@ -81,9 +178,7 @@ exports[`[Rating] render [Rating] Interaction should simulate props 2`] = `
onStartShouldSetResponder={[Function]}
style={
Object {
"height": "100%",
"opacity": 1,
"width": 30,
}
}
>
Expand All @@ -97,8 +192,8 @@ exports[`[Rating] render [Rating] Interaction should simulate props 2`] = `
style={
Array [
Object {
"height": "100%",
"width": "100%",
"height": 30,
"width": 30,
},
]
}
Expand All @@ -114,8 +209,7 @@ exports[`[Rating] render renders without crashing 1`] = `
Object {
"alignItems": "center",
"flexDirection": "row",
"height": 30,
"justifyContent": "center",
"justifyContent": "space-between",
"opacity": 1,
"width": 150,
},
Expand All @@ -135,9 +229,7 @@ exports[`[Rating] render renders without crashing 1`] = `
onStartShouldSetResponder={[Function]}
style={
Object {
"height": "100%",
"opacity": 1,
"width": 30,
}
}
>
Expand All @@ -151,8 +243,8 @@ exports[`[Rating] render renders without crashing 1`] = `
style={
Array [
Object {
"height": "100%",
"width": "100%",
"height": 30,
"width": 30,
},
]
}
Expand All @@ -170,9 +262,7 @@ exports[`[Rating] render renders without crashing 1`] = `
onStartShouldSetResponder={[Function]}
style={
Object {
"height": "100%",
"opacity": 1,
"width": 30,
}
}
>
Expand All @@ -186,8 +276,8 @@ exports[`[Rating] render renders without crashing 1`] = `
style={
Array [
Object {
"height": "100%",
"width": "100%",
"height": 30,
"width": 30,
},
]
}
Expand All @@ -205,9 +295,7 @@ exports[`[Rating] render renders without crashing 1`] = `
onStartShouldSetResponder={[Function]}
style={
Object {
"height": "100%",
"opacity": 1,
"width": 30,
}
}
>
Expand All @@ -221,8 +309,8 @@ exports[`[Rating] render renders without crashing 1`] = `
style={
Array [
Object {
"height": "100%",
"width": "100%",
"height": 30,
"width": 30,
},
]
}
Expand All @@ -240,9 +328,7 @@ exports[`[Rating] render renders without crashing 1`] = `
onStartShouldSetResponder={[Function]}
style={
Object {
"height": "100%",
"opacity": 1,
"width": 30,
}
}
>
Expand All @@ -256,8 +342,8 @@ exports[`[Rating] render renders without crashing 1`] = `
style={
Array [
Object {
"height": "100%",
"width": "100%",
"height": 30,
"width": 30,
},
]
}
Expand All @@ -275,9 +361,7 @@ exports[`[Rating] render renders without crashing 1`] = `
onStartShouldSetResponder={[Function]}
style={
Object {
"height": "100%",
"opacity": 1,
"width": 30,
}
}
>
Expand All @@ -291,8 +375,8 @@ exports[`[Rating] render renders without crashing 1`] = `
style={
Array [
Object {
"height": "100%",
"width": "100%",
"height": 30,
"width": 30,
},
]
}
Expand Down

0 comments on commit efc05bc

Please sign in to comment.