53 lines
2.0 KiB
JavaScript
53 lines
2.0 KiB
JavaScript
import { describe, it, expect } from 'vitest'
|
||
import * as fc from 'fast-check'
|
||
import { resolveMembershipButtons } from '../utils/membership.js'
|
||
|
||
describe('Property 9: 会员按钮状态正确性', () => {
|
||
/**
|
||
* **Feature: mobile-app, Property 9: 会员按钮状态正确性**
|
||
* **Validates: Requirements 5.5, 5.8, 5.9**
|
||
*
|
||
* 对于任意会员状态组合(非会员/单月会员/订阅会员),会员页按钮的显示状态应满足:
|
||
* - 非会员时显示"开通会员"可点击按钮
|
||
* - 单月会员时隐藏单月按钮、显示"订阅会员"可点击按钮
|
||
* - 订阅会员时显示"已购买订阅会员"灰色不可点击按钮
|
||
*/
|
||
it('按钮状态应根据会员/订阅状态正确显示', () => {
|
||
const stateArb = fc.record({
|
||
isMember: fc.boolean(),
|
||
isSubscribed: fc.boolean()
|
||
})
|
||
|
||
fc.assert(
|
||
fc.property(stateArb, (state) => {
|
||
const { monthly, subscription } = resolveMembershipButtons(state)
|
||
|
||
if (!state.isMember) {
|
||
// 非会员:单月按钮可见且可点击,显示"开通会员"
|
||
expect(monthly.visible).toBe(true)
|
||
expect(monthly.disabled).toBe(false)
|
||
expect(monthly.label).toBe('joinBtn')
|
||
} else {
|
||
// 已开通单月会员:隐藏单月按钮(需求5.8)
|
||
expect(monthly.visible).toBe(false)
|
||
expect(monthly.disabled).toBe(true)
|
||
expect(monthly.label).toBe('joinedBtn')
|
||
}
|
||
|
||
if (!state.isSubscribed) {
|
||
// 未订阅:订阅按钮可见且可点击
|
||
expect(subscription.visible).toBe(true)
|
||
expect(subscription.disabled).toBe(false)
|
||
expect(subscription.label).toBe('subscribeBtn')
|
||
} else {
|
||
// 已订阅:按钮灰色不可点击(需求5.9)
|
||
expect(subscription.visible).toBe(true)
|
||
expect(subscription.disabled).toBe(true)
|
||
expect(subscription.label).toBe('subscribedBtn')
|
||
}
|
||
}),
|
||
{ numRuns: 100 }
|
||
)
|
||
})
|
||
})
|