Skip to content
Open
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
14 changes: 6 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 44 additions & 4 deletions tests/unit/screens/SettingsScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { server } from '@tests/mocks/node';
import { fireEvent, render, screen, userEvent } from '@tests/mocks/test-utils';
import {
fireEvent,
render,
screen,
userEvent,
within,
} from '@tests/mocks/test-utils';
import { HttpResponse, http } from 'msw';
import { beforeEach, describe, expect, it, vi } from 'vitest';

Expand Down Expand Up @@ -174,9 +180,11 @@ describe('SettingsScreen', () => {
// Wait for results to render
await screen.findByText('Results');

// Click copy button (there are two — URL and code)
const copyButtons = screen.getAllByRole('button', { name: 'Copy' });
await user.click(copyButtons[0]!);
// Scope to the invite-URL row and click its Copy button
const inviteUrlRow = screen.getByText('Invite URL').closest('div')!;
await user.click(
within(inviteUrlRow).getByRole('button', { name: 'Copy' }),
);

expect(writeText).toHaveBeenCalledWith(
expect.stringContaining('/invite?code='),
Expand All @@ -186,6 +194,38 @@ describe('SettingsScreen', () => {
expect(screen.getByText('Copied!')).toBeInTheDocument();
});

it('copies invite code to clipboard', async () => {
const writeText = vi.fn().mockResolvedValue(undefined);
navigator.clipboard.writeText = writeText;

const user = userEvent.setup();
render(<SettingsScreen />);

// Fill form and generate
await user.type(
screen.getByLabelText('Remote Archive URL'),
'https://archive.example.com',
);
await user.type(screen.getByLabelText('Bearer Token'), 'my-secret-token');
await user.click(screen.getByRole('button', { name: 'Generate Invite' }));

// Wait for results to render
await screen.findByText('Results');

// Scope to the invite-code row and click its Copy button
const inviteCodeRow = screen.getByText('Invite Code').closest('div')!;
await user.click(
within(inviteCodeRow).getByRole('button', { name: 'Copy' }),
);

expect(writeText).toHaveBeenCalledWith(
expect.stringContaining('mock-encrypted-code-'),
);

// Should show "Copied!" feedback
expect(screen.getByText('Copied!')).toBeInTheDocument();
});

describe('Backup & Restore', () => {
it('renders Backup & Restore section heading', () => {
render(<SettingsScreen />);
Expand Down
Loading