|
|
@@ -3,17 +3,18 @@ import ApiConfigManager from "../ApiConfigManager"
|
|
|
|
|
|
// Mock VSCode components
|
|
|
jest.mock("@vscode/webview-ui-toolkit/react", () => ({
|
|
|
- VSCodeButton: ({ children, onClick, title, disabled }: any) => (
|
|
|
- <button onClick={onClick} title={title} disabled={disabled}>
|
|
|
+ VSCodeButton: ({ children, onClick, title, disabled, "data-testid": dataTestId }: any) => (
|
|
|
+ <button onClick={onClick} title={title} disabled={disabled} data-testid={dataTestId}>
|
|
|
{children}
|
|
|
</button>
|
|
|
),
|
|
|
- VSCodeTextField: ({ value, onInput, placeholder, onKeyDown }: any) => (
|
|
|
+ VSCodeTextField: ({ value, onInput, placeholder, onKeyDown, "data-testid": dataTestId }: any) => (
|
|
|
<input
|
|
|
value={value}
|
|
|
onChange={(e) => onInput(e)}
|
|
|
placeholder={placeholder}
|
|
|
onKeyDown={onKeyDown}
|
|
|
+ data-testid={dataTestId}
|
|
|
ref={undefined} // Explicitly set ref to undefined to avoid warning
|
|
|
/>
|
|
|
),
|
|
|
@@ -44,6 +45,24 @@ jest.mock("@/components/ui/dialog", () => ({
|
|
|
DialogTitle: ({ children }: any) => <div data-testid="dialog-title">{children}</div>,
|
|
|
}))
|
|
|
|
|
|
+// Mock UI components
|
|
|
+jest.mock("@/components/ui", () => ({
|
|
|
+ Button: ({ children, onClick, disabled, variant, "data-testid": dataTestId }: any) => (
|
|
|
+ <button onClick={onClick} disabled={disabled} data-testid={dataTestId}>
|
|
|
+ {children}
|
|
|
+ </button>
|
|
|
+ ),
|
|
|
+ Input: ({ value, onInput, placeholder, onKeyDown, "data-testid": dataTestId }: any) => (
|
|
|
+ <input
|
|
|
+ value={value}
|
|
|
+ onChange={(e) => onInput(e)}
|
|
|
+ placeholder={placeholder}
|
|
|
+ onKeyDown={onKeyDown}
|
|
|
+ data-testid={dataTestId}
|
|
|
+ />
|
|
|
+ ),
|
|
|
+}))
|
|
|
+
|
|
|
describe("ApiConfigManager", () => {
|
|
|
const mockOnSelectConfig = jest.fn()
|
|
|
const mockOnDeleteConfig = jest.fn()
|
|
|
@@ -72,26 +91,26 @@ describe("ApiConfigManager", () => {
|
|
|
it("opens new profile dialog when clicking add button", () => {
|
|
|
render(<ApiConfigManager {...defaultProps} />)
|
|
|
|
|
|
- const addButton = screen.getByTitle("Add profile")
|
|
|
+ const addButton = screen.getByTestId("add-profile-button")
|
|
|
fireEvent.click(addButton)
|
|
|
|
|
|
expect(screen.getByTestId("dialog")).toBeVisible()
|
|
|
- expect(screen.getByText("New Configuration Profile")).toBeInTheDocument()
|
|
|
+ expect(screen.getByTestId("dialog-title")).toHaveTextContent("settings:providers.newProfile")
|
|
|
})
|
|
|
|
|
|
it("creates new profile with entered name", () => {
|
|
|
render(<ApiConfigManager {...defaultProps} />)
|
|
|
|
|
|
// Open dialog
|
|
|
- const addButton = screen.getByTitle("Add profile")
|
|
|
+ const addButton = screen.getByTestId("add-profile-button")
|
|
|
fireEvent.click(addButton)
|
|
|
|
|
|
// Enter new profile name
|
|
|
- const input = screen.getByPlaceholderText("Enter profile name")
|
|
|
+ const input = screen.getByTestId("new-profile-input")
|
|
|
fireEvent.input(input, { target: { value: "New Profile" } })
|
|
|
|
|
|
// Click create button
|
|
|
- const createButton = screen.getByText("Create Profile")
|
|
|
+ const createButton = screen.getByText("settings:providers.createProfile")
|
|
|
fireEvent.click(createButton)
|
|
|
|
|
|
expect(mockOnUpsertConfig).toHaveBeenCalledWith("New Profile")
|
|
|
@@ -101,21 +120,21 @@ describe("ApiConfigManager", () => {
|
|
|
render(<ApiConfigManager {...defaultProps} />)
|
|
|
|
|
|
// Open dialog
|
|
|
- const addButton = screen.getByTitle("Add profile")
|
|
|
+ const addButton = screen.getByTestId("add-profile-button")
|
|
|
fireEvent.click(addButton)
|
|
|
|
|
|
// Enter existing profile name
|
|
|
- const input = screen.getByPlaceholderText("Enter profile name")
|
|
|
+ const input = screen.getByTestId("new-profile-input")
|
|
|
fireEvent.input(input, { target: { value: "Default Config" } })
|
|
|
|
|
|
// Click create button to trigger validation
|
|
|
- const createButton = screen.getByText("Create Profile")
|
|
|
+ const createButton = screen.getByText("settings:providers.createProfile")
|
|
|
fireEvent.click(createButton)
|
|
|
|
|
|
// Verify error message
|
|
|
const dialogContent = getDialogContent()
|
|
|
const errorMessage = within(dialogContent).getByTestId("error-message")
|
|
|
- expect(errorMessage).toHaveTextContent("A profile with this name already exists")
|
|
|
+ expect(errorMessage).toHaveTextContent("settings:providers.nameExists")
|
|
|
expect(mockOnUpsertConfig).not.toHaveBeenCalled()
|
|
|
})
|
|
|
|
|
|
@@ -123,15 +142,15 @@ describe("ApiConfigManager", () => {
|
|
|
render(<ApiConfigManager {...defaultProps} />)
|
|
|
|
|
|
// Open dialog
|
|
|
- const addButton = screen.getByTitle("Add profile")
|
|
|
+ const addButton = screen.getByTestId("add-profile-button")
|
|
|
fireEvent.click(addButton)
|
|
|
|
|
|
// Enter empty name
|
|
|
- const input = screen.getByPlaceholderText("Enter profile name")
|
|
|
+ const input = screen.getByTestId("new-profile-input")
|
|
|
fireEvent.input(input, { target: { value: " " } })
|
|
|
|
|
|
// Verify create button is disabled
|
|
|
- const createButton = screen.getByText("Create Profile")
|
|
|
+ const createButton = screen.getByText("settings:providers.createProfile")
|
|
|
expect(createButton).toBeDisabled()
|
|
|
expect(mockOnUpsertConfig).not.toHaveBeenCalled()
|
|
|
})
|
|
|
@@ -140,7 +159,7 @@ describe("ApiConfigManager", () => {
|
|
|
render(<ApiConfigManager {...defaultProps} />)
|
|
|
|
|
|
// Start rename
|
|
|
- const renameButton = screen.getByTitle("Rename profile")
|
|
|
+ const renameButton = screen.getByTestId("rename-profile-button")
|
|
|
fireEvent.click(renameButton)
|
|
|
|
|
|
// Find input and enter new name
|
|
|
@@ -148,7 +167,7 @@ describe("ApiConfigManager", () => {
|
|
|
fireEvent.input(input, { target: { value: "New Name" } })
|
|
|
|
|
|
// Save
|
|
|
- const saveButton = screen.getByTitle("Save")
|
|
|
+ const saveButton = screen.getByTestId("save-rename-button")
|
|
|
fireEvent.click(saveButton)
|
|
|
|
|
|
expect(mockOnRenameConfig).toHaveBeenCalledWith("Default Config", "New Name")
|
|
|
@@ -158,7 +177,7 @@ describe("ApiConfigManager", () => {
|
|
|
render(<ApiConfigManager {...defaultProps} />)
|
|
|
|
|
|
// Start rename
|
|
|
- const renameButton = screen.getByTitle("Rename profile")
|
|
|
+ const renameButton = screen.getByTestId("rename-profile-button")
|
|
|
fireEvent.click(renameButton)
|
|
|
|
|
|
// Find input and enter existing name
|
|
|
@@ -166,13 +185,13 @@ describe("ApiConfigManager", () => {
|
|
|
fireEvent.input(input, { target: { value: "Another Config" } })
|
|
|
|
|
|
// Save to trigger validation
|
|
|
- const saveButton = screen.getByTitle("Save")
|
|
|
+ const saveButton = screen.getByTestId("save-rename-button")
|
|
|
fireEvent.click(saveButton)
|
|
|
|
|
|
// Verify error message
|
|
|
const renameForm = getRenameForm()
|
|
|
const errorMessage = within(renameForm).getByTestId("error-message")
|
|
|
- expect(errorMessage).toHaveTextContent("A profile with this name already exists")
|
|
|
+ expect(errorMessage).toHaveTextContent("settings:providers.nameExists")
|
|
|
expect(mockOnRenameConfig).not.toHaveBeenCalled()
|
|
|
})
|
|
|
|
|
|
@@ -180,7 +199,7 @@ describe("ApiConfigManager", () => {
|
|
|
render(<ApiConfigManager {...defaultProps} />)
|
|
|
|
|
|
// Start rename
|
|
|
- const renameButton = screen.getByTitle("Rename profile")
|
|
|
+ const renameButton = screen.getByTestId("rename-profile-button")
|
|
|
fireEvent.click(renameButton)
|
|
|
|
|
|
// Find input and enter empty name
|
|
|
@@ -188,7 +207,7 @@ describe("ApiConfigManager", () => {
|
|
|
fireEvent.input(input, { target: { value: " " } })
|
|
|
|
|
|
// Verify save button is disabled
|
|
|
- const saveButton = screen.getByTitle("Save")
|
|
|
+ const saveButton = screen.getByTestId("save-rename-button")
|
|
|
expect(saveButton).toBeDisabled()
|
|
|
expect(mockOnRenameConfig).not.toHaveBeenCalled()
|
|
|
})
|
|
|
@@ -205,7 +224,7 @@ describe("ApiConfigManager", () => {
|
|
|
it("allows deleting the current config when not the only one", () => {
|
|
|
render(<ApiConfigManager {...defaultProps} />)
|
|
|
|
|
|
- const deleteButton = screen.getByTitle("Delete profile")
|
|
|
+ const deleteButton = screen.getByTestId("delete-profile-button")
|
|
|
expect(deleteButton).not.toBeDisabled()
|
|
|
|
|
|
fireEvent.click(deleteButton)
|
|
|
@@ -215,7 +234,7 @@ describe("ApiConfigManager", () => {
|
|
|
it("disables delete button when only one config exists", () => {
|
|
|
render(<ApiConfigManager {...defaultProps} listApiConfigMeta={[{ id: "default", name: "Default Config" }]} />)
|
|
|
|
|
|
- const deleteButton = screen.getByTitle("Cannot delete the only profile")
|
|
|
+ const deleteButton = screen.getByTestId("delete-profile-button")
|
|
|
expect(deleteButton).toHaveAttribute("disabled")
|
|
|
})
|
|
|
|
|
|
@@ -223,7 +242,7 @@ describe("ApiConfigManager", () => {
|
|
|
render(<ApiConfigManager {...defaultProps} />)
|
|
|
|
|
|
// Start rename
|
|
|
- const renameButton = screen.getByTitle("Rename profile")
|
|
|
+ const renameButton = screen.getByTestId("rename-profile-button")
|
|
|
fireEvent.click(renameButton)
|
|
|
|
|
|
// Find input and enter new name
|
|
|
@@ -231,7 +250,7 @@ describe("ApiConfigManager", () => {
|
|
|
fireEvent.input(input, { target: { value: "New Name" } })
|
|
|
|
|
|
// Cancel
|
|
|
- const cancelButton = screen.getByTitle("Cancel")
|
|
|
+ const cancelButton = screen.getByTestId("cancel-rename-button")
|
|
|
fireEvent.click(cancelButton)
|
|
|
|
|
|
// Verify rename was not called
|
|
|
@@ -245,10 +264,10 @@ describe("ApiConfigManager", () => {
|
|
|
render(<ApiConfigManager {...defaultProps} />)
|
|
|
|
|
|
// Open dialog
|
|
|
- const addButton = screen.getByTitle("Add profile")
|
|
|
+ const addButton = screen.getByTestId("add-profile-button")
|
|
|
fireEvent.click(addButton)
|
|
|
|
|
|
- const input = screen.getByPlaceholderText("Enter profile name")
|
|
|
+ const input = screen.getByTestId("new-profile-input")
|
|
|
|
|
|
// Test Enter key
|
|
|
fireEvent.input(input, { target: { value: "New Profile" } })
|
|
|
@@ -264,7 +283,7 @@ describe("ApiConfigManager", () => {
|
|
|
render(<ApiConfigManager {...defaultProps} />)
|
|
|
|
|
|
// Start rename
|
|
|
- const renameButton = screen.getByTitle("Rename profile")
|
|
|
+ const renameButton = screen.getByTestId("rename-profile-button")
|
|
|
fireEvent.click(renameButton)
|
|
|
|
|
|
const input = screen.getByDisplayValue("Default Config")
|