Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
import { render, screen } from '@testing-library/react';
import { CardSubtitle } from '../CardSubtitle';
import styles from '@patternfly/react-styles/css/components/Card/card';

describe('CardSubtitle', () => {
test('renders with PatternFly Core styles', () => {
const { asFragment } = render(<CardSubtitle>text</CardSubtitle>);
expect(asFragment()).toMatchSnapshot();
});
test('Renders without children', () => {
render(
<div data-testid="container">
<CardSubtitle />
</div>
);

test('extra props are spread to the root element', () => {
const testId = 'card-subtitle';
expect(screen.getByTestId('container').firstChild).toBeVisible();
});

test('Renders with children', () => {
render(<CardSubtitle>Subtitle content</CardSubtitle>);

expect(screen.getByText('Subtitle content')).toBeInTheDocument();
});

test(`Renders with class ${styles.cardSubtitle} by default`, () => {
render(<CardSubtitle>Subtitle content</CardSubtitle>);

expect(screen.getByText('Subtitle content')).toHaveClass(styles.cardSubtitle, { exact: true });
});

test('Renders with id when passed', () => {
render(<CardSubtitle id="subtitle-id">Subtitle content</CardSubtitle>);

expect(screen.getByText('Subtitle content')).toHaveAttribute('id', 'subtitle-id');
});

test('extra props are spread to the root element', () => {
const testId = 'card-subtitle';

render(<CardSubtitle data-testid={testId} />);
expect(screen.getByTestId(testId)).toBeInTheDocument();
});

test('Matches snapshot without children', () => {
const { asFragment } = render(<CardSubtitle />);
expect(asFragment()).toMatchSnapshot();
});

render(<CardSubtitle data-testid={testId} />);
expect(screen.getByTestId(testId)).toBeInTheDocument();
});
test('Matches snapshot with children', () => {
const { asFragment } = render(<CardSubtitle>Subtitle content</CardSubtitle>);
expect(asFragment()).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import { render, screen } from '@testing-library/react';
import { CardTitle } from '../CardTitle';

describe('CardTitle', () => {
test('renders with PatternFly Core styles', () => {
const { asFragment } = render(<CardTitle>text</CardTitle>);
expect(asFragment()).toMatchSnapshot();
});

test('className is added to the root element', () => {
render(<CardTitle className="extra-class">text</CardTitle>);
expect(screen.getByText('text')).toHaveClass('extra-class');
});

test('extra props are spread to the root element', () => {
const testId = 'card-header';

render(<CardTitle data-testid={testId} />);
expect(screen.getByTestId(testId)).toBeInTheDocument();
});
test('Renders with custom class when passed', () => {
render(<CardTitle className="extra-class">text</CardTitle>);
expect(screen.getByText('text')).toHaveClass('extra-class');
});

test('Does not render with card subtitle by default', () => {
render(<CardTitle>text</CardTitle>);

expect(screen.queryByText('text')?.nextElementSibling).not.toBeInTheDocument();
});

test('Renders with card subtitle when subtitle is passed', () => {
render(<CardTitle subtitle="subtitle content">text</CardTitle>);

expect(screen.getByText('subtitle content')).toBeInTheDocument();
});

test('extra props are spread to the root element', () => {
const testId = 'card-header';

render(<CardTitle data-testid={testId} />);
expect(screen.getByTestId(testId)).toBeInTheDocument();
});

test('Matches snapshot', () => {
const { asFragment } = render(<CardTitle>text</CardTitle>);
expect(asFragment()).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CardSubtitle renders with PatternFly Core styles 1`] = `
exports[`Matches snapshot with children 1`] = `
<DocumentFragment>
<div
class="pf-v6-c-card__subtitle"
id=""
>
text
Subtitle content
</div>
</DocumentFragment>
`;

exports[`Matches snapshot without children 1`] = `
<DocumentFragment>
<div
class="pf-v6-c-card__subtitle"
id=""
/>
</DocumentFragment>
`;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CardTitle renders with PatternFly Core styles 1`] = `
exports[`Matches snapshot 1`] = `
<DocumentFragment>
<div
class="pf-v6-c-card__title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ test('Renders custom class when passed', () => {
expect(screen.getByLabelText('list')).toHaveClass('data-list-custom');
});

test(`Renders with class ${styles.modifiers.plain} when isPlain is true`, () => {
render(<DataList key="list-id-1" isPlain aria-label="list" />);

expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.plain);
});

test('Renders with a hidden input to improve a11y when onSelectableRowChange is passed', () => {
render(
<DataList aria-label="this is a simple list" onSelectableRowChange={() => {}}>
Expand Down
60 changes: 60 additions & 0 deletions packages/react-core/src/components/Tabs/__tests__/Tabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,66 @@ test(`Does not render with class ${styles.modifiers.initializingAccent} when unc
expect(screen.getByRole('region')).not.toHaveClass(styles.modifiers.initializingAccent);
});

test(`Renders with class ${styles.modifiers.nav} when isNav is true`, () => {
render(
<Tabs isNav role="region">
<Tab title="Test title" eventKey={0}>
Tab Content
</Tab>
</Tabs>
);

expect(screen.getByRole('region')).toHaveClass(styles.modifiers.nav);
});

test(`Renders with div wrapper by default`, () => {
render(
<Tabs>
<Tab title="Test title" eventKey={0}>
Tab Content
</Tab>
</Tabs>
);

expect(screen.queryByRole('navigation')).not.toBeInTheDocument();
});

test(`Renders with nav wrapper when component="nav"`, () => {
render(
<Tabs component="nav">
<Tab title="Test title" eventKey={0}>
Tab Content
</Tab>
</Tabs>
);

expect(screen.getByRole('navigation')).toBeInTheDocument();
});

test(`Renders with nav wrapper when isNav is true`, () => {
render(
<Tabs isNav>
<Tab title="Test title" eventKey={0}>
Tab Content
</Tab>
</Tabs>
);

expect(screen.getByRole('navigation')).toBeInTheDocument();
});

test(`Overrides isNav nav wrapper when component="div" is passed`, () => {
render(
<Tabs component="div" isNav>
<Tab title="Test title" eventKey={0}>
Tab Content
</Tab>
</Tabs>
);

expect(screen.queryByRole('navigation')).not.toBeInTheDocument();
});

test('should render simple tabs', () => {
const { asFragment } = render(
<Tabs id="simpleTabs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`should render accessible tabs 1`] = `
<nav
aria-label="accessible Tabs example"
class="pf-v6-c-tabs pf-m-animate-current pf-m-initializing-accent"
data-ouia-component-id="OUIA-Generated-Tabs-14"
data-ouia-component-id="OUIA-Generated-Tabs-19"
data-ouia-component-type="PF6/Tabs"
data-ouia-safe="true"
id="accessibleTabs"
Expand Down Expand Up @@ -122,7 +122,7 @@ exports[`should render box tabs 1`] = `
<DocumentFragment>
<div
class="pf-v6-c-tabs pf-m-animate-current pf-m-box pf-m-initializing-accent"
data-ouia-component-id="OUIA-Generated-Tabs-13"
data-ouia-component-id="OUIA-Generated-Tabs-18"
data-ouia-component-type="PF6/Tabs"
data-ouia-safe="true"
id="boxTabs"
Expand Down Expand Up @@ -281,7 +281,7 @@ exports[`should render box tabs of secondary variant 1`] = `
<DocumentFragment>
<div
class="pf-v6-c-tabs pf-m-animate-current pf-m-box pf-m-secondary pf-m-initializing-accent"
data-ouia-component-id="OUIA-Generated-Tabs-24"
data-ouia-component-id="OUIA-Generated-Tabs-29"
data-ouia-component-type="PF6/Tabs"
data-ouia-safe="true"
id="boxSecondaryVariantTabs"
Expand Down Expand Up @@ -398,7 +398,7 @@ exports[`should render expandable vertical tabs 1`] = `
<DocumentFragment>
<div
class="pf-v6-c-tabs pf-m-animate-current pf-m-vertical pf-m-expandable pf-m-initializing-accent"
data-ouia-component-id="OUIA-Generated-Tabs-11"
data-ouia-component-id="OUIA-Generated-Tabs-16"
data-ouia-component-type="PF6/Tabs"
data-ouia-safe="true"
id="verticalTabs"
Expand Down Expand Up @@ -605,7 +605,7 @@ exports[`should render filled tabs 1`] = `
<DocumentFragment>
<div
class="pf-v6-c-tabs pf-m-animate-current pf-m-fill pf-m-initializing-accent"
data-ouia-component-id="OUIA-Generated-Tabs-15"
data-ouia-component-id="OUIA-Generated-Tabs-20"
data-ouia-component-type="PF6/Tabs"
data-ouia-safe="true"
id="filledTabs"
Expand Down Expand Up @@ -722,7 +722,7 @@ exports[`should render simple tabs 1`] = `
<DocumentFragment>
<div
class="pf-v6-c-tabs pf-m-animate-current pf-m-initializing-accent"
data-ouia-component-id="OUIA-Generated-Tabs-6"
data-ouia-component-id="OUIA-Generated-Tabs-11"
data-ouia-component-type="PF6/Tabs"
data-ouia-safe="true"
id="simpleTabs"
Expand Down Expand Up @@ -881,7 +881,7 @@ exports[`should render subtabs 1`] = `
<DocumentFragment>
<div
class="pf-v6-c-tabs pf-m-animate-current pf-m-initializing-accent"
data-ouia-component-id="OUIA-Generated-Tabs-16"
data-ouia-component-id="OUIA-Generated-Tabs-21"
data-ouia-component-type="PF6/Tabs"
data-ouia-safe="true"
id="primarieTabs"
Expand Down Expand Up @@ -967,7 +967,7 @@ exports[`should render subtabs 1`] = `
>
<div
class="pf-v6-c-tabs pf-m-animate-current pf-m-subtab pf-m-initializing-accent"
data-ouia-component-id="OUIA-Generated-Tabs-17"
data-ouia-component-id="OUIA-Generated-Tabs-22"
data-ouia-component-type="PF6/Tabs"
data-ouia-safe="true"
id="subtabs"
Expand Down Expand Up @@ -1110,7 +1110,7 @@ exports[`should render tabs with eventKey Strings 1`] = `
<DocumentFragment>
<div
class="pf-v6-c-tabs pf-m-animate-current pf-m-initializing-accent"
data-ouia-component-id="OUIA-Generated-Tabs-18"
data-ouia-component-id="OUIA-Generated-Tabs-23"
data-ouia-component-type="PF6/Tabs"
data-ouia-safe="true"
id="eventKeyTabs"
Expand Down Expand Up @@ -1228,7 +1228,7 @@ exports[`should render tabs with no bottom border 1`] = `
<DocumentFragment>
<div
class="pf-v6-c-tabs pf-m-animate-current pf-m-no-border-bottom pf-m-initializing-accent"
data-ouia-component-id="OUIA-Generated-Tabs-25"
data-ouia-component-id="OUIA-Generated-Tabs-30"
data-ouia-component-type="PF6/Tabs"
data-ouia-safe="true"
id="noBottomBorderTabs"
Expand Down Expand Up @@ -1345,7 +1345,7 @@ exports[`should render tabs with separate content 1`] = `
<DocumentFragment>
<div
class="pf-v6-c-tabs pf-m-animate-current pf-m-initializing-accent"
data-ouia-component-id="OUIA-Generated-Tabs-19"
data-ouia-component-id="OUIA-Generated-Tabs-24"
data-ouia-component-type="PF6/Tabs"
data-ouia-safe="true"
id="separateTabs"
Expand Down Expand Up @@ -1472,7 +1472,7 @@ exports[`should render uncontrolled tabs 1`] = `
<DocumentFragment>
<div
class="pf-v6-c-tabs pf-m-animate-current pf-m-initializing-accent"
data-ouia-component-id="OUIA-Generated-Tabs-9"
data-ouia-component-id="OUIA-Generated-Tabs-14"
data-ouia-component-type="PF6/Tabs"
data-ouia-safe="true"
style="--pf-v6-c-tabs--link-accent--length: 0px; --pf-v6-c-tabs--link-accent--start: 0px;"
Expand Down Expand Up @@ -1630,7 +1630,7 @@ exports[`should render vertical tabs 1`] = `
<DocumentFragment>
<div
class="pf-v6-c-tabs pf-m-animate-current pf-m-vertical pf-m-initializing-accent"
data-ouia-component-id="OUIA-Generated-Tabs-10"
data-ouia-component-id="OUIA-Generated-Tabs-15"
data-ouia-component-type="PF6/Tabs"
data-ouia-safe="true"
id="verticalTabs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,9 @@ test('Renders expandable toggle button in Th with pf-m-small class when variant
expect(button).toHaveClass('pf-m-small');
});
});

test(`Renders with class ${styles.modifiers.plain} when isPlain is true`, () => {
render(<Table isPlain aria-label="Test table" />);

expect(screen.getByRole('grid', { name: 'Test table' })).toHaveClass(styles.modifiers.plain);
});
Loading