import React from 'react'; import type { StoryObj } from '@storybook/react'; import { expect, within, waitFor } from 'storybook/test'; import ContentSidebarComponent from '../../ContentSidebar'; import type { CustomSidebarPanel } from '../../flowTypes'; const MockCustomPanel = React.forwardRef(({ title }, ref) => (

{title}

This is a custom sidebar panel content.

)); MockCustomPanel.displayName = 'MockCustomPanel'; const MockCustomBoxAIPanel = React.forwardRef((props, ref) => (

Custom Box AI Panel

This is a custom Box AI implementation provided by the consumer.

)); MockCustomBoxAIPanel.displayName = 'MockCustomBoxAIPanel'; const MockIcon = () => 📋; const MockBoxAIIcon = () => 🤖; const DISABLED_TOOLTIP = 'Box AI is not available for this file type'; const customPanelConfig: CustomSidebarPanel = { id: 'customPanel', path: 'customPanel', component: MockCustomPanel, title: 'Custom Panel', icon: MockIcon, }; const customBoxAIPanelConfig: CustomSidebarPanel = { id: 'boxai', path: 'boxai', component: MockCustomBoxAIPanel, title: 'Custom Box AI', icon: MockBoxAIIcon, }; const defaultFeatures = { ...global.FEATURE_FLAGS, metadata: { redesign: { enabled: true } }, boxai: { sidebar: { enabled: true } }, }; export default { title: 'Elements/ContentSidebar/tests/visual-regression-tests', component: ContentSidebarComponent, args: { detailsSidebarProps: { hasProperties: true, hasNotices: true, hasAccessStats: true, hasClassification: true, hasRetentionPolicy: true, }, features: global.FEATURE_FLAGS, fileId: global.FILE_ID, hasActivityFeed: true, hasMetadata: true, hasSkills: true, hasVersions: true, token: global.TOKEN, }, }; // Basic export const ContentSidebar: StoryObj = { args: { features: defaultFeatures }, }; export const withModernization: StoryObj = { args: { enableModernizedComponents: true }, }; export const ContentSidebarDetailsTab: StoryObj = { args: { hasActivityFeed: false, hasMetadata: false }, }; // Custom Panels export const WithMultipleCustomPanels: StoryObj = { args: { features: defaultFeatures, customSidebarPanels: [ customPanelConfig, { id: 'anotherCustomPanel', path: 'anotherCustomPanel', component: MockCustomPanel, title: 'Another Panel', icon: () => 📝, }, ], }, }; // Native Box AI export const NativeBoxAIDisabled: StoryObj = { args: { features: { ...defaultFeatures, boxai: { sidebar: { enabled: true, showOnlyNavButton: true, disabledTooltip: DISABLED_TOOLTIP } }, }, }, play: async ({ canvasElement }) => { const canvas = within(canvasElement); await waitFor( () => { const boxAiButton = canvas.getByTestId('sidebarboxai'); expect(boxAiButton).toHaveAttribute('aria-disabled', 'true'); expect(boxAiButton).toHaveClass('bdl-is-disabled'); expect(boxAiButton).toHaveAttribute('aria-selected', 'false'); }, { timeout: 5000 }, ); }, }; // Custom Box AI Panel export const WithCustomBoxAIPanel: StoryObj = { args: { features: { ...defaultFeatures, boxai: { sidebar: { enabled: false } } }, customSidebarPanels: [customBoxAIPanelConfig], }, play: async ({ canvasElement }) => { const canvas = within(canvasElement); await waitFor( () => { const boxAiButton = canvas.getByTestId('sidebarboxai'); expect(boxAiButton).toHaveAttribute('aria-selected', 'true'); expect(canvas.getByTestId('custom-boxai-panel')).toBeInTheDocument(); }, { timeout: 5000 }, ); }, };