Skip to content

Commit c84a6bb

Browse files
committed
Added otp input test cases
1 parent e989ab7 commit c84a6bb

10 files changed

Lines changed: 42 additions & 9 deletions

File tree

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ module.exports = {
1717
'.enum.ts',
1818
'/config/',
1919
'/coverage/',
20+
'.eslintrc.js',
21+
'.prettierrc.js',
22+
'babel.config.js',
2023
],
2124

2225
coverageReporters: ['html', 'text', 'lcov', 'text-summary'],

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { OTPInput } from '../src';
33
import { fireEvent, render } from './test-utils';
44

55
describe('OTP Component', () => {
6+
const mockOtpInputTestId = 'mock-otp-input-test-id';
7+
68
beforeEach(() => {
79
jest.clearAllMocks();
810
});
@@ -93,4 +95,20 @@ describe('OTP Component', () => {
9395
expect(input.props.value).toBe('');
9496
});
9597
});
98+
99+
it('should set the default values', () => {
100+
const { getByTestId } = render(<OTPInput testID={mockOtpInputTestId} length={3} defaultValue={'123'} />);
101+
102+
const firstInput = getByTestId(`${mockOtpInputTestId}-0`);
103+
expect(firstInput).toBeDefined();
104+
expect(firstInput.props.value).toEqual('1');
105+
106+
const secondInput = getByTestId(`${mockOtpInputTestId}-1`);
107+
expect(secondInput).toBeDefined();
108+
expect(secondInput.props.value).toEqual('2');
109+
110+
const thirdInput = getByTestId(`${mockOtpInputTestId}-2`);
111+
expect(thirdInput).toBeDefined();
112+
expect(thirdInput.props.value).toEqual('3');
113+
});
96114
});

src/packages/react-native-material-elements/__test__/styleGenerator.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,15 @@ describe('Style Utilities', () => {
7676
expect(result).toEqual({});
7777
consoleSpy.mockRestore();
7878
});
79+
80+
it('should warn in the console if the styles property not valid', () => {
81+
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation();
82+
const args: StylePalette = { unknown: undefined } as any;
83+
const result = generateElementStyles(args);
84+
85+
expect(consoleSpy).toHaveBeenCalledWith('Invalid element property name: undefined, and value: undefined');
86+
expect(result).toEqual({});
87+
consoleSpy.mockRestore();
88+
});
7989
});
8090
});

src/packages/react-native-material-elements/src/components/ActivityIndicator/ActivityIndicator.types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { ActivityIndicator } from 'react-native';
3-
import { Theme } from '../../libraries/themes/types';
3+
import { Theme } from '../../libraries/types';
44
import { VariantTypes } from '../../utils';
55

66
export interface ActivityIndicatorProps extends React.ComponentPropsWithRef<typeof ActivityIndicator> {

src/packages/react-native-material-elements/src/components/Alert/Alert.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React, { useMemo } from 'react';
22
import { ColorSchemeName, StyleSheet, TextStyle, useColorScheme, View, ViewStyle } from 'react-native';
3+
import { ThemedIconProp, useThemedProps } from '../../hooks';
34
import { useThemeColorsSelector } from '../../libraries';
4-
import { Theme } from '../../libraries/themes/types';
5+
import { Theme } from '../../libraries/types';
56
import { VariantTypes } from '../../utils';
67
import { Box } from '../Box';
78
import { BoxProps } from '../types';
89
import { Text } from '../Typography';
910
import { getAlertContainerStyles, getAlertTitleStyles } from './utils';
10-
import { ThemedIconProp, useThemedProps } from '../../hooks';
1111

1212
export interface AlertProps extends BoxProps {
1313
/** Main title text displayed in the alert */

src/packages/react-native-material-elements/src/components/Menu/Menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { useRestyle } from '../../hooks';
1313
import { useThemeColorsSelector } from '../../libraries';
1414
import { StyledProps } from '../../libraries/style/styleTypes';
15-
import { Theme } from '../../libraries/themes/types';
15+
import { Theme } from '../../libraries/types';
1616
import { MeasureElementRect, PortalProps } from '../../types';
1717
import { screenHeight, screenWidth } from '../../utils';
1818
import { Portal } from '../Portal';

src/packages/react-native-material-elements/src/components/Progress/Progress.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Animated, ColorValue, DimensionValue, I18nManager, LayoutChangeEvent, S
33
import { useRestyle } from '../../hooks';
44
import { useThemeColorsSelector } from '../../libraries';
55
import { StyledProps } from '../../libraries/style/styleTypes';
6-
import { Theme } from '../../libraries/themes/types';
6+
import { Theme } from '../../libraries/types';
77
import { VariantTypes } from '../../utils';
88
import { AnimatedView } from '../Box';
99
import { getProgressBarContainerStyles, getProgressBarIndicatorStyles } from './utils';

src/packages/react-native-material-elements/src/components/SegmentedControl/SegmentedControlContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
22
import { View, ViewProps } from 'react-native';
3+
import { useRestyle } from '../../hooks';
34
import { useThemeColorsSelector } from '../../libraries';
45
import { StyledProps } from '../../libraries/style/styleTypes';
5-
import { Theme } from '../../libraries/themes/types';
6+
import { Theme } from '../../libraries/types';
67
import { generateSegmentContainerStyle, styles } from './SegmentedControl.styles';
7-
import { useRestyle } from '../../hooks';
88

99
export interface SegmentedControlContainerProps extends ViewProps, StyledProps {}
1010
export interface GenerateSegmentContainerStyle {

src/packages/react-native-material-elements/src/components/TextField/OtpInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
ViewStyle,
1212
} from 'react-native';
1313
import { useThemeColorsSelector } from '../../libraries';
14-
import { Theme } from '../../libraries/themes/types';
14+
import { Theme } from '../../libraries/types';
1515
import { VariantTypes } from '../../utils';
1616
import { getOtpInputStyles } from './TextField.style';
1717

src/packages/react-native-material-elements/src/utils/styleGenerator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ export const generateElementStyles = (args: StylePalette) => {
4040
for (let property of keys) {
4141
const elementPropertyName = property as keyof typeof styles;
4242
if (args[elementPropertyName] === undefined) {
43-
console.warn(`Invalid element property name: ${String(args[elementPropertyName])}`);
43+
console.warn(
44+
`Invalid element property name: ${args[elementPropertyName]}, and value: ${String(args[elementPropertyName])}`,
45+
);
4446
continue;
4547
}
4648
nativeStyles = {

0 commit comments

Comments
 (0)