Skip to content

Commit d3f6e65

Browse files
committed
added unit tests
1 parent 64123db commit d3f6e65

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,27 @@ test(`Renders basic button`, () => {
249249
expect(asFragment()).toMatchSnapshot();
250250
});
251251

252-
test('Renders favorite icon with class pf-m-favorite when isFavorited = false', () => {
252+
test(`Renders with class ${styles.modifiers.favorite} when isFavorite is true`, () => {
253253
render(<Button isFavorite />);
254-
expect(screen.getByRole('button')).toHaveClass('pf-m-favorite');
254+
expect(screen.getByRole('button')).toHaveClass(styles.modifiers.favorite);
255255
});
256256

257-
test('Renders favorite icon with class pf-m-favorite when isFavorited = true', () => {
257+
test(`Renders with class ${styles.modifiers.favorited} when isFavorite is true and isFavorited is true`, () => {
258258
render(<Button isFavorite isFavorited />);
259-
expect(screen.getByRole('button')).toHaveClass('pf-m-favorited');
259+
expect(screen.getByRole('button')).toHaveClass(styles.modifiers.favorited);
260+
});
261+
262+
test(`Does not render with class ${styles.modifiers.favorite} when isFavorite is false`, () => {
263+
render(<Button />);
264+
expect(screen.getByRole('button')).not.toHaveClass(styles.modifiers.favorite);
265+
});
266+
267+
test(`Does not render with class ${styles.modifiers.favorited} when isFavorite is true and isFavorited is false`, () => {
268+
render(<Button isFavorite />);
269+
expect(screen.getByRole('button')).not.toHaveClass(styles.modifiers.favorited);
270+
});
271+
272+
test('Overrides icon prop when isFavorite is true', () => {
273+
render(<Button isFavorite icon={<div>Icon content</div>} />);
274+
expect(screen.queryByText('Icon content')).not.toBeInTheDocument();
260275
});

0 commit comments

Comments
 (0)