Skip to content

Commit bb161da

Browse files
fix test syntax
1 parent 19fbf6e commit bb161da

File tree

2 files changed

+14
-40
lines changed

2 files changed

+14
-40
lines changed

packages/compass-aggregations/src/components/stage-toolbar/stage-operator-select.spec.tsx

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React from 'react';
22
import { fireEvent, render, screen, within } from '@testing-library/react';
33
import { expect } from 'chai';
4+
import { Stage, StageOperatorSelect } from './stage-operator-select';
45
import Sinon from 'sinon';
5-
import * as stageSlice from '../../utils/stage';
6-
import { StageOperatorSelect } from './stage-operator-select';
76

87
describe('StageOperatorSelect', () => {
9-
const mockStages = [
8+
const mockStages: Stage[] = [
109
{
1110
name: 'basicStage',
1211
env: ['on-prem'],
@@ -26,7 +25,7 @@ describe('StageOperatorSelect', () => {
2625

2726
const defaultMockProps = {
2827
index: 0,
29-
onChange: () => {},
28+
onChange: Sinon.stub(),
3029
selectedStage: null,
3130
isDisabled: false,
3231
stages: mockStages,
@@ -36,27 +35,15 @@ describe('StageOperatorSelect', () => {
3635
pipeline: [{ $addFields: { field: 'value' } }],
3736
},
3837
};
39-
let filterStageOperatorsStub;
40-
beforeEach(() => {
41-
filterStageOperatorsStub = Sinon.stub(
42-
stageSlice,
43-
'filterStageOperators'
44-
).returns(mockStages);
45-
});
46-
47-
afterEach(() => {
48-
filterStageOperatorsStub.restore();
49-
});
5038

51-
const renderCombobox = (props) => render(<StageOperatorSelect {...props} />);
39+
const renderCombobox = (
40+
props: Partial<React.ComponentProps<typeof StageOperatorSelect>> = {}
41+
) => {
42+
return render(<StageOperatorSelect {...defaultMockProps} {...props} />);
43+
};
5244

5345
it('renders the correct descriptions if not in readonly view', () => {
54-
const mockProps = {
55-
...defaultMockProps,
56-
isReadonlyView: false,
57-
};
58-
59-
renderCombobox(mockProps);
46+
renderCombobox({ isReadonlyView: false });
6047
fireEvent.click(screen.getByRole('combobox'));
6148
const listbox = screen.getByRole('listbox');
6249

@@ -68,18 +55,15 @@ describe('StageOperatorSelect', () => {
6855
});
6956

7057
it('renders the correct descriptions if in readonly view with non queryable pipeline', () => {
71-
const mockProps = {
72-
...defaultMockProps,
58+
renderCombobox({
7359
isReadonlyView: true,
7460
collectionStats: {
7561
pipeline: [
7662
{ $addFields: { field: 'value' } },
7763
{ project: { newField: 1 } },
7864
],
7965
},
80-
};
81-
82-
renderCombobox(mockProps);
66+
});
8367
fireEvent.click(screen.getByRole('combobox'));
8468
const listbox = screen.getByRole('listbox'); // Target the dropdown
8569

@@ -94,13 +78,7 @@ describe('StageOperatorSelect', () => {
9478
});
9579

9680
it('renders the correct descriptions for $search stage in readonly view with incompatible version', () => {
97-
const mockProps = {
98-
...defaultMockProps,
99-
serverVersion: '7.0.0',
100-
isReadonlyView: true,
101-
};
102-
103-
renderCombobox(mockProps);
81+
renderCombobox({ serverVersion: '7.0.0', isReadonlyView: true });
10482
fireEvent.click(screen.getByRole('combobox'));
10583
const listbox = screen.getByRole('listbox');
10684

packages/compass-aggregations/src/components/stage-toolbar/stage-operator-select.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,13 @@ type StageOperatorSelectProps = {
4343
index: number;
4444
selectedStage: string | null;
4545
isDisabled: boolean;
46-
stages: {
47-
name: string;
48-
env: ServerEnvironment[];
49-
description: string;
50-
}[];
46+
stages: Stage[];
5147
serverVersion: string;
5248
isReadonlyView: boolean;
5349
collectionStats: CollectionStats;
5450
};
5551

56-
type Stage = {
52+
export type Stage = {
5753
name: string;
5854
env: ServerEnvironment[];
5955
description: string;

0 commit comments

Comments
 (0)