Skip to content

Commit a20879e

Browse files
author
Konstantinos Familonidis
committed
Refs #38822: update pf3 buttons to pf5 - common/table/Delete
1 parent 96c7103 commit a20879e

File tree

3 files changed

+45
-22
lines changed

3 files changed

+45
-22
lines changed

webpack/assets/javascripts/react_app/components/common/table/components/DeleteButton.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import { Button } from 'patternfly-react';
3+
import { Button } from '@patternfly/react-core';
44
import { translate as __ } from '../../../../common/I18n';
55

66
const DeleteButton = ({ active, onClick }) =>
77
active ? (
8-
<Button bsStyle="default" onClick={onClick}>
8+
<Button ouiaId="table-delete-button" variant="secondary" onClick={onClick}>
99
{__('Delete')}
1010
</Button>
1111
) : null;
Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers';
1+
import React from 'react';
2+
import { screen, fireEvent, render, act } from '@testing-library/react';
3+
import '@testing-library/jest-dom/extend-expect';
4+
25
import DeleteButton from '../DeleteButton';
36

47
const baseProps = {
@@ -9,13 +12,49 @@ const baseProps = {
912
};
1013

1114
const fixtures = {
12-
'should render delete button on active': {
15+
'active': {
1316
active: true,
1417
...baseProps,
1518
},
16-
'should render nothing on inactive': baseProps,
19+
'inactive': baseProps,
1720
};
1821

1922
describe('DeleteButton', () => {
20-
testComponentSnapshotsWithFixtures(DeleteButton, fixtures);
23+
describe('when active', () => {
24+
const props = { ...fixtures.active };
25+
26+
it('should render delete button', () => {
27+
render(<DeleteButton {...props} />);
28+
29+
const deleteButton = screen.getByRole('button', { name: /delete/i });
30+
expect(deleteButton).toBeInTheDocument();
31+
});
32+
33+
it('should have correct button text', () => {
34+
render(<DeleteButton {...props} />);
35+
36+
const deleteButton = screen.getByRole('button', { name: /delete/i });
37+
expect(deleteButton).toHaveTextContent('Delete');
38+
});
39+
40+
it('should have secondary variant style', () => {
41+
render(<DeleteButton {...props} />);
42+
43+
const deleteButton = screen.getByRole('button', { name: /delete/i });
44+
expect(deleteButton).toHaveClass('pf-m-secondary');
45+
});
46+
});
47+
48+
describe('when inactive', () => {
49+
const props = { ...fixtures.inactive };
50+
51+
it('should not render anything', () => {
52+
const { container } = render(<DeleteButton {...props} />);
53+
54+
const button = screen.queryByRole('button', { name: /delete/i });
55+
expect(button).not.toBeInTheDocument();
56+
57+
expect(container.firstChild).toBeNull();
58+
});
59+
});
2160
});

webpack/assets/javascripts/react_app/components/common/table/components/__tests__/__snapshots__/DeleteButton.test.js.snap

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)