-
Notifications
You must be signed in to change notification settings - Fork 376
chore(Banner): update tests to new react testing library standards #8160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
111 changes: 88 additions & 23 deletions
111
packages/react-core/src/components/Banner/__tests__/Banner.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,92 @@ | ||
| import * as React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { Banner } from '../Banner'; | ||
| import React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
|
|
||
| ['default', 'info', 'success', 'warning', 'danger'].forEach((variant: string) => { | ||
| test(`${variant} banner`, () => { | ||
| const { asFragment } = render( | ||
| <Banner | ||
| variant={variant as 'default' | 'info' | 'success' | 'warning' | 'danger'} | ||
| aria-label={variant} | ||
| screenReaderText={`${variant} banner`} | ||
| > | ||
| {variant} Banner | ||
| </Banner> | ||
| ); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
|
|
||
| test(`sticky banner`, () => { | ||
| const { asFragment } = render( | ||
| <Banner aria-label="sticky" isSticky> | ||
| Sticky Banner | ||
| </Banner> | ||
|
|
||
| test('Renders without children', () => { | ||
| render( | ||
| <div data-testid="banner"> | ||
| <Banner /> | ||
| </div> | ||
| ); | ||
| expect(screen.getByTestId('banner').firstChild).toBeVisible(); | ||
| }); | ||
|
|
||
| test('Renders children', () => { | ||
| render(<Banner>Test</Banner>); | ||
| expect(screen.getByText('Test')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('Renders with class name pf-c-banner', () => { | ||
| render(<Banner>Test</Banner>); | ||
| expect(screen.getByText('Test')).toHaveClass('pf-c-banner'); | ||
| }); | ||
|
|
||
| test('Renders with custom class name when className prop is provided', () => { | ||
| render(<Banner className="custom-class">Test</Banner>); | ||
| expect(screen.getByText('Test')).toHaveClass('custom-class'); | ||
| }); | ||
|
|
||
| test('Renders without any modifier class when variant prop is not passed', () => { | ||
| render(<Banner>Test</Banner>); | ||
| expect(screen.getByText('Test')).toHaveClass('pf-c-banner', { exact: true }); | ||
| }); | ||
|
|
||
| test('Renders with class name pf-m-success when "success" is passed to variant prop', () => { | ||
| render(<Banner variant="success">Test</Banner>); | ||
| expect(screen.getByText('Test')).toHaveClass('pf-m-success'); | ||
| }); | ||
|
|
||
| test('Renders with class name pf-m-danger when "danger" is passed to variant prop', () => { | ||
| render(<Banner variant="danger">Test</Banner>); | ||
| expect(screen.getByText('Test')).toHaveClass('pf-m-danger'); | ||
| }); | ||
|
|
||
| test('Renders with class name pf-m-warning when "warning" is passed to variant prop', () => { | ||
| render(<Banner variant="warning">Test</Banner>); | ||
| expect(screen.getByText('Test')).toHaveClass('pf-m-warning'); | ||
| }); | ||
|
|
||
| test('Renders with class name pf-m-info when "info" is passed to variant prop', () => { | ||
| render(<Banner variant="info">Test</Banner>); | ||
| expect(screen.getByText('Test')).toHaveClass('pf-m-info'); | ||
| }); | ||
|
|
||
| test('Renders pf-u-screen-reader class by default for screenReaderText', () => { | ||
| render(<Banner>Test</Banner>); | ||
| expect(screen.getByText('default banner')).toHaveClass('pf-u-screen-reader', { exact: true }); | ||
| }); | ||
|
|
||
| test('Renders screenReaderText as "default banner" by default', () => { | ||
| render(<Banner>Test</Banner>); | ||
| expect(screen.getByText('default banner')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('Renders screenReaderText as "success banner" when variant="success"', () => { | ||
| render(<Banner variant="success">Test</Banner>); | ||
| expect(screen.getByText('success banner')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('Renders custom screenReaderText passed via prop', () => { | ||
| render(<Banner screenReaderText="Custom screen reader text">Test</Banner>); | ||
| expect(screen.getByText('Custom screen reader text')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
samuelatefah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| test('Renders without pf-m-sticky by default', () => { | ||
| render(<Banner>Test</Banner>); | ||
| expect(screen.getByText('Test')).not.toHaveClass('pf-m-sticky'); | ||
| }); | ||
|
|
||
| test('Renders with class name pf-m-sticky when isSticky prop is passed', () => { | ||
| render(<Banner isSticky>Test</Banner>); | ||
| expect(screen.getByText('Test')).toHaveClass('pf-m-sticky'); | ||
| }); | ||
|
|
||
| test('Renders with inherited element props spread to the component', () => { | ||
| render(<Banner aria-label="Test label">Test</Banner>); | ||
| expect(screen.getByText('Test')).toHaveAccessibleName('Test label'); | ||
| }); | ||
|
|
||
| test('Matches the snapshot', () => { | ||
| const { asFragment } = render(<Banner>Test</Banner>); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.