Skip to content

Commit c57efcd

Browse files
authored
chore(aggregations,schema-validation,shell): replace enzyme usage with react-testing-library (#6975)
1 parent 6ce44ba commit c57efcd

File tree

14 files changed

+136
-227
lines changed

14 files changed

+136
-227
lines changed

package-lock.json

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-aggregations/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@
3838
"@mongodb-js/testing-library-compass": "^1.3.1",
3939
"@mongodb-js/tsconfig-compass": "^1.2.8",
4040
"@types/babel__generator": "^7.6.8",
41-
"@types/enzyme": "^3.10.14",
4241
"@types/lodash": "^4.14.188",
4342
"@types/semver": "^7.3.9",
4443
"chai": "^4.3.6",
4544
"depcheck": "^1.4.1",
4645
"electron-mocha": "^12.2.0",
47-
"enzyme": "^3.11.0",
4846
"mocha": "^10.2.0",
4947
"nyc": "^15.1.0",
5048
"react-dom": "^17.0.2",

packages/compass-aggregations/src/components/saving-pipeline-modal/saving-pipeline-modal.spec.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 72 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,90 @@
11
import React from 'react';
2-
import { mount } from 'enzyme';
2+
import {
3+
renderWithConnections,
4+
screen,
5+
userEvent,
6+
} from '@mongodb-js/testing-library-compass';
37
import sinon from 'sinon';
48
import { expect } from 'chai';
59

610
import Settings from './settings';
711
import { INITIAL_STATE } from '../../modules/settings';
812

13+
function renderSettings(
14+
props: Partial<React.ComponentProps<typeof Settings>> = {},
15+
preferences: {
16+
enableAggregationBuilderExtraOptions?: boolean;
17+
} = {}
18+
) {
19+
return renderWithConnections(
20+
<Settings
21+
isExpanded={false}
22+
isCommenting={false}
23+
applySettings={() => {}}
24+
toggleSettingsIsExpanded={() => {}}
25+
toggleSettingsIsCommentMode={() => {}}
26+
setSettingsSampleSize={() => {}}
27+
setSettingsLimit={() => {}}
28+
limit={INITIAL_STATE.sampleSize}
29+
largeLimit={INITIAL_STATE.limit}
30+
settings={INITIAL_STATE}
31+
{...props}
32+
/>,
33+
{
34+
preferences,
35+
}
36+
);
37+
}
38+
39+
const largeLimitOptionTestId = 'aggregation-settings-limit-input';
40+
941
describe('Settings [Component]', function () {
10-
let state: any;
11-
let component: ReturnType<typeof mount>;
1242
let applySettingsSpy: sinon.SinonSpy;
1343
let toggleSettingsIsExpandedSpy: sinon.SinonSpy;
14-
let toggleSettingsIsCommentModeSpy: sinon.SinonSpy;
15-
let setSettingsSampleSizeSpy: sinon.SinonSpy;
16-
let setSettingsLimitSpy: sinon.SinonSpy;
17-
let runStageSpy: sinon.SinonSpy;
1844

1945
context('when the component is not atlas deployed', function () {
20-
beforeEach(function () {
21-
applySettingsSpy = sinon.spy();
22-
toggleSettingsIsExpandedSpy = sinon.spy();
23-
toggleSettingsIsCommentModeSpy = sinon.spy();
24-
setSettingsSampleSizeSpy = sinon.spy();
25-
setSettingsLimitSpy = sinon.spy();
26-
runStageSpy = sinon.spy();
27-
28-
state = {
29-
...INITIAL_STATE,
30-
applySettings: applySettingsSpy,
31-
toggleSettingsIsExpanded: toggleSettingsIsExpandedSpy,
32-
toggleSettingsIsCommentMode: toggleSettingsIsCommentModeSpy,
33-
setSettingsSampleSize: setSettingsSampleSizeSpy,
34-
setSettingsLimit: setSettingsLimitSpy,
35-
isCommenting: true,
36-
limit: INITIAL_STATE.sampleSize,
37-
largeLimit: INITIAL_STATE.limit,
38-
runStage: runStageSpy,
39-
settings: INITIAL_STATE,
40-
};
41-
});
42-
4346
it('is hidden by default', function () {
44-
component = mount(<Settings {...state} />);
45-
expect(Object.keys(component).length).to.equal(0);
47+
renderSettings();
48+
expect(screen.queryByText('Settings')).to.not.exist;
4649
});
4750

4851
it('is rendered when isExpanded=true', function () {
49-
const props = { ...state, isExpanded: true };
50-
component = mount(<Settings {...props} />);
51-
expect(component.text()).to.contain('Settings');
52+
renderSettings({
53+
isExpanded: true,
54+
});
55+
expect(screen.getByText('Settings')).to.be.visible;
56+
});
57+
58+
it('shows the large limit option', function () {
59+
renderSettings({
60+
isExpanded: true,
61+
});
62+
expect(screen.getByTestId(largeLimitOptionTestId)).to.be.visible;
5263
});
5364

5465
describe('When opened', function () {
66+
beforeEach(function () {
67+
applySettingsSpy = sinon.spy();
68+
toggleSettingsIsExpandedSpy = sinon.spy();
69+
});
70+
5571
it('should close when Cancel is clicked', function () {
56-
const props = { ...state, isExpanded: true };
57-
component = mount(<Settings {...props} />);
58-
component
59-
.find('#aggregations-settings-cancel')
60-
.hostNodes()
61-
.simulate('click');
72+
renderSettings({
73+
isExpanded: true,
74+
applySettings: applySettingsSpy,
75+
toggleSettingsIsExpanded: toggleSettingsIsExpandedSpy,
76+
});
77+
userEvent.click(screen.getByTestId('aggregation-settings-cancel'));
6278
expect(toggleSettingsIsExpandedSpy.calledOnce).to.equal(true);
6379
});
6480

6581
it('should update the settings, re-run the pipeline, and Close', function () {
66-
const props = { ...state, isExpanded: true };
67-
68-
component = mount(<Settings {...props} />);
69-
component
70-
.find('#aggregation-settings-apply')
71-
.hostNodes()
72-
.simulate('click');
82+
renderSettings({
83+
isExpanded: true,
84+
applySettings: applySettingsSpy,
85+
toggleSettingsIsExpanded: toggleSettingsIsExpandedSpy,
86+
});
87+
userEvent.click(screen.getByTestId('aggregation-settings-apply'));
7388

7489
expect(applySettingsSpy.calledOnce).to.equal(true);
7590
expect(toggleSettingsIsExpandedSpy.calledOnce).to.equal(true);
@@ -79,32 +94,18 @@ describe('Settings [Component]', function () {
7994

8095
context('when the component is atlas deployed', function () {
8196
beforeEach(function () {
82-
applySettingsSpy = sinon.spy();
83-
toggleSettingsIsExpandedSpy = sinon.spy();
84-
toggleSettingsIsCommentModeSpy = sinon.spy();
85-
setSettingsSampleSizeSpy = sinon.spy();
86-
setSettingsLimitSpy = sinon.spy();
87-
runStageSpy = sinon.spy();
88-
89-
state = {
90-
...INITIAL_STATE,
91-
applySettings: applySettingsSpy,
92-
toggleSettingsIsExpanded: toggleSettingsIsExpandedSpy,
93-
toggleSettingsIsCommentMode: toggleSettingsIsCommentModeSpy,
94-
setSettingsSampleSize: setSettingsSampleSizeSpy,
95-
setSettingsLimit: setSettingsLimitSpy,
96-
isCommenting: true,
97-
limit: INITIAL_STATE.sampleSize,
98-
largeLimit: INITIAL_STATE.limit,
99-
runStage: runStageSpy,
100-
settings: INITIAL_STATE,
101-
};
97+
renderSettings(
98+
{
99+
isExpanded: true,
100+
},
101+
{
102+
enableAggregationBuilderExtraOptions: false,
103+
}
104+
);
102105
});
103106

104107
it('hides the large limit option', function () {
105-
const props = { ...state };
106-
component = mount(<Settings {...props} />);
107-
expect(component.find('label[innerText="Limit"]')).to.not.exist;
108+
expect(screen.queryByTestId(largeLimitOptionTestId)).to.not.exist;
108109
});
109110
});
110111
});

packages/compass-aggregations/src/components/settings/settings.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ function Settings({
169169
<Body weight="medium">Settings</Body>
170170
<div className={headerButtonGroupStyles}>
171171
<Button
172-
id="aggregations-settings-cancel"
172+
data-testid="aggregation-settings-cancel"
173173
size="xsmall"
174174
onClick={toggleSettingsIsExpanded}
175175
>
176176
Cancel
177177
</Button>
178178
<Button
179-
id="aggregation-settings-apply"
179+
data-testid="aggregation-settings-apply"
180180
size="xsmall"
181181
variant="primary"
182182
onClick={onApplyClicked}
@@ -253,6 +253,7 @@ function Settings({
253253
</div>
254254
<div className={inputControlStyles}>
255255
<TextInput
256+
data-testid="aggregation-settings-limit-input"
256257
id={aggregationLimitId}
257258
aria-labelledby={aggregationLimitLabelId}
258259
aria-describedby={aggregationLimitDescriptionId}

packages/compass-e2e-tests/helpers/selectors.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,8 @@ export const AggregationSettingsButton =
835835
export const AggregationPipelineName = '[data-testid="pipeline-name"]';
836836
export const AggregationCommentModeCheckbox = '#aggregation-comment-mode';
837837
export const AggregationSampleSizeInput = '#aggregation-sample-size';
838-
export const AggregationSettingsApplyButton = '#aggregation-settings-apply';
838+
export const AggregationSettingsApplyButton =
839+
'[data-testid="aggregation-settings-apply"]';
839840
export const AddStageButton = '[data-testid="add-stage"]';
840841
export const ExportAggregationToLanguage =
841842
'[data-testid="pipeline-toolbar-export-button"]';

packages/compass-schema-validation/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@
5353
"@mongodb-js/prettier-config-compass": "^1.2.8",
5454
"@mongodb-js/testing-library-compass": "^1.3.1",
5555
"@mongodb-js/tsconfig-compass": "^1.2.8",
56-
"@types/enzyme": "^3.10.14",
5756
"chai": "^4.2.0",
5857
"depcheck": "^1.4.1",
5958
"electron": "^32.3.3",
6059
"electron-mocha": "^12.2.0",
61-
"enzyme": "^3.11.0",
6260
"hadron-ipc": "^3.4.9",
6361
"mocha": "^10.2.0",
6462
"mongodb-instance-model": "^12.31.0",

0 commit comments

Comments
 (0)