Files
openhuman/src/utils/__tests__/deviceDetection.test.ts
T
ad9d001261 Feat/e2e appium mac2 (#116)
* Replace Playwright with Appium mac2 + WebDriverIO for E2E testing and add unit tests

- Remove Playwright config and old e2e/ directory
- Add WebDriverIO + Appium mac2 driver for true native macOS app testing
- Add wdio.conf.ts with platform-aware app path detection
- Add scripts/e2e.sh to manage Appium lifecycle under Node 24
- Add E2E smoke, navigation, and Tauri integration specs
- Add tsconfig.e2e.json for E2E test TypeScript config
- Add unit tests for components, store slices, selectors, services, and utils
- Add test infrastructure (setup.ts, MSW handlers, test-utils)
- Update vitest.config.ts with coverage thresholds and setup
- Update package.json scripts and dependencies

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Update skills submodule to latest

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add complete E2E login flow test with mock server and onboarding walkthrough

Implements end-to-end testing of the full deep link auth → onboarding → home
flow using Appium mac2, WebDriverIO, and a local HTTP/WebSocket mock server.

Key additions:
- Mock server (port 18473) with all API routes + Socket.IO/Engine.IO WebSocket
  handler to prevent Rust SocketManager crashes
- Deep link helpers to trigger alphahuman:// URLs via macOS `open` command
- Element helpers using XPath selectors (not iOS predicates, which crash on
  mac2 with non-string attributes) and W3C pointer actions for clicking
  WKWebView content (standard element.click() doesn't trigger DOM handlers)
- Login flow spec: 11 tests covering auth deep link, API call verification,
  all 4 onboarding steps, and home page arrival
- Dedicated e2e-build.sh script with cargo clean + mock URL injection
- Cache cleanup and mock URL verification in e2e.sh

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Harden E2E tests and fix config issues from PR review

- e2e.sh: fail fast when dist bundle is missing instead of silently skipping
- setup.ts: add React type import for PersistGate mock annotation
- app-helpers: throw descriptive error on waitForAppReady timeout
- element-helpers: XPath quote escaping via concat() for special chars
- login-flow: fail explicitly when invite code step retry doesn't advance
- smoke.spec: replace no-op assertion with real session ID checks
- vite/vitest configs: remove unused @alphahuman/skill-types alias and
  dead path/fileURLToPath imports

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add TypeScript types to E2E element helpers and configure ESLint for E2E files

Remove blanket eslint-disable/ts-nocheck from element-helpers.ts, add explicit
TypeScript types with ChainablePromiseElement import, and add ESLint config block
for test/e2e/ files using tsconfig.e2e.json with WebDriverIO/Mocha globals.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix CI submodule checkout by adding XGH_TOKEN_READ secret

The skills submodule is a private repo that requires authentication.
The build and package-android workflows were missing the token that
package-and-publish already had.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix CI: install skills deps, format with Prettier, lower coverage thresholds

- build.yml: add skills dependency install step and remove redundant
  frontend build (tauri build already runs build:app via beforeBuildCommand)
- Run Prettier --write on all 32 files with formatting drift
- Lower vitest coverage thresholds to match actual coverage (~20%)
  until test coverage improves organically

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Remove stray globals.d.ts that failed Prettier check

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix ESLint parsing for wdio.conf.ts and type remaining E2E helpers

- Add wdio.conf.ts to ESLint E2E config block so TS parser covers it
- Remove blanket eslint-disable/ts-nocheck from deep-link-helpers.ts
  and app-helpers.ts, add explicit TypeScript types

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix unnecessary regex escape in useSettingsNavigation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Ghost Scripter <ghostscripter@zerolend.xyz>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 17:10:06 +05:30

119 lines
4.0 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
getArchitectureDisplayName,
getDownloadLink,
getPlatformDisplayName,
type GitHubReleaseAsset,
parseReleaseAssetsByArchitecture,
} from '../deviceDetection';
describe('getArchitectureDisplayName', () => {
it('returns correct names for known architectures', () => {
expect(getArchitectureDisplayName('x64')).toBe('Intel (x64)');
expect(getArchitectureDisplayName('aarch64')).toBe('Apple Silicon (ARM64)');
expect(getArchitectureDisplayName('amd64')).toBe('AMD64');
expect(getArchitectureDisplayName('unknown')).toBe('Unknown');
});
});
describe('getPlatformDisplayName', () => {
it('returns human-readable platform names', () => {
expect(getPlatformDisplayName('windows')).toBe('Windows');
expect(getPlatformDisplayName('macos')).toBe('macOS');
expect(getPlatformDisplayName('linux')).toBe('Linux');
expect(getPlatformDisplayName('android')).toBe('Android');
expect(getPlatformDisplayName('ios')).toBe('iOS');
expect(getPlatformDisplayName('unknown')).toBe('Your Device');
});
});
describe('getDownloadLink', () => {
it('returns release links when available', () => {
const releaseLinks = {
windows: 'https://releases.example.com/app.exe',
macos: 'https://releases.example.com/app.dmg',
};
expect(getDownloadLink('windows', releaseLinks)).toBe('https://releases.example.com/app.exe');
expect(getDownloadLink('macos', releaseLinks)).toBe('https://releases.example.com/app.dmg');
});
it('falls back to dummy links when no release links', () => {
const link = getDownloadLink('linux');
expect(link).toContain('example.com');
expect(link).toContain('linux');
});
it('falls back for unknown and ios platforms', () => {
const releaseLinks = { windows: 'https://example.com/w.exe' };
const unknownLink = getDownloadLink('unknown', releaseLinks);
expect(unknownLink).toBe('https://example.com/download');
const iosLink = getDownloadLink('ios', releaseLinks);
expect(iosLink).toContain('apple.com');
});
});
describe('parseReleaseAssetsByArchitecture', () => {
const makeAsset = (name: string, url?: string): GitHubReleaseAsset => ({
name,
browser_download_url: url || `https://example.com/${name}`,
content_type: 'application/octet-stream',
size: 1000,
});
it('categorizes assets by platform', () => {
const assets = [
makeAsset('alphahuman-windows-x64-setup.exe'),
makeAsset('alphahuman-macos-aarch64.dmg'),
makeAsset('alphahuman-linux-x64.AppImage'),
makeAsset('alphahuman-android-arm64.apk'),
];
const links = parseReleaseAssetsByArchitecture(assets);
expect(links.windows).toHaveLength(1);
expect(links.macos).toHaveLength(1);
expect(links.linux).toHaveLength(1);
expect(links.android).toHaveLength(1);
});
it('skips .sig signature files', () => {
const assets = [
makeAsset('alphahuman-windows-x64-setup.exe'),
makeAsset('alphahuman-windows-x64-setup.exe.sig'),
];
const links = parseReleaseAssetsByArchitecture(assets);
expect(links.windows).toHaveLength(1);
});
it('groups multiple architectures per platform', () => {
const assets = [
makeAsset('alphahuman-macos-x64.dmg'),
makeAsset('alphahuman-macos-aarch64.dmg'),
];
const links = parseReleaseAssetsByArchitecture(assets);
expect(links.macos).toHaveLength(2);
});
it('returns empty when no matching assets', () => {
const links = parseReleaseAssetsByArchitecture([]);
expect(links.windows).toBeUndefined();
expect(links.macos).toBeUndefined();
expect(links.linux).toBeUndefined();
expect(links.android).toBeUndefined();
});
it('prefers AppImage over deb/rpm for Linux', () => {
const assets = [
makeAsset('alphahuman-linux-x64.rpm'),
makeAsset('alphahuman-linux-x64.AppImage'),
];
const links = parseReleaseAssetsByArchitecture(assets);
expect(links.linux).toHaveLength(1);
expect(links.linux![0].fileName).toContain('.AppImage');
});
});