Skip to content

Commit c3c2b57

Browse files
nedtwiggclaude
andcommitted
Add Storybook story for AppBar component
Mocks @tauri-apps/api/window via a Vite alias in viteFinal so the module-level getCurrentWindow() call doesn't crash Storybook. Stories cover the main content variants: default, home dir, long path, single shell, many shells, and path outside home. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7c5aff6 commit c3c2b57

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

lib/.storybook/main.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import type { StorybookConfig } from '@storybook/react-vite';
33
const config: StorybookConfig = {
44
stories: ['../src/**/*.stories.@(ts|tsx)'],
55
framework: '@storybook/react-vite',
6+
viteFinal: (config) => {
7+
config.resolve ??= {};
8+
config.resolve.alias = {
9+
...(config.resolve.alias as Record<string, string> ?? {}),
10+
'@tauri-apps/api/window': new URL('./tauri-window-mock.ts', import.meta.url).pathname,
11+
};
12+
return config;
13+
},
614
};
715

816
export default config;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const mockWindow = {
2+
isMaximized: () => Promise.resolve(false),
3+
onResized: (_callback: () => void) => Promise.resolve(() => {}),
4+
minimize: () => Promise.resolve(),
5+
toggleMaximize: () => Promise.resolve(),
6+
close: () => Promise.resolve(),
7+
};
8+
9+
export function getCurrentWindow() {
10+
return mockWindow;
11+
}

lib/src/stories/AppBar.stories.tsx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
import { AppBar } from '../../../standalone/src/AppBar';
3+
4+
const DEFAULT_SHELLS = [
5+
{ name: 'bash', path: '/bin/bash' },
6+
{ name: 'zsh', path: '/bin/zsh' },
7+
{ name: 'fish', path: '/usr/bin/fish' },
8+
];
9+
10+
function AppBarStory(props: React.ComponentProps<typeof AppBar>) {
11+
return (
12+
<div style={{ width: '100%' }}>
13+
<AppBar {...props} />
14+
</div>
15+
);
16+
}
17+
18+
const meta: Meta<typeof AppBarStory> = {
19+
title: 'Components/AppBar',
20+
component: AppBarStory,
21+
args: {
22+
projectDir: '/home/user/projects/mouseterm',
23+
homeDir: '/home/user',
24+
shells: DEFAULT_SHELLS,
25+
},
26+
};
27+
28+
export default meta;
29+
type Story = StoryObj<typeof AppBarStory>;
30+
31+
export const Default: Story = {};
32+
33+
export const HomeDirectory: Story = {
34+
args: {
35+
projectDir: '/home/user',
36+
homeDir: '/home/user',
37+
},
38+
};
39+
40+
export const LongPath: Story = {
41+
args: {
42+
projectDir: '/home/user/projects/very-deep/nested/directory/structure/my-project',
43+
homeDir: '/home/user',
44+
},
45+
};
46+
47+
export const SingleShell: Story = {
48+
args: {
49+
shells: [{ name: 'bash', path: '/bin/bash' }],
50+
},
51+
};
52+
53+
export const ManyShells: Story = {
54+
args: {
55+
shells: [
56+
{ name: 'bash', path: '/bin/bash' },
57+
{ name: 'zsh', path: '/bin/zsh' },
58+
{ name: 'fish', path: '/usr/bin/fish' },
59+
{ name: 'sh', path: '/bin/sh' },
60+
{ name: 'nu', path: '/usr/bin/nu' },
61+
],
62+
},
63+
};
64+
65+
export const AbsolutePathOutsideHome: Story = {
66+
args: {
67+
projectDir: '/var/www/my-site',
68+
homeDir: '/home/user',
69+
},
70+
};

0 commit comments

Comments
 (0)