Skip to content

Commit eb24889

Browse files
authored
Merge pull request #56 from Autopedia/feature/Button,Icon,TypographyProp업데이트
Feature/button,icon,typography prop업데이트
2 parents 9c0e2fa + bfcf6c9 commit eb24889

18 files changed

+6082
-2278
lines changed

src/assets/fonts/NotoSansKR-Black.otf

100755100644
File mode changed.

src/assets/fonts/NotoSansKR-Bold.otf

100755100644
File mode changed.

src/assets/fonts/NotoSansKR-Light.otf

100755100644
File mode changed.

src/assets/fonts/NotoSansKR-Medium.otf

100755100644
File mode changed.

src/assets/fonts/NotoSansKR-Regular.otf

100755100644
File mode changed.

src/assets/fonts/NotoSansKR-Thin.otf

100755100644
File mode changed.

src/atoms/Button/Button.stories.tsx

Lines changed: 249 additions & 72 deletions
Large diffs are not rendered by default.

src/atoms/Button/Button.test.tsx

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import 'jest-styled-components';
77
import React from 'react';
88
import Button from './Button';
99
import { shallow } from 'enzyme';
10+
import { systemColors } from '../../styles/system-colors';
11+
import { buttonTouchedColors } from './buttonColors';
12+
import { grayscaleColors } from '../../styles/grayscale-colors';
1013

1114
describe('[Button] Unit Test', () => {
1215
it('should fire onPress event', () => {
@@ -18,4 +21,141 @@ describe('[Button] Unit Test', () => {
1821
button.simulate('press');
1922
expect(onPressMock).toHaveBeenCalledTimes(1);
2023
});
24+
it('should not fire onPress event when disabled', () => {
25+
const onPressMock = jest.fn();
26+
const textMock = 'test';
27+
const button = shallow(
28+
<Button disabled onPress={onPressMock}>
29+
{textMock}
30+
</Button>,
31+
);
32+
button.simulate('press');
33+
expect(onPressMock).toHaveBeenCalledTimes(0);
34+
});
35+
it('should not fire onPress event when loading', () => {
36+
const onPressMock = jest.fn();
37+
const textMock = 'test';
38+
const button = shallow(
39+
<Button loading onPress={onPressMock}>
40+
{textMock}
41+
</Button>,
42+
);
43+
button.simulate('press');
44+
expect(onPressMock).toHaveBeenCalledTimes(0);
45+
});
46+
it('should not fire onPress event when loading and disabled', () => {
47+
const onPressMock = jest.fn();
48+
const textMock = 'test';
49+
const button = shallow(
50+
<Button loading disabled onPress={onPressMock}>
51+
{textMock}
52+
</Button>,
53+
);
54+
button.simulate('press');
55+
expect(onPressMock).toHaveBeenCalledTimes(0);
56+
});
57+
it('should show corresponding colors on pressed state', () => {
58+
const onPressMock = jest.fn();
59+
const textMock = 'test';
60+
const button = shallow(
61+
<Button
62+
color={systemColors.PRIMARY}
63+
onPress={onPressMock}
64+
icon={require('../../assets/icons/shop/shop.png')}
65+
>
66+
{textMock}
67+
</Button>,
68+
);
69+
const container = shallow(button.props().children(true));
70+
const buttonText = container.find('ButtonText');
71+
const buttonIcon = container.find('ButtonIcon');
72+
73+
const containerProps = container.props() as {
74+
containerTouchedColor?: string;
75+
};
76+
77+
const buttonTextProps = buttonText.props() as { textColor?: string };
78+
const buttonIconProps = buttonIcon.props() as { color?: string };
79+
80+
expect(containerProps.containerTouchedColor).toBe(
81+
buttonTouchedColors[systemColors.PRIMARY],
82+
);
83+
expect(buttonTextProps.textColor).toBe(systemColors.WHITE);
84+
expect(buttonIconProps.color).toBe(systemColors.WHITE);
85+
});
86+
it('should show fixed color on pressed state if touchedColor is set', () => {
87+
const onPressMock = jest.fn();
88+
const textMock = 'test';
89+
const button = shallow(
90+
<Button
91+
color={systemColors.PRIMARY}
92+
onPress={onPressMock}
93+
touchedColor={systemColors.SUCCESS}
94+
icon={require('../../assets/icons/shop/shop.png')}
95+
>
96+
{textMock}
97+
</Button>,
98+
);
99+
const container = shallow(button.props().children(true));
100+
const buttonText = container.find('ButtonText');
101+
const buttonIcon = container.find('ButtonIcon');
102+
103+
const containerProps = container.props() as {
104+
containerTouchedColor?: string;
105+
};
106+
107+
const buttonTextProps = buttonText.props() as { textColor?: string };
108+
const buttonIconProps = buttonIcon.props() as { color?: string };
109+
110+
expect(containerProps.containerTouchedColor).toBe(systemColors.SUCCESS);
111+
expect(buttonTextProps.textColor).toBe(systemColors.WHITE);
112+
expect(buttonIconProps.color).toBe(systemColors.WHITE);
113+
});
114+
it('should show grayscale color as touchedColor if type is text', () => {
115+
const onPressMock = jest.fn();
116+
const textMock = 'test';
117+
const button = shallow(
118+
<Button
119+
type="text"
120+
color={systemColors.PRIMARY}
121+
onPress={onPressMock}
122+
icon={require('../../assets/icons/shop/shop.png')}
123+
>
124+
{textMock}
125+
</Button>,
126+
);
127+
const container = shallow(button.props().children(true));
128+
129+
const containerProps = container.props() as {
130+
containerTouchedColor?: string;
131+
};
132+
133+
expect(containerProps.containerTouchedColor).toBe(grayscaleColors.GRAY_100);
134+
});
135+
136+
it('should show icon color with prop color if type is text', () => {
137+
const onPressMock = jest.fn();
138+
const textMock = 'test';
139+
const button = shallow(
140+
<Button
141+
type="text"
142+
color={systemColors.PRIMARY}
143+
onPress={onPressMock}
144+
icon={require('../../assets/icons/shop/shop.png')}
145+
>
146+
{textMock}
147+
</Button>,
148+
);
149+
const container = shallow(button.props().children(true));
150+
const buttonIcon = container.find('ButtonIcon');
151+
152+
const containerProps = container.props() as {
153+
containerTouchedColor?: string;
154+
};
155+
156+
const buttonIconProps = buttonIcon.props() as { color?: string };
157+
158+
expect(containerProps.containerTouchedColor).toBe(grayscaleColors.GRAY_100);
159+
expect(buttonIconProps.color).toBe(systemColors.PRIMARY);
160+
});
21161
});

0 commit comments

Comments
 (0)