mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 12:21:13 -05:00
Prettier backfill
This commit is contained in:
@@ -1,71 +1,65 @@
|
||||
import React from 'react'
|
||||
import { render, screen, act } from '@testing-library/react'
|
||||
import { ExtensionStateContextProvider, useExtensionState } from '../ExtensionStateContext'
|
||||
import React from "react"
|
||||
import { render, screen, act } from "@testing-library/react"
|
||||
import { ExtensionStateContextProvider, useExtensionState } from "../ExtensionStateContext"
|
||||
|
||||
// Test component that consumes the context
|
||||
const TestComponent = () => {
|
||||
const { allowedCommands, setAllowedCommands, soundEnabled } = useExtensionState()
|
||||
return (
|
||||
<div>
|
||||
<div data-testid="allowed-commands">{JSON.stringify(allowedCommands)}</div>
|
||||
<div data-testid="sound-enabled">{JSON.stringify(soundEnabled)}</div>
|
||||
<button
|
||||
data-testid="update-button"
|
||||
onClick={() => setAllowedCommands(['npm install', 'git status'])}
|
||||
>
|
||||
Update Commands
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
const { allowedCommands, setAllowedCommands, soundEnabled } = useExtensionState()
|
||||
return (
|
||||
<div>
|
||||
<div data-testid="allowed-commands">{JSON.stringify(allowedCommands)}</div>
|
||||
<div data-testid="sound-enabled">{JSON.stringify(soundEnabled)}</div>
|
||||
<button data-testid="update-button" onClick={() => setAllowedCommands(["npm install", "git status"])}>
|
||||
Update Commands
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
describe('ExtensionStateContext', () => {
|
||||
it('initializes with empty allowedCommands array', () => {
|
||||
render(
|
||||
<ExtensionStateContextProvider>
|
||||
<TestComponent />
|
||||
</ExtensionStateContextProvider>
|
||||
)
|
||||
describe("ExtensionStateContext", () => {
|
||||
it("initializes with empty allowedCommands array", () => {
|
||||
render(
|
||||
<ExtensionStateContextProvider>
|
||||
<TestComponent />
|
||||
</ExtensionStateContextProvider>,
|
||||
)
|
||||
|
||||
expect(JSON.parse(screen.getByTestId('allowed-commands').textContent!)).toEqual([])
|
||||
})
|
||||
expect(JSON.parse(screen.getByTestId("allowed-commands").textContent!)).toEqual([])
|
||||
})
|
||||
|
||||
it('initializes with soundEnabled set to false', () => {
|
||||
render(
|
||||
<ExtensionStateContextProvider>
|
||||
<TestComponent />
|
||||
</ExtensionStateContextProvider>
|
||||
)
|
||||
it("initializes with soundEnabled set to false", () => {
|
||||
render(
|
||||
<ExtensionStateContextProvider>
|
||||
<TestComponent />
|
||||
</ExtensionStateContextProvider>,
|
||||
)
|
||||
|
||||
expect(JSON.parse(screen.getByTestId('sound-enabled').textContent!)).toBe(false)
|
||||
})
|
||||
expect(JSON.parse(screen.getByTestId("sound-enabled").textContent!)).toBe(false)
|
||||
})
|
||||
|
||||
it('updates allowedCommands through setAllowedCommands', () => {
|
||||
render(
|
||||
<ExtensionStateContextProvider>
|
||||
<TestComponent />
|
||||
</ExtensionStateContextProvider>
|
||||
)
|
||||
it("updates allowedCommands through setAllowedCommands", () => {
|
||||
render(
|
||||
<ExtensionStateContextProvider>
|
||||
<TestComponent />
|
||||
</ExtensionStateContextProvider>,
|
||||
)
|
||||
|
||||
act(() => {
|
||||
screen.getByTestId('update-button').click()
|
||||
})
|
||||
act(() => {
|
||||
screen.getByTestId("update-button").click()
|
||||
})
|
||||
|
||||
expect(JSON.parse(screen.getByTestId('allowed-commands').textContent!)).toEqual([
|
||||
'npm install',
|
||||
'git status'
|
||||
])
|
||||
})
|
||||
expect(JSON.parse(screen.getByTestId("allowed-commands").textContent!)).toEqual(["npm install", "git status"])
|
||||
})
|
||||
|
||||
it('throws error when used outside provider', () => {
|
||||
// Suppress console.error for this test since we expect an error
|
||||
const consoleSpy = jest.spyOn(console, 'error')
|
||||
consoleSpy.mockImplementation(() => {})
|
||||
it("throws error when used outside provider", () => {
|
||||
// Suppress console.error for this test since we expect an error
|
||||
const consoleSpy = jest.spyOn(console, "error")
|
||||
consoleSpy.mockImplementation(() => {})
|
||||
|
||||
expect(() => {
|
||||
render(<TestComponent />)
|
||||
}).toThrow('useExtensionState must be used within an ExtensionStateContextProvider')
|
||||
expect(() => {
|
||||
render(<TestComponent />)
|
||||
}).toThrow("useExtensionState must be used within an ExtensionStateContextProvider")
|
||||
|
||||
consoleSpy.mockRestore()
|
||||
})
|
||||
consoleSpy.mockRestore()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user