|
| 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 | +}); |
0 commit comments