Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

test(web): move upload affordances to Browser Mode (#45690)

Stephen Zhouebf662d434ba
diff --git a/web/app/components/base/file-uploader/__tests__/file-list-in-log.browser.spec.tsx b/web/app/components/base/file-uploader/__tests__/file-list-in-log.browser.spec.tsx
new file mode 100644
index 00000000000..a9fd3fa86cd
--- /dev/null
+++ b/web/app/components/base/file-uploader/__tests__/file-list-in-log.browser.spec.tsx
@@ -0,0 +1,73 @@
+import type { FileEntity } from '../types'
+import { page, userEvent } from 'vite-plus/test/browser'
+import { render } from 'vitest-browser-react'
+import { TransferMethod } from '@/types/app'
+import FileListInLog from '../file-list-in-log'
+
+const imageDataUrl =
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII='
+
+const createFile = (overrides: Partial<FileEntity> = {}): FileEntity => ({
+ id: 'file-1',
+ name: 'test.txt',
+ size: 1024,
+ type: 'text/plain',
+ progress: 100,
+ transferMethod: TransferMethod.local_file,
+ supportFileType: 'document',
+ ...overrides,
+})
+
+it('reveals mixed log attachments with native hover and keyboard disclosure, then removes the empty disclosure', async () => {
+ const fileList = [
+ {
+ varName: 'images',
+ list: [
+ createFile({
+ id: 'photo',
+ name: 'photo.png',
+ supportFileType: 'image',
+ url: imageDataUrl,
+ }),
+ ],
+ },
+ { varName: 'documents', list: [createFile({ id: 'report', name: 'report.txt' })] },
+ ]
+ const view = await render(
+ <div>
+ <button type="button">Before attachments</button>
+ <FileListInLog fileList={fileList} />
+ </div>,
+ )
+
+ const preview = page.getByRole('img', { name: 'Preview' })
+ await expect.element(preview).toHaveAttribute('src', imageDataUrl)
+ await preview.hover()
+ await expect.element(page.getByText('photo.png')).toBeVisible()
+ await expect.element(page.getByText('documents')).not.toBeInTheDocument()
+
+ await page.getByRole('button', { name: 'Before attachments' }).click()
+ await userEvent.tab()
+ const disclosure = page.getByRole('button', { name: 'appLog.runDetail.fileListDetail' })
+ await expect.element(disclosure).toHaveFocus()
+ await userEvent.keyboard('{Enter}')
+ await expect.element(page.getByText('images')).toBeVisible()
+ await expect.element(page.getByText('documents')).toBeVisible()
+ await expect.element(page.getByText('photo.png')).toBeVisible()
+ await expect.element(page.getByText('report.txt')).toBeVisible()
+
+ await userEvent.tab({ shift: true })
+ const collapse = page.getByRole('button', { name: 'appLog.runDetail.fileListLabel' })
+ await expect.element(collapse).toHaveFocus()
+ await userEvent.keyboard('{Enter}')
+ await expect.element(page.getByText('documents')).not.toBeInTheDocument()
+ await expect.element(disclosure).toBeVisible()
+
+ await view.rerender(
+ <div>
+ <button type="button">Before attachments</button>
+ <FileListInLog fileList={[]} />
+ </div>,
+ )
+ await expect.element(disclosure).not.toBeInTheDocument()
+})
diff --git a/web/app/components/base/file-uploader/__tests__/file-list-in-log.spec.tsx b/web/app/components/base/file-uploader/__tests__/file-list-in-log.spec.tsx
deleted file mode 100644
index 5a8f36e1d7f..00000000000
--- a/web/app/components/base/file-uploader/__tests__/file-list-in-log.spec.tsx
+++ /dev/null
@@ -1,57 +0,0 @@
-import type { FileEntity } from '../types'
-import { render, screen } from '@testing-library/react'
-import userEvent from '@testing-library/user-event'
-import { TransferMethod } from '@/types/app'
-import FileListInLog from '../file-list-in-log'
-
-const createFile = (overrides: Partial<FileEntity> = {}): FileEntity => ({
- id: 'file-1',
- name: 'test.txt',
- size: 1024,
- type: 'text/plain',
- progress: 100,
- transferMethod: TransferMethod.local_file,
- supportFileType: 'document',
- ...overrides,
-})
-
-it('expands mixed log attachments into their variable groups and collapses them again', async () => {
- const user = userEvent.setup()
- render(
- <FileListInLog
- fileList={[
- {
- varName: 'images',
- list: [
- createFile({
- id: 'photo',
- name: 'photo.png',
- supportFileType: 'image',
- url: 'https://example.com/photo.png',
- }),
- ],
- },
- { varName: 'documents', list: [createFile({ id: 'report', name: 'report.txt' })] },
- ]}
- />,
- )
- expect(screen.getByRole('img')).toHaveAttribute('src', 'https://example.com/photo.png')
- expect(screen.queryByText('documents')).not.toBeInTheDocument()
- await user.click(screen.getByRole('button', { name: 'appLog.runDetail.fileListDetail' }))
- expect(screen.getByText('images')).toBeInTheDocument()
- expect(screen.getByText('documents')).toBeInTheDocument()
- expect(screen.getByText('photo.png')).toBeInTheDocument()
- expect(screen.getByText('report.txt')).toBeInTheDocument()
- await user.click(screen.getByRole('button', { name: 'appLog.runDetail.fileListLabel' }))
- expect(screen.queryByText('documents')).not.toBeInTheDocument()
- expect(
- screen.getByRole('button', { name: 'appLog.runDetail.fileListDetail' }),
- ).toBeInTheDocument()
-})
-
-it('omits the attachment disclosure when no files were logged', () => {
- render(<FileListInLog fileList={[]} />)
- expect(
- screen.queryByRole('button', { name: 'appLog.runDetail.fileListDetail' }),
- ).not.toBeInTheDocument()
-})
diff --git a/web/app/components/base/file-uploader/file-uploader-in-chat-input/__tests__/file-list.browser.spec.tsx b/web/app/components/base/file-uploader/file-uploader-in-chat-input/__tests__/file-list.browser.spec.tsx
new file mode 100644
index 00000000000..fe979448525
--- /dev/null
+++ b/web/app/components/base/file-uploader/file-uploader-in-chat-input/__tests__/file-list.browser.spec.tsx
@@ -0,0 +1,69 @@
+import type { FileEntity } from '../../types'
+import type { FileUpload } from '@/app/components/base/features/types'
+import { page, userEvent } from 'vite-plus/test/browser'
+import { render } from 'vitest-browser-react'
+import { createConsoleQueryWrapper } from '@/test/console/query-data'
+import { TransferMethod } from '@/types/app'
+import { FileContextProvider } from '../../store'
+import { FileListInChatInput } from '../file-list'
+
+vi.mock('@/next/navigation', () => ({ useParams: () => ({}), usePathname: () => '/' }))
+
+it('removes mixed chat attachments through their real keyboard and pointer affordances', async () => {
+ const files: FileEntity[] = [
+ {
+ id: 'photo',
+ name: 'photo.png',
+ type: 'image/png',
+ size: 1024,
+ progress: 100,
+ transferMethod: TransferMethod.local_file,
+ supportFileType: 'image',
+ base64Url:
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII=',
+ },
+ {
+ id: 'document',
+ name: 'document.pdf',
+ type: 'application/pdf',
+ size: 2048,
+ progress: 100,
+ transferMethod: TransferMethod.local_file,
+ supportFileType: 'document',
+ },
+ ]
+ const config: FileUpload = { enabled: true, allowed_file_types: ['image', 'document'] }
+ const onChange = vi.fn()
+ const { wrapper: ConsoleProvider } = createConsoleQueryWrapper()
+ await render(
+ <ConsoleProvider>
+ <button type="button">Before attachments</button>
+ <FileContextProvider value={files} onChange={onChange}>
+ <FileListInChatInput fileConfig={config} />
+ </FileContextProvider>
+ </ConsoleProvider>,
+ )
+
+ await expect.element(page.getByRole('img', { name: 'Preview' })).toBeVisible()
+ await expect.element(page.getByText('document.pdf')).toBeVisible()
+ await page.getByRole('button', { name: 'Before attachments' }).click()
+ await userEvent.tab()
+ await expect
+ .element(page.getByRole('button', { name: 'common.operation.view photo.png' }))
+ .toHaveFocus()
+ await userEvent.tab()
+ const imageRemove = page.getByRole('button', { name: 'common.operation.remove' }).first()
+ await expect.element(imageRemove).toHaveFocus()
+ await expect.poll(() => getComputedStyle(imageRemove.element()).opacity).toBe('1')
+ await userEvent.keyboard('{Enter}')
+ await expect.element(page.getByRole('img', { name: 'Preview' })).not.toBeInTheDocument()
+ await expect.element(page.getByText('document.pdf')).toBeVisible()
+ expect(onChange).toHaveBeenLastCalledWith([files[1]])
+
+ await page.getByText('document.pdf').hover()
+ const documentRemove = page.getByRole('button', { name: 'common.operation.remove' })
+ await expect.element(documentRemove).toBeVisible()
+ await documentRemove.click()
+ await expect.element(page.getByText('document.pdf')).not.toBeInTheDocument()
+ expect(onChange).toHaveBeenLastCalledWith([])
+})
diff --git a/web/app/components/base/file-uploader/file-uploader-in-chat-input/__tests__/file-list.spec.tsx b/web/app/components/base/file-uploader/file-uploader-in-chat-input/__tests__/file-list.spec.tsx
deleted file mode 100644
index 17aa5e10976..00000000000
--- a/web/app/components/base/file-uploader/file-uploader-in-chat-input/__tests__/file-list.spec.tsx
+++ /dev/null
@@ -1,52 +0,0 @@
-import type { FileEntity } from '../../types'
-import type { FileUpload } from '@/app/components/base/features/types'
-import { render, screen } from '@testing-library/react'
-import userEvent from '@testing-library/user-event'
-import { createConsoleQueryWrapper } from '@/test/console/query-data'
-import { TransferMethod } from '@/types/app'
-import { FileContextProvider } from '../../store'
-import { FileListInChatInput } from '../file-list'
-
-vi.mock('@/next/navigation', () => ({ useParams: () => ({}), usePathname: () => '/' }))
-
-it('removes the selected attachment from a mixed chat file list and reports the remaining files', async () => {
- const user = userEvent.setup()
- const files: FileEntity[] = [
- {
- id: 'photo',
- name: 'photo.png',
- type: 'image/png',
- size: 1024,
- progress: 100,
- transferMethod: TransferMethod.local_file,
- supportFileType: 'image',
- base64Url: 'data:image/png;base64,abc',
- },
- {
- id: 'document',
- name: 'document.pdf',
- type: 'application/pdf',
- size: 2048,
- progress: 100,
- transferMethod: TransferMethod.local_file,
- supportFileType: 'document',
- },
- ]
- const config: FileUpload = { enabled: true, allowed_file_types: ['image', 'document'] }
- const onChange = vi.fn()
- render(
- <FileContextProvider value={files} onChange={onChange}>
- <FileListInChatInput fileConfig={config} />
- </FileContextProvider>,
- { wrapper: createConsoleQueryWrapper().wrapper },
- )
- expect(screen.getByRole('img')).toBeInTheDocument()
- expect(screen.getByText('document.pdf')).toBeInTheDocument()
- await user.click(screen.getAllByRole('button', { name: 'common.operation.remove' })[0]!)
- expect(screen.queryByRole('img')).not.toBeInTheDocument()
- expect(screen.getByText('document.pdf')).toBeInTheDocument()
- expect(onChange).toHaveBeenLastCalledWith([files[1]])
- await user.click(screen.getByRole('button', { name: 'common.operation.remove' }))
- expect(screen.queryByText('document.pdf')).not.toBeInTheDocument()
- expect(onChange).toHaveBeenLastCalledWith([])
-})
diff --git a/web/app/components/base/form/components/__tests__/label.browser.spec.tsx b/web/app/components/base/form/components/__tests__/label.browser.spec.tsx
new file mode 100644
index 00000000000..46fdb3a2b6f
--- /dev/null
+++ b/web/app/components/base/form/components/__tests__/label.browser.spec.tsx
@@ -0,0 +1,56 @@
+import { page, userEvent } from 'vite-plus/test/browser'
+import { render } from 'vitest-browser-react'
+import Label from '../label'
+
+function FieldLabel({
+ isRequired = false,
+ showOptional = false,
+ tooltip,
+}: {
+ isRequired?: boolean
+ showOptional?: boolean
+ tooltip?: string
+}) {
+ return (
+ <div>
+ <Label
+ htmlFor="test-input"
+ label="Test Label"
+ isRequired={isRequired}
+ showOptional={showOptional}
+ tooltip={tooltip}
+ />
+ <input id="test-input" />
+ </div>
+ )
+}
+
+describe('Label', () => {
+ it('focuses its optional field and exposes the explanation from the keyboard', async () => {
+ await render(<FieldLabel showOptional tooltip="Test Tooltip" />)
+
+ const input = page.getByRole('textbox', { name: 'Test Label' })
+ await page.getByText('Test Label').click()
+ await expect.element(input).toHaveFocus()
+ await expect.element(page.getByText('common.label.optional')).toBeVisible()
+
+ await userEvent.tab({ shift: true })
+ const explanation = page.getByRole('button', { name: 'Test Label' })
+ await expect.element(explanation).toHaveFocus()
+ await userEvent.keyboard('{Enter}')
+ const dialog = page.getByRole('dialog', { name: 'Test Label' })
+ await expect.element(dialog).toHaveTextContent('Test Tooltip')
+ await userEvent.keyboard('{Escape}')
+ await expect.element(dialog).not.toBeInTheDocument()
+ await expect.element(explanation).toHaveFocus()
+ })
+
+ it('shows the required marker instead of the optional label without breaking association', async () => {
+ await render(<FieldLabel isRequired showOptional />)
+
+ await expect.element(page.getByText('common.label.optional')).not.toBeInTheDocument()
+ await expect.element(page.getByText('*')).toBeVisible()
+ await page.getByText('Test Label').click()
+ await expect.element(page.getByRole('textbox', { name: 'Test Label' })).toHaveFocus()
+ })
+})
diff --git a/web/app/components/base/form/components/__tests__/label.spec.tsx b/web/app/components/base/form/components/__tests__/label.spec.tsx
deleted file mode 100644
index 98b078ac549..00000000000
--- a/web/app/components/base/form/components/__tests__/label.spec.tsx
+++ /dev/null
@@ -1,30 +0,0 @@
-import { render, screen } from '@testing-library/react'
-import userEvent from '@testing-library/user-event'
-import Label from '../label'
-
-describe('Label', () => {
- const defaultProps = {
- htmlFor: 'test-input',
- label: 'Test Label',
- }
-
- it('should show optional text when the field is not required', () => {
- render(<Label {...defaultProps} showOptional />)
- expect(screen.getByText('common.label.optional')).toBeInTheDocument()
- })
-
- it('names the explanation from its field label', async () => {
- const user = userEvent.setup()
- const tooltipText = 'Test Tooltip'
- render(<Label {...defaultProps} tooltip={tooltipText} />)
-
- await user.click(screen.getByRole('button', { name: 'Test Label' }))
- expect(await screen.findByRole('dialog', { name: 'Test Label' })).toHaveTextContent(tooltipText)
- })
-
- it('should hide optional text when required is true', () => {
- render(<Label {...defaultProps} isRequired showOptional />)
- expect(screen.queryByText('common.label.optional')).not.toBeInTheDocument()
- expect(screen.getByText('*')).toBeInTheDocument()
- })
-})
diff --git a/web/app/components/base/icon-picker/__tests__/async-session.browser.spec.tsx b/web/app/components/base/icon-picker/__tests__/async-session.browser.spec.tsx
index c98a8f9881f..cd9db4152dc 100644
--- a/web/app/components/base/icon-picker/__tests__/async-session.browser.spec.tsx
+++ b/web/app/components/base/icon-picker/__tests__/async-session.browser.spec.tsx
@@ -5,15 +5,10 @@ import { render } from 'vitest-browser-react'
import { emojiCatalogOptions } from '../emoji-data'
import { IconPickerDialog } from './harness'
-const { cropImage, uploadImage } = vi.hoisted(() => ({
- cropImage: vi.fn<() => Promise<Blob>>(),
- uploadImage: vi.fn<() => Promise<PostFilesUploadResponse>>(),
+const { uploadImage } = vi.hoisted(() => ({
+ uploadImage: vi.fn<(request: { body: { file: File } }) => Promise<PostFilesUploadResponse>>(),
}))
-vi.mock('../image-crop', async (importOriginal) => ({
- ...(await importOriginal<typeof import('../image-crop')>()),
- default: cropImage,
-}))
vi.mock('@/service/console', () => ({
consoleQuery: {
files: { upload: { post: { mutationOptions: () => ({ mutationFn: uploadImage }) } } },
@@ -23,9 +18,13 @@ vi.mock('@/next/navigation', () => ({ useParams: () => ({}) }))
async function createImageFile() {
const canvas = document.createElement('canvas')
- canvas.width = 100
- canvas.height = 100
- canvas.getContext('2d')!.fillRect(0, 0, 100, 100)
+ canvas.width = 120
+ canvas.height = 80
+ const context = canvas.getContext('2d')!
+ context.fillStyle = '#ef4444'
+ context.fillRect(0, 0, 60, 80)
+ context.fillStyle = '#3b82f6'
+ context.fillRect(60, 0, 60, 80)
const blob = await new Promise<Blob>((resolve) =>
canvas.toBlob((value) => resolve(value!), 'image/png'),
)
@@ -57,6 +56,41 @@ async function openImageSession() {
return { screen, client, trigger, dialog, save, file, onConfirm }
}
+function deferNextCanvasBlob() {
+ const originalToBlob = HTMLCanvasElement.prototype.toBlob
+ let release!: () => void
+ let encodedBlob!: Blob
+ const encoded = new Promise<void>((resolve) => {
+ vi.spyOn(HTMLCanvasElement.prototype, 'toBlob').mockImplementation(function (
+ this: HTMLCanvasElement,
+ callback,
+ type,
+ quality,
+ ) {
+ originalToBlob.call(
+ this,
+ (blob) => {
+ if (!blob) {
+ callback(null)
+ resolve()
+ return
+ }
+ encodedBlob = blob
+ release = () => callback(blob)
+ resolve()
+ },
+ type,
+ quality,
+ )
+ })
+ })
+ return {
+ encoded,
+ getBlob: () => encodedBlob,
+ release: () => release(),
+ }
+}
+
beforeEach(() => {
vi.clearAllMocks()
vi.stubGlobal('BASE_UI_ANIMATIONS_DISABLED', false)
@@ -67,24 +101,22 @@ afterEach(() => {
})
it('ignores crop completion during the closing animation while Cancel remains available', async () => {
- let finishCrop!: (blob: Blob) => void
- cropImage.mockReturnValueOnce(
- new Promise<Blob>((resolve) => {
- finishCrop = resolve
- }),
- )
- const { client, trigger, dialog, save, file, onConfirm } = await openImageSession()
+ const { client, trigger, dialog, save, onConfirm } = await openImageSession()
+ const crop = deferNextCanvasBlob()
const popup = dialog.element()
await expect.poll(() => getComputedStyle(popup).opacity).toBe('1')
await save.click()
- await expect.poll(() => cropImage.mock.calls.length).toBe(1)
+ await crop.encoded
+ const bitmap = await createImageBitmap(crop.getBlob())
+ expect({ width: bitmap.width, height: bitmap.height }).toEqual({ width: 80, height: 80 })
+ bitmap.close()
const cancel = dialog.getByRole('button', { name: 'app.iconPicker.cancel' })
await expect.element(cancel).toBeEnabled()
const exitFrame = new Promise<number>((resolve) => {
const onTransition = (event: Event) => {
if (event.target !== popup || (event as TransitionEvent).propertyName !== 'opacity') return
popup.removeEventListener('transitionrun', onTransition)
- finishCrop(file)
+ crop.release()
resolve(Number(getComputedStyle(popup).opacity))
}
popup.addEventListener('transitionrun', onTransition)
@@ -112,9 +144,12 @@ it('ignores an old upload when reopened as soon as keyboard focus returns', asyn
})
uploadImage.mockReturnValueOnce(pendingUpload)
const { client, trigger, dialog, save, file, onConfirm } = await openImageSession()
- cropImage.mockResolvedValueOnce(file)
await save.click()
await expect.poll(() => uploadImage.mock.calls.length).toBe(1)
+ const uploadedFile = uploadImage.mock.calls[0]![0].body.file
+ const bitmap = await createImageBitmap(uploadedFile)
+ expect({ width: bitmap.width, height: bitmap.height }).toEqual({ width: 80, height: 80 })
+ bitmap.close()
await expect.element(dialog.getByRole('button', { name: 'app.iconPicker.cancel' })).toBeEnabled()
await userEvent.keyboard('{Escape}')
await expect.element(trigger).toHaveFocus()
diff --git a/web/features/new-rag/upload/__tests__/plan-notice.browser.spec.tsx b/web/features/new-rag/upload/__tests__/plan-notice.browser.spec.tsx
new file mode 100644
index 00000000000..c8867eff66e
--- /dev/null
+++ b/web/features/new-rag/upload/__tests__/plan-notice.browser.spec.tsx
@@ -0,0 +1,53 @@
+import { NuqsTestingAdapter } from 'nuqs/adapters/testing'
+import { page, userEvent } from 'vite-plus/test/browser'
+import { render } from 'vitest-browser-react'
+import { createConsoleQueryWrapper } from '@/test/console/query-data'
+import { DocumentUploadPlanNotice } from '../plan-notice'
+
+async function renderNotice(plan: 'sandbox' | 'professional') {
+ const onUrlUpdate = vi.fn()
+ const { wrapper: ConsoleProvider } = createConsoleQueryWrapper({
+ features: { billing: { subscription: { plan } } },
+ systemFeatures: { deployment_edition: 'CLOUD' },
+ })
+ await render(
+ <ConsoleProvider>
+ <NuqsTestingAdapter onUrlUpdate={onUrlUpdate}>
+ <DocumentUploadPlanNotice fileSizeLimitMb={15} />
+ </NuqsTestingAdapter>
+ </ConsoleProvider>,
+ )
+ return onUrlUpdate
+}
+
+it('shows the free upload constraints and opens the existing pricing flow from the keyboard', async () => {
+ const onUrlUpdate = await renderNotice('sandbox')
+ await expect.element(page.getByText('billing.upgrade.uploadMultiplePages.title')).toBeVisible()
+ await expect
+ .element(page.getByText(/datasetCreation\.stepOne\.uploader\.tip:.*"size":15.*"batchCount":1/))
+ .toBeVisible()
+ await expect
+ .element(page.getByText('billing.upgrade.uploadMultipleFiles.title'))
+ .not.toBeInTheDocument()
+ await expect
+ .element(page.getByText('billing.upgrade.uploadMultipleFiles.description'))
+ .not.toBeInTheDocument()
+
+ await userEvent.tab()
+ const upgrade = page.getByRole('button', { name: 'billing.triggerLimitModal.upgrade' })
+ await expect.element(upgrade).toHaveFocus()
+ await userEvent.keyboard('{Enter}')
+ await expect
+ .poll(() => onUrlUpdate.mock.calls.at(-1)?.[0].searchParams.get('pricing'))
+ .toBe('open')
+})
+
+it('does not show the free upload notice for a paid plan', async () => {
+ await renderNotice('professional')
+ await expect
+ .element(page.getByText('billing.upgrade.uploadMultiplePages.title'))
+ .not.toBeInTheDocument()
+ await expect
+ .element(page.getByRole('button', { name: 'billing.triggerLimitModal.upgrade' }))
+ .not.toBeInTheDocument()
+})
diff --git a/web/features/new-rag/upload/__tests__/plan-notice.spec.tsx b/web/features/new-rag/upload/__tests__/plan-notice.spec.tsx
deleted file mode 100644
index 309a8311c4e..00000000000
--- a/web/features/new-rag/upload/__tests__/plan-notice.spec.tsx
+++ /dev/null
@@ -1,46 +0,0 @@
-import { screen, waitFor } from '@testing-library/react'
-import userEvent from '@testing-library/user-event'
-import { NuqsTestingAdapter } from 'nuqs/adapters/testing'
-import { renderWithConsoleQuery } from '@/test/console/query-data'
-import { DocumentUploadPlanNotice } from '../plan-notice'
-
-function renderNotice(plan: 'sandbox' | 'professional' | 'team') {
- const onUrlUpdate = vi.fn()
- renderWithConsoleQuery(
- <NuqsTestingAdapter onUrlUpdate={onUrlUpdate}>
- <DocumentUploadPlanNotice fileSizeLimitMb={15} />
- </NuqsTestingAdapter>,
- {
- features: { billing: { subscription: { plan } } },
- systemFeatures: { deployment_edition: 'CLOUD' },
- },
- )
- return onUrlUpdate
-}
-
-it('shows the free upload constraints and opens the existing pricing flow for batch uploads', async () => {
- const user = userEvent.setup()
- const onUrlUpdate = renderNotice('sandbox')
- expect(screen.getByText('billing.upgrade.uploadMultiplePages.title')).toBeVisible()
- expect(
- screen.getByText(/datasetCreation\.stepOne\.uploader\.tip:.*"size":15.*"batchCount":1/),
- ).toBeVisible()
- expect(screen.queryByText('billing.upgrade.uploadMultipleFiles.title')).not.toBeInTheDocument()
- expect(
- screen.queryByText('billing.upgrade.uploadMultipleFiles.description'),
- ).not.toBeInTheDocument()
- await user.click(screen.getByRole('button', { name: 'billing.triggerLimitModal.upgrade' }))
- await waitFor(() => expect(onUrlUpdate).toHaveBeenCalledOnce())
- expect(onUrlUpdate.mock.calls[0]?.[0].searchParams.get('pricing')).toBe('open')
-})
-
-it.each(['professional', 'team'] as const)(
- 'does not show the free upload notice for %s',
- (plan) => {
- renderNotice(plan)
- expect(screen.queryByText('billing.upgrade.uploadMultiplePages.title')).not.toBeInTheDocument()
- expect(
- screen.queryByRole('button', { name: 'billing.triggerLimitModal.upgrade' }),
- ).not.toBeInTheDocument()
- },
-)