Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcfaul committed Jun 20, 2024
1 parent 3e2bf68 commit 49aba23
Show file tree
Hide file tree
Showing 6 changed files with 11,342 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ describe('Dropdown toggle', () => {
expect(screen.getByRole('button', { name: 'Dropdown' })).toHaveClass(styles.modifiers.plain);
});

test('Passes toggleWidth', () => {
render(<SimpleDropdown toggleContent="Dropdown" toggleWidth="500px" />);

expect(screen.getByRole('button', { name: 'Dropdown' })).toHaveAttribute('style', 'width: 500px;');
});

test('Passes additional toggleProps', () => {
render(<SimpleDropdown toggleContent="Dropdown" toggleProps={{ id: 'toggle' }} />);

expect(screen.getByRole('button', { name: 'Dropdown' })).toHaveAttribute('id', 'toggle');
});

test('Passes toggleAriaLabel', () => {
render(<SimpleDropdown toggleContent="Dropdown" toggleAriaLabel="Aria label content" />);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`Dropdown items Matches snapshot 1`] = `
<button
aria-expanded="true"
class="pf-v5-c-menu-toggle pf-m-expanded"
data-ouia-component-id="OUIA-Generated-MenuToggle-default-21"
data-ouia-component-id="OUIA-Generated-MenuToggle-default-23"
data-ouia-component-type="PF5/MenuToggle"
data-ouia-safe="true"
type="button"
Expand Down Expand Up @@ -117,7 +117,7 @@ exports[`Dropdown toggle Matches snapshot 1`] = `
<button
aria-expanded="false"
class="pf-v5-c-menu-toggle"
data-ouia-component-id="OUIA-Generated-MenuToggle-default-12"
data-ouia-component-id="OUIA-Generated-MenuToggle-default-14"
data-ouia-component-type="PF5/MenuToggle"
data-ouia-safe="true"
type="button"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { render, screen, waitForElementToBeRemoved } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { CheckboxSelect } from './CheckboxSelect';
import { CheckboxSelect } from '../CheckboxSelect';
import styles from '@patternfly/react-styles/css/components/Badge/badge';

test('renders checkbox select with options', async () => {
Expand Down Expand Up @@ -156,6 +156,34 @@ test('displays custom toggle content', async () => {
expect(toggleButton).toBeInTheDocument();
});

test('Passes toggleWidth', () => {
const initialOptions = [
{ content: 'Option 1', value: 'option1' },
{ content: 'Option 2', value: 'option2' },
{ content: 'Option 3', value: 'option3' }
];

render(<CheckboxSelect initialOptions={initialOptions} toggleContent="Custom Toggle" toggleWidth="500px" />);

const toggleButton = screen.getByRole('button', { name: 'Custom Toggle' });
expect(toggleButton).toHaveAttribute('style', 'width: 500px;');
});

test('Passes additional toggleProps', () => {
const initialOptions = [
{ content: 'Option 1', value: 'option1' },
{ content: 'Option 2', value: 'option2' },
{ content: 'Option 3', value: 'option3' }
];

render(
<CheckboxSelect initialOptions={initialOptions} toggleContent="Custom Toggle" toggleProps={{ id: 'toggle' }} />
);

const toggleButton = screen.getByRole('button', { name: 'Custom Toggle' });
expect(toggleButton).toHaveAttribute('id', 'toggle');
});

test('calls the onToggle callback when the select opens or closes', async () => {
const initialOptions = [
{ content: 'Option 1', value: 'option1' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { CheckboxSelect } from './CheckboxSelect';
import { CheckboxSelect } from '../CheckboxSelect';

jest.mock('@patternfly/react-core/dist/js/helpers/GenerateId/GenerateId', () => ({
GenerateId: ({ children }) => children('generated-id')
Expand Down
Loading

0 comments on commit 49aba23

Please sign in to comment.