Skip to content

Commit e1f49e5

Browse files
author
Konstantinos Familonidis
committed
Fixes #39492: Replace enzyme test in SettingsTable, SettingsCell, SettingsName with RTL
1 parent 2eccf03 commit e1f49e5

6 files changed

Lines changed: 91 additions & 268 deletions

File tree

webpack/assets/javascripts/react_app/components/SettingsTable/__tests__/SettingsTable.test.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
21
import React from "react";
32
import {render, screen, within} from '@testing-library/react'
43
import userEvent from '@testing-library/user-event';
@@ -12,23 +11,13 @@ import { groupedSettings } from '../../SettingRecords/__tests__/SettingRecords.f
1211
import SettingsTable from '../SettingsTable';
1312
import {APIActions} from "../../../redux/API";
1413

15-
const fixtures = {
16-
'should render': {
17-
settings: groupedSettings['General'],
18-
onEditClick: () => {},
19-
},
20-
};
2114
const mockStore = configureMockStore([thunk]);
2215
const store = mockStore({
2316

2417
})
2518

2619
jest.spyOn(APIActions, 'put').mockReturnValue({ type: 'DUMMY' });
2720

28-
describe('SettingsTableSnapshot', () =>
29-
testComponentSnapshotsWithFixtures(SettingsTable, fixtures)
30-
)
31-
3221
async function extracted(text = '') {
3322
const editButton = document.querySelector('button#http_proxy_except_list');
3423

webpack/assets/javascripts/react_app/components/SettingsTable/__tests__/__snapshots__/SettingsTable.test.js.snap

Lines changed: 0 additions & 103 deletions
This file was deleted.
Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers';
1+
import React from 'react';
2+
import { render, screen, within } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
24

35
import {
46
rootPass,
@@ -8,17 +10,53 @@ import {
810

911
import SettingValue from '../SettingValue';
1012

11-
const fixtures = {
12-
'render ordinary': {
13-
setting: stringSetting,
14-
},
15-
'render encrypted with fullName': {
16-
setting: rootPass,
17-
},
18-
'render without fullName': {
19-
setting: withoutFullName,
20-
},
21-
};
22-
23-
describe('SettingCell', () =>
24-
testComponentSnapshotsWithFixtures(SettingValue, fixtures));
13+
// Render the tooltip content inline instead of through the Popper, so the
14+
// computed tooltipText can be asserted without hover/async teardown issues.
15+
jest.mock('@patternfly/react-core', () => ({
16+
...jest.requireActual('@patternfly/react-core'),
17+
Tooltip: ({ content, children }) => (
18+
<div>
19+
<div data-testid="tooltip-content">{content}</div>
20+
{children}
21+
</div>
22+
),
23+
}));
24+
25+
const tooltip = () => screen.getByTestId('tooltip-content');
26+
27+
describe('SettingCell', () => {
28+
it('render ordinary', () => {
29+
render(<SettingValue setting={stringSetting} />);
30+
31+
const value = screen.getByText('root@example.com');
32+
expect(value).toBeInTheDocument();
33+
// value equals default, so it is not emphasized
34+
expect(value.closest('strong')).not.toBeInTheDocument();
35+
expect(
36+
within(tooltip()).getByText('Default: root@example.com')
37+
).toBeInTheDocument();
38+
});
39+
40+
it('render encrypted with fullName', () => {
41+
render(<SettingValue setting={rootPass} />);
42+
43+
// encrypted value is masked, and emphasized because it differs from default
44+
const value = screen.getByText('*****');
45+
expect(value).toBeInTheDocument();
46+
expect(value.closest('strong')).toBeInTheDocument();
47+
// encrypted default is masked with bullet operators, one per character
48+
expect(
49+
within(tooltip()).getByText(`Default: ${'∙'.repeat(6)}`)
50+
).toBeInTheDocument();
51+
});
52+
53+
it('render without fullName', () => {
54+
render(<SettingValue setting={withoutFullName} />);
55+
56+
// boolean false renders as "No"
57+
const value = screen.getByText('No');
58+
expect(value).toBeInTheDocument();
59+
expect(value.closest('strong')).not.toBeInTheDocument();
60+
expect(within(tooltip()).getByText('Default: No')).toBeInTheDocument();
61+
});
62+
});
Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers';
1+
import React from 'react';
2+
import { render, screen, within } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
24

35
import {
46
rootPass,
@@ -7,14 +9,38 @@ import {
79

810
import SettingName from '../SettingName';
911

10-
const fixtures = {
11-
'render with fullName': {
12-
setting: rootPass,
13-
},
14-
'render without fullName': {
15-
setting: withoutFullName,
16-
},
17-
};
18-
19-
describe('SettingName', () =>
20-
testComponentSnapshotsWithFixtures(SettingName, fixtures));
12+
// Render the tooltip content inline instead of through the Popper, so the
13+
// tooltipText can be asserted without hover/async teardown issues.
14+
jest.mock('@patternfly/react-core', () => ({
15+
...jest.requireActual('@patternfly/react-core'),
16+
Tooltip: ({ content, children }) => (
17+
<div>
18+
<div data-testid="tooltip-content">{content}</div>
19+
{children}
20+
</div>
21+
),
22+
}));
23+
24+
const tooltip = () => screen.getByTestId('tooltip-content');
25+
26+
describe('SettingName', () => {
27+
it('render with fullName', () => {
28+
render(<SettingName setting={rootPass} />);
29+
30+
// fullName is shown as the name, the technical name is the tooltip
31+
expect(screen.getByText('Root password')).toBeInTheDocument();
32+
expect(within(tooltip()).getByText('root_pass')).toBeInTheDocument();
33+
});
34+
35+
it('render without fullName', () => {
36+
render(<SettingName setting={withoutFullName} />);
37+
38+
// with no fullName, the technical name is used for both name and tooltip
39+
expect(
40+
within(tooltip()).getByText('always_show_configuration_status')
41+
).toBeInTheDocument();
42+
expect(
43+
screen.getAllByText('always_show_configuration_status')
44+
).toHaveLength(2);
45+
});
46+
});

webpack/assets/javascripts/react_app/components/SettingsTable/components/__tests__/__snapshots__/SettingCell.test.js.snap

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

webpack/assets/javascripts/react_app/components/SettingsTable/components/__tests__/__snapshots__/SettingName.test.js.snap

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

0 commit comments

Comments
 (0)