Skip to content

Commit c4a55a5

Browse files
committed
fix: resolve integration test assertions and add Storybook design tokens
1 parent 7851639 commit c4a55a5

9 files changed

Lines changed: 229 additions & 2 deletions

contracts/tests/integration_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn integration_rebalance_rejects_corrupted_allocations() {
216216
});
217217

218218
let result = client.try_execute_rebalance(&pid, &Map::new(&env));
219-
assert_eq!(result, Err(Ok(Error::InvalidAllocationSum)));
219+
assert_eq!(result, Err(Error::InvalidAllocationSum));
220220
}
221221

222222
// ── Portfolio value USD view (#862) ────────────────────────────────────
@@ -319,7 +319,7 @@ fn integration_emergency_stop_blocks_rebalance() {
319319
});
320320

321321
let result = client.try_execute_rebalance(&pid, &Map::new(&env));
322-
assert_eq!(result, Err(Ok(Error::EmergencyStop)));
322+
assert_eq!(result, Err(Error::EmergencyStop));
323323

324324
client.set_emergency_stop(&false);
325325
let result = client.try_execute_rebalance(&pid, &Map::new(&env));
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { Meta, StoryObj } from '@storybook/react'
2+
import { AllocationSlider } from '../components/ui/AllocationSlider'
3+
4+
const meta: Meta<typeof AllocationSlider> = {
5+
title: 'Components/AllocationSlider',
6+
component: AllocationSlider,
7+
tags: ['autodocs'],
8+
argTypes: {
9+
onChange: { action: 'changed' },
10+
},
11+
}
12+
export default meta
13+
type Story = StoryObj<typeof AllocationSlider>
14+
15+
export const Default: Story = {
16+
args: { label: 'XLM allocation', value: 40 },
17+
}
18+
19+
export const Disabled: Story = {
20+
args: { label: 'BTC allocation', value: 30, disabled: true },
21+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type { Meta, StoryObj } from '@storybook/react'
2+
import { Button } from '../components/ui/Button'
3+
4+
const meta: Meta<typeof Button> = {
5+
title: 'Components/Button',
6+
component: Button,
7+
tags: ['autodocs'],
8+
argTypes: {
9+
variant: {
10+
control: 'select',
11+
options: ['primary', 'secondary', 'danger', 'ghost'],
12+
},
13+
size: {
14+
control: 'select',
15+
options: ['sm', 'md', 'lg'],
16+
},
17+
disabled: { control: 'boolean' },
18+
},
19+
}
20+
export default meta
21+
type Story = StoryObj<typeof Button>
22+
23+
export const Primary: Story = {
24+
args: { children: 'Primary action', variant: 'primary' },
25+
}
26+
27+
export const Secondary: Story = {
28+
args: { children: 'Secondary action', variant: 'secondary' },
29+
}
30+
31+
export const Danger: Story = {
32+
args: { children: 'Delete', variant: 'danger' },
33+
}
34+
35+
export const Loading: Story = {
36+
args: { children: 'Saving...', loading: true, disabled: true },
37+
}
38+
39+
export const Disabled: Story = {
40+
args: { children: 'Disabled', disabled: true },
41+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { Meta, StoryObj } from '@storybook/react'
2+
3+
const meta: Meta = {
4+
title: 'Design Tokens',
5+
tags: ['docs'],
6+
parameters: {
7+
docs: { description: { component: 'Core design tokens used across the frontend.' } },
8+
},
9+
}
10+
export default meta
11+
12+
type Story = StoryObj<{ tokens: Record<string, string> }>
13+
14+
export const Colors: Story = {
15+
args: {
16+
tokens: {
17+
background: 'bg-gray-50 dark:bg-gray-900',
18+
surface: 'bg-white dark:bg-gray-800',
19+
border: 'border-gray-200 dark:border-gray-700',
20+
mutedText: 'text-gray-500 dark:text-gray-400',
21+
primaryText: 'text-gray-900 dark:text-gray-100',
22+
primaryAction: 'bg-blue-600 hover:bg-blue-700 text-white',
23+
danger: 'bg-red-600 hover:bg-red-700 text-white',
24+
},
25+
},
26+
render: (args) => (
27+
<div className="grid grid-cols-2 gap-4">
28+
{Object.entries(args.tokens).map(([key, value]) => (
29+
<div key={key} className="flex items-center gap-3">
30+
<span className="rounded-md border border-gray-200 px-2 py-1 text-xs text-gray-600">{key}</span>
31+
<span className={`rounded-md px-2 py-1 text-xs ${value}`}>Aa</span>
32+
</div>
33+
))}
34+
</div>
35+
),
36+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { Meta, StoryObj } from '@storybook/react-vite';
2+
3+
import { fn } from 'storybook/test';
4+
5+
import { Header } from './Header';
6+
7+
const meta = {
8+
title: 'Example/Header',
9+
component: Header,
10+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
11+
tags: ['autodocs'],
12+
parameters: {
13+
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
14+
layout: 'fullscreen',
15+
},
16+
args: {
17+
onLogin: fn(),
18+
onLogout: fn(),
19+
onCreateAccount: fn(),
20+
},
21+
} satisfies Meta<typeof Header>;
22+
23+
export default meta;
24+
type Story = StoryObj<typeof meta>;
25+
26+
export const LoggedIn: Story = {
27+
args: {
28+
user: {
29+
name: 'Jane Doe',
30+
},
31+
},
32+
};
33+
34+
export const LoggedOut: Story = {};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { Meta, StoryObj } from '@storybook/react'
2+
import { Modal } from '../components/ui/Modal'
3+
import { Button } from '../components/ui/Button'
4+
5+
const meta: Meta<typeof Modal> = {
6+
title: 'Components/Modal',
7+
component: Modal,
8+
tags: ['autodocs'],
9+
}
10+
export default meta
11+
type Story = StoryObj<typeof Modal>
12+
13+
export const Default: Story = {
14+
args: {
15+
open: true,
16+
title: 'Delete your data?',
17+
description: 'This will reset the demo portfolio to its default state.',
18+
children: 'Proceeding will discard unsaved allocations.',
19+
footer: (
20+
<>
21+
<Button variant="secondary">Cancel</Button>
22+
<Button variant="danger">Confirm</Button>
23+
</>
24+
),
25+
},
26+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { Meta, StoryObj } from '@storybook/react-vite';
2+
3+
import { expect, userEvent, within } from 'storybook/test';
4+
5+
import { Page } from './Page';
6+
7+
const meta = {
8+
title: 'Example/Page',
9+
component: Page,
10+
parameters: {
11+
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
12+
layout: 'fullscreen',
13+
},
14+
} satisfies Meta<typeof Page>;
15+
16+
export default meta;
17+
type Story = StoryObj<typeof meta>;
18+
19+
export const LoggedOut: Story = {};
20+
21+
// More on component testing: https://storybook.js.org/docs/writing-tests/interaction-testing
22+
export const LoggedIn: Story = {
23+
play: async ({ canvasElement }) => {
24+
const canvas = within(canvasElement);
25+
const loginButton = canvas.getByRole('button', { name: /Log in/i });
26+
await expect(loginButton).toBeInTheDocument();
27+
await userEvent.click(loginButton);
28+
await expect(loginButton).not.toBeInTheDocument();
29+
30+
const logoutButton = canvas.getByRole('button', { name: /Log out/i });
31+
await expect(logoutButton).toBeInTheDocument();
32+
},
33+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { Meta, StoryObj } from '@storybook/react'
2+
import { PortfolioCard } from '../components/ui/PortfolioCard'
3+
import { Button } from '../components/ui/Button'
4+
5+
const meta: Meta<typeof PortfolioCard> = {
6+
title: 'Components/PortfolioCard',
7+
component: PortfolioCard,
8+
tags: ['autodocs'],
9+
}
10+
export default meta
11+
type Story = StoryObj<typeof PortfolioCard>
12+
13+
export const Default: Story = {
14+
args: {
15+
title: 'Total Value',
16+
value: '$10,000.00',
17+
change: 3.4,
18+
subtitle: 'Last rebalanced 2 hours ago',
19+
actions: <Button variant="secondary">Export</Button>,
20+
},
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { Meta, StoryObj } from '@storybook/react'
2+
import { Toast } from '../components/ui/Toast'
3+
4+
const meta: Meta<typeof Toast> = {
5+
title: 'Components/Toast',
6+
component: Toast,
7+
tags: ['autodocs'],
8+
}
9+
export default meta
10+
type Story = StoryObj<typeof Toast>
11+
12+
export const Info: Story = { args: { title: 'Info message', description: 'Something you should know.', tone: 'info' } }
13+
export const Success: Story = { args: { title: 'Success', description: 'Operation completed.', tone: 'success' } }
14+
export const Warning: Story = { args: { title: 'Warning', description: 'Please review before continuing.', tone: 'warning' } }
15+
export const Error: Story = { args: { title: 'Error', description: 'Something failed.', tone: 'error' } }

0 commit comments

Comments
 (0)