Skip to content

Commit 94a2c42

Browse files
committed
test(LoginPage): enhance brand image tests with aria-label and className attributes
Signed-off-by: Mohamed Fall <ps.hackmaster@gmail.com>
1 parent 9df125d commit 94a2c42

2 files changed

Lines changed: 24 additions & 53 deletions

File tree

packages/react-core/src/components/LoginPage/__tests__/LoginPage.test.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Fragment } from 'react';
2-
import { render } from '@testing-library/react';
2+
import { render, screen } from '@testing-library/react';
33

44
import { LoginPage } from '../LoginPage';
55
import { ListVariant } from '../../List';
@@ -38,8 +38,28 @@ test('brand is present with brandImgSrc prop', () => {
3838
});
3939

4040
test('brandImgProps successfully renders brand with props', () => {
41-
const { asFragment } = render(
42-
<LoginPage brandImgProps={{ src: 'Brand src', alt: 'Pf-logo' }} loginTitle="Log into your account" />
41+
render(
42+
<LoginPage
43+
brandImgProps={{ src: 'Brand src', alt: 'Pf-logo', 'aria-label': 'PatternFly logo', className: 'custom-class' }}
44+
loginTitle="Log into your account"
45+
/>
4346
);
44-
expect(asFragment()).toMatchSnapshot();
47+
const brandImg = screen.getByRole('img', { name: 'PatternFly logo' });
48+
expect(brandImg).toHaveAttribute('src', 'Brand src');
49+
expect(brandImg).toHaveAttribute('alt', 'Pf-logo');
50+
expect(brandImg).toHaveAttribute('aria-label', 'PatternFly logo');
51+
expect(brandImg).toHaveClass('custom-class');
52+
});
53+
54+
test('Brand is rendered correctly with both brandImgSrc and brandImgProps, prioritizing brandImgProps.src', () => {
55+
render(
56+
<LoginPage
57+
brandImgSrc="Brand-src-that-should-be-ignored"
58+
brandImgProps={{ src: 'Brand-src-from-props', alt: 'Pf-logo from props' }}
59+
loginTitle="Log into your account"
60+
/>
61+
);
62+
const brandImg = screen.getByRole('img', { name: 'Pf-logo from props' });
63+
expect(brandImg).toHaveAttribute('src', 'Brand-src-from-props');
64+
expect(brandImg).toHaveAttribute('alt', 'Pf-logo from props');
4565
});

packages/react-core/src/components/LoginPage/__tests__/__snapshots__/LoginPage.test.tsx.snap

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -92,55 +92,6 @@ exports[`brand is present with brandImgSrc prop 1`] = `
9292
</DocumentFragment>
9393
`;
9494

95-
exports[`brandImgProps successfully renders brand with props 1`] = `
96-
<DocumentFragment>
97-
<div
98-
class="pf-v6-c-login"
99-
>
100-
<div
101-
class="pf-v6-c-login__container"
102-
>
103-
<header
104-
class="pf-v6-c-login__header"
105-
>
106-
<img
107-
alt="Pf-logo"
108-
class="pf-v6-c-brand"
109-
src="Brand src"
110-
/>
111-
</header>
112-
<main
113-
class="pf-v6-c-login__main"
114-
>
115-
<div
116-
class="pf-v6-c-login__main-header"
117-
>
118-
<h2
119-
class="pf-v6-c-title pf-m-3xl"
120-
data-ouia-component-id="OUIA-Generated-Title-4"
121-
data-ouia-component-type="PF6/Title"
122-
data-ouia-safe="true"
123-
>
124-
Log into your account
125-
</h2>
126-
</div>
127-
<div
128-
class="pf-v6-c-login__main-body"
129-
/>
130-
</main>
131-
<footer
132-
class="pf-v6-c-login__footer"
133-
>
134-
<p />
135-
<ul
136-
class="pf-v6-c-list"
137-
/>
138-
</footer>
139-
</div>
140-
</div>
141-
</DocumentFragment>
142-
`;
143-
14495
exports[`check loginpage example against snapshot 1`] = `
14596
<DocumentFragment>
14697
<div

0 commit comments

Comments
 (0)