Skip to content

Commit 99e291d

Browse files
committed
[workflow/test] Updated test cases
1 parent fdca890 commit 99e291d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+583
-47
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
root: true,
33
extends: ['@react-native', 'plugin:testing-library/react'],
4-
ignorePatterns: ['.eslintrc.js', '**/*.test.tsx', '**/*.test.ts'],
4+
ignorePatterns: ['.eslintrc.js', '**/*.test.tsx', '**/*.test.ts', '**/*.config.js'],
55
env: { jest: true },
66
parserOptions: {
77
sourceType: 'module',

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
eslint:
11-
name: "Es lint check"
11+
name: "Eslint check"
1212
runs-on: ubuntu-latest
1313

1414
steps:

src/packages/react-native-material-elements/__test__/BaseButton.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,12 @@ describe('Base button component', () => {
6969
expect(mockOnPress).toHaveBeenCalled();
7070
expect(mockOnPress).toHaveBeenCalledTimes(1);
7171
});
72+
73+
it('should called the onLongPress function', () => {
74+
jest.useFakeTimers();
75+
const { getByTestId } = render(<BaseButton onLongPress={mockOnLongPress} testID={mockTestId} />);
76+
const button = getByTestId(mockTestId);
77+
fireEvent(button, 'longPress', { nativeEvent: {} });
78+
expect(mockOnLongPress).toHaveBeenCalled();
79+
});
7280
});

src/packages/react-native-material-elements/__test__/DropDown.test.tsx

Lines changed: 219 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React from 'react';
2-
import { DropDown, Text } from '../src';
2+
import * as RN from 'react-native';
3+
import { DropDown, DropDownListContainer, gray, Text } from '../src';
34
import { fireEvent, render, waitFor } from './test-utils';
45

56
describe('DropDown Component', () => {
67
const mockInputWrapperTouchTestId = 'input-wrapper-touch-test-id';
8+
const mockInputTestId = 'input-test-id';
79

810
beforeEach(() => {
911
jest.clearAllMocks();
@@ -42,4 +44,220 @@ describe('DropDown Component', () => {
4244
expect(mockOnDropDownClicked).toHaveBeenCalled();
4345
expect(mockOnDropDownClicked).toHaveBeenCalledTimes(1);
4446
});
47+
48+
it('should render the input component', () => {
49+
const { getByTestId } = render(<DropDown dropDownInputTestId={mockInputTestId} />);
50+
51+
const input = getByTestId(mockInputTestId);
52+
expect(input).toBeDefined();
53+
});
54+
55+
it('should render icon input component when variation prop passed as icon', () => {
56+
const { getByTestId } = render(<DropDown variation="icon" dropDownInputTestId={mockInputTestId} />);
57+
58+
const input = getByTestId(mockInputTestId);
59+
expect(input).toBeDefined();
60+
});
61+
62+
it('should show empty value when input component mount', () => {
63+
const { getByTestId } = render(<DropDown variation="icon" dropDownInputTestId={mockInputTestId} />);
64+
65+
const input = getByTestId(mockInputTestId);
66+
expect(input.props.value).toEqual('');
67+
});
68+
69+
it('should not render any input component when invalid variation prop passed', () => {
70+
const { queryByTestId } = render(<DropDown variation={'unknown' as any} dropDownInputTestId={mockInputTestId} />);
71+
72+
const input = queryByTestId(mockInputTestId);
73+
expect(input).toBeNull();
74+
});
75+
76+
it('should show the selected list item title', () => {
77+
const { getByTestId } = render(
78+
<DropDown
79+
data={[{ id: '1', title: 'first_item' }]}
80+
selectedListItems={[{ id: '1', title: 'first_item' }]}
81+
variation="icon"
82+
dropDownInputTestId={mockInputTestId}
83+
/>,
84+
);
85+
86+
const input = getByTestId(mockInputTestId);
87+
88+
expect(input.props.value).toEqual('first_item');
89+
});
90+
91+
it('should show the multiselect message', () => {
92+
const { getByTestId } = render(
93+
<DropDown
94+
data={[{ id: '1', title: 'first_item' }]}
95+
selectedListItems={[{ id: '1', title: 'first_item' }]}
96+
variation="icon"
97+
multiselect
98+
dropDownInputTestId={mockInputTestId}
99+
/>,
100+
);
101+
102+
const input = getByTestId(mockInputTestId);
103+
104+
expect(input.props.value).toEqual('Selected items 1');
105+
});
106+
});
107+
108+
describe('DropDownListContainer component', () => {
109+
const mockListItemTestId = 'mock-list-item-test-id';
110+
111+
const mockOnItemClickedHandler = jest.fn();
112+
const mockOnCloseHandler = jest.fn();
113+
114+
beforeEach(() => {
115+
jest.clearAllMocks();
116+
});
117+
118+
it('should render properly with default props', () => {
119+
const { toJSON } = render(
120+
<DropDownListContainer
121+
inputLayoutRectangle={{ x: 0, y: 0, width: 0, height: 0 }}
122+
dropDownContainerRect={{ x: 0, y: 0, width: 0, height: 0, pageX: 0, pageY: 0 }}
123+
/>,
124+
);
125+
126+
expect(toJSON()).toMatchSnapshot();
127+
});
128+
129+
it('should render the list item', () => {
130+
const { getByTestId } = render(
131+
<DropDownListContainer
132+
inputLayoutRectangle={{ x: 0, y: 0, width: 0, height: 0 }}
133+
dropDownContainerRect={{ x: 0, y: 0, width: 0, height: 0, pageX: 0, pageY: 0 }}
134+
data={[{ id: '1', title: 'first_item' }]}
135+
listItemTestId={mockListItemTestId}
136+
/>,
137+
);
138+
139+
const listItem = getByTestId(mockListItemTestId);
140+
expect(listItem).toBeDefined();
141+
});
142+
143+
it('should called the onItemClicked when onItemClicked props will passed and user tap on the list item', () => {
144+
const { getByTestId } = render(
145+
<DropDownListContainer
146+
inputLayoutRectangle={{ x: 0, y: 0, width: 0, height: 0 }}
147+
dropDownContainerRect={{ x: 0, y: 0, width: 0, height: 0, pageX: 0, pageY: 0 }}
148+
data={[{ id: '1', title: 'first_item' }]}
149+
onItemClicked={mockOnItemClickedHandler}
150+
listItemTestId={mockListItemTestId}
151+
/>,
152+
);
153+
154+
const listItem = getByTestId(mockListItemTestId);
155+
156+
fireEvent(listItem, 'press', { nativeEvent: {} });
157+
158+
expect(mockOnItemClickedHandler).toHaveBeenCalledTimes(1);
159+
expect(mockOnItemClickedHandler).toHaveBeenCalledWith({ id: '1', title: 'first_item' });
160+
});
161+
162+
it('should show the gray[900] color for title text', () => {
163+
const { getByText } = render(
164+
<DropDownListContainer
165+
inputLayoutRectangle={{ x: 0, y: 0, width: 0, height: 0 }}
166+
dropDownContainerRect={{ x: 0, y: 0, width: 0, height: 0, pageX: 0, pageY: 0 }}
167+
data={[{ id: '1', title: 'first_item' }]}
168+
onItemClicked={mockOnItemClickedHandler}
169+
listItemTestId={mockListItemTestId}
170+
/>,
171+
);
172+
173+
const title = getByText('first_item');
174+
expect(title).toBeDefined();
175+
expect(title.props.style.color).toEqual(gray[900]);
176+
});
177+
178+
it('should show the gray[50] color for title text if item is selected', () => {
179+
const { getByText } = render(
180+
<DropDownListContainer
181+
inputLayoutRectangle={{ x: 0, y: 0, width: 0, height: 0 }}
182+
dropDownContainerRect={{ x: 0, y: 0, width: 0, height: 0, pageX: 0, pageY: 0 }}
183+
data={[{ id: '1', title: 'first_item' }]}
184+
onItemClicked={mockOnItemClickedHandler}
185+
listItemTestId={mockListItemTestId}
186+
selectedListItems={[{ id: '1', title: 'first_item' }]}
187+
showSelectedItem
188+
/>,
189+
);
190+
191+
const title = getByText('first_item');
192+
expect(title).toBeDefined();
193+
expect(title.props.style.color).toEqual(gray[50]);
194+
});
195+
196+
it('should show the light color of the title text when color scheme is dark', () => {
197+
jest.spyOn(RN, 'useColorScheme').mockReturnValue('dark');
198+
199+
const { getByText } = render(
200+
<DropDownListContainer
201+
inputLayoutRectangle={{ x: 0, y: 0, width: 0, height: 0 }}
202+
dropDownContainerRect={{ x: 0, y: 0, width: 0, height: 0, pageX: 0, pageY: 0 }}
203+
data={[{ id: '1', title: 'first_item' }]}
204+
onItemClicked={mockOnItemClickedHandler}
205+
listItemTestId={mockListItemTestId}
206+
/>,
207+
);
208+
209+
const title = getByText('first_item');
210+
expect(title).toBeDefined();
211+
expect(title.props.style.color).toEqual(gray[900]);
212+
});
213+
214+
it('should show the listItemEndAdornment item when list items is isSelected', () => {
215+
const { getByText } = render(
216+
<DropDownListContainer
217+
inputLayoutRectangle={{ x: 0, y: 0, width: 0, height: 0 }}
218+
dropDownContainerRect={{ x: 0, y: 0, width: 0, height: 0, pageX: 0, pageY: 0 }}
219+
data={[{ id: '1', title: 'first_item' }]}
220+
selectedListItems={[{ id: '1', title: 'first_item' }]}
221+
listItemEndAdornment={<Text>Hello</Text>}
222+
displaySelectedAdornment
223+
showSelectedItem
224+
/>,
225+
);
226+
227+
const listItemEndAdornment = getByText('Hello');
228+
expect(listItemEndAdornment).toBeDefined();
229+
});
230+
231+
it('should render the search bar component', () => {
232+
const { toJSON, getByPlaceholderText } = render(
233+
<DropDownListContainer
234+
inputLayoutRectangle={{ x: 0, y: 0, width: 0, height: 0 }}
235+
dropDownContainerRect={{ x: 0, y: 0, width: 0, height: 0, pageX: 0, pageY: 0 }}
236+
search
237+
/>,
238+
);
239+
240+
expect(toJSON()).toMatchSnapshot();
241+
242+
const search = getByPlaceholderText('Search');
243+
expect(search).toBeDefined();
244+
});
245+
246+
it('should call the onClose function when press on item', () => {
247+
const { getByText } = render(
248+
<DropDownListContainer
249+
inputLayoutRectangle={{ x: 0, y: 0, width: 0, height: 0 }}
250+
dropDownContainerRect={{ x: 0, y: 0, width: 0, height: 0, pageX: 0, pageY: 0 }}
251+
data={[{ id: '1', title: 'first_item' }]}
252+
onItemClicked={mockOnItemClickedHandler}
253+
listItemTestId={mockListItemTestId}
254+
onClose={mockOnCloseHandler}
255+
/>,
256+
);
257+
258+
const title = getByText('first_item');
259+
fireEvent(title, 'press', { nativeEvent: {} });
260+
expect(mockOnCloseHandler).toHaveBeenCalled();
261+
expect(mockOnCloseHandler).toHaveBeenCalledTimes(1);
262+
});
45263
});

src/packages/react-native-material-elements/__test__/Text.test.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { render as testingRenderer, waitFor } from '@testing-library/react-native';
22
import React from 'react';
33
import { Text as RnText, StyleSheet } from 'react-native';
4-
import { red, secondary, Text, ThemeProvider } from '../src';
4+
import { FormHelperText, red, secondary, Text, ThemeProvider } from '../src';
55
import { TextVariation, TextVariationThemeConfig } from '../src/components/types';
66
import { render } from './test-utils';
77

@@ -397,3 +397,10 @@ describe('Text Component', () => {
397397
});
398398
});
399399
});
400+
401+
describe('FormHelperText component', () => {
402+
it('should render correct', () => {
403+
const { toJSON } = render(<FormHelperText>Hello</FormHelperText>);
404+
expect(toJSON()).toMatchSnapshot();
405+
});
406+
});

src/packages/react-native-material-elements/__test__/__snapshots__/Accordion.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Accordion Component should render correctly 1`] = `
44
<View

src/packages/react-native-material-elements/__test__/__snapshots__/Alert.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Alert should render correctly with zero props 1`] = `
44
<View

src/packages/react-native-material-elements/__test__/__snapshots__/AppBar.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`AppBar should render correctly without any props 1`] = `
44
<View

src/packages/react-native-material-elements/__test__/__snapshots__/Avatar.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Avatar Component should match the snapshot with props 1`] = `
44
<View>

src/packages/react-native-material-elements/__test__/__snapshots__/Backdrop.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Backdrop should render correctly 1`] = `
44
<Modal

0 commit comments

Comments
 (0)