Skip to content

Commit fcd4dcc

Browse files
Copilothotlong
andcommitted
test(auth): add tests for linkComponent and labels props
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent f39db8f commit fcd4dcc

3 files changed

Lines changed: 92 additions & 0 deletions

File tree

packages/auth/src/__tests__/ForgotPasswordForm.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,30 @@ describe('ForgotPasswordForm', () => {
9090
});
9191
expect(onError).toHaveBeenCalled();
9292
});
93+
94+
it('uses custom linkComponent for login link', () => {
95+
const CustomLink = ({ href, className, children }: { href: string; className?: string; children: React.ReactNode }) => (
96+
<span data-testid="custom-link" data-href={href} className={className}>{children}</span>
97+
);
98+
renderWithAuth(<ForgotPasswordForm loginUrl="/login" linkComponent={CustomLink} />);
99+
const link = screen.getByTestId('custom-link');
100+
expect(link.getAttribute('data-href')).toBe('/login');
101+
});
102+
103+
it('renders custom labels when provided', () => {
104+
renderWithAuth(
105+
<ForgotPasswordForm
106+
labels={{
107+
emailLabel: 'E-Mail',
108+
submitButton: 'Link senden',
109+
rememberPasswordText: 'Passwort eingefallen?',
110+
signInText: 'Anmelden',
111+
}}
112+
/>
113+
);
114+
expect(screen.getByLabelText('E-Mail')).toBeTruthy();
115+
expect(screen.getByRole('button', { name: 'Link senden' })).toBeTruthy();
116+
expect(screen.getByText('Passwort eingefallen?')).toBeTruthy();
117+
expect(screen.getByText('Anmelden')).toBeTruthy();
118+
});
93119
});

packages/auth/src/__tests__/LoginForm.test.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,38 @@ describe('LoginForm', () => {
120120
expect(screen.getByRole('alert')).toBeTruthy();
121121
});
122122
});
123+
124+
it('uses custom linkComponent for links', () => {
125+
const CustomLink = ({ href, className, children }: { href: string; className?: string; children: React.ReactNode }) => (
126+
<span data-testid="custom-link" data-href={href} className={className}>{children}</span>
127+
);
128+
renderWithAuth(
129+
<LoginForm registerUrl="/register" forgotPasswordUrl="/forgot" linkComponent={CustomLink} />
130+
);
131+
const links = screen.getAllByTestId('custom-link');
132+
expect(links).toHaveLength(2);
133+
expect(links[0].getAttribute('data-href')).toBe('/forgot');
134+
expect(links[1].getAttribute('data-href')).toBe('/register');
135+
});
136+
137+
it('renders custom labels when provided', () => {
138+
renderWithAuth(
139+
<LoginForm
140+
labels={{
141+
emailLabel: 'Correo',
142+
passwordLabel: 'Contraseña',
143+
submitButton: 'Iniciar sesión',
144+
forgotPasswordText: '¿Olvidaste tu contraseña?',
145+
noAccountText: '¿No tienes cuenta?',
146+
signUpText: 'Regístrate',
147+
}}
148+
/>
149+
);
150+
expect(screen.getByLabelText('Correo')).toBeTruthy();
151+
expect(screen.getByLabelText('Contraseña')).toBeTruthy();
152+
expect(screen.getByRole('button', { name: 'Iniciar sesión' })).toBeTruthy();
153+
expect(screen.getByText('¿Olvidaste tu contraseña?')).toBeTruthy();
154+
expect(screen.getByText('¿No tienes cuenta?')).toBeTruthy();
155+
expect(screen.getByText('Regístrate')).toBeTruthy();
156+
});
123157
});

packages/auth/src/__tests__/RegisterForm.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,36 @@ describe('RegisterForm', () => {
132132
});
133133
expect(onError).toHaveBeenCalled();
134134
});
135+
136+
it('uses custom linkComponent for login link', () => {
137+
const CustomLink = ({ href, className, children }: { href: string; className?: string; children: React.ReactNode }) => (
138+
<span data-testid="custom-link" data-href={href} className={className}>{children}</span>
139+
);
140+
renderWithAuth(<RegisterForm loginUrl="/login" linkComponent={CustomLink} />);
141+
const link = screen.getByTestId('custom-link');
142+
expect(link.getAttribute('data-href')).toBe('/login');
143+
});
144+
145+
it('renders custom labels when provided', () => {
146+
renderWithAuth(
147+
<RegisterForm
148+
labels={{
149+
nameLabel: '名前',
150+
emailLabel: 'メール',
151+
passwordLabel: 'パスワード',
152+
confirmPasswordLabel: 'パスワード確認',
153+
submitButton: 'アカウント作成',
154+
hasAccountText: 'アカウントをお持ちですか?',
155+
signInText: 'ログイン',
156+
}}
157+
/>
158+
);
159+
expect(screen.getByLabelText('名前')).toBeTruthy();
160+
expect(screen.getByLabelText('メール')).toBeTruthy();
161+
expect(screen.getByLabelText('パスワード')).toBeTruthy();
162+
expect(screen.getByLabelText('パスワード確認')).toBeTruthy();
163+
expect(screen.getByRole('button', { name: 'アカウント作成' })).toBeTruthy();
164+
expect(screen.getByText('アカウントをお持ちですか?')).toBeTruthy();
165+
expect(screen.getByText('ログイン')).toBeTruthy();
166+
});
135167
});

0 commit comments

Comments
 (0)