Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
0d70ddf
refactor: update WorkspaceInstruction to use function-based react
DanielMicrosoft Oct 13, 2025
1b1318a
refactor: update WorkspacePage to use class-based
DanielMicrosoft Oct 13, 2025
6fb255f
refactor: extract workspacecreatedialog to own component
DanielMicrosoft Oct 13, 2025
a4376b2
refactor: WorkspaceSelector to function-based
DanielMicrosoft Oct 13, 2025
cafe4dc
Merge branch 'dev' of https://github.com/Azure/aaz-dev-tools into 345…
DanielMicrosoft Oct 14, 2025
7ed997b
refactor: WSEditorCommandGroupContent to function-based
DanielMicrosoft Oct 14, 2025
37771cb
refactor: CommandGroupDeleteDialog
DanielMicrosoft Oct 14, 2025
d6460fa
refactor: CommandGroupDialog to function-based
DanielMicrosoft Oct 14, 2025
a89367c
refactor: WSEditorCommandGroupContent to function-based
DanielMicrosoft Oct 14, 2025
c027765
refactor: export command_prefix to own file
DanielMicrosoft Oct 14, 2025
4a5c25d
refactor: WorkspaceCreateDialog
DanielMicrosoft Oct 14, 2025
b5415f3
refactor: WSEditorCommandArgumentsContent
DanielMicrosoft Oct 14, 2025
26b0f55
refactor: WSECommandTree
DanielMicrosoft Oct 14, 2025
7d6613c
refactor : WSEditorExamplePicker
DanielMicrosoft Oct 14, 2025
b46c6da
refactor: move SwaggerItemSelector to own file
DanielMicrosoft Oct 14, 2025
dd31ed5
refactor: remove old comments
DanielMicrosoft Oct 14, 2025
c1a9324
refactor: remove old ocmments
DanielMicrosoft Oct 14, 2025
16d1826
refactor: extract ArgumentPropsReviewer to own component
DanielMicrosoft Oct 14, 2025
b2bf5a7
refactor: extract ArgumentNavigation to own file
DanielMicrosoft Oct 14, 2025
7fb3c18
refactor: extract ArgumentDialog to own file
DanielMicrosoft Oct 14, 2025
48d7bef
refactor: extract UnwrapClsDialog to own component
DanielMicrosoft Oct 14, 2025
a6849cb
feature: add tests for WSECArgumentSimilarPicker
DanielMicrosoft Oct 15, 2025
ff7253e
refactor: update WSECArgumentSimilarPicker to modern syntax
DanielMicrosoft Oct 15, 2025
2f57e0f
refactor: ArgNavBar to own file
DanielMicrosoft Oct 15, 2025
b188146
refactor: ArReviewer to own component
DanielMicrosoft Oct 15, 2025
bb63475
refactor: ExampleDialog extracted to own file
DanielMicrosoft Oct 15, 2025
4e92b64
refactor: handle conflict
DanielMicrosoft Oct 15, 2025
2e8e37f
refactor: extract AddSubcommandDialog
DanielMicrosoft Oct 15, 2025
3ed73a1
refactor: extract CommandDeleteDialog
DanielMicrosoft Oct 15, 2025
0c48a57
refactor: extract Outputcard
DanielMicrosoft Oct 15, 2025
f02d380
refactor: address console error about App render
DanielMicrosoft Oct 15, 2025
0ce767a
refactor: remove reportWebVitals
DanielMicrosoft Oct 15, 2025
81da6e0
refactor: move out flattendialog
DanielMicrosoft Oct 15, 2025
d02a4c9
refactor: move ArgumentsContent components to own sub-dir
DanielMicrosoft Oct 15, 2025
bc0605f
refactor: move out Outputdialog to own file
DanielMicrosoft Oct 15, 2025
e497b52
refactor: move out WSEditorCommandContent to own dir
DanielMicrosoft Oct 15, 2025
fb0b923
refactor: update syntax for Outputcard
DanielMicrosoft Oct 15, 2025
34f34b4
refactor: WSEditorCommandContent to function-based component
DanielMicrosoft Oct 15, 2025
f947e10
refactor: get WSEditorCommandCOntent tests passing
DanielMicrosoft Oct 15, 2025
d06dd20
refactor: start to export interfaces
DanielMicrosoft Oct 15, 2025
a6e6760
refactor: move WSEditorCommandGroupContenet and sub-components to own…
DanielMicrosoft Oct 15, 2025
23fcdff
refactor: change dir names to match main component in dir
DanielMicrosoft Oct 15, 2025
2530315
refactor: change dir names to match main component in dir
DanielMicrosoft Oct 15, 2025
1819819
feature: add unit tests for DecodeArgs
DanielMicrosoft Oct 15, 2025
2509bc9
refactor: extract decodeArgs to utils
DanielMicrosoft Oct 15, 2025
a82ea13
refactor: extract CommandDialog
DanielMicrosoft Oct 15, 2025
e4ea4b7
refactor: swagger picker into common
DanielMicrosoft Oct 15, 2025
eb56185
refactor: delete old swagger picker
DanielMicrosoft Oct 15, 2025
82881e0
refactor: move WSEditor.tsx into own dir
DanielMicrosoft Oct 15, 2025
22e7b7c
refactor: move WSEditorCommandTree into same dir
DanielMicrosoft Oct 15, 2025
7ead189
refactor: move Toolbar
DanielMicrosoft Oct 15, 2025
f92673c
refactor: move workspaceselectors
DanielMicrosoft Oct 15, 2025
20b6fe0
refactor: move examplepicker
DanielMicrosoft Oct 15, 2025
854e343
refactor: remove dupe file
DanielMicrosoft Oct 15, 2025
4e85d66
refactor: change dir name
DanielMicrosoft Oct 15, 2025
46fb23f
refactor: WorkspaceSelector to change React import style
DanielMicrosoft Oct 16, 2025
c5dc703
refactor: WSEditorExportDialog to function-based
DanielMicrosoft Oct 16, 2025
c5d740d
refactor: WSEditorSwaggerReloadDialog to function-based
DanielMicrosoft Oct 16, 2025
79a4621
refactor: WSEditorToolbar to function-based
DanielMicrosoft Oct 16, 2025
3a9c760
refactor: WSRenameDialog to function-based
DanielMicrosoft Oct 16, 2025
53c008e
refactor: WSrenameDialog to async/await pattern
DanielMicrosoft Oct 16, 2025
39fa2b3
refactor: WSEditorDeleteDialog to modern syntax
DanielMicrosoft Oct 16, 2025
8d93131
refactor: ArgumentDialog extract method and add unit tests
DanielMicrosoft Oct 16, 2025
3f9ea93
refactor: address ArgumentNavigation typescript issues
DanielMicrosoft Oct 16, 2025
e92c526
refactor: address ts interface issues in ArgumentPropsReviewer
DanielMicrosoft Oct 16, 2025
f9848c7
refactor: change named imports for CommandDeleteDialog
DanielMicrosoft Oct 16, 2025
428777c
refactor: CommandDeleteDialog to async/await
DanielMicrosoft Oct 16, 2025
1e847f1
Refactor: index.tsx to index.ts
DanielMicrosoft Oct 16, 2025
a9954e7
refactor: extract spliceArgOptionsString
DanielMicrosoft Oct 16, 2025
5439a2f
refactor: WSEditorCommandContent hook bug fixes
DanielMicrosoft Oct 16, 2025
980f819
refactor: WSEditor add interface
DanielMicrosoft Oct 16, 2025
c6943bc
refactor: WSEditor to async/await pattern
DanielMicrosoft Oct 16, 2025
7d31245
refactor: WSEditor to function expresion
DanielMicrosoft Oct 16, 2025
3e5524d
refactor: WSEditorSwaggerPicker to function-based
DanielMicrosoft Oct 16, 2025
e3b4d28
refactor: WSEditorSwaggerPicker bug fixes and hook extraction
DanielMicrosoft Oct 16, 2025
78284b3
refactor: remove unused CommandsPage and references
DanielMicrosoft Oct 18, 2025
f37d703
refactor: rename AppAppBar to AppNavBar
DanielMicrosoft Oct 18, 2025
7da9762
refactor: AppNavBar to function-based
DanielMicrosoft Oct 18, 2025
4240325
Refactor: EditorPageLayout to modern syntax
DanielMicrosoft Oct 18, 2025
6242eca
refactor: PageLayout to modern syntax
DanielMicrosoft Oct 18, 2025
d89cdc9
refactor: CLIInstruction to function-based
DanielMicrosoft Oct 18, 2025
6274d17
refactor: CLIModGeneratorProfileTabs
DanielMicrosoft Oct 18, 2025
e7bc5e6
Refactor: CLIModGeneratorToolBar to function based
DanielMicrosoft Oct 18, 2025
373abe7
refactor: CLIPage to function-based
DanielMicrosoft Oct 18, 2025
293adad
refactor: interfaces for CLI view into /interfaces/ dir
DanielMicrosoft Oct 18, 2025
878f8ec
refactor: CLIModGeneratorProfileCommandTree remove unused method
DanielMicrosoft Oct 18, 2025
8b30fba
refactor: remove unused interfaces
DanielMicrosoft Oct 18, 2025
68332b6
feature: add tests for CLIModGeneratorProfileCommandTree
DanielMicrosoft Oct 18, 2025
8371c55
refactor: extract CommandGroupItem
DanielMicrosoft Oct 18, 2025
b52bad3
refactor: add displayName for CommandGroupItem to find in DOM
DanielMicrosoft Oct 18, 2025
2d91a75
refactor: extract COmmandItem to own file
DanielMicrosoft Oct 18, 2025
20100ef
Refactor: CommandItem components to named immport and function expres…
DanielMicrosoft Oct 18, 2025
7426a99
refactor: methods to camelCase
DanielMicrosoft Oct 19, 2025
324ad0d
refactor: extract GenerateDialog
DanielMicrosoft Oct 19, 2025
7b0ad7d
refactor: extract commandTreeUtils
DanielMicrosoft Oct 19, 2025
d59f016
refactor: CLIModuleGenerator named imports
DanielMicrosoft Oct 19, 2025
eb61cb6
refactor: extract useSpecsCommandTree
DanielMicrosoft Oct 19, 2025
327f835
refactor: remove redundant import/exports
DanielMicrosoft Oct 19, 2025
58e1f57
refactor: move react component files to /components
DanielMicrosoft Oct 19, 2025
0546acc
refactor: delete unused legacy files from CRA
DanielMicrosoft Oct 19, 2025
4962ba3
refactor: fix some typos/grammar
DanielMicrosoft Oct 19, 2025
6fac297
fix: testing if this fixes pipeline issues
DanielMicrosoft Oct 20, 2025
686f010
fix: typespec resource loading bug
DanielMicrosoft Oct 20, 2025
4d098f0
Merge branch 'dev' of https://github.com/Azure/aaz-dev-tools into 345…
DanielMicrosoft Oct 20, 2025
18d3651
feature: add test for pre-pop bug
DanielMicrosoft Oct 21, 2025
b80125f
fix: default plane workspace create bug fix
DanielMicrosoft Oct 21, 2025
f7f217a
fix: auto expand bug
DanielMicrosoft Oct 21, 2025
ff951c9
fix: type param included
DanielMicrosoft Oct 22, 2025
4bc0c4f
fix: hide already loaded resources from sawgger picker"
DanielMicrosoft Oct 22, 2025
a23d22a
fix: update all fix
DanielMicrosoft Oct 22, 2025
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
419 changes: 419 additions & 0 deletions src/web/src/__tests__/components/WSECArgumentSimilarPicker.test.tsx

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/web/src/__tests__/components/WSEditor.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
import { vi } from "vitest";
import { MemoryRouter } from "react-router-dom";
import { WSEditor } from "../../views/workspace/WSEditor";
import { WSEditor } from "../../views/workspace/components/WSEditor";
import { workspaceApi, specsApi, errorHandlerApi } from "../../services";

vi.mock("../../views/workspace/WSEditorToolBar", () => ({
vi.mock("../../views/workspace/components/WSEditor/WSEditorToolBar", () => ({
default: ({ workspaceName, onHomePage, onGenerate, onDelete, onModify }: any) => (
<div data-testid="ws-editor-toolbar">
<span data-testid="workspace-name">{workspaceName}</span>
Expand All @@ -24,7 +24,7 @@ vi.mock("../../views/workspace/WSEditorToolBar", () => ({
),
}));

vi.mock("../../views/workspace/WSEditorCommandTree", () => ({
vi.mock("../../views/workspace/components/WSEditor/WSEditorCommandTree", () => ({
default: ({ onSelected, onToggle, onAdd, onReload, selected, expanded, onEditClientConfig }: any) => (
<div data-testid="ws-editor-command-tree">
<button onClick={() => onSelected("command:test-command")} data-testid="select-command">
Expand Down Expand Up @@ -55,7 +55,7 @@ vi.mock("../../views/workspace/WSEditorCommandTree", () => ({
CommandTreeNode: {},
}));

vi.mock("../../views/workspace/WSEditorCommandGroupContent", () => ({
vi.mock("../../views/workspace/components/WSEditorCommandGroupContent", () => ({
default: ({ commandGroup, onUpdateCommandGroup }: any) => (
<div data-testid="ws-editor-command-group-content">
<span data-testid="command-group-id">{commandGroup.id}</span>
Expand All @@ -70,7 +70,7 @@ vi.mock("../../views/workspace/WSEditorCommandGroupContent", () => ({
ResponseCommandGroups: {},
}));

vi.mock("../../views/workspace/WSEditorCommandContent", () => ({
vi.mock("../../views/workspace/components/WSEditorCommandContent", () => ({
default: ({ previewCommand, onUpdateCommand }: any) => (
<div data-testid="ws-editor-command-content">
<span data-testid="command-id">{previewCommand.id}</span>
Expand All @@ -85,7 +85,7 @@ vi.mock("../../views/workspace/WSEditorCommandContent", () => ({
ResponseCommand: {},
}));

vi.mock("../../views/workspace/WSEditorSwaggerPicker", () => ({
vi.mock("../../views/workspace/components/WSEditorSwaggerPicker", () => ({
default: ({ plane, workspaceName, onClose }: any) => (
<div data-testid="ws-editor-swagger-picker">
<span data-testid="picker-plane">{plane}</span>
Expand All @@ -100,7 +100,7 @@ vi.mock("../../views/workspace/WSEditorSwaggerPicker", () => ({
),
}));

vi.mock("../../views/workspace/WSEditorClientConfig", () => ({
vi.mock("../../views/workspace/components/WSEditor/WSEditorClientConfig", () => ({
default: ({ workspaceUrl, open, onClose }: any) =>
open ? (
<div data-testid="ws-editor-client-config-dialog">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { describe, it, expect, beforeEach, vi } from "vitest";
import { screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { render } from "../test-utils";
import WSEditorClientConfigDialog from "../../views/workspace/WSEditorClientConfig";
import WSEditorClientConfigDialog from "../../views/workspace/components/WSEditor/WSEditorClientConfig";
import { workspaceApi, specsApi, errorHandlerApi } from "../../services";

vi.mock("../../services", () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { fireEvent, screen } from "@testing-library/react";
import WSEditorCommandArgumentsContent from "../../views/workspace/WSEditorCommandArgumentsContent";
import type { CMDArg, ClsArgDefinitionMap } from "../../views/workspace/WSEditorCommandArgumentsContent";
import WSEditorCommandArgumentsContent from "../../views/workspace/components/WSEditorCommandArgumentsContent/WSEditorCommandArgumentsContent";
import { render } from "../test-utils";
import { ClsArgDefinitionMap, CMDArg } from "../../views/workspace/components/WSEditorCommandArgumentsContent";

vi.mock("../../services/commandApi");
vi.mock("../../services/errorHandlerApi");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { fireEvent, screen, waitFor, within } from "@testing-library/react";
import WSEditorCommandContent from "../../views/workspace/WSEditorCommandContent";
import type { Command, Example, Resource } from "../../views/workspace/WSEditorCommandContent";
import WSEditorCommandContent from "../../views/workspace/components/WSEditorCommandContent";
import type { Command, Example, Resource } from "../../views/workspace/interfaces";
import { render } from "../test-utils";
import { commandApi } from "../../services/commandApi";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { vi } from "vitest";
import WSEditorCommandGroupContent from "../../views/workspace/WSEditorCommandGroupContent";
import WSEditorCommandGroupContent from "../../views/workspace/components/WSEditorCommandGroupContent/WSEditorCommandGroupContent";
import * as commandApi from "../../services/commandApi";

interface CommandGroup {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { vi } from "vitest";
import WSEditorCommandTree, { CommandTreeNode, CommandTreeLeaf } from "../../views/workspace/WSEditorCommandTree";
import WSEditorCommandTree, {
CommandTreeNode,
CommandTreeLeaf,
} from "../../views/workspace/components/WSEditor/WSEditorCommandTree";

describe("WSEditorCommandTree", () => {
const mockLeaf: CommandTreeLeaf = {
Expand Down
187 changes: 186 additions & 1 deletion src/web/src/__tests__/components/WSEditorSwaggerPicker.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { fireEvent, screen, waitFor } from "@testing-library/react";
import WSEditorSwaggerPicker, { SwaggerItemSelector } from "../../views/workspace/WSEditorSwaggerPicker";
import WSEditorSwaggerPicker from "../../views/workspace/components/WSEditorSwaggerPicker";
import SwaggerItemSelector from "../../views/workspace/common/SwaggerItemSelector";
import { render } from "../test-utils";
import { workspaceApi, specsApi } from "../../services";

Expand Down Expand Up @@ -210,6 +211,71 @@ describe("WSEditorSwaggerPicker", () => {
expect(vi.mocked(workspaceApi).getWorkspaceResourcesByName).toHaveBeenCalledWith("test-workspace");
});
});

it("calls getResourceProvidersWithType with type=OpenAPI parameter", async () => {
render(<WSEditorSwaggerPicker {...defaultProps} />);

await waitFor(() => {
expect(vi.mocked(specsApi).getResourceProvidersWithType).toHaveBeenCalledWith(
"/Swagger/Specs/ResourceManagement/microsoft.storage",
"Swagger",
);
});
});

it("passes sourceOverride parameter when loading resource providers", async () => {
vi.mocked(workspaceApi).getSwaggerDefault.mockResolvedValue({
...mockSwaggerDefault,
source: "TypeSpec",
});

render(<WSEditorSwaggerPicker {...defaultProps} />);

await waitFor(() => {
expect(vi.mocked(specsApi).getResourceProvidersWithType).toHaveBeenCalledWith(
"/Swagger/Specs/ResourceManagement/microsoft.storage",
"TypeSpec",
);
});
});

it("reloads resources when existingResources change", async () => {
const { rerender } = render(<WSEditorSwaggerPicker {...defaultProps} />);

await waitFor(() => {
expect(vi.mocked(specsApi).getResourceProvidersWithType).toHaveBeenCalledTimes(1);
});

const newMockWorkspaceResources = [
...mockWorkspaceResources,
{
id: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/default",
},
];
vi.mocked(workspaceApi).getWorkspaceResourcesByName.mockResolvedValue(newMockWorkspaceResources);

rerender(<WSEditorSwaggerPicker {...defaultProps} />);

expect(vi.mocked(specsApi).getResourceProvidersWithType).toHaveBeenCalledWith(
"/Swagger/Specs/ResourceManagement/microsoft.storage",
"Swagger",
);
});

it("correctly filters existing resources when displaying available options", async () => {
const availableResources = [mockResources[0], mockResources[1]];
vi.mocked(specsApi).getProviderResources.mockResolvedValue(availableResources);

render(<WSEditorSwaggerPicker {...defaultProps} />);

await waitFor(() => {
expect(vi.mocked(workspaceApi).getWorkspaceResourcesByName).toHaveBeenCalledWith("test-workspace");
});

await waitFor(() => {
expect(vi.mocked(specsApi).getProviderResources).toHaveBeenCalled();
});
});
});

describe("Resource Selection", () => {
Expand Down Expand Up @@ -490,6 +556,125 @@ describe("WSEditorSwaggerPicker", () => {
});
});

describe("API Type Parameter Handling", () => {
it("includes type=OpenAPI parameter for Swagger sources", async () => {
vi.mocked(workspaceApi).getSwaggerDefault.mockResolvedValue({
...mockSwaggerDefault,
source: "Swagger",
});

render(<WSEditorSwaggerPicker {...defaultProps} />);

await waitFor(() => {
expect(vi.mocked(specsApi).getResourceProvidersWithType).toHaveBeenCalledWith(
"/Swagger/Specs/ResourceManagement/microsoft.storage",
"Swagger",
);
});
});

it("includes type=TypeSpec parameter for TypeSpec sources", async () => {
vi.mocked(workspaceApi).getSwaggerDefault.mockResolvedValue({
...mockSwaggerDefault,
source: "TypeSpec",
});

render(<WSEditorSwaggerPicker {...defaultProps} />);

await waitFor(() => {
expect(vi.mocked(specsApi).getResourceProvidersWithType).toHaveBeenCalledWith(
"/Swagger/Specs/ResourceManagement/microsoft.storage",
"TypeSpec",
);
});
});

it("uses default source when no source override is available", async () => {
vi.mocked(workspaceApi).getSwaggerDefault.mockResolvedValue({
...mockSwaggerDefault,
source: undefined,
});

render(<WSEditorSwaggerPicker {...defaultProps} />);

await waitFor(() => {
expect(vi.mocked(specsApi).getResourceProvidersWithType).toHaveBeenCalledWith(
"/Swagger/Specs/ResourceManagement/microsoft.storage",
undefined,
);
});
});
});

describe("Existing Resources State Management", () => {
it("reloads resources when existing workspace resources change", async () => {
render(<WSEditorSwaggerPicker {...defaultProps} />);

await waitFor(() => {
expect(vi.mocked(specsApi).getResourceProvidersWithType).toHaveBeenCalledTimes(1);
});

expect(vi.mocked(specsApi).getResourceProvidersWithType).toHaveBeenCalledWith(
"/Swagger/Specs/ResourceManagement/microsoft.storage",
"Swagger",
);
});

it("prevents duplicate resources from appearing in selector", async () => {
const duplicateResource = {
id: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}",
};

vi.mocked(workspaceApi).getWorkspaceResourcesByName.mockResolvedValue([duplicateResource]);
vi.mocked(specsApi).getProviderResources.mockResolvedValue([
{
...mockResources[0],
id: duplicateResource.id,
},
mockResources[1],
]);

render(<WSEditorSwaggerPicker {...defaultProps} />);

await waitFor(() => {
expect(vi.mocked(workspaceApi).getWorkspaceResourcesByName).toHaveBeenCalledWith("test-workspace");
});

await waitFor(() => {
expect(vi.mocked(specsApi).getProviderResources).toHaveBeenCalled();
});
});

it("handles empty workspace resources correctly", async () => {
vi.mocked(workspaceApi).getWorkspaceResourcesByName.mockResolvedValue([]);

render(<WSEditorSwaggerPicker {...defaultProps} />);

await waitFor(() => {
expect(vi.mocked(workspaceApi).getWorkspaceResourcesByName).toHaveBeenCalledWith("test-workspace");
});

await waitFor(() => {
expect(vi.mocked(specsApi).getResourceProvidersWithType).toHaveBeenCalledWith(
"/Swagger/Specs/ResourceManagement/microsoft.storage",
"Swagger",
);
});
});

it("validates existingResources dependency in useCallback", async () => {
render(<WSEditorSwaggerPicker {...defaultProps} />);

await waitFor(() => {
expect(vi.mocked(workspaceApi).getWorkspaceResourcesByName).toHaveBeenCalledWith("test-workspace");
});

await waitFor(() => {
expect(vi.mocked(specsApi).getResourceProvidersWithType).toHaveBeenCalledTimes(1);
});
});
});

describe("Close Functionality", () => {
it("calls onClose when close button is clicked", async () => {
const onCloseMock = vi.fn();
Expand Down
38 changes: 36 additions & 2 deletions src/web/src/__tests__/components/WorkspaceSelector.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { describe, it, expect, beforeEach, vi } from "vitest";
import { screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { render } from "../test-utils";
import WorkspaceSelector from "../../views/workspace/WorkspaceSelector";
import WorkspaceSelector from "../../views/workspace/components/WorkspaceInstruction/WorkspaceSelector";
import { workspaceApi } from "../../services";

vi.mock("../../services", () => ({
Expand Down Expand Up @@ -298,4 +298,38 @@ describe("Workspace Management", () => {
expect(result).toEqual(expectedResult);
});
});

describe("WorkspaceCreateDialog Component", () => {
it("should pre-select the first plane after planes are loaded in the create dialog", async () => {
const user = userEvent.setup();
const mockPlanes = [
{ name: "MgmtClient", displayName: "Control plane", moduleOptions: ["mod1", "mod2"] },
{ name: "DataPlaneClient", displayName: "Data plane", moduleOptions: ["mod3"] },
];
const { specsApi } = await import("../../services");
(specsApi.getPlanes as any).mockResolvedValue(mockPlanes);

render(<WorkspaceSelector name="Select Workspace" />);

await waitFor(() => {
expect(workspaceApi.getWorkspaces).toHaveBeenCalled();
});

const autocomplete = screen.getByLabelText("Select Workspace");
await user.click(autocomplete);
await user.type(autocomplete, "new-test-workspace");

const createOption = await screen.findByText('Create "new-test-workspace"');
await user.click(createOption);

await screen.findByText("Create a new workspace");

await waitFor(() => {
expect(specsApi.getPlanes).toHaveBeenCalled();
});

const planeDropdown = await screen.findByLabelText(/Plane/i);
expect(planeDropdown).toHaveValue("Control plane");
});
});
});
Loading