///
import { vi } from 'vitest'
vi.mock('next-view-transitions', () => ({ Link: (p: any) => {p.children} }))
import React from 'react'
import { render, fireEvent, waitFor } from '@testing-library/react'
import { describe, it, expect } from 'vitest'
import {
ConnectingToUploader,
DownloadComplete,
DownloadInProgress,
ReadyToDownload,
PasswordEntry,
} from '../../src/components/Downloader'
const files = [{ fileName: 'a.txt', size: 1, type: 'text/plain' }]
describe('Downloader subcomponents', () => {
it('ConnectingToUploader shows troubleshooting', async () => {
const { getByText } = render(
,
)
await waitFor(() => {
expect(getByText('Having trouble connecting?')).toBeInTheDocument()
})
})
it('DownloadComplete lists files', () => {
const { getByText } = render(
,
)
expect(getByText('You downloaded 1 file.')).toBeInTheDocument()
})
it('DownloadInProgress shows stop button', () => {
const { getByText } = render(
{}} />,
)
expect(getByText('Stop Download')).toBeInTheDocument()
})
it('ReadyToDownload shows start button', () => {
const { getByText } = render(
{}} />,
)
expect(getByText('Download')).toBeInTheDocument()
})
it('PasswordEntry submits value', () => {
let submitted = ''
const { getByPlaceholderText, getByText } = render(
(submitted = v)} />,
)
fireEvent.change(
getByPlaceholderText('Enter a secret password for this slice of FilePizza...'),
{ target: { value: 'secret' } },
)
fireEvent.submit(getByText('Unlock'))
expect(submitted).toBe('secret')
})
})