ChatSidebar.stories.svelte 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <script module lang="ts">
  2. import { defineMeta } from '@storybook/addon-svelte-csf';
  3. import ChatSidebar from '$lib/components/app/chat/ChatSidebar/ChatSidebar.svelte';
  4. import { waitFor } from 'storybook/test';
  5. import { screen } from 'storybook/test';
  6. const { Story } = defineMeta({
  7. title: 'Components/ChatSidebar',
  8. component: ChatSidebar,
  9. parameters: {
  10. layout: 'centered'
  11. }
  12. });
  13. // Mock conversations for the sidebar
  14. const mockConversations: DatabaseConversation[] = [
  15. {
  16. id: 'conv-1',
  17. name: 'Getting Started with AI',
  18. lastModified: Date.now() - 1000 * 60 * 5, // 5 minutes ago
  19. currNode: 'msg-1'
  20. },
  21. {
  22. id: 'conv-2',
  23. name: 'Python Programming Help',
  24. lastModified: Date.now() - 1000 * 60 * 60 * 2, // 2 hours ago
  25. currNode: 'msg-2'
  26. },
  27. {
  28. id: 'conv-3',
  29. name: 'Creative Writing Ideas',
  30. lastModified: Date.now() - 1000 * 60 * 60 * 24, // 1 day ago
  31. currNode: 'msg-3'
  32. },
  33. {
  34. id: 'conv-4',
  35. name: 'This is a very long conversation title that should be truncated properly when displayed',
  36. lastModified: Date.now() - 1000 * 60 * 60 * 24 * 3, // 3 days ago
  37. currNode: 'msg-4'
  38. },
  39. {
  40. id: 'conv-5',
  41. name: 'Math Problem Solving',
  42. lastModified: Date.now() - 1000 * 60 * 60 * 24 * 7, // 1 week ago
  43. currNode: 'msg-5'
  44. }
  45. ];
  46. </script>
  47. <Story
  48. asChild
  49. name="Default"
  50. play={async () => {
  51. const { conversationsStore } = await import('$lib/stores/conversations.svelte');
  52. waitFor(() => setTimeout(() => {
  53. conversationsStore.conversations = mockConversations;
  54. }, 0));
  55. }}
  56. >
  57. <div class="flex-column h-full h-screen w-72 bg-background">
  58. <ChatSidebar />
  59. </div>
  60. </Story>
  61. <Story
  62. asChild
  63. name="SearchActive"
  64. play={async ({ userEvent }) => {
  65. const { conversationsStore } = await import('$lib/stores/conversations.svelte');
  66. waitFor(() => setTimeout(() => {
  67. conversationsStore.conversations = mockConversations;
  68. }, 0));
  69. const searchTrigger = screen.getByText('Search conversations');
  70. userEvent.click(searchTrigger);
  71. }}
  72. >
  73. <div class="flex-column h-full h-screen w-72 bg-background">
  74. <ChatSidebar />
  75. </div>
  76. </Story>
  77. <Story
  78. asChild
  79. name="Empty"
  80. play={async () => {
  81. // Mock empty conversations store
  82. const { conversationsStore } = await import('$lib/stores/conversations.svelte');
  83. conversationsStore.conversations = [];
  84. }}
  85. >
  86. <div class="flex-column h-full h-screen w-72 bg-background">
  87. <ChatSidebar />
  88. </div>
  89. </Story>