Skip to content

AI-native design editor. Open-source Figma alternative.

1.9 KB
Raw Blame
import type { Meta, StoryObj } from '@storybook/vue3-vite'
import { expect, userEvent, within } from 'storybook/test'

import PropertyPrimitivesStates from './examples/States.vue'

const meta = {
  title: 'Vue SDK/Primitives/Property Primitives',
  component: PropertyPrimitivesStates,
  tags: ['autodocs'],
  parameters: {
    docs: {
      description: {
        component:
          'Headless PropertySection, SegmentedControl, and typed PropertyList composition states.'
      }
    }
  }
} satisfies Meta<typeof PropertyPrimitivesStates>

export default meta
type Story = StoryObj<typeof meta>

export const StateMatrix: Story = {
  play: async ({ canvasElement }) => {
    const canvas = within(canvasElement)

    // Section titles are static, as in Figma: clicking one keeps the section open.
    await userEvent.click(canvas.getByText('Layer', { exact: true }))
    await expect(canvas.getByText('Section content')).toBeVisible()

    await userEvent.click(canvas.getByRole('button', { name: 'Add first effect' }))
    await expect(canvas.getByText('Drop shadow')).toBeVisible()

    const center = canvas.getByRole('button', { name: 'center' })
    await userEvent.click(center)
    await expect(center).toHaveAttribute('data-state', 'on')
    await userEvent.keyboard('{ArrowRight}{Enter}')
    await expect(canvas.getByRole('button', { name: 'right' })).toHaveAttribute('data-state', 'on')

    await userEvent.click(canvas.getByRole('button', { name: 'rotate-90' }))
    await expect(canvas.getByText('Action: rotate-90')).toBeVisible()

    const hiddenItem = canvas.getByText('Fill 2').closest('[data-slot="item"]')
    await expect(hiddenItem).toHaveAttribute('data-hidden')
    await userEvent.click(canvas.getByRole('button', { name: 'Show' }))
    await expect(hiddenItem).not.toHaveAttribute('data-hidden')

    await userEvent.click(canvas.getByRole('button', { name: 'Add fill' }))
    await expect(canvas.getByText('Fill 3')).toBeVisible()
  }
}