Files
dify/web/app/components/header/utils/__tests__/util.spec.ts
T
Coding On StarGitHubCodingOnStarautofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
6da802eb2a refactor(custom): reorganize web app brand module and raise coverage threshold (#33531)
Co-authored-by: CodingOnStar <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-03-16 18:17:21 +08:00

62 lines
2.1 KiB
TypeScript

import { generateMailToLink, mailToSupport } from '../util'
describe('generateMailToLink', () => {
// Email-only: both subject and body branches false
it('should return mailto link with email only when no subject or body provided', () => {
// Act
const result = generateMailToLink('[email protected]')
// Assert
expect(result).toBe('mailto:[email protected]')
})
// Subject provided, body not: subject branch true, body branch false
it('should append subject when subject is provided without body', () => {
// Act
const result = generateMailToLink('[email protected]', 'Hello World')
// Assert
expect(result).toBe('mailto:[email protected]?subject=Hello%20World')
})
// Body provided, no subject: subject branch false, body branch true
it('should append body with question mark when body is provided without subject', () => {
// Act
const result = generateMailToLink('[email protected]', undefined, 'Some body text')
// Assert
expect(result).toBe('mailto:[email protected]&body=Some%20body%20text')
})
// Both subject and body provided: both branches true
it('should append both subject and body when both are provided', () => {
// Act
const result = generateMailToLink('[email protected]', 'Subject', 'Body text')
// Assert
expect(result).toBe('mailto:[email protected]?subject=Subject&body=Body%20text')
})
})
describe('mailToSupport', () => {
// Transitive coverage: exercises generateMailToLink with all params
it('should generate a mailto link with support recipient, plan, account, and version info', () => {
// Act
const result = mailToSupport('[email protected]', 'Pro', '1.0.0')
// Assert
expect(result.startsWith('mailto:[email protected]?')).toBe(true)
const query = result.split('?')[1]
expect(query).toBeDefined()
const params = new URLSearchParams(query)
expect(params.get('subject')).toBe('Technical Support Request Pro [email protected]')
const body = params.get('body')
expect(body).toContain('Current Plan: Pro')
expect(body).toContain('Account: [email protected]')
expect(body).toContain('Version: 1.0.0')
})
})