Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { AgentOnboardingEntry } from './AgentOnboardingEntry';
import { useConditionalFeature } from '../../../hooks/useConditionalFeature';
import { useViewSize } from '../../../hooks/useViewSize';
import { agentOnboardingPrompt } from '../prompt';

jest.mock('../../../hooks/useConditionalFeature', () => ({
useConditionalFeature: jest.fn(),
Expand All @@ -14,20 +16,44 @@ jest.mock('../../../hooks/useViewSize', () => ({

const mockFlag = jest.mocked(useConditionalFeature);
const mockViewSize = jest.mocked(useViewSize);
const writeText = jest.fn();

beforeEach(() => {
jest.clearAllMocks();
mockViewSize.mockReturnValue(true);
mockFlag.mockReturnValue({ value: true, isLoading: false });
writeText.mockResolvedValue(undefined);
Object.defineProperty(navigator, 'clipboard', {
configurable: true,
value: { writeText },
});
});

const copyButton = () =>
screen.getByRole('button', { name: 'Set up with your coding agent' });

describe('AgentOnboardingEntry', () => {
it('links to agent onboarding when the experiment is on', () => {
it('copies the prompt and says what to do next', async () => {
render(<AgentOnboardingEntry />);

await userEvent.click(copyButton());

expect(writeText).toHaveBeenCalledWith(agentOnboardingPrompt);
expect(
screen.getByRole('link', { name: 'Let it set up daily.dev for you' }),
).toHaveAttribute('href', '/agents/onboarding');
await screen.findByRole('button', { name: 'Prompt copied' }),
).toBeInTheDocument();
expect(
screen.getByText(/Paste it into your coding agent/),
).toBeInTheDocument();
});

it('shows the prompt when the clipboard is blocked', async () => {
writeText.mockRejectedValue(new Error('denied'));
render(<AgentOnboardingEntry />);

await userEvent.click(copyButton());

expect(await screen.findByText(agentOnboardingPrompt)).toBeInTheDocument();
});

it('renders nothing for the control group', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import type { ReactElement } from 'react';
import React from 'react';
import React, { useState } from 'react';
import classNames from 'classnames';
import Link from '../../../components/utilities/Link';
import { Button } from '../../../components/buttons/Button';
import { ButtonSize, ButtonVariant } from '../../../components/buttons/common';
import { TerminalIcon } from '../../../components/icons/Terminal';
import { VIcon } from '../../../components/icons/V';
import { useLogContext } from '../../../contexts/LogContext';
import { useConditionalFeature } from '../../../hooks/useConditionalFeature';
import { useViewSize, ViewSize } from '../../../hooks/useViewSize';
import { webappUrl } from '../../../lib/constants';
import { featureAgentOnboardingEntry } from '../../../lib/featureManagement';
import { LogEvent } from '../../../lib/log';

const agentOnboardingUrl = `${webappUrl}agents/onboarding`;
import { agentOnboardingPrompt } from '../prompt';

type AgentOnboardingEntryProps = {
className?: string;
};

type CopyState = 'idle' | 'copied' | 'blocked';

// Agents run on a computer, so smaller screens are left out of the experiment.
export const AgentOnboardingEntry = ({
className,
}: AgentOnboardingEntryProps): ReactElement | null => {
const { logEvent } = useLogContext();
const [copyState, setCopyState] = useState<CopyState>('idle');
const isLaptop = useViewSize(ViewSize.Laptop);
const { value: isEnabled } = useConditionalFeature({
feature: featureAgentOnboardingEntry,
Expand All @@ -30,20 +34,46 @@ export const AgentOnboardingEntry = ({
return null;
}

const onCopy = async () => {
logEvent({ event_name: LogEvent.ClickAgentOnboardingEntry });

try {
await navigator.clipboard.writeText(agentOnboardingPrompt);
setCopyState('copied');
} catch {
setCopyState('blocked');
}
};

const isCopied = copyState === 'copied';

return (
<span className={classNames('text-text-tertiary typo-callout', className)}>
Use a coding agent?{' '}
<Link href={agentOnboardingUrl} passHref>
<a
href={agentOnboardingUrl}
className="text-text-primary underline underline-offset-4"
onClick={() =>
logEvent({ event_name: LogEvent.ClickAgentOnboardingEntry })
}
>
Let it set up daily.dev for you
</a>
</Link>
</span>
<div className={classNames('flex flex-col gap-2', className)}>
<Button
className="w-full"
icon={isCopied ? <VIcon /> : <TerminalIcon />}
onClick={onCopy}
size={ButtonSize.Large}
type="button"
variant={ButtonVariant.Float}
>
{isCopied ? 'Prompt copied' : 'Set up with your coding agent'}
</Button>
<p aria-live="polite" className="text-text-tertiary typo-footnote">
{copyState === 'idle' &&
'Copies a prompt for Claude Code, Codex, or Cursor.'}
{isCopied &&
'Paste it into your coding agent. It sets up daily.dev for you.'}
{copyState === 'blocked' && (
<>
Your browser blocked the clipboard. Copy this prompt into your
coding agent:{' '}
<span className="select-all break-words text-text-primary">
{agentOnboardingPrompt}
</span>
</>
)}
</p>
</div>
);
};
5 changes: 3 additions & 2 deletions packages/shared/src/lib/featureManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,9 @@ export const featureWeeklyPicksChecks = new Feature(
false,
);

// Experiment: a link from the sign-up screen into agent onboarding.
// Experiment: a sign-up screen button that copies the agent onboarding prompt.
// TEMP: on for preview testing only. Revert to false before merging.
export const featureAgentOnboardingEntry = new Feature(
'agent_onboarding_entry',
false,
true,
);
Loading