143 lines
4.8 KiB
TypeScript
143 lines
4.8 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
|
|
import {
|
|
computeLandscapeBounds,
|
|
computePortraitBounds,
|
|
detectWindowOrientation,
|
|
EARTH_MOBILE_MAX_WIDTH,
|
|
MIN_WINDOW_HEIGHT,
|
|
MIN_WINDOW_WIDTH,
|
|
resolveInitialWindowBounds,
|
|
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)
|
|
})
|
|
|
|
test('resolveInitialWindowBounds pre-sizes maximized and fullscreen windows to display work area or bounds', () => {
|
|
const displayWorkArea: Rect = { x: 0, y: 0, width: 1920, height: 1032 }
|
|
const displayBounds: Rect = { x: 0, y: 0, width: 1920, height: 1080 }
|
|
const savedNormal = { x: 160, y: 36, width: 1600, height: 960 }
|
|
|
|
expect(
|
|
resolveInitialWindowBounds({
|
|
saved: { ...savedNormal, isMaximized: true, isFullScreen: false },
|
|
launchFullScreen: false,
|
|
headlessSmoke: false,
|
|
displayWorkArea,
|
|
displayBounds,
|
|
}),
|
|
).toEqual({
|
|
initialBounds: displayWorkArea,
|
|
shouldRestoreNormalBoundsOnUnmaximize: true,
|
|
})
|
|
|
|
expect(
|
|
resolveInitialWindowBounds({
|
|
saved: { ...savedNormal, isMaximized: true, isFullScreen: true },
|
|
launchFullScreen: false,
|
|
headlessSmoke: false,
|
|
displayWorkArea,
|
|
displayBounds,
|
|
}),
|
|
).toEqual({
|
|
initialBounds: displayBounds,
|
|
shouldRestoreNormalBoundsOnUnmaximize: true,
|
|
})
|
|
|
|
expect(
|
|
resolveInitialWindowBounds({
|
|
saved: { ...savedNormal, isMaximized: false, isFullScreen: false },
|
|
launchFullScreen: true,
|
|
headlessSmoke: false,
|
|
displayWorkArea,
|
|
displayBounds,
|
|
}),
|
|
).toEqual({
|
|
initialBounds: displayBounds,
|
|
shouldRestoreNormalBoundsOnUnmaximize: false,
|
|
})
|
|
|
|
expect(
|
|
resolveInitialWindowBounds({
|
|
saved: { ...savedNormal, isMaximized: false, isFullScreen: false },
|
|
launchFullScreen: false,
|
|
headlessSmoke: false,
|
|
displayWorkArea,
|
|
displayBounds,
|
|
}),
|
|
).toEqual({
|
|
initialBounds: savedNormal,
|
|
shouldRestoreNormalBoundsOnUnmaximize: false,
|
|
})
|
|
|
|
expect(
|
|
resolveInitialWindowBounds({
|
|
saved: { ...savedNormal, isMaximized: true, isFullScreen: true },
|
|
launchFullScreen: true,
|
|
headlessSmoke: true,
|
|
displayWorkArea,
|
|
displayBounds,
|
|
}),
|
|
).toEqual({
|
|
initialBounds: savedNormal,
|
|
shouldRestoreNormalBoundsOnUnmaximize: false,
|
|
})
|
|
})
|
|
})
|