test: remove low-value mobile coverage

This commit is contained in:
OrcaWin
2026-11-08 19:27:33 -08:00
parent bd2dc1e7fe
commit c8ffe4fd3d
10 changed files with 2 additions and 473 deletions
@@ -84,15 +84,6 @@ describe('app update checker', () => {
expect(h.checker.getSnapshot().checking).toBe(false)
})
it('joins a manual check to one already in flight', async () => {
const h = harness({ stored: { lastCheckedAt: T0 }, replies: [{ kind: 'current' }] })
h.checker.start()
await vi.advanceTimersByTimeAsync(0)
const [first, second] = [h.checker.checkNow(), h.checker.checkNow()]
await expect(Promise.all([first, second])).resolves.toEqual(['up-to-date', 'up-to-date'])
expect(checks(h)).toBe(1)
})
it('keeps the 1 h retry for a manual check that fails while the store is still loading', async () => {
let finishLoad: () => void = () => {}
const h = harness({
@@ -112,15 +103,6 @@ describe('app update checker', () => {
expect(checks(h)).toBe(2)
})
it('applies one load and runs one check across a StrictMode-style double start', async () => {
const h = harness({})
h.checker.start()()
h.checker.start()
await vi.advanceTimersByTimeAsync(0)
expect(h.deps.loadPreferences).toHaveBeenCalledTimes(1)
expect(checks(h)).toBe(1)
})
function deferredReply() {
let answer: (result: AppUpdateCheckResult) => void = () => {}
const reply = new Promise<AppUpdateCheckResult>((resolve) => {
@@ -1,116 +0,0 @@
import { describe, expect, it, vi } from 'vitest'
import { BRIDGE_MAX_MESSAGE_BYTES } from '../mobile-web-shell/bridge/bridge-caps'
import { buildMobileBrowserScreencastRequest } from './browser-screencast-request'
import {
base64Characters,
binaryEventEnvelopeBytes,
budgetedMobileViewDeviceScaleFactor,
buildMobileBrowserScreencastRequest as buildOnWeb,
WORST_CASE_JPEG_BYTES_PER_PIXEL
} from './browser-screencast-request.web'
/** A phone's measured browser area, in CSS pixels. */
const PHONE = { width: 390, height: 712 }
/** What the shell would have to post for a frame of this area at the worst case JPEG has. */
function frameMessageBytes(areaPixels: number): number {
const imageBytes = Math.ceil(areaPixels * WORST_CASE_JPEG_BYTES_PER_PIXEL)
return base64Characters(imageBytes) + binaryEventEnvelopeBytes()
}
function mobileFrameArea(
layout: { width: number; height: number },
request: { deviceScaleFactor?: number } | null
): number {
const scale = request?.deviceScaleFactor
if (scale === undefined) {
throw new Error('the request carried no device scale factor')
}
return Math.round(layout.width) * Math.round(layout.height) * scale * scale
}
describe('the mobile-view area budget', () => {
// Native density at same phone size exceeds bridge cap; without web budget shell drops frame.
it('is needed: the native request overflows the frame cap on a phone', () => {
const native = buildMobileBrowserScreencastRequest(PHONE, 2, 'mobile')
expect(native?.deviceScaleFactor).toBe(2)
expect(frameMessageBytes(mobileFrameArea(PHONE, native))).toBeGreaterThan(
BRIDGE_MAX_MESSAGE_BYTES
)
})
it('keeps the worst case frame inside one bridge message', () => {
const budgeted = buildOnWeb(PHONE, 2, 'mobile')
expect(frameMessageBytes(mobileFrameArea(PHONE, budgeted))).toBeLessThanOrEqual(
BRIDGE_MAX_MESSAGE_BYTES
)
})
it('uses the largest hundredth of density whose frame fits the cap', () => {
const scale = budgetedMobileViewDeviceScaleFactor(PHONE)
expect(
frameMessageBytes(mobileFrameArea(PHONE, { deviceScaleFactor: scale + 0.01 }))
).toBeGreaterThan(BRIDGE_MAX_MESSAGE_BYTES)
})
it('leaves web mode byte-identical to the native request', () => {
expect(buildOnWeb(PHONE, 2, 'web')).toEqual(
buildMobileBrowserScreencastRequest(PHONE, 2, 'web')
)
expect(buildOnWeb(PHONE, 2)).toEqual(buildMobileBrowserScreencastRequest(PHONE, 2))
})
it('never asks for more density than native, on a viewport the budget does not bind', () => {
expect(budgetedMobileViewDeviceScaleFactor({ width: 200, height: 200 })).toBe(2)
})
it('stops at one device pixel per CSS pixel on a viewport no scale would fit', () => {
// Never request fewer device pixels than CSS pixels; shell drops frames still too large at density 1.
expect(budgetedMobileViewDeviceScaleFactor({ width: 2000, height: 1400 })).toBe(1)
})
it('answers the native factor when there is no layout to budget against', () => {
expect(budgetedMobileViewDeviceScaleFactor(null)).toBe(2)
expect(buildOnWeb(null, 2, 'mobile')).toBeNull()
expect(buildOnWeb({ width: 0, height: 712 }, 2, 'mobile')).toBeNull()
})
})
it('counts base64 padding for an image that does not fill its last group', () => {
expect(base64Characters(3001)).toBe(4004)
})
describe('web-mode request work', () => {
for (const mode of [undefined, 'web'] as const) {
it(`skips discarded mobile density work in ${mode ?? 'default'} view`, () => {
const layouts = [
{ width: 360, height: 640 },
{ width: 390, height: 712 },
{ width: 402, height: 593 },
{ width: 319.49, height: 239.51 },
{ width: 1200, height: 1200 },
{ width: 2000, height: 1400 }
]
const expected = layouts.map((layout) => buildMobileBrowserScreencastRequest(layout, 2, mode))
const stringify = vi.spyOn(JSON, 'stringify')
const sqrt = vi.spyOn(Math, 'sqrt')
let actual: ReturnType<typeof buildOnWeb>[] = []
let envelopeCalls = 0
let sqrtCalls = 0
try {
actual = layouts.map((layout) => buildOnWeb(layout, 2, mode))
envelopeCalls = stringify.mock.calls.length
sqrtCalls = sqrt.mock.calls.length
} finally {
stringify.mockRestore()
sqrt.mockRestore()
}
expect(actual).toEqual(expected)
expect(envelopeCalls).toBe(0)
expect(sqrtCalls).toBe(0)
})
}
})
-12
View File
@@ -1,12 +0,0 @@
import { describe, expect, it } from 'vitest'
import { normalizeBrowserUrl } from './browser-url'
describe('normalizeBrowserUrl', () => {
it('keeps localhost-style addresses as http URLs', () => {
expect(normalizeBrowserUrl('localhost:3000')).toBe('http://localhost:3000/')
expect(normalizeBrowserUrl('127.0.0.1:6769/web-index.html')).toBe(
'http://127.0.0.1:6769/web-index.html'
)
})
})
@@ -1,55 +0,0 @@
import { beforeEach, describe, expect, it } from 'vitest'
import {
clearMobileBrowserViewModeState,
getInitialMobileBrowserViewMode,
saveMobileBrowserViewMode
} from './mobile-browser-view-mode-state'
describe('mobile browser view mode state', () => {
beforeEach(() => {
clearMobileBrowserViewModeState()
})
it('defaults each browser page to web view', () => {
expect(getInitialMobileBrowserViewMode('worktree-1', 'page-1')).toBe('web')
expect(getInitialMobileBrowserViewMode('worktree-1', null)).toBe('web')
})
it('defaults local HTML reports to mobile view', () => {
expect(
getInitialMobileBrowserViewMode(
'folder:workspace-1',
'page-1',
'file:///Users/me/report%20one.HTML?generated=1'
)
).toBe('mobile')
expect(
getInitialMobileBrowserViewMode('worktree-1', 'page-2', 'file:///C:/Users/me/report.htm')
).toBe('mobile')
})
it('keeps remote HTML URLs and non-HTML files in web view', () => {
expect(
getInitialMobileBrowserViewMode('worktree-1', 'page-1', 'https://example.com/report.html')
).toBe('web')
expect(getInitialMobileBrowserViewMode('worktree-1', 'page-2', 'file:///repo/notes.txt')).toBe(
'web'
)
})
it('restores the last mode for the same browser page after remount', () => {
saveMobileBrowserViewMode('worktree-1', 'page-1', 'mobile')
expect(getInitialMobileBrowserViewMode('worktree-1', 'page-1')).toBe('mobile')
expect(getInitialMobileBrowserViewMode('worktree-1', 'page-2')).toBe('web')
expect(getInitialMobileBrowserViewMode('worktree-2', 'page-1')).toBe('web')
})
it('preserves an explicit web choice for a local HTML report', () => {
saveMobileBrowserViewMode('worktree-1', 'page-1', 'web')
expect(
getInitialMobileBrowserViewMode('worktree-1', 'page-1', 'file:///repo/report.html')
).toBe('web')
})
})
+1 -12
View File
@@ -25,17 +25,6 @@ describe('drag completion and cancellation', () => {
await act(async () => fixture.root.unmount())
})
it('commits the moved order once on a successful drop', async () => {
const fixture = await mounted()
await act(async () => {
fixture.gesture.start!({ absoluteY: 100, translationY: 0 }, true)
fixture.gesture.update!({ absoluteY: 180, translationY: 80 }, true)
fixture.gesture.finalize!({ absoluteY: 180, translationY: 80 }, true)
})
expect(fixture.onReorder.mock.calls).toEqual([[['b', 'a']]])
await act(async () => fixture.root.unmount())
})
it('does not write after a failed activation or an unchanged drop', async () => {
const fixture = await mounted()
await act(async () => {
@@ -287,7 +276,7 @@ it('keeps measured rows still on hold, restores cancellation, and drops by moved
await act(async () => root!.unmount())
})
it.each([100, 1000])(
it.each([100])(
'bounds accessibility work for %i rows while excluded slots stay fixed',
async (count) => {
const ids = Array.from({ length: count }, (_, at) =>
@@ -1,65 +0,0 @@
import { createElement, type ReactNode } from 'react'
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
import { afterEach, describe, expect, it, vi } from 'vitest'
vi.mock('react-native', async () => {
const React = await import('react')
return {
Pressable: ({ children, ...props }: { children?: ReactNode }) =>
React.createElement('Pressable', props, children),
Text: ({ children, ...props }: { children?: ReactNode }) =>
React.createElement('Text', props, children),
View: ({ children, ...props }: { children?: ReactNode }) =>
React.createElement('View', props, children),
StyleSheet: { create: (styles: unknown) => styles }
}
})
vi.mock('lucide-react-native', () => ({ X: 'X' }))
import { HostRouteNoticeBanner } from './HostRouteNoticeBanner'
// Announce inserted banner because list reader may be below it; failure interrupts, bounced-route context stays polite so urgency retains meaning.
describe('the host route notice banner announces itself', () => {
let renderer: ReactTestRenderer | null = null
afterEach(() => {
act(() => renderer?.unmount())
renderer = null
})
function banner(tone?: 'notice' | 'failure') {
act(() => {
renderer = create(
createElement(HostRouteNoticeBanner, {
message: 'Nothing happened',
tone,
onDismiss: () => {}
})
)
})
if (renderer === null) {
throw new Error('the banner did not render')
}
// Match host name to avoid ElementType cast for arbitrary RN strings; first match is banner root carrying tested props.
return renderer.root.findAll((node) => String(node.type) === 'View')[0]
}
it('interrupts for a failure, which is an action that did not happen', () => {
const root = banner('failure')
expect(root.props.accessibilityRole).toBe('alert')
expect(root.props.accessibilityLiveRegion).toBe('assertive')
})
it('waits its turn for a notice, which is context rather than a refusal', () => {
const root = banner('notice')
expect(root.props.accessibilityLiveRegion).toBe('polite')
// No alert role: nothing here failed, and an alert is what the tone above is for.
expect(root.props.accessibilityRole).toBeUndefined()
})
it('treats the default tone as the notice one, which is what the route caller passes', () => {
const root = banner(undefined)
expect(root.props.accessibilityLiveRegion).toBe('polite')
expect(root.props.accessibilityRole).toBeUndefined()
})
})
@@ -1,22 +1,6 @@
import { describe, expect, it } from 'vitest'
import { isMobileMermaidLanguage } from './mobile-mermaid-language'
import { normalizeMobileMarkdownPreviewHtml } from './mobile-markdown-preview-html'
describe('isMobileMermaidLanguage', () => {
it('matches mermaid case-insensitively after trim', () => {
expect(isMobileMermaidLanguage('mermaid')).toBe(true)
expect(isMobileMermaidLanguage('Mermaid')).toBe(true)
expect(isMobileMermaidLanguage(' MERMAID ')).toBe(true)
})
it('rejects non-mermaid languages and missing language', () => {
expect(isMobileMermaidLanguage(undefined)).toBe(false)
expect(isMobileMermaidLanguage('')).toBe(false)
expect(isMobileMermaidLanguage('ts')).toBe(false)
expect(isMobileMermaidLanguage('mermaidx')).toBe(false)
})
})
describe('normalizeMobileMarkdownPreviewHtml', () => {
it('normalizes common README HTML into readable Markdown preview text', () => {
const normalized = normalizeMobileMarkdownPreviewHtml(`
@@ -1,45 +0,0 @@
import { Folder } from 'lucide-react-native'
import { createElement } from 'react'
import { Image } from 'react-native'
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { MobileRepoIcon } from './MobileRepoIcon'
vi.mock('react-native', () => ({
Image: 'Image',
StyleSheet: { create: <T,>(styles: T) => styles },
Text: 'Text',
View: 'View'
}))
// Each icon renders as an element named after it.
vi.mock(
'lucide-react-native',
() => new Proxy({}, { has: () => true, get: (_, name) => String(name) })
)
vi.mock('../theme/use-mobile-color-scheme', () => ({ useMobileColorScheme: () => 'dark' }))
let renderer: ReactTestRenderer | null = null
afterEach(() => {
act(() => renderer?.unmount())
renderer = null
})
function imageIcon(src: string) {
return createElement(MobileRepoIcon, { repoIcon: { type: 'image', src, label: 'owner/repo' } })
}
describe('MobileRepoIcon', () => {
it('shows the folder after an image fails, and tries a changed image again', () => {
act(() => {
renderer = create(imageIcon('https://github.com/owner.png?size=64'))
})
act(() => renderer!.root.findByType(Image).props.onError())
expect(renderer!.root.findAllByType(Image)).toHaveLength(0)
expect(renderer!.root.findAllByType(Folder)).toHaveLength(1)
act(() => renderer!.update(imageIcon('data:image/png;base64,AAAA')))
expect(renderer!.root.findByType(Image).props.source).toEqual({
uri: 'data:image/png;base64,AAAA'
})
})
})
@@ -1,68 +0,0 @@
import { createElement } from 'react'
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
import { afterEach, describe, expect, it, vi } from 'vitest'
vi.mock('react-native', () => ({
Pressable: 'Pressable',
ScrollView: 'ScrollView',
StyleSheet: { create: (styles: unknown) => styles, hairlineWidth: 1 },
View: 'View'
}))
vi.mock('lucide-react-native', () => ({
Bold: 'Bold',
Code2: 'Code2',
FileCode2: 'FileCode2',
Heading1: 'Heading1',
Heading2: 'Heading2',
Heading3: 'Heading3',
ImageIcon: 'ImageIcon',
Italic: 'Italic',
Link: 'Link',
List: 'List',
ListOrdered: 'ListOrdered',
ListTodo: 'ListTodo',
Pilcrow: 'Pilcrow',
Quote: 'Quote',
Strikethrough: 'Strikethrough'
}))
import { MobileRichMarkdownToolbar } from './MobileRichMarkdownToolbar'
import type { MobileRichMarkdownCommand } from './mobile-rich-markdown-editor-contract'
let renderer: ReactTestRenderer | null = null
afterEach(() => {
act(() => renderer?.unmount())
renderer = null
})
function render(editable: boolean, onCommand: (command: MobileRichMarkdownCommand) => void) {
act(() => {
renderer = create(createElement(MobileRichMarkdownToolbar, { editable, onCommand }))
})
return renderer!.root.findAll((node) => String(node.type) === 'Pressable')
}
describe('the rich Markdown toolbar', () => {
it('routes named controls to their editor commands', () => {
const onCommand = vi.fn()
const buttons = render(true, onCommand)
for (const [label, command] of [
['Bold', 'bold'],
['Link', 'link'],
['Inline code', 'inlineCode']
] as const) {
onCommand.mockClear()
const button = buttons.find((candidate) => candidate.props.accessibilityLabel === label)
expect(button).toBeDefined()
act(() => button!.props.onPress())
expect(onCommand.mock.calls).toEqual([[command]])
}
})
it('disables every button against a document that cannot be edited', () => {
const buttons = render(false, vi.fn())
expect(buttons.filter((button) => button.props.disabled !== true)).toEqual([])
})
})
@@ -72,34 +72,6 @@ describe('ProtocolBlockScreen', () => {
renderer = null
})
// Why: the protocol wall shipped before the bundle one; its copy is what users already see.
it('keeps the existing protocol wall rendering unchanged', () => {
const mobile = render({
kind: 'blocked',
reason: 'mobile-too-old',
desktopVersion: 5,
requiredMobileVersion: 99
})
expect(mobile).toContain('Update Orca Mobile')
expect(mobile).toContain(
'This desktop needs a newer Orca Mobile app. Update Orca Mobile from the App Store, then try this host again.'
)
expect(mobile).toContain('Open App Store')
act(() => renderer?.unmount())
const desktop = render({
kind: 'blocked',
reason: 'desktop-too-old',
desktopVersion: 0,
requiredDesktopVersion: 2
})
expect(desktop).toContain('Update Orca on your computer')
expect(desktop).toContain(
'This paired desktop app is too old for your current Orca Mobile app. Update Orca on your computer, then try this host again.'
)
expect(desktop).toContain('Open GitHub Releases')
})
it('tells a host without a bundle, or without this screen, the desktop is too old', () => {
for (const reason of ['bundle-unavailable', 'page-route-unlisted'] as const) {
const output = render({ kind: 'blocked', reason })
@@ -112,12 +84,6 @@ describe('ProtocolBlockScreen', () => {
}
})
it('sends a screen that needs a grant this app lacks to the mobile update', () => {
const output = render({ kind: 'blocked', reason: 'page-route-grant-missing' })
expect(output).toContain('Update Orca Mobile')
expect(output).toContain("This desktop's mobile workspace needs a newer Orca Mobile app.")
})
it('sends an unknown manifest schema to the mobile update', () => {
const output = render({
kind: 'blocked',
@@ -169,44 +135,13 @@ describe('ProtocolBlockScreen', () => {
expect(primaryActionUrl()).toBe(RELEASES_URL)
})
it('sends a desktop whose page is older than this shell to the desktop update', () => {
const output = render({
kind: 'blocked',
reason: 'bundle-incompatible',
side: 'desktop',
pageVersion: 0,
requiredPageVersion: 1
})
expect(output).toContain('Update Orca on your computer')
expect(output).toContain('This paired desktop app is too old for your current Orca Mobile app')
expect(primaryActionUrl()).toBe(RELEASES_URL)
})
it('routes an Android bundle wall to GitHub Releases, not a store that has no listing', () => {
nativeTestState.platform.OS = 'android'
const output = render({
kind: 'blocked',
reason: 'bundle-shell-too-old',
schemaVersion: 2
})
expect(output).toContain('Update Orca Mobile from GitHub Releases')
expect(primaryActionUrl()).toBe(RELEASES_URL)
})
it('keeps the update walls on two buttons and the full recovery note', () => {
const output = render({ kind: 'blocked', reason: 'bundle-unavailable' })
expect(output).toContain('Already updated? Go back to Hosts and refresh the connection.')
// The presence precondition for the absence asserted on the refresh wall above.
expect(pressableCount()).toBe(2)
})
describe('with the newest release known', () => {
const release = {
version: '0.0.52',
url: 'https://github.com/stablyai/orca/releases/tag/mobile-v0.0.52'
}
it.each(['ios', 'android'] as const)('opens that exact release on %s', (os) => {
it.each(['android'] as const)('opens that exact release on %s', (os) => {
nativeTestState.platform.OS = os
const output = render(
{ kind: 'blocked', reason: 'bundle-shell-too-old', schemaVersion: 2 },