11import React from 'react' ;
22import { fireEvent , render , screen , within } from '@testing-library/react' ;
33import { expect } from 'chai' ;
4+ import { Stage , StageOperatorSelect } from './stage-operator-select' ;
45import Sinon from 'sinon' ;
5- import * as stageSlice from '../../utils/stage' ;
6- import { StageOperatorSelect } from './stage-operator-select' ;
76
87describe ( '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
0 commit comments