The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Move twenty-ui component behavior tests into stories (#25623)
Raphaël Bosi6b31f8af30a5
diff --git a/packages/twenty-ui/README.md b/packages/twenty-ui/README.mdindex 9df9f8c1b14..e4110cfa748 100644--- a/packages/twenty-ui/README.md+++ b/packages/twenty-ui/README.md@@ -68,6 +68,8 @@ import { Button } from 'twenty-ui/input';# Development+Component interaction and behavior tests belong in Storybook stories (`*.stories.tsx`) using `play` functions. Component unit tests are reserved for conformance (native props, refs, class names, rendering, and prop types). Keep non-interactive utility, hook, and token tests in the Vitest unit project; avoid duplicating story coverage there.+```bashnpx nx build twenty-ui # Build the library (dual ESM/CJS + types)npx nx storybook:serve:dev twenty-ui # Run Storybookdiff --git a/packages/twenty-ui/src/input/Checkbox/__stories__/Checkbox.stories.tsx b/packages/twenty-ui/src/input/Checkbox/__stories__/Checkbox.stories.tsxindex ef7a4ad79dd..cd1b7d8a54a 100644--- a/packages/twenty-ui/src/input/Checkbox/__stories__/Checkbox.stories.tsx+++ b/packages/twenty-ui/src/input/Checkbox/__stories__/Checkbox.stories.tsx@@ -1,4 +1,6 @@import { type Meta, type StoryObj } from '@storybook/react-vite';+import { useState } from 'react';+import { expect, fn, userEvent, within } from 'storybook/test';import {A11Y_DEFER_COLOR_CONTRAST,CatalogDecorator,@@ -22,6 +24,54 @@ const meta: Meta<typeof Checkbox> = {export default meta;type Story = StoryObj<typeof Checkbox>;+type ControlledCheckboxExampleProps = {+ onCheckedChange?: (checked: boolean) => void;+};++const ControlledCheckboxExample = ({+ onCheckedChange,+}: ControlledCheckboxExampleProps) => {+ const [checked, setChecked] = useState(false);++ return (+ <>+ <Checkbox+ checked={checked}+ onCheckedChange={onCheckedChange}+ aria-label="Controlled checkbox"+ />+ <button type="button" onClick={() => setChecked(true)}>+ Apply selection+ </button>+ </>+ );+};++export const Controlled: Story = {+ args: { onCheckedChange: fn() },+ decorators: [ComponentDecorator],+ render: (args) => (+ <ControlledCheckboxExample onCheckedChange={args.onCheckedChange} />+ ),+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const checkbox = canvas.getByRole('checkbox', {+ name: 'Controlled checkbox',+ });++ await userEvent.click(checkbox);++ await expect(args.onCheckedChange).toHaveBeenCalledWith(true);+ await expect(checkbox).not.toBeChecked();++ await userEvent.click(+ canvas.getByRole('button', { name: 'Apply selection' }),+ );++ await expect(checkbox).toBeChecked();+ },+};+export const Default: Story = {args: {checked: false,diff --git a/packages/twenty-ui/src/input/Checkbox/__tests__/Checkbox.test.tsx b/packages/twenty-ui/src/input/Checkbox/__tests__/Checkbox.test.tsxdeleted file mode 100644index 85b25513e7e..00000000000--- a/packages/twenty-ui/src/input/Checkbox/__tests__/Checkbox.test.tsx+++ /dev/null@@ -1,37 +0,0 @@-import { render, screen } from '@testing-library/react';-import userEvent from '@testing-library/user-event';-import { vi } from 'vitest';--import { Checkbox } from '../Checkbox';--describe('Checkbox', () => {- it('keeps the rendered state controlled by the checked prop', async () => {- const user = userEvent.setup();- const onCheckedChange = vi.fn();- const { rerender } = render(- <Checkbox- checked={false}- onCheckedChange={onCheckedChange}- aria-label="Controlled checkbox"- />,- );- const checkbox = screen.getByRole('checkbox', {- name: 'Controlled checkbox',- });-- await user.click(checkbox);-- expect(onCheckedChange).toHaveBeenCalledWith(true);- expect(checkbox).not.toBeChecked();-- rerender(- <Checkbox- checked- onCheckedChange={onCheckedChange}- aria-label="Controlled checkbox"- />,- );-- expect(checkbox).toBeChecked();- });-});diff --git a/packages/twenty-ui/src/input/Field/__tests__/Field.test.tsx b/packages/twenty-ui/src/input/Field/__tests__/Field.test.tsxindex 283fce94e7c..5f25c1855c3 100644--- a/packages/twenty-ui/src/input/Field/__tests__/Field.test.tsx+++ b/packages/twenty-ui/src/input/Field/__tests__/Field.test.tsx@@ -1,6 +1,4 @@-import { render } from '@testing-library/react';import { type ReactNode } from 'react';-import { vi } from 'vitest';import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';@@ -43,19 +41,3 @@ runComponentConformance({wrapper: FieldRootWrapper,ownClassName: errorStyles.error,});--describe('Field.Label', () => {- it('throws outside Field.Root', () => {- const consoleErrorSpy = vi- .spyOn(console, 'error')- .mockImplementation(() => undefined);-- try {- expect(() => render(<Field.Label>Label</Field.Label>)).toThrow(- 'Base UI: FieldRootContext is missing',- );- } finally {- consoleErrorSpy.mockRestore();- }- });-});diff --git a/packages/twenty-ui/src/input/Input/__stories__/Input.stories.tsx b/packages/twenty-ui/src/input/Input/__stories__/Input.stories.tsxindex e14ece2838b..b2815fd37c8 100644--- a/packages/twenty-ui/src/input/Input/__stories__/Input.stories.tsx+++ b/packages/twenty-ui/src/input/Input/__stories__/Input.stories.tsx@@ -1,4 +1,5 @@import { type Meta, type StoryObj } from '@storybook/react-vite';+import { expect, userEvent, within } from 'storybook/test';import {A11Y_DEFER_COLOR_CONTRAST,@@ -42,6 +43,14 @@ export const WithField: Story = {<Field.Description>We never share it</Field.Description></Field.Root>),+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const input = canvas.getByRole('textbox', { name: 'Email' });++ await userEvent.click(canvas.getByText('Email'));++ await expect(input).toHaveFocus();+ },};type InputCatalogState = 'default' | 'focus' | 'invalid' | 'disabled';diff --git a/packages/twenty-ui/src/input/Input/__stories__/InputInteractions.stories.tsx b/packages/twenty-ui/src/input/Input/__stories__/InputInteractions.stories.tsxnew file mode 100644index 00000000000..854fe74e179--- /dev/null+++ b/packages/twenty-ui/src/input/Input/__stories__/InputInteractions.stories.tsx@@ -0,0 +1,130 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { useState } from 'react';+import { expect, fn, userEvent, within } from 'storybook/test';++import { Field } from '@ui/input/Field/Field';+import { ComponentDecorator } from '@ui/testing';++import { Input } from '../Input';+import styles from '../Input.module.scss';+import { type InputProps } from '../types/InputProps';++const ControlledInputExample = (props: InputProps) => {+ const [value, setValue] = useState('a');++ return (+ <>+ <Input {...props} value={value} />+ <button type="button" onClick={() => setValue('ab')}>+ Apply value+ </button>+ </>+ );+};++const FieldInputExample = (props: InputProps) => {+ const [disabled, setDisabled] = useState(false);++ return (+ <>+ <Field.Root invalid disabled={disabled}>+ <Input {...props} />+ </Field.Root>+ <button type="button" onClick={() => setDisabled(true)}>+ Disable input+ </button>+ </>+ );+};++const meta: Meta<typeof Input> = {+ title: 'UI/Input/Input/Interactions',+ component: Input,+ tags: ['!autodocs'],+ decorators: [ComponentDecorator],+ args: { 'aria-label': 'Name', onValueChange: fn() },+};++export default meta;+type Story = StoryObj<typeof Input>;++export const Uncontrolled: Story = {+ args: { defaultValue: 'a' },+ play: async ({ canvasElement, args }) => {+ const input = within(canvasElement).getByRole('textbox', { name: 'Name' });++ await userEvent.type(input, 'b');++ await expect(input).toHaveValue('ab');+ await expect(args.onValueChange).toHaveBeenCalledWith(+ 'ab',+ expect.objectContaining({ reason: 'none' }),+ );+ },+};++export const Controlled: Story = {+ render: (args) => <ControlledInputExample {...args} />,+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const input = canvas.getByRole('textbox', { name: 'Name' });++ await userEvent.type(input, 'b');++ await expect(args.onValueChange).toHaveBeenCalledWith(+ 'ab',+ expect.anything(),+ );+ await expect(input).toHaveValue('a');++ await userEvent.click(canvas.getByRole('button', { name: 'Apply value' }));++ await expect(input).toHaveValue('ab');+ },+};++export const Sizes: Story = {+ render: () => (+ <>+ <Input aria-label="Default size" />+ <Input aria-label="Small size" size="sm" />+ </>+ ),+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const defaultInput = canvas.getByRole('textbox', { name: 'Default size' });+ const smallInput = canvas.getByRole('textbox', { name: 'Small size' });++ await expect(defaultInput).toHaveClass(styles.md);+ await expect(smallInput).toHaveClass(styles.sm);+ await expect(smallInput).not.toHaveClass(styles.md);+ await expect(defaultInput.clientHeight).toBeGreaterThan(+ smallInput.clientHeight,+ );+ },+};++export const FieldStates: Story = {+ render: (args) => <FieldInputExample {...args} />,+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const input = canvas.getByRole('textbox', { name: 'Name' });++ await expect(input).toHaveAttribute('aria-invalid', 'true');+ await expect(input).toHaveAttribute('data-invalid');+ await expect(input).toBeEnabled();++ await userEvent.click(+ canvas.getByRole('button', { name: 'Disable input' }),+ );++ await expect(input).not.toHaveAttribute('aria-invalid');+ await expect(input).toHaveAttribute('data-invalid');+ await expect(input).toBeDisabled();++ await userEvent.type(input, 'ignored');++ await expect(input).toHaveValue('');+ await expect(args.onValueChange).not.toHaveBeenCalled();+ },+};diff --git a/packages/twenty-ui/src/input/Input/__tests__/Input.test.tsx b/packages/twenty-ui/src/input/Input/__tests__/Input.test.tsxindex b255c648cd8..a63dc7b7b8c 100644--- a/packages/twenty-ui/src/input/Input/__tests__/Input.test.tsx+++ b/packages/twenty-ui/src/input/Input/__tests__/Input.test.tsx@@ -1,11 +1,5 @@-import { render, screen } from '@testing-library/react';-import userEvent from '@testing-library/user-event';-import { vi } from 'vitest';-import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';-import { Field } from '@ui/input/Field/Field';-import { Input } from '../Input';import styles from '../Input.module.scss';@@ -16,96 +10,3 @@ runComponentConformance({ownClassName: styles.input,renderPropTagName: 'input',});--describe('Input', () => {- it('updates its value and reports it when uncontrolled', async () => {- const user = userEvent.setup();- const onValueChange = vi.fn();-- render(- <Input- defaultValue="a"- onValueChange={onValueChange}- aria-label="Name"- />,- );-- const input = screen.getByRole('textbox', { name: 'Name' });-- await user.type(input, 'b');-- expect(input).toHaveValue('ab');- expect(onValueChange).toHaveBeenCalledWith(- 'ab',- expect.objectContaining({ reason: 'none' }),- );- });-- it('keeps the rendered value controlled by the value prop', async () => {- const user = userEvent.setup();- const onValueChange = vi.fn();-- render(<Input value="a" onValueChange={onValueChange} aria-label="Name" />);-- const input = screen.getByRole('textbox', { name: 'Name' });-- await user.type(input, 'b');-- expect(onValueChange).toHaveBeenCalledWith('ab', expect.anything());- expect(input).toHaveValue('a');- });-- it('applies the medium size by default and the small size on demand', () => {- const { rerender } = render(<Input aria-label="Name" />);-- const input = screen.getByRole('textbox', { name: 'Name' });-- expect(input).toHaveClass(styles.md);-- rerender(<Input aria-label="Name" size="sm" />);-- expect(input).toHaveClass(styles.sm);- expect(input).not.toHaveClass(styles.md);- });-- it('is labelled and focused by Field.Label inside Field.Root', async () => {- const user = userEvent.setup();-- render(- <Field.Root>- <Field.Label>Name</Field.Label>- <Input />- </Field.Root>,- );-- const input = screen.getByRole('textbox', { name: 'Name' });-- await user.click(screen.getByText('Name'));-- expect(input).toHaveFocus();- });-- it('reflects the invalid and disabled state of its Field.Root', () => {- const { rerender } = render(- <Field.Root invalid>- <Input aria-label="Name" />- </Field.Root>,- );-- const input = screen.getByRole('textbox', { name: 'Name' });-- expect(input).toHaveAttribute('aria-invalid', 'true');- expect(input).toHaveAttribute('data-invalid');- expect(input).toBeEnabled();-- rerender(- <Field.Root invalid disabled>- <Input aria-label="Name" />- </Field.Root>,- );-- expect(input).not.toHaveAttribute('aria-invalid');- expect(input).toHaveAttribute('data-invalid');- expect(input).toBeDisabled();- });-});diff --git a/packages/twenty-ui/src/input/InputGroup/__stories__/InputGroup.stories.tsx b/packages/twenty-ui/src/input/InputGroup/__stories__/InputGroup.stories.tsxindex 18109ceb132..4e357342502 100644--- a/packages/twenty-ui/src/input/InputGroup/__stories__/InputGroup.stories.tsx+++ b/packages/twenty-ui/src/input/InputGroup/__stories__/InputGroup.stories.tsx@@ -1,4 +1,5 @@import { type Meta, type StoryObj } from '@storybook/react-vite';+import { expect, within } from 'storybook/test';import {A11Y_DEFER_COLOR_CONTRAST,@@ -9,6 +10,7 @@ import {import { IconSearch } from '@ui/icon';import { Input } from '@ui/input/Input/Input';+import inputStyles from '@ui/input/Input/Input.module.scss';import { InputGroup } from '@ui/input/InputGroup/InputGroup';import { type InputSize } from '@ui/input/types/InputSize';@@ -44,6 +46,70 @@ export const WithEndElement: Story = {},};+export const WithBothElements: Story = {+ decorators: [ComponentDecorator],+ parameters: { a11y: A11Y_DEFER_COLOR_CONTRAST },+ args: {+ startElement: '$',+ endElement: 'USD',+ children: <Input aria-label="Amount" />,+ },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);++ await expect(canvas.getByText('$')).toBeVisible();+ await expect(canvas.getByText('USD')).toBeVisible();+ await expect(canvas.getByRole('textbox', { name: 'Amount' })).toBeVisible();+ },+};++export const EmptyElements: Story = {+ decorators: [ComponentDecorator],+ render: () => (+ <>+ <InputGroup startElement={false} endElement="">+ <Input aria-label="Empty adornments" />+ </InputGroup>+ <InputGroup>+ <Input aria-label="No adornments" />+ </InputGroup>+ </>+ ),+ play: async ({ canvasElement }) => {+ for (const input of within(canvasElement).getAllByRole('textbox')) {+ await expect(input.parentElement?.children).toHaveLength(1);+ }+ },+};++export const SizeInheritance: Story = {+ decorators: [ComponentDecorator],+ render: () => (+ <>+ <InputGroup size="sm">+ <Input aria-label="Inherited size" />+ </InputGroup>+ <InputGroup size="sm">+ <Input aria-label="Explicit size" size="md" />+ </InputGroup>+ </>+ ),+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const inheritedInput = canvas.getByRole('textbox', {+ name: 'Inherited size',+ });+ const explicitInput = canvas.getByRole('textbox', {+ name: 'Explicit size',+ });++ await expect(inheritedInput).toHaveClass(inputStyles.sm);+ await expect(inheritedInput).toHaveAttribute('data-grouped');+ await expect(explicitInput).toHaveClass(inputStyles.md);+ await expect(explicitInput).not.toHaveClass(inputStyles.sm);+ },+};+type InputGroupCatalogAdornment = 'start' | 'end' | 'both';const getInputGroupCatalogAdornmentProps = (diff --git a/packages/twenty-ui/src/input/InputGroup/__tests__/InputGroup.test.tsx b/packages/twenty-ui/src/input/InputGroup/__tests__/InputGroup.test.tsxindex fdc5b5655c2..714657ad47d 100644--- a/packages/twenty-ui/src/input/InputGroup/__tests__/InputGroup.test.tsx+++ b/packages/twenty-ui/src/input/InputGroup/__tests__/InputGroup.test.tsx@@ -1,9 +1,6 @@-import { render, screen } from '@testing-library/react';-import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';import { Input } from '@ui/input/Input/Input';-import inputStyles from '@ui/input/Input/Input.module.scss';import { InputGroup } from '../InputGroup';import styles from '../InputGroup.module.scss';@@ -18,66 +15,3 @@ runComponentConformance({refInstanceOf: HTMLDivElement,ownClassName: styles.root,});--describe('InputGroup', () => {- it('renders the start and end elements around the input', () => {- render(- <InputGroup startElement="$" endElement="USD">- <Input aria-label="Amount" />- </InputGroup>,- );-- expect(screen.getByText('$')).toBeInTheDocument();- expect(screen.getByText('USD')).toBeInTheDocument();- expect(screen.getByRole('textbox', { name: 'Amount' })).toBeInTheDocument();- });-- it('renders no wrapper for a boolean or empty adornment', () => {- render(- <InputGroup startElement={false} endElement="">- <Input aria-label="Amount" />- </InputGroup>,- );-- expect(- screen.getByRole('textbox', { name: 'Amount' }).parentElement?.children,- ).toHaveLength(1);- });-- it('renders only the input when no element is given', () => {- render(- <InputGroup>- <Input aria-label="Amount" />- </InputGroup>,- );-- expect(- screen.getByRole('textbox', { name: 'Amount' }).parentElement?.children,- ).toHaveLength(1);- });-- it('passes its size to the input and marks it as grouped', () => {- render(- <InputGroup size="sm">- <Input aria-label="Amount" />- </InputGroup>,- );-- const input = screen.getByRole('textbox', { name: 'Amount' });-- expect(input).toHaveClass(inputStyles.sm);- expect(input).toHaveAttribute('data-grouped');- });-- it('lets an explicit input size win over the group size', () => {- render(- <InputGroup size="sm">- <Input aria-label="Amount" size="md" />- </InputGroup>,- );-- expect(screen.getByRole('textbox', { name: 'Amount' })).toHaveClass(- inputStyles.md,- );- });-});diff --git a/packages/twenty-ui/src/input/Textarea/__stories__/Textarea.stories.tsx b/packages/twenty-ui/src/input/Textarea/__stories__/Textarea.stories.tsxindex 34a50e39b1f..ecc14e34f21 100644--- a/packages/twenty-ui/src/input/Textarea/__stories__/Textarea.stories.tsx+++ b/packages/twenty-ui/src/input/Textarea/__stories__/Textarea.stories.tsx@@ -40,6 +40,10 @@ export const AutoResize: Story = {const textarea = canvas.getByRole('textbox', { name: 'Textarea' });const initialHeight = textarea.clientHeight;+ await expect(+ textarea.style.getPropertyValue('--tw-textarea-max-rows'),+ ).toBe('4');+await userEvent.type(textarea, 'one{enter}two{enter}three');await expect(textarea.clientHeight).toBeGreaterThan(initialHeight);diff --git a/packages/twenty-ui/src/input/Textarea/__stories__/TextareaAutoResize.stories.tsx b/packages/twenty-ui/src/input/Textarea/__stories__/TextareaAutoResize.stories.tsxnew file mode 100644index 00000000000..39bef001e25--- /dev/null+++ b/packages/twenty-ui/src/input/Textarea/__stories__/TextareaAutoResize.stories.tsx@@ -0,0 +1,112 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { useState } from 'react';+import { expect, userEvent, within } from 'storybook/test';++import { ComponentDecorator } from '@ui/testing';++import { Textarea } from '../Textarea';+import { type TextareaProps } from '../types/TextareaProps';++const TextareaResizeExample = ({ style, ...props }: TextareaProps) => {+ const [autoResize, setAutoResize] = useState(true);+ const [rows, setRows] = useState(1);+ const [blockSize, setBlockSize] = useState(style?.blockSize);++ return (+ <>+ <Textarea+ {...props}+ rows={rows}+ autoResize={autoResize}+ style={{ ...style, blockSize }}+ />+ <button type="button" onClick={() => setRows(3)}>+ Show three rows+ </button>+ <button type="button" onClick={() => setAutoResize(false)}>+ Disable auto resize+ </button>+ <button+ type="button"+ onClick={() => {+ setAutoResize(false);+ setBlockSize(120);+ }}+ >+ Set fixed height+ </button>+ </>+ );+};++const meta: Meta<typeof Textarea> = {+ title: 'UI/Input/Textarea/Auto resize',+ component: Textarea,+ tags: ['!autodocs'],+ decorators: [ComponentDecorator],+ parameters: { container: { width: 240 } },+ args: { 'aria-label': 'Notes' },+ render: (args) => <TextareaResizeExample {...args} />,+};++export default meta;+type Story = StoryObj<typeof Textarea>;++export const RowsChange: Story = {+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const textarea = canvas.getByRole('textbox', { name: 'Notes' });+ const initialHeight = textarea.clientHeight;++ await expect(textarea).toHaveAttribute('data-auto-resize');+ await userEvent.click(+ canvas.getByRole('button', { name: 'Show three rows' }),+ );++ await expect(textarea.clientHeight).toBeGreaterThan(initialHeight);+ },+};++export const DisableAutoResize: Story = {+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const textarea = canvas.getByRole('textbox', { name: 'Notes' });++ await expect(textarea.style.blockSize).not.toBe('');+ await userEvent.click(+ canvas.getByRole('button', { name: 'Disable auto resize' }),+ );++ await expect(textarea.style.blockSize).toBe('');+ await expect(textarea).not.toHaveAttribute('data-auto-resize');+ },+};++export const RestoreConsumerHeight: Story = {+ args: { style: { blockSize: 80 } },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const textarea = canvas.getByRole('textbox', { name: 'Notes' });++ await expect(textarea.style.blockSize).not.toBe('80px');+ await userEvent.click(+ canvas.getByRole('button', { name: 'Disable auto resize' }),+ );++ await expect(textarea.style.blockSize).toBe('80px');+ },+};++export const ReplaceConsumerHeight: Story = {+ args: { style: { blockSize: 80 } },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const textarea = canvas.getByRole('textbox', { name: 'Notes' });++ await userEvent.click(+ canvas.getByRole('button', { name: 'Set fixed height' }),+ );++ await expect(textarea.style.blockSize).toBe('120px');+ },+};diff --git a/packages/twenty-ui/src/input/Textarea/__stories__/TextareaInteractions.stories.tsx b/packages/twenty-ui/src/input/Textarea/__stories__/TextareaInteractions.stories.tsxnew file mode 100644index 00000000000..f91506916e4--- /dev/null+++ b/packages/twenty-ui/src/input/Textarea/__stories__/TextareaInteractions.stories.tsx@@ -0,0 +1,112 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { useState } from 'react';+import { expect, fn, userEvent, within } from 'storybook/test';++import { Field } from '@ui/input/Field/Field';+import { A11Y_DEFER_COLOR_CONTRAST, ComponentDecorator } from '@ui/testing';++import { Textarea } from '../Textarea';+import styles from '../Textarea.module.scss';+import { type TextareaProps } from '../types/TextareaProps';++const ControlledTextareaExample = (props: TextareaProps) => {+ const [value, setValue] = useState('a');++ return (+ <>+ <Textarea {...props} value={value} />+ <button type="button" onClick={() => setValue('a\nb\nc')}>+ Apply value+ </button>+ </>+ );+};++const meta: Meta<typeof Textarea> = {+ title: 'UI/Input/Textarea/Interactions',+ component: Textarea,+ tags: ['!autodocs'],+ decorators: [ComponentDecorator],+ parameters: { container: { width: 240 } },+ args: { 'aria-label': 'Notes', onValueChange: fn() },+};++export default meta;+type Story = StoryObj<typeof Textarea>;++export const Uncontrolled: Story = {+ args: { defaultValue: 'a' },+ play: async ({ canvasElement, args }) => {+ const textarea = within(canvasElement).getByRole('textbox', {+ name: 'Notes',+ });++ await userEvent.type(textarea, 'b');++ await expect(textarea).toHaveValue('ab');+ await expect(args.onValueChange).toHaveBeenCalledWith(+ 'ab',+ expect.objectContaining({ reason: 'none' }),+ );+ },+};++export const Controlled: Story = {+ args: { autoResize: true, rows: 1 },+ render: (args) => <ControlledTextareaExample {...args} />,+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const textarea = canvas.getByRole('textbox', { name: 'Notes' });+ const initialHeight = textarea.clientHeight;++ await userEvent.type(textarea, '{enter}b{enter}c');++ await expect(args.onValueChange).toHaveBeenCalledWith(+ 'a\n',+ expect.anything(),+ );+ await expect(textarea).toHaveValue('a');+ await expect(textarea.clientHeight).toBe(initialHeight);++ await userEvent.click(canvas.getByRole('button', { name: 'Apply value' }));++ await expect(textarea).toHaveValue('a\nb\nc');+ await expect(textarea.clientHeight).toBeGreaterThan(initialHeight);+ },+};++export const RowsAndSize: Story = {+ args: { rows: 5, size: 'sm' },+ play: async ({ canvasElement }) => {+ const textarea = within(canvasElement).getByRole('textbox', {+ name: 'Notes',+ });++ await expect(textarea).toHaveAttribute('rows', '5');+ await expect(textarea).toHaveClass(styles.sm);+ },+};++export const WithField: Story = {+ parameters: { a11y: A11Y_DEFER_COLOR_CONTRAST },+ render: () => (+ <Field.Root invalid>+ <Field.Label>Notes</Field.Label>+ <Textarea+ className={(state) => (state.valid === false ? 'invalid' : 'valid')}+ />+ </Field.Root>+ ),+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const textarea = canvas.getByRole('textbox', { name: 'Notes' });++ await userEvent.click(canvas.getByText('Notes'));++ await expect(textarea).toHaveFocus();+ await expect(textarea).toHaveAttribute('aria-invalid', 'true');+ await expect(textarea).toHaveAttribute('data-invalid');+ await expect(textarea).toHaveClass(styles.textarea, 'invalid');+ await expect(textarea).not.toHaveClass('valid');+ },+};diff --git a/packages/twenty-ui/src/input/Textarea/__tests__/Textarea.test.tsx b/packages/twenty-ui/src/input/Textarea/__tests__/Textarea.test.tsxindex d4dc8ffa26f..d89505f5db7 100644--- a/packages/twenty-ui/src/input/Textarea/__tests__/Textarea.test.tsx+++ b/packages/twenty-ui/src/input/Textarea/__tests__/Textarea.test.tsx@@ -1,11 +1,5 @@-import { render, screen } from '@testing-library/react';-import userEvent from '@testing-library/user-event';-import { type MockInstance, vi } from 'vitest';-import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';-import { Field } from '@ui/input/Field/Field';-import { Textarea } from '../Textarea';import styles from '../Textarea.module.scss';@@ -16,271 +10,3 @@ runComponentConformance({ownClassName: styles.textarea,renderPropTagName: 'textarea',});--describe('Textarea', () => {- it('updates its value and reports it when uncontrolled', async () => {- const user = userEvent.setup();- const onValueChange = vi.fn();-- render(- <Textarea- defaultValue="a"- onValueChange={onValueChange}- aria-label="Notes"- />,- );-- const textarea = screen.getByRole('textbox', { name: 'Notes' });-- await user.type(textarea, 'b');-- expect(textarea).toHaveValue('ab');- expect(onValueChange).toHaveBeenCalledWith(- 'ab',- expect.objectContaining({ reason: 'none' }),- );- });-- it('keeps the rendered value controlled by the value prop', async () => {- const user = userEvent.setup();- const onValueChange = vi.fn();-- render(- <Textarea value="a" onValueChange={onValueChange} aria-label="Notes" />,- );-- const textarea = screen.getByRole('textbox', { name: 'Notes' });-- await user.type(textarea, 'b');-- expect(onValueChange).toHaveBeenCalledWith('ab', expect.anything());- expect(textarea).toHaveValue('a');- });-- it('passes rows through and applies the size', () => {- render(<Textarea aria-label="Notes" rows={5} size="sm" />);-- const textarea = screen.getByRole('textbox', { name: 'Notes' });-- expect(textarea).toHaveAttribute('rows', '5');- expect(textarea).toHaveClass(styles.sm);- });-- it('resolves a function className against the field state', () => {- render(- <Field.Root invalid>- <Textarea- aria-label="Notes"- className={(state) => (state.valid === false ? 'invalid' : 'valid')}- />- </Field.Root>,- );-- const textarea = screen.getByRole('textbox', { name: 'Notes' });-- expect(textarea).toHaveClass(styles.textarea, 'invalid');- expect(textarea).not.toHaveClass('valid');- });-- it('exposes maxRows as a custom property', () => {- render(<Textarea aria-label="Notes" maxRows={4} />);-- expect(- screen- .getByRole('textbox', { name: 'Notes' })- .style.getPropertyValue('--tw-textarea-max-rows'),- ).toBe('4');- });-- it('runs the cleanup of a callback ref on unmount', () => {- const refCleanup = vi.fn();- const callbackRef = vi.fn(() => refCleanup);-- const { unmount } = render(- <Textarea aria-label="Notes" ref={callbackRef} />,- );-- expect(callbackRef).toHaveBeenCalledWith(- screen.getByRole('textbox', { name: 'Notes' }),- );-- unmount();-- expect(refCleanup).toHaveBeenCalledTimes(1);- expect(callbackRef).toHaveBeenCalledTimes(1);- });-- describe('autoResize', () => {- let scrollHeightSpy: MockInstance<() => number>;-- beforeEach(() => {- scrollHeightSpy = vi- .spyOn(Element.prototype, 'scrollHeight', 'get')- .mockReturnValue(40);- });-- afterEach(() => {- scrollHeightSpy.mockRestore();- });-- it('sizes the textarea to its content on mount and while typing', async () => {- const user = userEvent.setup();-- render(<Textarea aria-label="Notes" autoResize />);-- const textarea = screen.getByRole('textbox', { name: 'Notes' });-- expect(textarea).toHaveAttribute('data-auto-resize');- expect(textarea.style.blockSize).toBe('40px');-- scrollHeightSpy.mockReturnValue(56);-- await user.type(textarea, 'a');-- expect(textarea.style.blockSize).toBe('56px');- });-- it('resizes when a controlled value changes', () => {- const onValueChange = vi.fn();- const { rerender } = render(- <Textarea- aria-label="Notes"- autoResize- value="a"- onValueChange={onValueChange}- />,- );-- scrollHeightSpy.mockReturnValue(72);-- rerender(- <Textarea- aria-label="Notes"- autoResize- value={'a\nb'}- onValueChange={onValueChange}- />,- );-- expect(- screen.getByRole('textbox', { name: 'Notes' }).style.blockSize,- ).toBe('72px');- });-- it('keeps the height when a controlled parent rejects the edit', async () => {- const user = userEvent.setup();-- render(- <Textarea- aria-label="Notes"- autoResize- value="a"- onValueChange={() => undefined}- />,- );-- const textarea = screen.getByRole('textbox', { name: 'Notes' });-- scrollHeightSpy.mockReturnValue(56);-- await user.type(textarea, 'b');-- expect(textarea).toHaveValue('a');- expect(textarea.style.blockSize).toBe('40px');- });-- it('measures again when rows changes', () => {- const { rerender } = render(- <Textarea aria-label="Notes" autoResize rows={1} />,- );-- scrollHeightSpy.mockReturnValue(56);-- rerender(<Textarea aria-label="Notes" autoResize rows={3} />);-- expect(- screen.getByRole('textbox', { name: 'Notes' }).style.blockSize,- ).toBe('56px');- });-- it('clears the inline height when autoResize is turned off', () => {- const { rerender } = render(<Textarea aria-label="Notes" autoResize />);-- const textarea = screen.getByRole('textbox', { name: 'Notes' });-- expect(textarea.style.blockSize).toBe('40px');-- rerender(<Textarea aria-label="Notes" autoResize={false} />);-- expect(textarea.style.blockSize).toBe('');- });-- it('restores the consumer block size when autoResize is turned off', () => {- const { rerender } = render(- <Textarea aria-label="Notes" autoResize style={{ blockSize: 80 }} />,- );-- const textarea = screen.getByRole('textbox', { name: 'Notes' });-- expect(textarea.style.blockSize).toBe('40px');-- rerender(- <Textarea- aria-label="Notes"- autoResize={false}- style={{ blockSize: 80 }}- />,- );-- expect(textarea.style.blockSize).toBe('80px');- });-- it('applies a block size changed in the same render that turns autoResize off', () => {- const { rerender } = render(- <Textarea aria-label="Notes" autoResize style={{ blockSize: 80 }} />,- );-- rerender(- <Textarea- aria-label="Notes"- autoResize={false}- style={{ blockSize: 120 }}- />,- );-- expect(- screen.getByRole('textbox', { name: 'Notes' }).style.blockSize,- ).toBe('120px');- });- });-- it('is labelled and focused by Field.Label inside Field.Root', async () => {- const user = userEvent.setup();-- render(- <Field.Root>- <Field.Label>Notes</Field.Label>- <Textarea />- </Field.Root>,- );-- const textarea = screen.getByRole('textbox', { name: 'Notes' });-- await user.click(screen.getByText('Notes'));-- expect(textarea).toHaveFocus();- });-- it('reflects the invalid state of its Field.Root', () => {- render(- <Field.Root invalid>- <Textarea aria-label="Notes" />- </Field.Root>,- );-- const textarea = screen.getByRole('textbox', { name: 'Notes' });-- expect(textarea).toHaveAttribute('aria-invalid', 'true');- expect(textarea).toHaveAttribute('data-invalid');- });-});diff --git a/packages/twenty-ui/src/navigation/ListItem/__stories__/ListItemInteractions.stories.tsx b/packages/twenty-ui/src/navigation/ListItem/__stories__/ListItemInteractions.stories.tsxnew file mode 100644index 00000000000..59f741221b7--- /dev/null+++ b/packages/twenty-ui/src/navigation/ListItem/__stories__/ListItemInteractions.stories.tsx@@ -0,0 +1,187 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { useState } from 'react';+import { expect, fn, userEvent, within } from 'storybook/test';++import { A11Y_DEFER_COLOR_CONTRAST, ComponentDecorator } from '@ui/testing';++import { ListItem } from '../ListItem';+import styles from '../ListItem.module.scss';+import { type ListItemProps } from '../types/ListItemProps';++const SelectableListItemExample = (props: ListItemProps) => {+ const [selected, setSelected] = useState(false);++ return (+ <ListItem+ {...props}+ selected={selected}+ focused={selected}+ color={selected ? 'danger' : 'neutral'}+ onClick={() => setSelected(!selected)}+ render={(renderProps, state) => (+ <div {...renderProps} data-render-highlighted={state.highlighted} />+ )}+ />+ );+};++const ActionListItemExample = (props: ListItemProps) => {+ const [deleted, setDeleted] = useState(false);++ return (+ <ListItem+ {...props}+ actions={+ <button type="button" onClick={() => setDeleted(true)}>+ Delete+ </button>+ }+ >+ {deleted ? 'Deleted' : 'Item'}+ </ListItem>+ );+};++const meta: Meta<typeof ListItem> = {+ title: 'UI/Navigation/ListItem/Interactions',+ component: ListItem,+ tags: ['!autodocs'],+ decorators: [+ ComponentDecorator,+ (Story) => (+ <div role="list">+ <Story />+ </div>+ ),+ ],+ parameters: { container: { width: 320 } },+ args: {+ children: 'Item',+ onClick: fn(),+ role: 'listitem',+ 'aria-label': 'Item',+ },+};++export default meta;+type Story = StoryObj<typeof ListItem>;++export const ClickPropagation: Story = {+ play: async ({ canvasElement, args }) => {+ const onAncestorClick = fn();+ canvasElement.addEventListener('click', onAncestorClick);++ try {+ await userEvent.click(+ within(canvasElement).getByRole('listitem', { name: 'Item' }),+ );++ await expect(args.onClick).toHaveBeenCalledTimes(1);+ await expect(args.onClick).toHaveBeenCalledWith(+ expect.objectContaining({ defaultPrevented: false }),+ );+ await expect(onAncestorClick).toHaveBeenCalledTimes(1);+ } finally {+ canvasElement.removeEventListener('click', onAncestorClick);+ }+ },+};++export const Disabled: Story = {+ args: { disabled: true },+ play: async ({ canvasElement, args }) => {+ const item = within(canvasElement).getByRole('listitem', { name: 'Item' });++ await userEvent.click(item);++ await expect(args.onClick).not.toHaveBeenCalled();+ await expect(item).toHaveAttribute('aria-disabled', 'true');+ await expect(item).toHaveAttribute('data-disabled');+ },+};++export const DisabledLink: Story = {+ args: {+ disabled: true,+ role: 'link',+ render: <a href="#target" aria-label="Item link" />,+ },+ render: (args) => (+ <div role="listitem">+ <ListItem {...args} />+ </div>+ ),+ play: async ({ canvasElement, args }) => {+ const item = within(canvasElement).getByRole('link');+ const onAncestorClick = fn();+ canvasElement.addEventListener('click', onAncestorClick);++ try {+ await userEvent.click(item);++ await expect(item).toHaveAttribute('href', '#target');+ await expect(args.onClick).not.toHaveBeenCalled();+ await expect(onAncestorClick).toHaveBeenCalledWith(+ expect.objectContaining({ defaultPrevented: true }),+ );+ } finally {+ canvasElement.removeEventListener('click', onAncestorClick);+ }+ },+};++export const ActionPropagation: Story = {+ render: (args) => <ActionListItemExample {...args} />,+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const action = canvas.getByRole('button', { name: 'Delete', hidden: true });++ await userEvent.hover(canvas.getByRole('listitem', { name: 'Item' }));+ await userEvent.click(action);++ await expect(canvas.getByText('Deleted')).toBeVisible();+ await expect(args.onClick).toHaveBeenCalledTimes(1);+ },+};++export const SelectionAndRenderState: Story = {+ parameters: { a11y: A11Y_DEFER_COLOR_CONTRAST },+ args: { indicator: 'check' },+ render: (args) => <SelectableListItemExample {...args} />,+ play: async ({ canvasElement }) => {+ const item = within(canvasElement).getByRole('listitem', { name: 'Item' });++ await expect(item).not.toHaveAttribute('data-selected');+ await expect(item).not.toHaveAttribute('data-highlighted');+ await expect(item).not.toHaveAttribute('data-disabled');+ await expect(item).toHaveAttribute('data-color', 'neutral');+ await expect(item).toHaveAttribute('data-indicator', 'check');+ await expect(item.querySelector(`.${styles.checkIndicator}`)).toBeNull();++ await userEvent.click(item);++ await expect(item).toHaveAttribute('data-selected');+ await expect(item).toHaveAttribute('data-highlighted');+ await expect(item).toHaveAttribute('data-render-highlighted', 'true');+ await expect(item).toHaveAttribute('data-color', 'danger');+ await expect(item.querySelector(`.${styles.checkIndicator}`)).toBeVisible();+ },+};++export const DecorativeCheckbox: Story = {+ parameters: { a11y: A11Y_DEFER_COLOR_CONTRAST },+ args: { indicator: 'checkbox' },+ render: (args) => <SelectableListItemExample {...args} />,+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const item = canvas.getByRole('listitem', { name: 'Item' });++ await expect(canvas.queryByRole('checkbox')).toBeNull();+ await expect(item.querySelector('[data-checked]')).toBeNull();++ await userEvent.click(item);++ await expect(canvas.queryByRole('checkbox')).toBeNull();+ await expect(item.querySelector('[data-checked]')).not.toBeNull();+ },+};diff --git a/packages/twenty-ui/src/navigation/ListItem/__tests__/ListItem.test.tsx b/packages/twenty-ui/src/navigation/ListItem/__tests__/ListItem.test.tsxindex 7d0a03df20f..b4f6b6d9b31 100644--- a/packages/twenty-ui/src/navigation/ListItem/__tests__/ListItem.test.tsx+++ b/packages/twenty-ui/src/navigation/ListItem/__tests__/ListItem.test.tsx@@ -1,7 +1,3 @@-import { render, screen } from '@testing-library/react';-import userEvent from '@testing-library/user-event';-import { vi } from 'vitest';-import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';import { ListItem } from '../ListItem';@@ -13,222 +9,3 @@ runComponentConformance({refInstanceOf: HTMLDivElement,ownClassName: styles.root,});--describe('ListItem', () => {- it('renders its children, icons and inline description', () => {- render(- <ListItem- startIcon={<span>start</span>}- endIcon={<span>end</span>}- description="Description"- >- Item- </ListItem>,- );-- expect(screen.getByText('Item')).toBeInTheDocument();- expect(screen.getByText('start')).toBeInTheDocument();- expect(screen.getByText('end')).toBeInTheDocument();- expect(screen.getByText('Description')).toHaveClass(- styles.inlineDescription,- );- });-- it('places the description at the end on demand', () => {- render(- <ListItem description="Description" descriptionPlacement="end">- Item- </ListItem>,- );-- expect(screen.getByText('Description')).toHaveClass(styles.endDescription);- });-- it('renders every hotkey', () => {- render(<ListItem hotkeys={['⌘', 'K']}>Item</ListItem>);-- expect(screen.getByText('⌘')).toBeInTheDocument();- expect(screen.getByText('K')).toBeInTheDocument();- });-- it('renders a chevron only when it opens a submenu', () => {- const { container, rerender } = render(<ListItem>Item</ListItem>);-- expect(container.querySelector('svg')).toBeNull();-- rerender(<ListItem hasSubmenu>Item</ListItem>);-- expect(container.querySelectorAll('svg')).toHaveLength(1);- });-- it('calls onClick and lets the click bubble without preventing its default', async () => {- const user = userEvent.setup();- const onClick = vi.fn();- const onAncestorClick = vi.fn();-- const { container } = render(<ListItem onClick={onClick}>Item</ListItem>);-- container.addEventListener('click', onAncestorClick);-- await user.click(screen.getByText('Item'));-- expect(onClick).toHaveBeenCalledTimes(1);- expect(onClick.mock.calls[0][0].defaultPrevented).toBe(false);- expect(onAncestorClick).toHaveBeenCalledTimes(1);- });-- it('ignores clicks and exposes its state when disabled', async () => {- const user = userEvent.setup();- const onClick = vi.fn();-- render(- <ListItem disabled onClick={onClick} data-testid="item">- Item- </ListItem>,- );-- const item = screen.getByTestId('item');-- await user.click(item);-- expect(onClick).not.toHaveBeenCalled();- expect(item).toHaveAttribute('aria-disabled', 'true');- expect(item).toHaveAttribute('data-disabled');- });-- it('cancels the native action of a disabled polymorphic root', async () => {- const user = userEvent.setup();- const onClick = vi.fn();- const onAncestorClick = vi.fn();-- const { container } = render(- <ListItem- disabled- onClick={onClick}- render={<a href="#target" aria-label="Item link" />}- >- Item- </ListItem>,- );-- container.addEventListener('click', onAncestorClick);-- await user.click(screen.getByText('Item'));-- expect(screen.getByText('Item').closest('a')).toHaveAttribute(- 'href',- '#target',- );- expect(onClick).not.toHaveBeenCalled();- expect(onAncestorClick.mock.calls[0][0].defaultPrevented).toBe(true);- });-- it('exposes its state as data attributes', () => {- const { rerender } = render(<ListItem data-testid="item">Item</ListItem>);-- const item = screen.getByTestId('item');-- expect(item).not.toHaveAttribute('data-selected');- expect(item).not.toHaveAttribute('data-highlighted');- expect(item).not.toHaveAttribute('data-disabled');- expect(item).toHaveAttribute('data-color', 'neutral');- expect(item).toHaveAttribute('data-indicator', 'none');-- rerender(- <ListItem- data-testid="item"- selected- focused- color="danger"- indicator="check"- >- Item- </ListItem>,- );-- expect(item).toHaveAttribute('data-selected');- expect(item).toHaveAttribute('data-highlighted');- expect(item).toHaveAttribute('data-color', 'danger');- expect(item).toHaveAttribute('data-indicator', 'check');- });-- it('passes its state to a render function', () => {- render(- <ListItem- focused- render={(props, state) => (- <div- {...props}- data-testid="item"- data-render-highlighted={state.highlighted}- />- )}- >- Item- </ListItem>,- );-- expect(screen.getByTestId('item')).toHaveAttribute(- 'data-render-highlighted',- 'true',- );- });-- it('shows the check indicator only when selected', () => {- const { container, rerender } = render(- <ListItem indicator="check">Item</ListItem>,- );-- expect(container.querySelector('svg')).toBeNull();-- rerender(- <ListItem indicator="check" selected>- Item- </ListItem>,- );-- expect(container.querySelectorAll('svg')).toHaveLength(1);- });-- it('renders a decorative checkbox that follows the selected state', () => {- const { container, rerender } = render(- <ListItem indicator="checkbox">Item</ListItem>,- );-- expect(screen.queryByRole('checkbox')).toBeNull();- expect(container.querySelector('[data-checked]')).toBeNull();-- rerender(- <ListItem indicator="checkbox" selected>- Item- </ListItem>,- );-- expect(screen.queryByRole('checkbox')).toBeNull();- expect(container.querySelector('[data-checked]')).not.toBeNull();- });-- it('lets an action click reach both the action and the item', async () => {- const user = userEvent.setup();- const onClick = vi.fn();- const onActionClick = vi.fn();-- render(- <ListItem- onClick={onClick}- actions={- <button type="button" onClick={onActionClick}>- Delete- </button>- }- >- Item- </ListItem>,- );-- await user.click(screen.getByRole('button', { name: 'Delete' }));-- expect(onActionClick).toHaveBeenCalledTimes(1);- expect(onClick).toHaveBeenCalledTimes(1);- });-});diff --git a/packages/twenty-ui/src/theme-constants/__stories__/ThemeProvider.stories.tsx b/packages/twenty-ui/src/theme-constants/__stories__/ThemeProvider.stories.tsxnew file mode 100644index 00000000000..c4aa45283a9--- /dev/null+++ b/packages/twenty-ui/src/theme-constants/__stories__/ThemeProvider.stories.tsx@@ -0,0 +1,188 @@+import { isNonEmptyString } from '@sniptt/guards';+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { useState } from 'react';+import { expect, userEvent, within } from 'storybook/test';++import { ThemeProvider } from '../ThemeProvider';+import { themeCssVariables } from '../themeCssVariables';+import { useTheme } from '../useTheme';++const ThemeTokens = () => {+ const theme = useTheme();++ return (+ <>+ <output aria-label="Medium icon size">+ {JSON.stringify(theme.icon.size.md)}+ </output>+ <output aria-label="Small icon size">+ {JSON.stringify(theme.icon.size.sm)}+ </output>+ <output aria-label="Primary font color">+ {JSON.stringify(theme.font.color.primary)}+ </output>+ <output aria-label="Small border radius">+ {JSON.stringify(theme.border.radius.sm)}+ </output>+ </>+ );+};++type ScaleExampleProps = {+ initialScale?: number | null;+};++const ScaleExample = ({ initialScale = 1.25 }: ScaleExampleProps) => {+ const [scale, setScale] = useState<number | undefined>(+ initialScale ?? undefined,+ );+ const [mounted, setMounted] = useState(true);++ return (+ <>+ {mounted && (+ <ThemeProvider colorScheme="light" scale={scale}>+ <span>Theme active</span>+ </ThemeProvider>+ )}+ <button type="button" onClick={() => setScale(0.9)}>+ Change scale+ </button>+ <button type="button" onClick={() => setScale(undefined)}>+ Reset scale+ </button>+ <button type="button" onClick={() => setMounted(false)}>+ Unmount theme+ </button>+ </>+ );+};++const readInlineScale = () =>+ document.documentElement.style.getPropertyValue('--t-scale-user');++const meta: Meta<typeof ThemeProvider> = {+ title: 'UI/Theme/ThemeProvider',+ component: ThemeProvider,+ args: { colorScheme: 'light', children: <ThemeTokens /> },+ beforeEach: () => {+ const previousScale = readInlineScale();+ document.documentElement.style.removeProperty('--t-scale-user');++ return () => {+ if (isNonEmptyString(previousScale)) {+ document.documentElement.style.setProperty(+ '--t-scale-user',+ previousScale,+ );+ } else {+ document.documentElement.style.removeProperty('--t-scale-user');+ }+ };+ },+};++export default meta;+type Story = StoryObj<typeof ThemeProvider>;++export const ScaleChanges: Story = {+ render: () => <ScaleExample />,+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);++ await expect(readInlineScale()).toBe('1.25');+ await userEvent.click(canvas.getByRole('button', { name: 'Change scale' }));+ await expect(readInlineScale()).toBe('0.9');+ await userEvent.click(canvas.getByRole('button', { name: 'Reset scale' }));+ await expect(readInlineScale()).toBe('');+ },+};++export const ScaleCleanup: Story = {+ render: () => <ScaleExample />,+ play: async ({ canvasElement }) => {+ await expect(readInlineScale()).toBe('1.25');+ await userEvent.click(+ within(canvasElement).getByRole('button', { name: 'Unmount theme' }),+ );+ await expect(readInlineScale()).toBe('');+ },+};++export const ScopedScale: Story = {+ args: { overrides: {}, scale: 1.25 },+ play: async () => {+ await expect(readInlineScale()).toBe('');+ },+};++export const ExistingScale: Story = {+ beforeEach: () => {+ document.documentElement.style.setProperty('--t-scale-user', '1.25');+ },+ render: () => <ScaleExample initialScale={null} />,+ play: async ({ canvasElement }) => {+ await expect(readInlineScale()).toBe('1.25');+ await userEvent.click(+ within(canvasElement).getByRole('button', { name: 'Unmount theme' }),+ );+ await expect(readInlineScale()).toBe('1.25');+ },+};++export const UnresolvedTokens: Story = {+ args: {+ applyToRoot: false,+ overrides: {+ '--t-icon-size-md': 'initial',+ '--t-font-color-primary': 'initial',+ },+ },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);++ await expect(canvas.getByLabelText('Medium icon size')).toHaveTextContent(+ JSON.stringify(themeCssVariables.icon.size.md),+ );+ await expect(canvas.getByLabelText('Primary font color')).toHaveTextContent(+ JSON.stringify(themeCssVariables.font.color.primary),+ );+ },+};++export const NumericTokens: Story = {+ args: {+ applyToRoot: false,+ overrides: { '--t-icon-size-md': '16', '--t-icon-size-sm': 'initial' },+ },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);++ await expect(canvas.getByLabelText('Medium icon size').textContent).toBe(+ '16',+ );+ await expect(canvas.getByLabelText('Small icon size')).toHaveTextContent(+ JSON.stringify(themeCssVariables.icon.size.sm),+ );+ },+};++export const StringTokens: Story = {+ args: {+ applyToRoot: false,+ overrides: {+ '--t-font-color-primary': '#181d27',+ '--t-border-radius-sm': '4px',+ },+ },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);++ await expect(canvas.getByLabelText('Primary font color').textContent).toBe(+ '"#181d27"',+ );+ await expect(canvas.getByLabelText('Small border radius').textContent).toBe(+ '"4px"',+ );+ },+};diff --git a/packages/twenty-ui/src/theme-constants/__tests__/ThemeProvider.test.tsx b/packages/twenty-ui/src/theme-constants/__tests__/ThemeProvider.test.tsxdeleted file mode 100644index caf2ad313ff..00000000000--- a/packages/twenty-ui/src/theme-constants/__tests__/ThemeProvider.test.tsx+++ /dev/null@@ -1,147 +0,0 @@-import { render } from '@testing-library/react';-import { vi } from 'vitest';--import { ThemeProvider } from '../ThemeProvider';-import { type ThemeType } from '../themeTypes';-import { themeCssVariables } from '../themeCssVariables';-import { useTheme } from '../useTheme';--const readInlineScale = () =>- document.documentElement.style.getPropertyValue('--t-scale-user');--const renderProvider = (scale?: number) =>- render(- <ThemeProvider colorScheme="light" scale={scale}>- <div />- </ThemeProvider>,- );--describe('ThemeProvider scale', () => {- afterEach(() => {- document.documentElement.style.removeProperty('--t-scale-user');- });-- it('should write the scale onto the root element', () => {- renderProvider(1.25);-- expect(readInlineScale()).toBe('1.25');- });-- it('should update the scale on rerender', () => {- const { rerender } = renderProvider(1.1);- expect(readInlineScale()).toBe('1.1');-- rerender(- <ThemeProvider colorScheme="light" scale={0.9}>- <div />- </ThemeProvider>,- );-- expect(readInlineScale()).toBe('0.9');- });-- it('should remove the scale from the root element on unmount', () => {- const { unmount } = renderProvider(1.25);- expect(readInlineScale()).toBe('1.25');-- unmount();-- expect(readInlineScale()).toBe('');- });-- it('should remove the scale when the scale prop goes back to undefined', () => {- const { rerender } = renderProvider(1.25);- expect(readInlineScale()).toBe('1.25');-- rerender(- <ThemeProvider colorScheme="light">- <div />- </ThemeProvider>,- );-- expect(readInlineScale()).toBe('');- });-- it('should ignore the scale on a scoped provider', () => {- render(- <ThemeProvider colorScheme="light" overrides={{}} scale={1.25}>- <div />- </ThemeProvider>,- );-- expect(readInlineScale()).toBe('');- });-- it('should not remove a scale another provider set when mounted without one', () => {- document.documentElement.style.setProperty('--t-scale-user', '1.25');-- const { unmount } = renderProvider();- expect(readInlineScale()).toBe('1.25');-- unmount();-- expect(readInlineScale()).toBe('1.25');- });-});--describe('ThemeProvider token resolution', () => {- let latestTheme: ThemeType | undefined;-- const ThemeSpy = () => {- latestTheme = useTheme();- return null;- };-- const mockResolvedTokens = (resolvedTokens: Record<string, string>) => {- vi.spyOn(window, 'getComputedStyle').mockReturnValue({- getPropertyValue: (property: string) => resolvedTokens[property] ?? '',- } as CSSStyleDeclaration);- };-- const renderThemeSpy = () =>- render(- <ThemeProvider colorScheme="light">- <ThemeSpy />- </ThemeProvider>,- );-- beforeEach(() => {- latestTheme = undefined;- });-- afterEach(() => {- vi.restoreAllMocks();- });-- it('should keep the CSS variable reference when no custom property resolves', () => {- mockResolvedTokens({});-- renderThemeSpy();-- expect(latestTheme?.icon.size.md).toBe(themeCssVariables.icon.size.md);- expect(latestTheme?.font.color.primary).toBe(- themeCssVariables.font.color.primary,- );- });-- it('should resolve numeric custom properties and keep the reference for the rest', () => {- mockResolvedTokens({ '--t-icon-size-md': '16' });-- renderThemeSpy();-- expect(latestTheme?.icon.size.md).toBe(16);- expect(latestTheme?.icon.size.sm).toBe(themeCssVariables.icon.size.sm);- });-- it('should resolve string custom properties to their computed value', () => {- mockResolvedTokens({- '--t-font-color-primary': '#181d27',- '--t-border-radius-sm': '4px',- });-- renderThemeSpy();-- expect(latestTheme?.font.color.primary).toBe('#181d27');- expect(latestTheme?.border.radius.sm).toBe('4px');- });-});diff --git a/packages/twenty-ui/src/typography/Text/__tests__/Text.test.tsx b/packages/twenty-ui/src/typography/Text/__tests__/Text.test.tsxindex dfca9dc890b..2b847448c75 100644--- a/packages/twenty-ui/src/typography/Text/__tests__/Text.test.tsx+++ b/packages/twenty-ui/src/typography/Text/__tests__/Text.test.tsx@@ -1,5 +1,3 @@-import { render, screen } from '@testing-library/react';-import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';import { Text } from '../Text';@@ -7,60 +5,7 @@ import styles from '../Text.module.scss';runComponentConformance({name: 'Text',- element: <Text>Body</Text>,+ element: <Text truncate>Body</Text>,+ ownClassName: styles.truncate,refInstanceOf: HTMLDivElement,});--describe('Text', () => {- it('adds the truncate class when truncate is set', () => {- render(- <Text truncate data-testid="text">- Body- </Text>,- );-- expect(screen.getByTestId('text')).toHaveClass(styles.truncate);- });-- it('adds the line clamp class and custom property when lineClamp is set', () => {- render(- <Text lineClamp={2} data-testid="text">- Body- </Text>,- );-- const text = screen.getByTestId('text');-- expect(text).toHaveClass(styles.lineClamp);- expect(text.style.getPropertyValue('--text-line-clamp')).toBe('2');- });-- it('renders the element given to render with the merged className', () => {- render(- <Text- render={<span className="from-render" />}- className="consumer"- data-testid="text"- >- Body- </Text>,- );-- const text = screen.getByTestId('text');-- expect(text.tagName).toBe('SPAN');- expect(text).toHaveClass('from-render', 'consumer');- });-- it('places the consumer className last', () => {- render(- <Text truncate className="consumer" data-testid="text">- Body- </Text>,- );-- expect(screen.getByTestId('text').className).toBe(- `${styles.truncate} consumer`,- );- });-});diff --git a/packages/twenty-ui/test-utilities/conformance/runComponentConformance.tsx b/packages/twenty-ui/test-utilities/conformance/runComponentConformance.tsxindex 23edff913e4..c4cf88a270e 100644--- a/packages/twenty-ui/test-utilities/conformance/runComponentConformance.tsx+++ b/packages/twenty-ui/test-utilities/conformance/runComponentConformance.tsx@@ -110,6 +110,19 @@ export const runComponentConformance = ({expect(ref.current).toBe(screen.getByTestId(CONFORMANCE_TEST_ID));});+ itUnlessSkipped('ref', 'cleans up callback refs on unmount', () => {+ const cleanup = vi.fn();+ const ref = vi.fn(() => cleanup);+ const { unmount } = render(compose({ ref }));++ expect(ref).toHaveBeenCalledWith(screen.getByTestId(CONFORMANCE_TEST_ID));+ expect(cleanup).toHaveBeenCalledTimes(ref.mock.calls.length - 1);++ unmount();++ expect(cleanup).toHaveBeenCalledTimes(ref.mock.calls.length);+ });+itUnlessSkipped('dataAttributes', 'passes data attributes through', () => {render(compose({ 'data-conformance': CONFORMANCE_DATA_ATTRIBUTE_VALUE }));@@ -134,6 +147,7 @@ export const runComponentConformance = ({const rootNode = screen.getByTestId(CONFORMANCE_TEST_ID);expect(rootNode).toHaveClass(CONFORMANCE_CLASS_NAME);+ expect(rootNode.className.split(' ').pop()).toBe(CONFORMANCE_CLASS_NAME);if (isDefined(ownClassName)) {expect(rootNode).toHaveClass(ownClassName);