Skip to content

Commit cab72ad

Browse files
committed
fix tests for create-index-actions.spec.tsx
1 parent e7d6b24 commit cab72ad

File tree

1 file changed

+23
-57
lines changed

1 file changed

+23
-57
lines changed
Lines changed: 23 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ import {
88
userEvent,
99
within,
1010
} from '@mongodb-js/testing-library-compass';
11+
import { setupStore } from '../../../test/setup-store';
12+
import { Provider } from 'react-redux';
1113

12-
import CreateIndexActions from '../create-index-actions';
14+
import CreateIndexActions from '.';
1315

1416
describe('CreateIndexActions Component', function () {
1517
let clearErrorSpy;
1618
let onCreateIndexClickSpy;
1719
let closeCreateIndexModalSpy;
20+
const store = setupStore();
1821

1922
beforeEach(function () {
2023
clearErrorSpy = sinon.spy();
@@ -28,30 +31,29 @@ describe('CreateIndexActions Component', function () {
2831
closeCreateIndexModalSpy = null;
2932
});
3033

31-
it('renders a cancel button', function () {
34+
const renderComponent = (error?: string) => {
3235
render(
33-
<CreateIndexActions
34-
error={null}
35-
onErrorBannerCloseClick={clearErrorSpy}
36-
onCreateIndexClick={onCreateIndexClickSpy}
37-
onCancelCreateIndexClick={closeCreateIndexModalSpy}
38-
/>
36+
<Provider store={store}>
37+
<CreateIndexActions
38+
error={error || null}
39+
onErrorBannerCloseClick={clearErrorSpy}
40+
onCreateIndexClick={onCreateIndexClickSpy}
41+
onCancelCreateIndexClick={closeCreateIndexModalSpy}
42+
showIndexesGuidanceVariant={false}
43+
/>
44+
</Provider>
3945
);
46+
};
47+
it('renders a cancel button', function () {
48+
renderComponent();
4049

4150
const button = screen.getByTestId('create-index-actions-cancel-button');
4251
expect(button.textContent).to.be.equal('Cancel');
4352
});
4453

4554
context('onCancel', function () {
4655
it('calls the closeCreateIndexModal function', function () {
47-
render(
48-
<CreateIndexActions
49-
error={null}
50-
onErrorBannerCloseClick={clearErrorSpy}
51-
onCreateIndexClick={onCreateIndexClickSpy}
52-
onCancelCreateIndexClick={closeCreateIndexModalSpy}
53-
/>
54-
);
56+
renderComponent();
5557

5658
const button = screen.getByTestId('create-index-actions-cancel-button');
5759
userEvent.click(button);
@@ -61,14 +63,7 @@ describe('CreateIndexActions Component', function () {
6163

6264
context('onConfirm', function () {
6365
it('calls the onCreateIndexClick function', function () {
64-
render(
65-
<CreateIndexActions
66-
error={null}
67-
onErrorBannerCloseClick={clearErrorSpy}
68-
onCreateIndexClick={onCreateIndexClickSpy}
69-
onCancelCreateIndexClick={closeCreateIndexModalSpy}
70-
/>
71-
);
66+
renderComponent();
7267

7368
const button = screen.getByTestId(
7469
'create-index-actions-create-index-button'
@@ -79,15 +74,7 @@ describe('CreateIndexActions Component', function () {
7974
});
8075

8176
it('renders a create index button', function () {
82-
render(
83-
<CreateIndexActions
84-
error={null}
85-
onErrorBannerCloseClick={clearErrorSpy}
86-
onCreateIndexClick={onCreateIndexClickSpy}
87-
onCancelCreateIndexClick={closeCreateIndexModalSpy}
88-
/>
89-
);
90-
77+
renderComponent();
9178
const button = screen.getByTestId(
9279
'create-index-actions-create-index-button'
9380
);
@@ -96,14 +83,7 @@ describe('CreateIndexActions Component', function () {
9683

9784
context('with error', function () {
9885
it('renders error banner', function () {
99-
render(
100-
<CreateIndexActions
101-
error={'Some error happened!'}
102-
onErrorBannerCloseClick={clearErrorSpy}
103-
onCreateIndexClick={onCreateIndexClickSpy}
104-
onCancelCreateIndexClick={closeCreateIndexModalSpy}
105-
/>
106-
);
86+
renderComponent('Some error happened!');
10787

10888
const errorBanner = screen.getByTestId(
10989
'create-index-actions-error-banner-wrapper'
@@ -112,14 +92,7 @@ describe('CreateIndexActions Component', function () {
11292
});
11393

11494
it('closes error banner', function () {
115-
render(
116-
<CreateIndexActions
117-
error={'Some error happened!'}
118-
onErrorBannerCloseClick={clearErrorSpy}
119-
onCreateIndexClick={onCreateIndexClickSpy}
120-
onCancelCreateIndexClick={closeCreateIndexModalSpy}
121-
/>
122-
);
95+
renderComponent('Some error happened!');
12396

12497
const errorBanner = screen.getByTestId(
12598
'create-index-actions-error-banner-wrapper'
@@ -133,14 +106,7 @@ describe('CreateIndexActions Component', function () {
133106

134107
context('without error', function () {
135108
it('does not render error banner', function () {
136-
render(
137-
<CreateIndexActions
138-
error={null}
139-
onErrorBannerCloseClick={clearErrorSpy}
140-
onCreateIndexClick={onCreateIndexClickSpy}
141-
onCancelCreateIndexClick={closeCreateIndexModalSpy}
142-
/>
143-
);
109+
renderComponent();
144110

145111
const errorBanner = screen.queryByTestId(
146112
'create-index-actions-error-banner-wrapper'

0 commit comments

Comments
 (0)