Skip to content

Commit 286be91

Browse files
add test
1 parent f215e0c commit 286be91

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import React from 'react';
2+
import { fireEvent, render, screen, within } from '@testing-library/react';
3+
import { expect } from 'chai';
4+
import Sinon from 'sinon';
5+
import * as stageSlice from '../../utils/stage';
6+
import { StageOperatorSelect } from './stage-operator-select';
7+
8+
describe('StageOperatorSelect', () => {
9+
const mockStages = [
10+
{
11+
name: 'basicStage',
12+
env: ['on-prem'],
13+
description: 'basicStage description.',
14+
},
15+
{
16+
name: 'atlasOnlyStage',
17+
env: ['atlas'],
18+
description: 'atlasOnlyStage description.',
19+
},
20+
{
21+
name: '$search',
22+
env: ['atlas'],
23+
description: 'searchStage description.',
24+
},
25+
];
26+
27+
const defaultMockProps = {
28+
index: 0,
29+
onChange: () => {},
30+
selectedStage: null,
31+
isDisabled: false,
32+
stages: mockStages,
33+
serverVersion: '8.1.0',
34+
isReadonlyView: false,
35+
collectionStats: {
36+
pipeline: [{ $addFields: { field: 'value' } }],
37+
},
38+
};
39+
let filterStageOperatorsStub;
40+
beforeEach(() => {
41+
filterStageOperatorsStub = Sinon.stub(
42+
stageSlice,
43+
'filterStageOperators'
44+
).returns(mockStages);
45+
});
46+
47+
afterEach(() => {
48+
filterStageOperatorsStub.restore();
49+
});
50+
51+
const renderCombobox = (props) => render(<StageOperatorSelect {...props} />);
52+
53+
it('renders the correct descriptions if not in readonly view', () => {
54+
const mockProps = {
55+
...defaultMockProps,
56+
isReadonlyView: false,
57+
};
58+
59+
renderCombobox(mockProps);
60+
fireEvent.click(screen.getByRole('combobox'));
61+
const listbox = screen.getByRole('listbox');
62+
63+
expect(within(listbox).getByText('basicStage description.')).to.exist;
64+
expect(within(listbox).getByText('Atlas only. atlasOnlyStage description.'))
65+
.to.exist;
66+
expect(within(listbox).getByText('Atlas only. searchStage description.')).to
67+
.exist;
68+
});
69+
70+
it('renders the correct descriptions if in readonly view with non queryable pipeline', () => {
71+
const mockProps = {
72+
...defaultMockProps,
73+
isReadonlyView: true,
74+
collectionStats: {
75+
pipeline: [
76+
{ $addFields: { field: 'value' } },
77+
{ project: { newField: 1 } },
78+
],
79+
},
80+
};
81+
82+
renderCombobox(mockProps);
83+
fireEvent.click(screen.getByRole('combobox'));
84+
const listbox = screen.getByRole('listbox'); // Target the dropdown
85+
86+
expect(within(listbox).getByText('basicStage description.')).to.exist;
87+
expect(within(listbox).getByText('Atlas only. atlasOnlyStage description.'))
88+
.to.exist;
89+
expect(
90+
within(listbox).getByText(
91+
'Atlas only. Only views containing $addFields, $set or $match stages with the $expr operator are compatible with search indexes. searchStage description.'
92+
)
93+
).to.exist;
94+
});
95+
96+
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);
104+
fireEvent.click(screen.getByRole('combobox'));
105+
const listbox = screen.getByRole('listbox');
106+
107+
expect(within(listbox).getByText('basicStage description.')).to.exist;
108+
expect(within(listbox).getByText('Atlas only. atlasOnlyStage description.'))
109+
.to.exist;
110+
expect(
111+
within(listbox).getByText(
112+
'Atlas only. Requires MongoDB 8.1+ to run on a view. searchStage description.'
113+
)
114+
).to.exist;
115+
});
116+
});

0 commit comments

Comments
 (0)