-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Search] Switch over to V2 index management details #259866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
seialkali
merged 5 commits into
elastic:main
from
seialkali:switch-to-index-management-v2
Mar 31, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
14 changes: 0 additions & 14 deletions
14
.../index_management/public/application/hooks/use_is_platform_index_management_v2_enabled.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
183 changes: 183 additions & 0 deletions
183
...ment/public/application/sections/home/index_list/create_index/create_index_modal.test.tsx
This file contains hidden or 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,183 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| import { render, screen, fireEvent, waitFor } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { EuiThemeProvider } from '@elastic/eui'; | ||
| import { I18nProvider } from '@kbn/i18n-react'; | ||
| import { CreateIndexModal } from './create_index_modal'; | ||
|
|
||
| const mockCreateIndex = jest.fn(); | ||
| jest.mock('../../../../services', () => ({ | ||
| createIndex: (...args: unknown[]) => mockCreateIndex(...args), | ||
| })); | ||
|
|
||
| const mockShowSuccessToast = jest.fn(); | ||
| jest.mock('../../../../services/notification', () => ({ | ||
| notificationService: { | ||
| showSuccessToast: (...args: unknown[]) => mockShowSuccessToast(...args), | ||
| }, | ||
| })); | ||
|
|
||
| jest.mock('./utils', () => ({ | ||
| generateRandomIndexName: () => 'search-abcd', | ||
| isValidIndexName: (name: string) => { | ||
| if (!name || name !== name.toLowerCase() || name.length === 0) return false; | ||
| return true; | ||
| }, | ||
| })); | ||
|
|
||
| const renderModal = (props: Partial<React.ComponentProps<typeof CreateIndexModal>> = {}) => { | ||
| const defaultProps = { | ||
| closeModal: jest.fn(), | ||
| loadIndices: jest.fn(), | ||
| }; | ||
|
|
||
| return render( | ||
| <I18nProvider> | ||
| <EuiThemeProvider> | ||
| <CreateIndexModal {...defaultProps} {...props} /> | ||
| </EuiThemeProvider> | ||
| </I18nProvider> | ||
| ); | ||
| }; | ||
|
|
||
| describe('CreateIndexModal', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('renders the modal with title and description', () => { | ||
| renderModal(); | ||
| expect(screen.getByText('Create your index')).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByText('An index stores and defines the schema of your data.') | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('pre-fills the index name with a generated random name', () => { | ||
| renderModal(); | ||
| const input = screen.getByTestId('createIndexNameFieldText'); | ||
| expect(input).toHaveValue('search-abcd'); | ||
| }); | ||
|
|
||
| it('shows index name and index mode form fields', () => { | ||
| renderModal(); | ||
| expect(screen.getByTestId('createIndexNameFieldText')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('indexModeField')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows a validation error for invalid index names', async () => { | ||
| renderModal(); | ||
| const input = screen.getByTestId('createIndexNameFieldText'); | ||
| await userEvent.clear(input); | ||
| await userEvent.type(input, 'INVALID'); | ||
|
|
||
| expect(screen.getByText('Index name is not valid')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('clears validation error when a valid name is entered', async () => { | ||
| renderModal(); | ||
| const input = screen.getByTestId('createIndexNameFieldText'); | ||
|
|
||
| await userEvent.clear(input); | ||
| await userEvent.type(input, 'INVALID'); | ||
| expect(screen.getByText('Index name is not valid')).toBeInTheDocument(); | ||
|
|
||
| await userEvent.clear(input); | ||
| await userEvent.type(input, 'valid-name'); | ||
| expect(screen.queryByText('Index name is not valid')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('calls closeModal when cancel button is clicked', () => { | ||
| const closeModal = jest.fn(); | ||
| renderModal({ closeModal }); | ||
| fireEvent.click(screen.getByTestId('createIndexCancelButton')); | ||
| expect(closeModal).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('toggles the API code block when Show/Hide API button is clicked', () => { | ||
| renderModal(); | ||
| expect(screen.getByText('Show API')).toBeInTheDocument(); | ||
|
|
||
| fireEvent.click(screen.getByTestId('createIndexShowApiButton')); | ||
| expect(screen.getByText('Hide API')).toBeInTheDocument(); | ||
| expect(screen.getByText(/PUT search-abcd/)).toBeInTheDocument(); | ||
|
|
||
| fireEvent.click(screen.getByTestId('createIndexShowApiButton')); | ||
| expect(screen.getByText('Show API')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('reflects the selected index mode in the API code block', async () => { | ||
| renderModal(); | ||
| fireEvent.click(screen.getByTestId('createIndexShowApiButton')); | ||
|
|
||
| expect(screen.getByText(/\"mode\":\"standard\"/)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('creates the index on submit with valid name', async () => { | ||
| const closeModal = jest.fn(); | ||
| const loadIndices = jest.fn(); | ||
| mockCreateIndex.mockResolvedValue({ error: undefined }); | ||
|
|
||
| renderModal({ closeModal, loadIndices }); | ||
| fireEvent.click(screen.getByTestId('createIndexSaveButton')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockCreateIndex).toHaveBeenCalledWith('search-abcd', 'standard'); | ||
| }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockShowSuccessToast).toHaveBeenCalled(); | ||
| expect(closeModal).toHaveBeenCalled(); | ||
| expect(loadIndices).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| it('creates the index when pressing Enter in the index name input', async () => { | ||
| const closeModal = jest.fn(); | ||
| const loadIndices = jest.fn(); | ||
| mockCreateIndex.mockResolvedValue({ error: undefined }); | ||
|
|
||
| renderModal({ closeModal, loadIndices }); | ||
| fireEvent.submit(screen.getByTestId('createIndexModalForm')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockCreateIndex).toHaveBeenCalledWith('search-abcd', 'standard'); | ||
| }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockShowSuccessToast).toHaveBeenCalled(); | ||
| expect(closeModal).toHaveBeenCalled(); | ||
| expect(loadIndices).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| it('displays an error callout when index creation fails', async () => { | ||
| mockCreateIndex.mockResolvedValue({ error: { message: 'Index already exists' } }); | ||
|
|
||
| renderModal(); | ||
| fireEvent.click(screen.getByTestId('createIndexSaveButton')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Error creating index')).toBeInTheDocument(); | ||
| expect(screen.getByText(/Index already exists/)).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| it('does not submit when the index name is invalid', async () => { | ||
| renderModal(); | ||
| const input = screen.getByTestId('createIndexNameFieldText'); | ||
|
|
||
| await userEvent.clear(input); | ||
|
|
||
| fireEvent.click(screen.getByTestId('createIndexSaveButton')); | ||
|
|
||
| expect(mockCreateIndex).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.