Skip to content

Commit 16912d5

Browse files
committed
add test
1 parent b136e92 commit 16912d5

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { SignInPage } from './SignInPage.tsx';
2+
import { useAuthOnboarding } from '../../auth/AuthContextOnboarding.tsx';
3+
import { useLink } from '../../../../lib/shared/useLink.ts'; // if useLink relies on router
4+
5+
describe('SignInPage', () => {
6+
let logInCalled = false;
7+
const fakeUseAuthOnboarding = (() => ({
8+
login: () => {
9+
logInCalled = true;
10+
},
11+
})) as typeof useAuthOnboarding;
12+
13+
beforeEach(() => {
14+
logInCalled = false;
15+
});
16+
17+
it('renders the SignInPage', () => {
18+
cy.mount(<SignInPage useAuthOnboarding={fakeUseAuthOnboarding} />);
19+
20+
cy.get('ui5-title').should('exist');
21+
});
22+
23+
it('calls the login function when the user clicks the "Sign In" button', () => {
24+
cy.mount(<SignInPage useAuthOnboarding={fakeUseAuthOnboarding} />);
25+
26+
cy.wrap(null).then(() => {
27+
expect(logInCalled).to.equal(false);
28+
});
29+
30+
cy.get('ui5-button').eq(0).should('contain', 'Sign In').click();
31+
32+
cy.wrap(null).then(() => {
33+
expect(logInCalled).to.equal(true);
34+
});
35+
});
36+
37+
it('contains a link to the documentation', () => {
38+
const fakeUseLink = (() => ({
39+
documentationHomepage: 'https://link-to-documentation.com',
40+
})) as typeof useLink;
41+
42+
cy.mount(<SignInPage useAuthOnboarding={fakeUseAuthOnboarding} useLink={fakeUseLink} />);
43+
44+
cy.get('a')
45+
.should('have.attr', 'target', '_blank')
46+
.and('have.attr', 'rel', 'noreferrer')
47+
.and('have.attr', 'href', 'https://link-to-documentation.com');
48+
});
49+
});

src/spaces/onboarding/pages/SignInPage/SignInPage.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@ import * as Sentry from '@sentry/react';
55
import { Button, Card, FlexBox, Text, Title } from '@ui5/webcomponents-react';
66
import ButtonDesign from '@ui5/webcomponents/dist/types/ButtonDesign.js';
77

8-
import { useAuthOnboarding } from '../../auth/AuthContextOnboarding';
9-
import { useLink } from '../../../../lib/shared/useLink';
8+
import { useAuthOnboarding as _useAuthOnboarding } from '../../auth/AuthContextOnboarding';
9+
import { useLink as _useLink } from '../../../../lib/shared/useLink';
1010
import { useTheme } from '../../../../hooks/useTheme';
1111

1212
import LogoLight from '../../../../assets/images/co-logo-orchestrating.png';
1313
import LogoDark from '../../../../assets/images/co-logo-orchestrating-dark.png';
1414

1515
import styles from './SignInPage.module.css';
1616

17-
export function SignInPage() {
18-
const auth = useAuthOnboarding();
17+
export interface SignInPageProps {
18+
useAuthOnboarding?: typeof _useAuthOnboarding;
19+
useLink?: typeof _useLink;
20+
}
21+
export function SignInPage({ useAuthOnboarding = _useAuthOnboarding, useLink = _useLink }: SignInPageProps) {
22+
const { login } = useAuthOnboarding();
1923
const { documentationHomepage } = useLink();
2024
const { t } = useTranslation();
2125
const { isDarkTheme } = useTheme();
@@ -41,7 +45,7 @@ export function SignInPage() {
4145
<img className={styles.logo} src={isDarkTheme ? LogoDark : LogoLight} alt="" />
4246

4347
<FlexBox direction="Column" alignItems="Center" gap="1em">
44-
<Button design={ButtonDesign.Emphasized} onClick={() => void auth.login()}>
48+
<Button design={ButtonDesign.Emphasized} onClick={() => void login()}>
4549
{t('SignInPage.signInButton')}
4650
</Button>
4751
</FlexBox>

0 commit comments

Comments
 (0)