-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These changes introduce a new UI feature that allows users to create resources from the associated list view. Clicking the 'Create' button opens up the EditorDialog used in the generic 'Create / Apply' button, now accepting generic YAML/JSON text rather than explicitly expecting an item that looks like a Kubernetes resource. The dialog box also includes a generic template for each resource. The apply logic for this new feature (as well as the original 'Create / Apply' button) has been consolidated in EditorDialog, with a flag allowing external components to utilize their own dispatch functionality. Fixes: #1820 Signed-off-by: Evangelos Skopelitis <eskopelitis@microsoft.com>
- Loading branch information
Showing
36 changed files
with
1,577 additions
and
225 deletions.
There are no files selected for viewing
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
97 changes: 97 additions & 0 deletions
97
frontend/src/components/common/CreateResourceButton.stories.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,97 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { expect, userEvent, waitFor } from '@storybook/test'; | ||
import { screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import ConfigMap from '../../lib/k8s/configMap'; | ||
import store from '../../redux/stores/store'; | ||
import { TestContext } from '../../test'; | ||
import { CreateResourceButton, CreateResourceButtonProps } from './CreateResourceButton'; | ||
|
||
export default { | ||
title: 'CreateResourceButton', | ||
component: CreateResourceButton, | ||
parameters: { | ||
storyshots: { | ||
disable: true, | ||
}, | ||
}, | ||
decorators: [ | ||
Story => { | ||
return ( | ||
<Provider store={store}> | ||
<TestContext> | ||
<Story /> | ||
</TestContext> | ||
</Provider> | ||
); | ||
}, | ||
], | ||
} as Meta; | ||
|
||
type Story = StoryObj<CreateResourceButtonProps>; | ||
|
||
export const ValidResource: Story = { | ||
args: { resourceClass: ConfigMap }, | ||
|
||
play: async ({ args }) => { | ||
await userEvent.click( | ||
screen.getByRole('button', { | ||
name: `Create ${(args.resourceClass as typeof ConfigMap).kind}`, | ||
}) | ||
); | ||
|
||
await waitFor(() => expect(screen.getByRole('textbox')).toBeVisible()); | ||
|
||
await userEvent.click(screen.getByRole('textbox')); | ||
|
||
await userEvent.keyboard('{Control>}a{/Control} {Backspace}'); | ||
await userEvent.keyboard(`apiVersion: v1{Enter}`); | ||
await userEvent.keyboard(`kind: ConfigMap{Enter}`); | ||
await userEvent.keyboard(`metadata:{Enter}`); | ||
await userEvent.keyboard(` name: base-configmap`); | ||
|
||
const button = await screen.findByRole('button', { name: 'Apply' }); | ||
expect(button).toBeVisible(); | ||
}, | ||
}; | ||
|
||
export const InvalidResource: Story = { | ||
args: { resourceClass: ConfigMap }, | ||
|
||
play: async ({ args }) => { | ||
await userEvent.click( | ||
screen.getByRole('button', { | ||
name: `Create ${(args.resourceClass as typeof ConfigMap).kind}`, | ||
}) | ||
); | ||
|
||
await waitFor(() => expect(screen.getByRole('textbox')).toBeVisible()); | ||
|
||
await userEvent.click(screen.getByRole('textbox')); | ||
|
||
await userEvent.keyboard('{Control>}a{/Control}'); | ||
await userEvent.keyboard(`apiVersion: v1{Enter}`); | ||
await userEvent.keyboard(`kind: ConfigMap{Enter}`); | ||
await userEvent.keyboard(`metadata:{Enter}`); | ||
await userEvent.keyboard(` name: base-configmap{Enter}`); | ||
await userEvent.keyboard(`creationTimestamp: ''`); | ||
|
||
const button = await screen.findByRole('button', { name: 'Apply' }); | ||
expect(button).toBeVisible(); | ||
|
||
await userEvent.click(button); | ||
|
||
await waitFor(() => | ||
userEvent.click( | ||
screen.getByRole('button', { | ||
name: `Create ${(args.resourceClass as typeof ConfigMap).kind}`, | ||
}) | ||
) | ||
); | ||
|
||
await waitFor(() => expect(screen.getByText(/Failed/)).toBeVisible(), { | ||
timeout: 15000, | ||
}); | ||
}, | ||
}; |
Oops, something went wrong.