mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-19 20:14:43 +00:00
feat(ui): reposition providers around quality and local lanes
This commit is contained in:
1 parent
63b67f1c1c
commit
ad70f93b1b
6 files changed
+352
-121
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import i18n from '@/lib/i18n';
|
||||
import { OpenRouterQuickStart } from '@/components/profiles/openrouter-quick-start';
|
||||
import { render, screen } from '@tests/setup/test-utils';
|
||||
import { render, screen, userEvent } from '@tests/setup/test-utils';
|
||||
|
||||
vi.mock('@/hooks/use-openrouter-models', () => ({
|
||||
useOpenRouterReady: () => ({
|
||||
@@ -10,12 +10,40 @@ vi.mock('@/hooks/use-openrouter-models', () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('@/hooks/use-local-runtime-readiness', () => ({
|
||||
useLocalRuntimeReadiness: () => ({
|
||||
data: {
|
||||
runtimes: [
|
||||
{
|
||||
id: 'ollama',
|
||||
status: 'offline',
|
||||
endpoint: 'http://127.0.0.1:11434',
|
||||
commandHint: 'ollama serve',
|
||||
recommendedModel: 'gemma4:e4b',
|
||||
recommendedModelInstalled: false,
|
||||
},
|
||||
{
|
||||
id: 'llamacpp',
|
||||
status: 'ready',
|
||||
endpoint: 'http://127.0.0.1:8080',
|
||||
commandHint: './server --host 0.0.0.0 --port 8080 -m model.gguf',
|
||||
recommendedModel: null,
|
||||
recommendedModelInstalled: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
isLoading: false,
|
||||
}),
|
||||
}));
|
||||
|
||||
describe('OpenRouterQuickStart', () => {
|
||||
const props = {
|
||||
onOpenRouterClick: vi.fn(),
|
||||
onAlibabaCodingPlanClick: vi.fn(),
|
||||
onCliproxyClick: vi.fn(),
|
||||
onCustomClick: vi.fn(),
|
||||
onOllamaClick: vi.fn(),
|
||||
onLlamacppClick: vi.fn(),
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -25,16 +53,28 @@ describe('OpenRouterQuickStart', () => {
|
||||
it('prompts the user to select an existing API profile instead of showing the empty-state copy', () => {
|
||||
render(<OpenRouterQuickStart hasProfiles profileCount={1} {...props} />);
|
||||
|
||||
expect(screen.getByRole('heading', { name: 'Select an API profile' })).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole('heading', { name: 'Choose a profile or add another lane' })
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText('1 profile')).toBeInTheDocument();
|
||||
expect(screen.getByText(/You already have 1 profile in this workspace\./)).toBeInTheDocument();
|
||||
expect(screen.queryByText('No API profiles yet')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('keeps the original empty-state title when no API profiles exist', () => {
|
||||
it('shows the new local lane with readiness-aware calls to action', async () => {
|
||||
render(<OpenRouterQuickStart hasProfiles={false} profileCount={0} {...props} />);
|
||||
|
||||
expect(screen.getByRole('heading', { name: 'No API profiles yet' })).toBeInTheDocument();
|
||||
expect(screen.getAllByText('Recommended')).not.toHaveLength(0);
|
||||
expect(
|
||||
screen.getByRole('heading', { name: 'Choose your first profile lane' })
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText('Ollama + Gemma 4')).toBeInTheDocument();
|
||||
expect(screen.getByText('llama.cpp')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText('Run `ollama serve` to bring the local endpoint online.')
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText('Endpoint ready at http://127.0.0.1:8080')).toBeInTheDocument();
|
||||
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Set up Ollama' }));
|
||||
expect(props.onOllamaClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
@@ -33,7 +33,7 @@ describe('ProfileCreateDialog', () => {
|
||||
mutateAsync.mockReset();
|
||||
});
|
||||
|
||||
it('keeps advanced presets collapsed until explicitly opened and deselects custom after choosing a template', async () => {
|
||||
it('keeps More Presets visible by default and deselects custom after choosing a template', async () => {
|
||||
render(
|
||||
<ProfileCreateDialog
|
||||
open
|
||||
@@ -44,22 +44,14 @@ describe('ProfileCreateDialog', () => {
|
||||
);
|
||||
|
||||
expect(screen.getByText('Featured Providers')).toBeInTheDocument();
|
||||
expect(screen.getByText('More Presets')).toBeInTheDocument();
|
||||
expect(screen.getByText('Local Runtimes')).toBeInTheDocument();
|
||||
expect(screen.getByText('Alibaba Coding Plan')).toBeVisible();
|
||||
const morePresetsToggle = screen.getByRole('button', { name: /More Presets/i });
|
||||
expect(morePresetsToggle).toHaveAttribute('aria-expanded', 'false');
|
||||
expect(document.body.querySelectorAll('.overflow-x-auto')).toHaveLength(1);
|
||||
expect(document.body.querySelectorAll('.overflow-x-auto')).toHaveLength(2);
|
||||
|
||||
const customButton = screen.getByRole('button', { name: /Custom Endpoint/i });
|
||||
await userEvent.click(customButton);
|
||||
|
||||
expect(morePresetsToggle).toHaveAttribute('aria-expanded', 'false');
|
||||
expect(document.body.querySelectorAll('.overflow-x-auto')).toHaveLength(1);
|
||||
|
||||
await userEvent.click(morePresetsToggle);
|
||||
|
||||
expect(morePresetsToggle).toHaveAttribute('aria-expanded', 'true');
|
||||
expect(document.body.querySelectorAll('.overflow-x-auto')).toHaveLength(2);
|
||||
|
||||
const glmButton = screen.getByText('GLM').closest('button');
|
||||
expect(glmButton).not.toBeNull();
|
||||
if (!glmButton) {
|
||||
@@ -67,10 +59,19 @@ describe('ProfileCreateDialog', () => {
|
||||
}
|
||||
await userEvent.click(glmButton);
|
||||
|
||||
expect(morePresetsToggle).toHaveAttribute('aria-expanded', 'true');
|
||||
await waitFor(() => {
|
||||
expect(customButton).not.toHaveClass('border-primary');
|
||||
});
|
||||
expect(glmButton).toHaveClass('border-primary');
|
||||
});
|
||||
|
||||
it('supports opening directly into the Ollama preset from the providers landing page', async () => {
|
||||
render(
|
||||
<ProfileCreateDialog open onOpenChange={vi.fn()} onSuccess={vi.fn()} initialMode="ollama" />
|
||||
);
|
||||
|
||||
expect(screen.getByDisplayValue('ollama')).toBeInTheDocument();
|
||||
expect(screen.getByDisplayValue('http://localhost:11434')).toBeInTheDocument();
|
||||
expect(screen.getByText('Local Runtimes')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user