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,14 +1,49 @@
import * as React from 'react';
import { render } from '@testing-library/react';
import React from 'react';
import { render, screen } from '@testing-library/react';
import { ActionList } from '../ActionList';

describe('action list', () => {
test('renders successfully', () => {
const { asFragment } = render(<ActionList>test</ActionList>);
expect(asFragment()).toMatchSnapshot();
});
test('isIconList flag adds modifier', () => {
const { asFragment } = render(<ActionList isIconList>test</ActionList>);
expect(asFragment()).toMatchSnapshot();
});
test('Renders without children', () => {
render(<ActionList data-testid="action-list" />);
expect(screen.getByTestId('action-list')).toBeVisible();
});

test('Renders children', () => {
render(<ActionList>Test</ActionList>);

expect(screen.getByText('Test')).toBeVisible();
});

test('Renders with class pf-c-action-list', () => {
render(<ActionList>Test</ActionList>);

expect(screen.getByText('Test')).toHaveClass('pf-c-action-list');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be reasonable to combine this test with the last since they are rendering the same thing?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and there are a couple other below that also render the same thing?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely wouldn't call it unreasonable to combine them, but I personally would advocate for a testing approach that only makes assertions about one aspect of component behavior in each test.

The primary reason being that I believe single behavior tests provide maximum utility from the test suite, as with this approach a failing test (or combination of them) can often point you straight to where a regression was introduced.

});

test('Renders with custom class names provided via prop', () => {
render(<ActionList className="custom-class">Test</ActionList>);

expect(screen.getByText('Test')).toHaveClass('custom-class');
});

test('Does not render with class pf-m-icons by default', () => {
render(<ActionList>Test</ActionList>);

expect(screen.getByText('Test')).not.toHaveClass('pf-m-icons');
});

test('Renders with class pf-m-icons when isIconList is true', () => {
render(<ActionList isIconList={true}>Test</ActionList>);

expect(screen.getByText('Test')).toHaveClass('pf-m-icons');
});

test('Renders with inherited element props spread to the component', () => {
render(<ActionList aria-label="Test label">Test</ActionList>);

expect(screen.getByText('Test')).toHaveAccessibleName('Test label');
})

test('Matches the snapshot', () => {
const { asFragment } = render(<ActionList>test</ActionList>);
expect(asFragment()).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
import * as React from 'react';
import { render } from '@testing-library/react';
import React from 'react';
import { render, screen } from '@testing-library/react';
import { ActionListGroup } from '../ActionListGroup';

describe('action list group', () => {
test('renders successfully', () => {
const { asFragment } = render(<ActionListGroup>test</ActionListGroup>);
expect(asFragment()).toMatchSnapshot();
});
test('Renders without children', () => {
render(<ActionListGroup data-testid="action-list-group" />);
expect(screen.getByTestId('action-list-group')).toBeVisible();
});

test('Renders children', () => {
render(<ActionListGroup>Test</ActionListGroup>);

expect(screen.getByText('Test')).toBeVisible();
});

test('Renders with class pf-c-action-list__group', () => {
render(<ActionListGroup>Test</ActionListGroup>);

expect(screen.getByText('Test')).toHaveClass('pf-c-action-list__group');
});

test('Renders with custom class names provided via prop', () => {
render(<ActionListGroup className="custom-class">Test</ActionListGroup>);

expect(screen.getByText('Test')).toHaveClass('custom-class');
});

test('Renders with inherited element props spread to the component', () => {
render(<ActionListGroup aria-label="Test label">Test</ActionListGroup>);

expect(screen.getByText('Test')).toHaveAccessibleName('Test label');
})

test('Matches the snapshot', () => {
const { asFragment } = render(<ActionListGroup>test</ActionListGroup>);
expect(asFragment()).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
import * as React from 'react';
import { render } from '@testing-library/react';
import React from 'react';
import { render, screen } from '@testing-library/react';
import { ActionListItem } from '../ActionListItem';

describe('action list item', () => {
test('renders successfully', () => {
const { asFragment } = render(<ActionListItem>test</ActionListItem>);
expect(asFragment()).toMatchSnapshot();
});
test('Renders without children', () => {
render(<ActionListItem data-testid="action-list-item" />);
expect(screen.getByTestId('action-list-item')).toBeVisible();
});

test('Renders children', () => {
render(<ActionListItem>Test</ActionListItem>);

expect(screen.getByText('Test')).toBeVisible();
});

test('Renders with class pf-c-action-list__item', () => {
render(<ActionListItem>Test</ActionListItem>);

expect(screen.getByText('Test')).toHaveClass('pf-c-action-list__item');
});

test('Renders with custom class names provided via prop', () => {
render(<ActionListItem className="custom-class">Test</ActionListItem>);

expect(screen.getByText('Test')).toHaveClass('custom-class');
});

test('Renders with inherited element props spread to the component', () => {
render(<ActionListItem aria-label="Test label">Test</ActionListItem>);

expect(screen.getByText('Test')).toHaveAccessibleName('Test label');
})

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

exports[`action list isIconList flag adds modifier 1`] = `
<DocumentFragment>
<div
class="pf-c-action-list pf-m-icons"
>
test
</div>
</DocumentFragment>
`;

exports[`action list renders successfully 1`] = `
exports[`Matches the snapshot 1`] = `
<DocumentFragment>
<div
class="pf-c-action-list"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`action list group renders successfully 1`] = `
exports[`Matches the snapshot 1`] = `
<DocumentFragment>
<div
class="pf-c-action-list__group"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`action list item renders successfully 1`] = `
exports[`Matches the snapshot 1`] = `
<DocumentFragment>
<div
class="pf-c-action-list__item"
Expand Down