71 lines
2.7 KiB
TypeScript
71 lines
2.7 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
|
|
import {
|
|
computeLandscapeBounds,
|
|
computePortraitBounds,
|
|
detectWindowOrientation,
|
|
EARTH_MOBILE_MAX_WIDTH,
|
|
MIN_WINDOW_HEIGHT,
|
|
MIN_WINDOW_WIDTH,
|
|
type Rect,
|
|
} from '../src/main/orientation'
|
|
|
|
describe('window orientation calculations', () => {
|
|
test('detectWindowOrientation distinguishes portrait, landscape, maximized, and fullscreen', () => {
|
|
expect(detectWindowOrientation({ width: 520, height: 920 }, { isMaximized: false, isFullScreen: false })).toBe(
|
|
'portrait',
|
|
)
|
|
expect(detectWindowOrientation({ width: 1600, height: 960 }, { isMaximized: false, isFullScreen: false })).toBe(
|
|
'landscape',
|
|
)
|
|
expect(detectWindowOrientation({ width: 520, height: 920 }, { isMaximized: true, isFullScreen: false })).toBe(
|
|
'landscape',
|
|
)
|
|
expect(detectWindowOrientation({ width: 520, height: 920 }, { isMaximized: false, isFullScreen: true })).toBe(
|
|
'landscape',
|
|
)
|
|
})
|
|
|
|
test('computePortraitBounds adapts across 1080p@100%, 1080p@150%, and 1440p work areas into mobile layout', () => {
|
|
const workAreas: Rect[] = [
|
|
{ x: 0, y: 0, width: 1920, height: 1032 },
|
|
{ x: 0, y: 0, width: 1280, height: 688 },
|
|
{ x: 0, y: 0, width: 2560, height: 1392 },
|
|
]
|
|
|
|
for (const workArea of workAreas) {
|
|
const anchor: Rect = { x: workArea.x, y: workArea.y, width: workArea.width, height: workArea.height }
|
|
const portrait = computePortraitBounds({ workArea, anchorBounds: anchor })
|
|
|
|
expect(portrait.width).toBeGreaterThanOrEqual(MIN_WINDOW_WIDTH)
|
|
expect(portrait.height).toBeGreaterThanOrEqual(MIN_WINDOW_HEIGHT)
|
|
expect(portrait.width).toBeLessThan(portrait.height)
|
|
expect(portrait.width).toBeLessThanOrEqual(EARTH_MOBILE_MAX_WIDTH)
|
|
expect(portrait.x).toBeGreaterThanOrEqual(workArea.x)
|
|
expect(portrait.y).toBeGreaterThanOrEqual(workArea.y)
|
|
expect(portrait.x + portrait.width).toBeLessThanOrEqual(workArea.x + workArea.width)
|
|
expect(portrait.y + portrait.height).toBeLessThanOrEqual(workArea.y + workArea.height)
|
|
}
|
|
})
|
|
|
|
test('preserves saved custom portrait and landscape bounds across round-trip toggles', () => {
|
|
const workArea: Rect = { x: 0, y: 0, width: 1920, height: 1032 }
|
|
const savedPortrait: Rect = { x: 240, y: 60, width: 412, height: 880 }
|
|
const savedLandscape: Rect = { x: 120, y: 40, width: 1440, height: 900 }
|
|
|
|
const portrait = computePortraitBounds({
|
|
workArea,
|
|
anchorBounds: savedLandscape,
|
|
savedPortraitBounds: savedPortrait,
|
|
})
|
|
expect(portrait).toEqual(savedPortrait)
|
|
|
|
const landscape = computeLandscapeBounds({
|
|
workArea,
|
|
anchorBounds: portrait,
|
|
savedLandscapeBounds: savedLandscape,
|
|
})
|
|
expect(landscape).toEqual(savedLandscape)
|
|
})
|
|
})
|