-
Notifications
You must be signed in to change notification settings - Fork 76
OSAC-3781: Add lifecycle and delete row actions #134
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
openshift-merge-bot
merged 8 commits into
osac-project:main
from
batzionb:feature/OSAC-3781
Aug 11, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
febaa4d
OSAC-3781: add instance type lifecycle and delete mutation hooks
batzionb 02fe14c
OSAC-3781: add instance type lifecycle actions menu and delete confir…
batzionb 58603b3
OSAC-3781: fix formatting in instance type delete confirmation and tests
batzionb 4a8cb26
OSAC-3781: wire lifecycle and delete row actions into the instance ty…
batzionb 0d4574b
OSAC-3781: address validation review findings
batzionb 4abc2fa
OSAC-3781: generalize instance type update hook per review feedback
batzionb feeaed9
OSAC-3781: wire up the generalized instance type update hook
batzionb f25d7b8
OSAC-3781: use InstanceTypeState directly for lifecycle actions
batzionb 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
176 changes: 176 additions & 0 deletions
176
libs/ui-components/src/components/InstanceType/AdminInstanceTypeActionsMenu.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,176 @@ | ||
| import { create } from '@bufbuild/protobuf'; | ||
| import { Code, ConnectError } from '@connectrpc/connect'; | ||
| import { screen, waitFor } from '@testing-library/react'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { | ||
| InstanceTypeSchema, | ||
| InstanceTypeState, | ||
| InstanceTypesDeleteResponseSchema, | ||
| InstanceTypesUpdateResponseSchema, | ||
| type InstanceType as PrivateInstanceType, | ||
| } from '@osac/types/private'; | ||
|
|
||
| import AdminInstanceTypeActionsMenu from './AdminInstanceTypeActionsMenu'; | ||
| import { renderWithProviders } from '../../test-utils/TestProviders'; | ||
|
|
||
| const makeInstanceType = (state: InstanceTypeState): PrivateInstanceType => | ||
| create(InstanceTypeSchema, { | ||
| id: 'it-1', | ||
| metadata: { name: 'general-4-16' }, | ||
| spec: { cores: 4, memoryGib: 16, description: '', state }, | ||
| }); | ||
|
|
||
| const renderMenu = ( | ||
| instanceType: PrivateInstanceType, | ||
| options?: Parameters<typeof renderWithProviders>[1], | ||
| ) => renderWithProviders(<AdminInstanceTypeActionsMenu instanceType={instanceType} />, options); | ||
|
|
||
| const openMenu = async (user: ReturnType<typeof renderWithProviders>['user']) => { | ||
| await user.click(screen.getByRole('button', { name: 'Actions for general-4-16' })); | ||
| }; | ||
|
|
||
| describe('AdminInstanceTypeActionsMenu', () => { | ||
| it('exposes Deprecate and Obsolete, but not Reactivate or Delete, for an ACTIVE instance type', async () => { | ||
| const { user } = renderMenu(makeInstanceType(InstanceTypeState.ACTIVE)); | ||
| await openMenu(user); | ||
|
|
||
| expect(screen.getByRole('menuitem', { name: 'Deprecate' })).toBeInTheDocument(); | ||
| expect(screen.getByRole('menuitem', { name: 'Obsolete' })).toBeInTheDocument(); | ||
| expect(screen.queryByRole('menuitem', { name: 'Reactivate' })).not.toBeInTheDocument(); | ||
| expect(screen.queryByRole('menuitem', { name: 'Delete' })).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('exposes Obsolete and Reactivate, but not Deprecate or Delete, for a DEPRECATED instance type', async () => { | ||
| const { user } = renderMenu(makeInstanceType(InstanceTypeState.DEPRECATED)); | ||
| await openMenu(user); | ||
|
|
||
| expect(screen.getByRole('menuitem', { name: 'Obsolete' })).toBeInTheDocument(); | ||
| expect(screen.getByRole('menuitem', { name: 'Reactivate' })).toBeInTheDocument(); | ||
| expect(screen.queryByRole('menuitem', { name: 'Deprecate' })).not.toBeInTheDocument(); | ||
| expect(screen.queryByRole('menuitem', { name: 'Delete' })).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('exposes Deprecate, Reactivate, and Delete, but not Obsolete, for an OBSOLETE instance type', async () => { | ||
| const { user } = renderMenu(makeInstanceType(InstanceTypeState.OBSOLETE)); | ||
| await openMenu(user); | ||
|
|
||
| expect(screen.getByRole('menuitem', { name: 'Deprecate' })).toBeInTheDocument(); | ||
| expect(screen.getByRole('menuitem', { name: 'Reactivate' })).toBeInTheDocument(); | ||
| expect(screen.getByRole('menuitem', { name: 'Delete' })).toBeInTheDocument(); | ||
| expect(screen.queryByRole('menuitem', { name: 'Obsolete' })).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('exposes Deprecate and Obsolete, but not Reactivate or Delete, for an unset (UNSPECIFIED) state, same as ACTIVE', async () => { | ||
| const { user } = renderMenu(makeInstanceType(InstanceTypeState.UNSPECIFIED)); | ||
| await openMenu(user); | ||
|
|
||
| expect(screen.getByRole('menuitem', { name: 'Deprecate' })).toBeInTheDocument(); | ||
| expect(screen.getByRole('menuitem', { name: 'Obsolete' })).toBeInTheDocument(); | ||
| expect(screen.queryByRole('menuitem', { name: 'Reactivate' })).not.toBeInTheDocument(); | ||
| expect(screen.queryByRole('menuitem', { name: 'Delete' })).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('sends a spec.state update targeting DEPRECATED when Deprecate is clicked', async () => { | ||
| let captured: Record<string, unknown> | undefined; | ||
| const { user } = renderMenu(makeInstanceType(InstanceTypeState.ACTIVE), { | ||
| transportOverrides: { | ||
| onInstanceTypeUpdate: (req) => { | ||
| captured = req as unknown as Record<string, unknown>; | ||
| return create(InstanceTypesUpdateResponseSchema, { | ||
| object: makeInstanceType(InstanceTypeState.DEPRECATED), | ||
| }); | ||
| }, | ||
| }, | ||
| }); | ||
| await openMenu(user); | ||
| await user.click(screen.getByRole('menuitem', { name: 'Deprecate' })); | ||
|
|
||
| await waitFor(() => expect(captured).toBeDefined()); | ||
| const object = captured?.object as { id?: string; spec?: { state?: InstanceTypeState } }; | ||
| expect(object.id).toBe('it-1'); | ||
| expect(object.spec?.state).toBe(InstanceTypeState.DEPRECATED); | ||
| }); | ||
|
|
||
| it('shows a toast with the deprecate failure title and backend message when the update fails', async () => { | ||
| const { user } = renderMenu(makeInstanceType(InstanceTypeState.ACTIVE), { | ||
| transportOverrides: { | ||
| onInstanceTypeUpdate: () => { | ||
| throw new ConnectError('deprecation rejected', Code.FailedPrecondition); | ||
| }, | ||
| }, | ||
| }); | ||
| await openMenu(user); | ||
| await user.click(screen.getByRole('menuitem', { name: 'Deprecate' })); | ||
|
|
||
| expect(await screen.findByText('Failed to deprecate instance type')).toBeInTheDocument(); | ||
| expect(screen.getByText('deprecation rejected')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows a toast with the reactivate failure title when the reactivate update fails', async () => { | ||
| const { user } = renderMenu(makeInstanceType(InstanceTypeState.DEPRECATED), { | ||
| transportOverrides: { | ||
| onInstanceTypeUpdate: () => { | ||
| throw new ConnectError('reactivation rejected', Code.FailedPrecondition); | ||
| }, | ||
| }, | ||
| }); | ||
| await openMenu(user); | ||
| await user.click(screen.getByRole('menuitem', { name: 'Reactivate' })); | ||
|
|
||
| expect(await screen.findByText('Failed to reactivate instance type')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows a toast with the obsolete failure title when the obsolete update fails', async () => { | ||
| const { user } = renderMenu(makeInstanceType(InstanceTypeState.ACTIVE), { | ||
| transportOverrides: { | ||
| onInstanceTypeUpdate: () => { | ||
| throw new ConnectError('obsolete rejected', Code.FailedPrecondition); | ||
| }, | ||
| }, | ||
| }); | ||
| await openMenu(user); | ||
| await user.click(screen.getByRole('menuitem', { name: 'Obsolete' })); | ||
|
|
||
| expect(await screen.findByText('Failed to mark instance type as obsolete')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('opens a confirm modal for Delete and deletes the instance type on confirmation', async () => { | ||
| let deleteCalled = false; | ||
| const { user } = renderMenu(makeInstanceType(InstanceTypeState.OBSOLETE), { | ||
| transportOverrides: { | ||
| onInstanceTypeDelete: () => { | ||
| deleteCalled = true; | ||
| return create(InstanceTypesDeleteResponseSchema); | ||
| }, | ||
| }, | ||
| }); | ||
| await openMenu(user); | ||
| await user.click(screen.getByRole('menuitem', { name: 'Delete' })); | ||
|
|
||
| expect(screen.getByRole('dialog')).toBeInTheDocument(); | ||
|
|
||
| await user.click(screen.getByRole('button', { name: 'Delete' })); | ||
|
|
||
| await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument()); | ||
| expect(deleteCalled).toBe(true); | ||
| }); | ||
|
|
||
| it('shows an inline alert in the confirm modal, not a toast, when delete fails', async () => { | ||
| const { user } = renderMenu(makeInstanceType(InstanceTypeState.OBSOLETE), { | ||
| transportOverrides: { | ||
| onInstanceTypeDelete: () => { | ||
| throw new ConnectError('instance type is in use', Code.FailedPrecondition); | ||
| }, | ||
| }, | ||
| }); | ||
| await openMenu(user); | ||
| await user.click(screen.getByRole('menuitem', { name: 'Delete' })); | ||
| await user.click(screen.getByRole('button', { name: 'Delete' })); | ||
|
|
||
| const modal = screen.getByRole('dialog'); | ||
| expect(await screen.findByText('Failed to delete instance type')).toBeInTheDocument(); | ||
| expect(screen.getByText('instance type is in use')).toBeInTheDocument(); | ||
| expect(modal).toBeInTheDocument(); | ||
| }); | ||
| }); |
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.