Skip to content

Commit 2340dfa

Browse files
committed
test: add OneTimePasswordInput test
1 parent 44e4000 commit 2340dfa

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { render, screen } from '@testing-library/react';
2+
import { describe, expect, it } from 'vitest';
3+
4+
import { OneTimePasswordInput } from './OneTimePasswordInput';
5+
6+
type Props = React.ComponentPropsWithoutRef<typeof OneTimePasswordInput>;
7+
8+
const TEST_ID = 'OneTimePasswordInput';
9+
10+
const TestOneTimePasswordInput: React.FC<Partial<Props>> = (props) => {
11+
return <OneTimePasswordInput data-testid={TEST_ID} {...(props as Props)} />;
12+
};
13+
14+
describe('OneTimePasswordInput', () => {
15+
it('should render', () => {
16+
render(<TestOneTimePasswordInput />);
17+
expect(screen.getByTestId(TEST_ID)).toBeInTheDocument();
18+
});
19+
});

src/components/OneTimePasswordInput/OneTimePasswordInput.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const CODE_LENGTH = 6;
1111
const EMPTY_CODE = Object.freeze(Array<null>(CODE_LENGTH).fill(null));
1212

1313
type OneTimePasswordInputProps = {
14+
[key: `data-${string}`]: unknown;
1415
className?: string;
1516
onComplete: (code: number) => Promisable<void>;
1617
};
@@ -21,7 +22,7 @@ function getUpdatedDigits(digits: (null | number)[], index: number, value: null
2122
return updatedDigits;
2223
}
2324

24-
export const OneTimePasswordInput = ({ className, onComplete }: OneTimePasswordInputProps) => {
25+
export const OneTimePasswordInput = ({ className, onComplete, ...props }: OneTimePasswordInputProps) => {
2526
const notifications = useNotificationsStore();
2627
const { t } = useTranslation('libui');
2728
const [digits, setDigits] = useState<(null | number)[]>([...EMPTY_CODE]);
@@ -85,7 +86,7 @@ export const OneTimePasswordInput = ({ className, onComplete }: OneTimePasswordI
8586
};
8687

8788
return (
88-
<div className={cn('flex gap-2', className)}>
89+
<div className={cn('flex gap-2', className)} {...props}>
8990
{digits.map((_, index) => (
9091
<input
9192
className="w-1/6 rounded-md border border-slate-300 bg-transparent p-2 shadow-xs hover:border-slate-300 focus:border-sky-800 focus:outline-hidden dark:border-slate-600 dark:hover:border-slate-400 dark:focus:border-sky-500"

0 commit comments

Comments
 (0)