-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(search-indexes): new modal to update search indexes COMPASS-7166 (…
…#4854) Co-authored-by: Basit <[email protected]>
- Loading branch information
Showing
21 changed files
with
1,045 additions
and
379 deletions.
There are no files selected for viewing
38 changes: 0 additions & 38 deletions
38
packages/compass-e2e-tests/helpers/commands/create-search-index.ts
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
packages/compass-e2e-tests/helpers/commands/drop-search-index.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...ges/compass-indexes/src/components/search-indexes-modals/base-search-index-modal.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { expect } from 'chai'; | ||
import { BaseSearchIndexModal } from './base-search-index-modal'; | ||
import sinon from 'sinon'; | ||
import type { SinonSpy } from 'sinon'; | ||
|
||
import { render, screen, cleanup } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import React from 'react'; | ||
import { getCodemirrorEditorValue } from '@mongodb-js/compass-editor'; | ||
|
||
describe('Create Search Index Modal', function () { | ||
let onSubmitSpy: SinonSpy; | ||
let onCloseSpy: SinonSpy; | ||
|
||
beforeEach(function () { | ||
onSubmitSpy = sinon.spy(); | ||
onCloseSpy = sinon.spy(); | ||
|
||
render( | ||
<BaseSearchIndexModal | ||
mode="create" | ||
initialIndexName={'default'} | ||
initialIndexDefinition={'{}'} | ||
isModalOpen={true} | ||
isBusy={false} | ||
onSubmit={onSubmitSpy} | ||
onClose={onCloseSpy} | ||
error={'Invalid index definition.'} | ||
/> | ||
); | ||
}); | ||
|
||
afterEach(cleanup); | ||
|
||
describe('default behaviour', function () { | ||
it('uses the initial index name as the default index name', function () { | ||
const inputText: HTMLInputElement = screen.getByTestId( | ||
'name-of-search-index' | ||
); | ||
|
||
expect(inputText).to.not.be.null; | ||
expect(inputText?.value).to.equal('default'); | ||
}); | ||
|
||
it('uses a dynamic mapping as the default index definition', function () { | ||
const defaultIndexDef = getCodemirrorEditorValue( | ||
'definition-of-search-index' | ||
); | ||
|
||
expect(defaultIndexDef).to.not.be.null; | ||
expect(defaultIndexDef).to.equal('{}'); | ||
}); | ||
}); | ||
|
||
describe('form validation', function () { | ||
it('shows an error when the index name is empty', async function () { | ||
const inputText: HTMLInputElement = screen.getByTestId( | ||
'name-of-search-index' | ||
); | ||
|
||
userEvent.clear(inputText); | ||
expect(await screen.findByText('Please enter the name of the index.')).to | ||
.exist; | ||
}); | ||
|
||
it('shows server errors', async function () { | ||
expect(await screen.findByText('Invalid index definition.')).to.exist; | ||
}); | ||
}); | ||
|
||
describe('form behaviour', function () { | ||
it('closes the modal on cancel', function () { | ||
const cancelButton: HTMLButtonElement = screen | ||
.getByText('Cancel') | ||
.closest('button')!; | ||
|
||
userEvent.click(cancelButton); | ||
expect(onCloseSpy).to.have.been.calledOnce; | ||
}); | ||
|
||
it('submits the modal on create search index', function () { | ||
const submitButton: HTMLButtonElement = screen | ||
.getByTestId('search-index-submit-button') | ||
.closest('button')!; | ||
|
||
userEvent.click(submitButton); | ||
expect(onSubmitSpy).to.have.been.calledOnceWithExactly('default', {}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.