Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,37 @@ describe('HeaderButtons', () => {
expect(getByTestId('siemMigrationsSelectMigrationButton')).toBeInTheDocument();
});

it('marks only the option with the selected migration id as selected when names are duplicated', () => {
const [first, second] = getMigrationsStatsMock();
const migrationsWithDuplicateNames = [
{ ...first, name: 'Same name', id: '1' },
{ ...second, name: 'Same name', id: '2' },
];

const { getByTestId } = render(
<TestProviders>
<HeaderButtons
migrationType="dashboard"
migrationsStats={migrationsWithDuplicateNames}
selectedMigrationId="1"
onMigrationIdChange={onMigrationIdChange}
/>
</TestProviders>
);

const siemMigrationsSelectMigrationButton = getByTestId('siemMigrationsSelectMigrationButton');
const comboBoxToggleListButton = within(siemMigrationsSelectMigrationButton).getByTestId(
'comboBoxToggleListButton'
);
fireEvent.click(comboBoxToggleListButton);

const option1 = getByTestId('migrationSelectionOption-1');
const option2 = getByTestId('migrationSelectionOption-2');

expect(option1).toHaveAttribute('aria-selected', 'true');
expect(option2).toHaveAttribute('aria-selected', 'false');
});

it('calls onMigrationIdChange when a migration is selected', () => {
const { getByTestId, getByText } = render(
<TestProviders>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const SIEM_MIGRATIONS_SELECT_MIGRATION_BUTTON_ID = 'siemMigrationsSelectM
const migrationStatsToComboBoxOption = (
stats: MigrationTaskStats
): EuiComboBoxOptionOption<string> => ({
key: stats.id,
value: stats.id,
label: stats.name,
'data-test-subj': `migrationSelectionOption-${stats.id}`,
Expand Down Expand Up @@ -60,8 +61,10 @@ export const HeaderButtons: React.FC<HeaderButtonsProps> = React.memo(
const migrationVendor = useMemo(() => selectedMigrationStats?.vendor, [selectedMigrationStats]);

const selectedMigrationOption = useMemo<Array<EuiComboBoxOptionOption<string>>>(() => {
return selectedMigrationStats ? [migrationStatsToComboBoxOption(selectedMigrationStats)] : [];
}, [selectedMigrationStats]);
if (!selectedMigrationId) return [];
const selected = migrationOptions.find((opt) => opt.value === selectedMigrationId);
return selected ? [selected] : [];
}, [migrationOptions, selectedMigrationId]);

const onChange = (selected: Array<EuiComboBoxOptionOption<string>>) => {
onMigrationIdChange(selected[0].value);
Expand Down
Loading