Skip to content

Commit 7e6218c

Browse files
committed
added tests
1 parent e61dc72 commit 7e6218c

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React from 'react';
2+
import { render, screen, fireEvent } from '@mongodb-js/testing-library-compass';
3+
import { CreateIndexForm } from './create-index-form';
4+
import type { Field } from '../../modules/create-index';
5+
import { expect } from 'chai';
6+
7+
import sinon from 'sinon';
8+
9+
describe('CreateIndexForm', () => {
10+
let onTabClickSpy;
11+
12+
beforeEach(function () {
13+
onTabClickSpy = sinon.spy();
14+
});
15+
16+
afterEach(function () {
17+
onTabClickSpy = null;
18+
});
19+
20+
const renderComponent = ({
21+
showIndexesGuidanceVariant,
22+
}: {
23+
showIndexesGuidanceVariant?: boolean;
24+
}) => {
25+
render(
26+
<CreateIndexForm
27+
namespace="testNamespace"
28+
fields={
29+
[
30+
{ name: 'field1', type: 'string' },
31+
{ name: 'field2', type: 'number' },
32+
] as Field[]
33+
}
34+
serverVersion="5.0.0"
35+
currentTab="IndexFlow"
36+
onSelectFieldNameClick={() => {}}
37+
onSelectFieldTypeClick={() => {}}
38+
onAddFieldClick={() => {}}
39+
onRemoveFieldClick={() => {}}
40+
onTabClick={onTabClickSpy}
41+
showIndexesGuidanceVariant={showIndexesGuidanceVariant || false}
42+
/>
43+
);
44+
};
45+
46+
it('renders the create index form', () => {
47+
renderComponent({});
48+
expect(screen.getByTestId('create-index-form')).to.exist;
49+
});
50+
51+
describe('when showIndexesGuidanceVariant is false', () => {
52+
it('renders the RadioBoxGroup', () => {
53+
renderComponent({});
54+
expect(screen.queryByTestId('create-index-form-flows')).not.to.exist;
55+
});
56+
});
57+
58+
describe('when showIndexesGuidanceVariant is true', () => {
59+
it('renders the RadioBoxGroup', () => {
60+
renderComponent({ showIndexesGuidanceVariant: true });
61+
expect(screen.getByTestId('create-index-form-flows')).to.exist;
62+
});
63+
it('calls onTabClick when a RadioBox is selected', () => {
64+
renderComponent({ showIndexesGuidanceVariant: true });
65+
const radioBox = screen.getByLabelText('Start with a Query');
66+
fireEvent.click(radioBox);
67+
expect(onTabClickSpy).to.be.calledWith('QueryFlow');
68+
});
69+
});
70+
});

packages/compass-indexes/src/components/create-index-form/create-index-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const createIndexModalFlowsStyles = css({
3535
marginBottom: spacing[600],
3636
});
3737

38-
type CreateIndexFormProps = {
38+
export type CreateIndexFormProps = {
3939
namespace: string;
4040
fields: Field[];
4141
serverVersion: string;

0 commit comments

Comments
 (0)