mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-18 00:55:35 +00:00
instead of window.opener - it is more robust inspired by #4110 closes #6246 closes #4107 Biggest caveat: In cases where window.opener is null (Dropbox), the auth window will not be auto closed (I don't know how to fix that). It will show the user a message "Authentication successful. You may now close this page." https://github.com/transloadit/uppy/pull/6248/changes#diff-ef5b69c4ab5b83168eaba6f57047bb07c53e3a426f375b42fcb32d79c746872cR22 --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Prakash <qxprakash@gmail.com>
133 lines
4.3 KiB
TypeScript
133 lines
4.3 KiB
TypeScript
import { userEvent } from '@vitest/browser/context'
|
|
import { setupWorker } from 'msw/browser'
|
|
import { afterAll, beforeAll, describe, expect, test } from 'vitest'
|
|
import { render } from 'vitest-browser-react'
|
|
import { tusHandlers } from '../../shared/tusHandlers.js'
|
|
import App from '../src/App'
|
|
|
|
const worker = setupWorker(...tusHandlers)
|
|
beforeAll(async () => {
|
|
await worker.start({ onUnhandledRequest: 'bypass' })
|
|
})
|
|
afterAll(() => {
|
|
worker.stop()
|
|
})
|
|
|
|
const createMockFile = (name: string, type: string, size: number = 1024) => {
|
|
return new File(['test content'], name, { type })
|
|
}
|
|
|
|
describe('App', () => {
|
|
test('renders all main sections and upload button is initially disabled', async () => {
|
|
const screen = render(<App />)
|
|
|
|
await expect.element(screen.getByText('With list')).toBeInTheDocument()
|
|
await expect.element(screen.getByText('With grid')).toBeInTheDocument()
|
|
await expect
|
|
.element(screen.getByText('With custom dropzone'))
|
|
.toBeInTheDocument()
|
|
|
|
const uploadButton = screen.getByRole('button', { name: /upload/i })
|
|
await expect.element(uploadButton).toBeInTheDocument()
|
|
await expect.element(uploadButton).toBeDisabled()
|
|
})
|
|
|
|
test('can add and remove files and upload', async () => {
|
|
const screen = render(<App />)
|
|
|
|
const fileInput = document.getElementById(
|
|
'uppy-dropzone-file-input-uppy',
|
|
) as Element
|
|
await userEvent.upload(fileInput, createMockFile('test.txt', 'text/plain'))
|
|
|
|
// for list and grid
|
|
for (const element of screen.getByText('test.txt').elements()) {
|
|
await expect.element(element).toBeInTheDocument()
|
|
}
|
|
await screen.getByText('remove').first().click()
|
|
for (const element of screen.getByText('test.txt').elements()) {
|
|
await expect.element(element).not.toBeInTheDocument()
|
|
}
|
|
|
|
await userEvent.upload(fileInput, createMockFile('test.txt', 'text/plain'))
|
|
await screen.getByRole('button', { name: /upload/i }).click()
|
|
await expect
|
|
.element(screen.getByRole('button', { name: /complete/i }))
|
|
.toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('ScreenCapture Component', () => {
|
|
test('renders with title, control buttons, and close functionality works', async () => {
|
|
const screen = render(<App />)
|
|
|
|
await screen.getByRole('button', { name: 'Screen Capture' }).click()
|
|
|
|
await expect
|
|
.element(screen.getByRole('heading', { name: 'Screen Capture' }))
|
|
.toBeInTheDocument()
|
|
|
|
await expect
|
|
.element(screen.getByRole('button', { name: 'Screenshot' }))
|
|
.toBeInTheDocument()
|
|
await expect
|
|
.element(screen.getByRole('button', { name: 'Record' }))
|
|
.toBeInTheDocument()
|
|
await expect
|
|
.element(screen.getByRole('button', { name: 'Stop' }))
|
|
.toBeInTheDocument()
|
|
await expect
|
|
.element(screen.getByRole('button', { name: 'Submit' }))
|
|
.toBeInTheDocument()
|
|
await expect
|
|
.element(screen.getByRole('button', { name: 'Discard' }))
|
|
.toBeInTheDocument()
|
|
|
|
const closeButton = screen.getByText('✕')
|
|
await closeButton.click()
|
|
})
|
|
})
|
|
|
|
describe('Webcam Component', () => {
|
|
test('renders with title, control buttons, and close functionality works', async () => {
|
|
const screen = render(<App />)
|
|
|
|
await screen.getByRole('button', { name: 'Webcam' }).click()
|
|
|
|
await expect
|
|
.element(screen.getByRole('heading', { name: 'Camera' }))
|
|
.toBeInTheDocument()
|
|
|
|
await expect
|
|
.element(screen.getByRole('button', { name: 'Snapshot' }))
|
|
.toBeInTheDocument()
|
|
await expect
|
|
.element(screen.getByRole('button', { name: 'Record' }))
|
|
.toBeInTheDocument()
|
|
await expect
|
|
.element(screen.getByRole('button', { name: 'Stop' }))
|
|
.toBeInTheDocument()
|
|
await expect
|
|
.element(screen.getByRole('button', { name: 'Submit' }))
|
|
.toBeInTheDocument()
|
|
await expect
|
|
.element(screen.getByRole('button', { name: 'Discard' }))
|
|
.toBeInTheDocument()
|
|
|
|
const closeButton = screen.getByText('✕')
|
|
await closeButton.click()
|
|
})
|
|
})
|
|
|
|
describe('RemoteSource Component', () => {
|
|
test('renders login button and login interaction works', async () => {
|
|
const screen = render(<App />)
|
|
|
|
await screen.getByRole('button', { name: 'Dropbox' }).click()
|
|
|
|
const loginButton = screen.getByRole('button', { name: 'Login' })
|
|
await expect.element(loginButton).toBeInTheDocument()
|
|
|
|
await loginButton.click()
|
|
})
|
|
})
|