diff --git a/src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.test.tsx b/src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.test.tsx
index bd424211325e..3a2713e8ed48 100644
--- a/src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.test.tsx
+++ b/src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.test.tsx
@@ -4,7 +4,7 @@
*/
import React from 'react';
-import { render, act } from '@testing-library/react';
+import { render, act, screen, fireEvent } from '@testing-library/react';
import { DataSourceSelectable } from './datasource_selectable';
import { DataSourceType, GenericDataSource } from '../datasource_services';
import { DataSourceGroup, DataSourceOption } from './types';
@@ -81,4 +81,114 @@ describe('DataSourceSelectable', () => {
expect(onFetchDataSetErrorMock).toHaveBeenCalledWith(new Error('Fetch error'));
});
+
+ it('should sort index patterns list alphabetically', async () => {
+ const mockDataSourceOptionList = [
+ {
+ label: 'Index patterns',
+ options: [
+ { label: 'logstash-*' },
+ { label: '000-*' },
+ { label: 'p000-1' },
+ { label: 'pattern_archive' },
+ { label: 'index_main' },
+ { label: 'index-2024' },
+ ],
+ },
+ ] as any;
+
+ render(
+
+ );
+
+ const button = screen.getByLabelText('Open list of options');
+ fireEvent.click(button);
+ expect(
+ screen.getByTestId('comboBoxOptionsList dataExplorerDSSelect-optionsList')
+ ).toBeInTheDocument();
+ const defaultDSOptions = document.querySelectorAll('.euiComboBoxOption__content');
+ const optionTexts = Array.from(defaultDSOptions).map((option) => option.innerHTML);
+ const expectedIndexPatternSortedOrder = [
+ '000-*',
+ 'index_main',
+ 'index-2024',
+ 'logstash-*',
+ 'p000-1',
+ 'pattern_archive',
+ ];
+ expect(optionTexts).toEqual(expectedIndexPatternSortedOrder);
+ });
+
+ it('should sort non index patterns list alphabetically', async () => {
+ const mockDataSourceOptionList = [
+ {
+ label: 'Amazon S3',
+ options: [
+ { label: 'mys3' },
+ { label: '*starred' },
+ { label: 'alpha-test-s3' },
+ { label: '@special' },
+ { label: 's3-2024' },
+ { label: 'S3_Archive' },
+ ],
+ },
+ ] as any;
+
+ render(
+
+ );
+
+ const button = screen.getByLabelText('Open list of options');
+ fireEvent.click(button);
+ expect(
+ screen.getByTestId('comboBoxOptionsList dataExplorerDSSelect-optionsList')
+ ).toBeInTheDocument();
+ const defaultDSOptions = document.querySelectorAll('.euiComboBoxOption__content');
+ const optionTexts = Array.from(defaultDSOptions).map((option) => option.innerHTML);
+ const expectedIndexPatternSortedOrder = [
+ '@special',
+ '*starred',
+ 'alpha-test-s3',
+ 'mys3',
+ 'S3_Archive',
+ 's3-2024',
+ ];
+ expect(optionTexts).toEqual(expectedIndexPatternSortedOrder);
+ });
});