Skip to content

Commit f45131c

Browse files
feat(shadcn): component unit tests (#1275)
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent f40ba89 commit f45131c

37 files changed

Lines changed: 2873 additions & 22 deletions

docs/storybook/stories/agents-ui/AgentAudioVisualizerRadial.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default {
3939
control: { type: 'radio' },
4040
},
4141
barCount: {
42-
control: { type: 'range', min: 4, max: 64, step: 4 },
42+
control: { type: 'range', min: 4, max: 64, step: 1 },
4343
},
4444
radius: {
4545
control: { type: 'range', min: 1, max: 500, step: 1 },

packages/shadcn/components/agents-ui/agent-audio-visualizer-aura.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ export function AgentAudioVisualizerAura({
429429
return (
430430
<AuraShader
431431
ref={ref}
432+
data-lk-state={state}
432433
blur={0.2}
433434
color={color}
434435
colorShift={colorShift}

packages/shadcn/components/agents-ui/agent-audio-visualizer-bar.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ export function AgentAudioVisualizerBar({
172172
);
173173

174174
return (
175-
<div className={cn(AgentAudioVisualizerBarVariants({ size }), className)} {...props}>
175+
<div
176+
data-lk-state={state}
177+
className={cn(AgentAudioVisualizerBarVariants({ size }), className)}
178+
{...props}
179+
>
176180
{bands.map((band: number, idx: number) =>
177181
children ? (
178182
<React.Fragment key={idx}>

packages/shadcn/components/agents-ui/agent-audio-visualizer-grid.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ export function AgentAudioVisualizerGrid({
266266

267267
return (
268268
<div
269+
data-lk-state={state}
269270
className={cn(AgentAudioVisualizerGridVariants({ size }), className)}
270271
style={{ ...style, gridTemplateColumns: `repeat(${columnCount}, 1fr)` }}
271272
{...props}

packages/shadcn/components/agents-ui/agent-audio-visualizer-radial.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export function AgentAudioVisualizerRadial({
173173

174174
return (
175175
<div
176+
data-lk-state={state}
176177
className={cn(AgentAudioVisualizerRadialVariants({ size }), 'relative', className)}
177178
{...props}
178179
>

packages/shadcn/components/agents-ui/agent-audio-visualizer-wave.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ export function AgentAudioVisualizerWave({
283283
blur,
284284
audioTrack,
285285
className,
286-
style,
287286
ref,
288287
...props
289288
}: AgentAudioVisualizerWaveProps &
@@ -310,13 +309,13 @@ export function AgentAudioVisualizerWave({
310309
return (
311310
<WaveShader
312311
ref={ref}
312+
data-lk-state={state}
313313
speed={speed}
314314
color={color}
315315
amplitude={amplitude}
316316
frequency={frequency}
317317
lineWidth={_lineWidth}
318318
blur={blur}
319-
style={{ opacity, ...style }}
320319
className={cn(
321320
AgentAudioVisualizerWaveVariants({ size }),
322321
'mask-[linear-gradient(90deg,transparent_0%,black_20%,black_80%,transparent_100%)]',

packages/shadcn/components/agents-ui/agent-chat-indicator.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Ref } from 'react';
1+
import { type Ref, type ComponentProps } from 'react';
22
import { cva, type VariantProps } from 'class-variance-authority';
33
import { motion, type MotionProps } from 'motion/react';
44

@@ -78,7 +78,9 @@ export function AgentChatIndicator({
7878
size = 'md',
7979
className,
8080
...props
81-
}: AgentChatIndicatorProps & VariantProps<typeof agentChatIndicatorVariants>) {
81+
}: AgentChatIndicatorProps &
82+
ComponentProps<'span'> &
83+
VariantProps<typeof agentChatIndicatorVariants>) {
8284
return (
8385
<motion.span
8486
{...motionAnimationProps}

packages/shadcn/components/agents-ui/agent-chat-transcript.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use client';
22

3+
import { type ComponentProps } from 'react';
34
import { type AgentState, type ReceivedMessage } from '@livekit/components-react';
45
import {
56
Conversation,
@@ -13,7 +14,7 @@ import { AnimatePresence } from 'motion/react';
1314
/**
1415
* Props for the AgentChatTranscript component.
1516
*/
16-
export interface AgentChatTranscriptProps {
17+
export interface AgentChatTranscriptProps extends ComponentProps<'div'> {
1718
/**
1819
* The current state of the agent. When 'thinking', displays a loading indicator.
1920
*/

packages/shadcn/components/agents-ui/agent-disconnect-button.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ export function AgentDisconnectButton({
5959
const { end } = useSessionContext();
6060
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
6161
onClick?.(event);
62-
end();
62+
if (typeof end === 'function') {
63+
end();
64+
}
6365
};
6466

6567
return (

packages/shadcn/components/agents-ui/agent-track-toggle.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Fragment, type ComponentProps } from 'react';
1+
import { Fragment, type ComponentProps, useMemo, useState } from 'react';
22
import { type VariantProps, cva } from 'class-variance-authority';
33
import { Track } from 'livekit-client';
44
import {
@@ -120,22 +120,34 @@ export function AgentTrackToggle({
120120
variant = 'default',
121121
source,
122122
pending = false,
123-
pressed = false,
123+
pressed,
124124
defaultPressed = false,
125125
className,
126126
onPressedChange,
127127
...props
128128
}: AgentTrackToggleProps) {
129-
const IconComponent = getSourceIcon(source as Track.Source, pressed ?? false, pending);
129+
const [uncontrolledPressed, setUncontrolledPressed] = useState(defaultPressed ?? false);
130+
const isControlled = pressed !== undefined;
131+
const resolvedPressed = useMemo(
132+
() => (isControlled ? pressed : uncontrolledPressed) ?? false,
133+
[isControlled, pressed, uncontrolledPressed],
134+
);
135+
const IconComponent = getSourceIcon(source as Track.Source, resolvedPressed, pending);
136+
const handlePressedChange = (nextPressed: boolean) => {
137+
if (!isControlled) {
138+
setUncontrolledPressed(nextPressed);
139+
}
140+
onPressedChange?.(nextPressed);
141+
};
130142

131143
return (
132144
<Toggle
133145
size={size}
134146
variant={variant}
135-
pressed={pressed}
136-
defaultPressed={defaultPressed}
147+
pressed={isControlled ? pressed : undefined}
148+
defaultPressed={isControlled ? undefined : defaultPressed}
137149
aria-label={`Toggle ${source}`}
138-
onPressedChange={onPressedChange}
150+
onPressedChange={handlePressedChange}
139151
className={cn(
140152
agentTrackToggleVariants({
141153
size,

0 commit comments

Comments
 (0)