-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '01/08/25-serialize-and-deserialize-state' into ser/dese…
…r-with-new-state-management
- Loading branch information
Showing
20 changed files
with
749 additions
and
314 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
34 changes: 34 additions & 0 deletions
34
packages/ui-components/src/__tests__/DeploymentTile.test.ts
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,34 @@ | ||
import { render, screen } from '@testing-library/svelte'; | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import { goto } from '$app/navigation'; | ||
import DeploymentTile from '../lib/components/deployment/DeploymentTile.svelte'; | ||
|
||
// Mock the goto function | ||
vi.mock('$app/navigation', () => ({ | ||
goto: vi.fn() | ||
})); | ||
|
||
describe('DeploymentTile', () => { | ||
const mockProps = { | ||
strategyName: 'test-strategy', | ||
key: 'test-key', | ||
name: 'Test Deployment', | ||
description: 'This is a test deployment description' | ||
}; | ||
|
||
it('renders the deployment name and description', () => { | ||
render(DeploymentTile, mockProps); | ||
|
||
expect(screen.getByText('Test Deployment')).toBeInTheDocument(); | ||
expect(screen.getByText('This is a test deployment description')).toBeInTheDocument(); | ||
}); | ||
|
||
it('navigates to the correct URL when clicked', async () => { | ||
const { getByRole } = render(DeploymentTile, mockProps); | ||
|
||
const button = getByRole('button'); | ||
await button.click(); | ||
|
||
expect(goto).toHaveBeenCalledWith('/deploy/test-strategy/test-key'); | ||
}); | ||
}); |
71 changes: 71 additions & 0 deletions
71
packages/ui-components/src/__tests__/DeploymentsSection.test.ts
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,71 @@ | ||
import { render, screen } from '@testing-library/svelte'; | ||
import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
import DeploymentsSection from '../lib/components/deployment/DeploymentsSection.svelte'; | ||
import { DotrainOrderGui } from '@rainlanguage/orderbook/js_api'; | ||
|
||
// Mock the DotrainOrderGui | ||
vi.mock('@rainlanguage/orderbook/js_api', () => ({ | ||
DotrainOrderGui: { | ||
getDeploymentDetails: vi.fn() | ||
} | ||
})); | ||
|
||
describe('DeploymentsSection', () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('should render deployments when data is available', async () => { | ||
const mockDeployments = new Map([ | ||
['key1', { name: 'Deployment 1', description: 'Description 1' }], | ||
['key2', { name: 'Deployment 2', description: 'Description 2' }] | ||
]); | ||
|
||
vi.mocked(DotrainOrderGui.getDeploymentDetails).mockResolvedValue(mockDeployments); | ||
|
||
render(DeploymentsSection, { | ||
props: { | ||
dotrain: 'test-dotrain', | ||
strategyName: 'Test Strategy' | ||
} | ||
}); | ||
|
||
// Wait for deployments to load | ||
const deployment1 = await screen.findByText('Deployment 1'); | ||
const deployment2 = await screen.findByText('Deployment 2'); | ||
|
||
expect(deployment1).toBeInTheDocument(); | ||
expect(deployment2).toBeInTheDocument(); | ||
}); | ||
|
||
it('should handle error when fetching deployments fails', async () => { | ||
vi.mocked(DotrainOrderGui.getDeploymentDetails).mockRejectedValue(new Error('API Error')); | ||
|
||
render(DeploymentsSection, { | ||
props: { | ||
dotrain: 'test-dotrain', | ||
strategyName: 'Test Strategy' | ||
} | ||
}); | ||
|
||
const errorMessage = await screen.findByText( | ||
'Error loading deployments: Error getting deployments.' | ||
); | ||
expect(errorMessage).toBeInTheDocument(); | ||
}); | ||
|
||
it('should fetch deployments when dotrain prop changes', async () => { | ||
const { rerender } = render(DeploymentsSection, { | ||
props: { | ||
dotrain: '', | ||
strategyName: 'Test Strategy' | ||
} | ||
}); | ||
|
||
expect(DotrainOrderGui.getDeploymentDetails).not.toHaveBeenCalled(); | ||
|
||
await rerender({ dotrain: 'new-dotrain', strategyName: 'Test Strategy' }); | ||
|
||
expect(DotrainOrderGui.getDeploymentDetails).toHaveBeenCalledWith('new-dotrain'); | ||
}); | ||
}); |
Oops, something went wrong.