mirror of
https://github.com/langgenius/dify.git
synced 2026-05-10 05:56:31 +08:00
Signed-off-by: majiayu000 <1835304752@qq.com> Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: NeatGuyCoding <15627489+NeatGuyCoding@users.noreply.github.com> Signed-off-by: -LAN- <laipz8200@outlook.com> Signed-off-by: yihong0618 <zouzou0208@gmail.com> Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com> Co-authored-by: 盐粒 Yanli <yanli@dify.ai> Co-authored-by: wangxiaolei <fatelei@gmail.com> Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Cursx <33718736+Cursx@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: lif <1835304752@qq.com> Co-authored-by: 非法操作 <hjlarry@163.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: fenglin <790872612@qq.com> Co-authored-by: qiaofenglin <qiaofenglin@baidu.com> Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: TomoOkuyama <49631611+TomoOkuyama@users.noreply.github.com> Co-authored-by: Tomo Okuyama <tomo.okuyama@intersystems.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: zyssyz123 <916125788@qq.com> Co-authored-by: hj24 <mambahj24@gmail.com> Co-authored-by: Coding On Star <447357187@qq.com> Co-authored-by: CodingOnStar <hanxujiang@dify.ai> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com> Co-authored-by: Xiangxuan Qu <fghpdf@outlook.com> Co-authored-by: fghpdf <fghpdf@users.noreply.github.com> Co-authored-by: coopercoder <whitetiger0127@163.com> Co-authored-by: zhaiguangpeng <zhaiguangpeng@didiglobal.com> Co-authored-by: Junyan Qin (Chin) <rockchinq@gmail.com> Co-authored-by: E.G <146701565+GlobalStar117@users.noreply.github.com> Co-authored-by: GlobalStar117 <GlobalStar117@users.noreply.github.com> Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com> Co-authored-by: CodingOnStar <hanxujiang@dify.com> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: heyszt <270985384@qq.com> Co-authored-by: NeatGuyCoding <15627489+NeatGuyCoding@users.noreply.github.com> Co-authored-by: Yeuoly <45712896+Yeuoly@users.noreply.github.com> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: moonpanda <chuanzegao@163.com> Co-authored-by: warlocgao <warlocgao@tencent.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: KVOJJJin <jzongcode@gmail.com> Co-authored-by: eux <euxx@users.noreply.github.com> Co-authored-by: bangjiehan <bangjiehan@gmail.com> Co-authored-by: FFXN <31929997+FFXN@users.noreply.github.com> Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com> Co-authored-by: Nie Ronghua <nieronghua@sf-express.com> Co-authored-by: JQSevenMiao <141806521+JQSevenMiao@users.noreply.github.com> Co-authored-by: jiasiqi <jiasiqi3@tal.com> Co-authored-by: Seokrin Taron Sung <sungsjade@gmail.com> Co-authored-by: CrabSAMA <40541269+CrabSAMA@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: yihong <zouzou0208@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com> Co-authored-by: yessenia <yessenia.contact@gmail.com> Co-authored-by: Jax <anobaka@qq.com> Co-authored-by: niveshdandyan <155956228+niveshdandyan@users.noreply.github.com> Co-authored-by: OSS Contributor <oss-contributor@example.com> Co-authored-by: niveshdandyan <niveshdandyan@users.noreply.github.com> Co-authored-by: Sean Kenneth Doherty <Smaster7772@gmail.com>
340 lines
11 KiB
TypeScript
340 lines
11 KiB
TypeScript
import { render, screen } from '@testing-library/react'
|
|
import DevelopMain from './index'
|
|
|
|
// Mock the app store with a factory function to control state
|
|
const mockAppDetailValue: { current: unknown } = { current: undefined }
|
|
vi.mock('@/app/components/app/store', () => ({
|
|
useStore: (selector: (state: unknown) => unknown) => {
|
|
const state = { appDetail: mockAppDetailValue.current }
|
|
return selector(state)
|
|
},
|
|
}))
|
|
|
|
// Mock the Doc component since it has complex dependencies
|
|
vi.mock('@/app/components/develop/doc', () => ({
|
|
default: ({ appDetail }: { appDetail: { name?: string } | null }) => (
|
|
<div data-testid="doc-component">
|
|
Doc Component -
|
|
{appDetail?.name}
|
|
</div>
|
|
),
|
|
}))
|
|
|
|
// Mock the ApiServer component
|
|
vi.mock('@/app/components/develop/ApiServer', () => ({
|
|
default: ({ apiBaseUrl, appId }: { apiBaseUrl: string, appId: string }) => (
|
|
<div data-testid="api-server">
|
|
API Server -
|
|
{apiBaseUrl}
|
|
{' '}
|
|
-
|
|
{appId}
|
|
</div>
|
|
),
|
|
}))
|
|
|
|
describe('DevelopMain', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
mockAppDetailValue.current = undefined
|
|
})
|
|
|
|
describe('loading state', () => {
|
|
it('should show loading when appDetail is undefined', () => {
|
|
mockAppDetailValue.current = undefined
|
|
render(<DevelopMain appId="app-123" />)
|
|
|
|
// Loading component renders with role="status"
|
|
expect(screen.getByRole('status')).toBeInTheDocument()
|
|
})
|
|
|
|
it('should show loading when appDetail is null', () => {
|
|
mockAppDetailValue.current = null
|
|
render(<DevelopMain appId="app-123" />)
|
|
|
|
expect(screen.getByRole('status')).toBeInTheDocument()
|
|
})
|
|
|
|
it('should have centered loading container', () => {
|
|
mockAppDetailValue.current = undefined
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
|
|
const loadingContainer = container.querySelector('.flex.h-full.items-center.justify-center')
|
|
expect(loadingContainer).toBeInTheDocument()
|
|
})
|
|
|
|
it('should have correct background on loading state', () => {
|
|
mockAppDetailValue.current = undefined
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
|
|
const loadingContainer = container.querySelector('.bg-background-default')
|
|
expect(loadingContainer).toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('with appDetail loaded', () => {
|
|
const mockAppDetail = {
|
|
id: 'app-123',
|
|
name: 'Test Application',
|
|
api_base_url: 'https://api.example.com/v1',
|
|
mode: 'chat',
|
|
}
|
|
|
|
beforeEach(() => {
|
|
mockAppDetailValue.current = mockAppDetail
|
|
})
|
|
|
|
it('should render ApiServer component', () => {
|
|
render(<DevelopMain appId="app-123" />)
|
|
expect(screen.getByTestId('api-server')).toBeInTheDocument()
|
|
})
|
|
|
|
it('should pass api_base_url to ApiServer', () => {
|
|
render(<DevelopMain appId="app-123" />)
|
|
expect(screen.getByTestId('api-server')).toHaveTextContent('https://api.example.com/v1')
|
|
})
|
|
|
|
it('should pass appId to ApiServer', () => {
|
|
render(<DevelopMain appId="app-123" />)
|
|
expect(screen.getByTestId('api-server')).toHaveTextContent('app-123')
|
|
})
|
|
|
|
it('should render Doc component', () => {
|
|
render(<DevelopMain appId="app-123" />)
|
|
expect(screen.getByTestId('doc-component')).toBeInTheDocument()
|
|
})
|
|
|
|
it('should pass appDetail to Doc component', () => {
|
|
render(<DevelopMain appId="app-123" />)
|
|
expect(screen.getByTestId('doc-component')).toHaveTextContent('Test Application')
|
|
})
|
|
|
|
it('should not show loading when appDetail exists', () => {
|
|
render(<DevelopMain appId="app-123" />)
|
|
expect(screen.queryByRole('status')).not.toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('layout structure', () => {
|
|
const mockAppDetail = {
|
|
id: 'app-123',
|
|
name: 'Test Application',
|
|
api_base_url: 'https://api.example.com',
|
|
mode: 'chat',
|
|
}
|
|
|
|
beforeEach(() => {
|
|
mockAppDetailValue.current = mockAppDetail
|
|
})
|
|
|
|
it('should have flex column layout', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const mainContainer = container.firstChild as HTMLElement
|
|
expect(mainContainer.className).toContain('flex')
|
|
expect(mainContainer.className).toContain('flex-col')
|
|
})
|
|
|
|
it('should have relative positioning', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const mainContainer = container.firstChild as HTMLElement
|
|
expect(mainContainer.className).toContain('relative')
|
|
})
|
|
|
|
it('should have full height', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const mainContainer = container.firstChild as HTMLElement
|
|
expect(mainContainer.className).toContain('h-full')
|
|
})
|
|
|
|
it('should have overflow-hidden', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const mainContainer = container.firstChild as HTMLElement
|
|
expect(mainContainer.className).toContain('overflow-hidden')
|
|
})
|
|
})
|
|
|
|
describe('header section', () => {
|
|
const mockAppDetail = {
|
|
id: 'app-123',
|
|
name: 'Test Application',
|
|
api_base_url: 'https://api.example.com',
|
|
mode: 'chat',
|
|
}
|
|
|
|
beforeEach(() => {
|
|
mockAppDetailValue.current = mockAppDetail
|
|
})
|
|
|
|
it('should have header with border', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const header = container.querySelector('.border-b')
|
|
expect(header).toBeInTheDocument()
|
|
})
|
|
|
|
it('should have shrink-0 on header to prevent shrinking', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const header = container.querySelector('.shrink-0')
|
|
expect(header).toBeInTheDocument()
|
|
})
|
|
|
|
it('should have horizontal padding on header', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const header = container.querySelector('.px-6')
|
|
expect(header).toBeInTheDocument()
|
|
})
|
|
|
|
it('should have vertical padding on header', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const header = container.querySelector('.py-2')
|
|
expect(header).toBeInTheDocument()
|
|
})
|
|
|
|
it('should have items centered in header', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const header = container.querySelector('.items-center')
|
|
expect(header).toBeInTheDocument()
|
|
})
|
|
|
|
it('should have justify-between in header', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const header = container.querySelector('.justify-between')
|
|
expect(header).toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('content section', () => {
|
|
const mockAppDetail = {
|
|
id: 'app-123',
|
|
name: 'Test Application',
|
|
api_base_url: 'https://api.example.com',
|
|
mode: 'chat',
|
|
}
|
|
|
|
beforeEach(() => {
|
|
mockAppDetailValue.current = mockAppDetail
|
|
})
|
|
|
|
it('should have grow class for content area', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const content = container.querySelector('.grow')
|
|
expect(content).toBeInTheDocument()
|
|
})
|
|
|
|
it('should have overflow-auto for content scrolling', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const content = container.querySelector('.overflow-auto')
|
|
expect(content).toBeInTheDocument()
|
|
})
|
|
|
|
it('should have horizontal padding on content', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const content = container.querySelector('.px-4')
|
|
expect(content).toBeInTheDocument()
|
|
})
|
|
|
|
it('should have vertical padding on content', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const content = container.querySelector('.py-4')
|
|
expect(content).toBeInTheDocument()
|
|
})
|
|
|
|
it('should have responsive padding', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const content = container.querySelector('[class*="sm:px-10"]')
|
|
expect(content).toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('with different appIds', () => {
|
|
const mockAppDetail = {
|
|
id: 'app-456',
|
|
name: 'Another App',
|
|
api_base_url: 'https://another-api.com',
|
|
mode: 'completion',
|
|
}
|
|
|
|
beforeEach(() => {
|
|
mockAppDetailValue.current = mockAppDetail
|
|
})
|
|
|
|
it('should pass different appId to ApiServer', () => {
|
|
render(<DevelopMain appId="app-456" />)
|
|
expect(screen.getByTestId('api-server')).toHaveTextContent('app-456')
|
|
})
|
|
|
|
it('should handle app with different api_base_url', () => {
|
|
render(<DevelopMain appId="app-456" />)
|
|
expect(screen.getByTestId('api-server')).toHaveTextContent('https://another-api.com')
|
|
})
|
|
})
|
|
|
|
describe('empty state handling', () => {
|
|
it('should handle appDetail with minimal properties', () => {
|
|
mockAppDetailValue.current = {
|
|
api_base_url: 'https://api.test.com',
|
|
}
|
|
render(<DevelopMain appId="app-minimal" />)
|
|
expect(screen.getByTestId('api-server')).toBeInTheDocument()
|
|
})
|
|
|
|
it('should handle appDetail with empty api_base_url', () => {
|
|
mockAppDetailValue.current = {
|
|
api_base_url: '',
|
|
name: 'Empty URL App',
|
|
}
|
|
render(<DevelopMain appId="app-empty-url" />)
|
|
expect(screen.getByTestId('api-server')).toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('title element', () => {
|
|
const mockAppDetail = {
|
|
id: 'app-123',
|
|
name: 'Test Application',
|
|
api_base_url: 'https://api.example.com',
|
|
mode: 'chat',
|
|
}
|
|
|
|
beforeEach(() => {
|
|
mockAppDetailValue.current = mockAppDetail
|
|
})
|
|
|
|
it('should have title div with correct styling', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const title = container.querySelector('.text-lg.font-medium.text-text-primary')
|
|
expect(title).toBeInTheDocument()
|
|
})
|
|
|
|
it('should render empty title div', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const title = container.querySelector('.text-lg.font-medium.text-text-primary')
|
|
expect(title?.textContent).toBe('')
|
|
})
|
|
})
|
|
|
|
describe('border styling', () => {
|
|
const mockAppDetail = {
|
|
id: 'app-123',
|
|
name: 'Test Application',
|
|
api_base_url: 'https://api.example.com',
|
|
mode: 'chat',
|
|
}
|
|
|
|
beforeEach(() => {
|
|
mockAppDetailValue.current = mockAppDetail
|
|
})
|
|
|
|
it('should have solid border style', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const header = container.querySelector('.border-solid')
|
|
expect(header).toBeInTheDocument()
|
|
})
|
|
|
|
it('should have divider regular color on border', () => {
|
|
const { container } = render(<DevelopMain appId="app-123" />)
|
|
const header = container.querySelector('.border-b-divider-regular')
|
|
expect(header).toBeInTheDocument()
|
|
})
|
|
})
|
|
})
|