29 lines
1.8 KiB
TypeScript
29 lines
1.8 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
resolveInitialGuideRenderMode,
|
|
shouldPreferTwoDimensionalGuide
|
|
} from '@/services/performance/guideRenderModePolicy'
|
|
|
|
describe('guideRenderModePolicy', () => {
|
|
it('starts with the two-dimensional guide when the browser requests data saving or reports a constrained network', () => {
|
|
expect(shouldPreferTwoDimensionalGuide({ saveData: true })).toBe(true)
|
|
expect(shouldPreferTwoDimensionalGuide({ effectiveType: '2g' })).toBe(true)
|
|
expect(shouldPreferTwoDimensionalGuide({ effectiveType: '3g' })).toBe(false)
|
|
expect(shouldPreferTwoDimensionalGuide({ effectiveType: 'slow-2g' })).toBe(true)
|
|
expect(shouldPreferTwoDimensionalGuide({ effectiveType: '4g', downlink: 1.49, rtt: 80 })).toBe(true)
|
|
expect(shouldPreferTwoDimensionalGuide({ effectiveType: '4g', downlink: 8, rtt: 500 })).toBe(true)
|
|
expect(shouldPreferTwoDimensionalGuide({ effectiveType: '3g', downlink: 1.2, rtt: 120 })).toBe(true)
|
|
expect(shouldPreferTwoDimensionalGuide({ effectiveType: '3g', rtt: 900 })).toBe(true)
|
|
})
|
|
|
|
it('keeps the full model on an unconstrained connection and honours an explicit visitor choice', () => {
|
|
expect(shouldPreferTwoDimensionalGuide({ effectiveType: '4g', downlink: 12, rtt: 50 })).toBe(false)
|
|
expect(shouldPreferTwoDimensionalGuide({ effectiveType: '3g' })).toBe(false)
|
|
expect(shouldPreferTwoDimensionalGuide({ effectiveType: '4g', downlink: 0, rtt: 0 })).toBe(false)
|
|
expect(shouldPreferTwoDimensionalGuide({ effectiveType: '4g', downlink: 1.5, rtt: 499 })).toBe(false)
|
|
expect(resolveInitialGuideRenderMode(null, { effectiveType: '4g' })).toBe('three-d')
|
|
expect(resolveInitialGuideRenderMode('2d', { effectiveType: '4g' })).toBe('two-d')
|
|
expect(resolveInitialGuideRenderMode('3d', { effectiveType: '2g', downlink: 0.2, rtt: 1200 })).toBe('three-d')
|
|
})
|
|
})
|