vending-machine/mobile/__tests__/banner-navigation.property.test.js
2026-04-08 20:45:41 +08:00

52 lines
1.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, it, expect } from 'vitest'
import * as fc from 'fast-check'
import { resolveBannerNavigation } from '../utils/navigation.js'
describe('Property 7: Banner导航正确性', () => {
/**
* **Feature: mobile-app, Property 7: Banner导航正确性**
* **Validates: Requirements 3.2**
*
* 对于任意Banner配置项当linkType为"internal"时点击应调用内部页面导航,
* 当linkType为"external"时点击应调用外部链接打开,
* 且目标URL应等于配置的linkUrl。
*/
it('internal类型Banner应返回internal导航external类型应返回external导航URL保持一致', () => {
const linkTypeArb = fc.constantFrom('internal', 'external')
const urlArb = fc.string({ minLength: 1, maxLength: 200 }).filter(s => s.trim().length > 0)
fc.assert(
fc.property(linkTypeArb, urlArb, (linkType, linkUrl) => {
const banner = { id: '1', imageUrl: 'http://img.test/a.png', linkType, linkUrl }
const result = resolveBannerNavigation(banner)
// 导航结果不为null
expect(result).not.toBeNull()
// 导航类型与Banner配置一致
expect(result.type).toBe(linkType)
// 导航URL与Banner配置一致
expect(result.url).toBe(linkUrl)
}),
{ numRuns: 100 }
)
})
it('无效Banner无linkUrl或null应返回null', () => {
const invalidBannerArb = fc.constantFrom(
null,
undefined,
{},
{ linkType: 'internal' },
{ linkType: 'external', linkUrl: '' }
)
fc.assert(
fc.property(invalidBannerArb, (banner) => {
const result = resolveBannerNavigation(banner)
expect(result).toBeNull()
}),
{ numRuns: 20 }
)
})
})