The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { |
| 4 | type MicrophoneEntry, |
| 5 | microphoneEntryKey, |
| 6 | microphoneOrder, |
| 7 | preferredMicrophoneInput, |
| 8 | rememberMicrophones, |
| 9 | } from "./microphonePriority"; |
| 10 | |
| 11 | const iPhone = { uid: "Built-In Microphone", name: "iPhone Microphone", type: "MicrophoneBuiltIn" }; |
| 12 | const airPods = { uid: "airpods", name: "Julius’s AirPods Pro", type: "BluetoothHFP" }; |
| 13 | const bose = { uid: "bose", name: "Julius’s Bose QC", type: "BluetoothHFP" }; |
| 14 | const civic = { uid: "civic", name: "Honda Civic", type: "BluetoothHFP" }; |
| 15 | const carPlay = { uid: "carplay", name: "CarPlay", type: "CarAudio" }; |
| 16 | const usb = { uid: "usb", name: "Shure MV7", type: "USBAudio" }; |
| 17 | |
| 18 | const keys = (order: ReadonlyArray<MicrophoneEntry>) => order.map(microphoneEntryKey); |
| 19 | |
| 20 | describe("microphoneOrder", () => { |
| 21 | it("keeps a saved order and files missing kinds after their devices", () => { |
| 22 | const saved: MicrophoneEntry[] = [ |
| 23 | { kind: "builtIn" }, |
| 24 | { kind: "bluetooth", uid: "airpods", name: "AirPods" }, |
| 25 | { kind: "builtIn" }, |
| 26 | ]; |
| 27 | expect(keys(microphoneOrder(saved))).toEqual([ |
| 28 | "kind:wired", |
| 29 | "kind:builtIn", |
| 30 | "airpods", |
| 31 | "kind:bluetooth", |
| 32 | "kind:carPlay", |
| 33 | ]); |
| 34 | expect(keys(microphoneOrder([{ kind: "carPlay" }, ...saved], "android"))).toEqual([ |
| 35 | "kind:wired", |
| 36 | "kind:builtIn", |
| 37 | "airpods", |
| 38 | "kind:bluetooth", |
| 39 | ]); |
| 40 | }); |
| 41 | }); |
| 42 | |
| 43 | describe("rememberMicrophones", () => { |
| 44 | it("lists a new device just above its kind and leaves built-in and CarPlay as kinds", () => { |
| 45 | const order = microphoneOrder(); |
| 46 | expect(keys(rememberMicrophones(order, [iPhone, carPlay, airPods]))).toEqual([ |
| 47 | "kind:wired", |
| 48 | "airpods", |
| 49 | "kind:bluetooth", |
| 50 | "kind:builtIn", |
| 51 | "kind:carPlay", |
| 52 | ]); |
| 53 | }); |
| 54 | |
| 55 | it("refreshes renamed devices and returns the same order when nothing changed", () => { |
| 56 | const order = rememberMicrophones(microphoneOrder(), [airPods]); |
| 57 | expect(rememberMicrophones(order, [airPods, iPhone])).toBe(order); |
| 58 | |
| 59 | const renamed = rememberMicrophones(order, [{ ...airPods, name: "AirPods Max" }]); |
| 60 | expect(renamed.find((entry) => microphoneEntryKey(entry) === "airpods")).toEqual({ |
| 61 | kind: "bluetooth", |
| 62 | uid: "airpods", |
| 63 | name: "AirPods Max", |
| 64 | }); |
| 65 | }); |
| 66 | }); |
| 67 | |
| 68 | describe("preferredMicrophoneInput", () => { |
| 69 | const order: MicrophoneEntry[] = [ |
| 70 | { kind: "builtIn" }, |
| 71 | { kind: "bluetooth", uid: "bose", name: bose.name }, |
| 72 | { kind: "wired" }, |
| 73 | { kind: "bluetooth" }, |
| 74 | { kind: "bluetooth", uid: "airpods", name: airPods.name }, |
| 75 | { kind: "carPlay" }, |
| 76 | ]; |
| 77 | |
| 78 | it("ranks unlisted devices of a kind at that kind, ahead of a device listed below it", () => { |
| 79 | expect(preferredMicrophoneInput([airPods, civic], order)).toBe(civic); |
| 80 | expect(preferredMicrophoneInput([airPods, bose], order)).toBe(bose); |
| 81 | expect(preferredMicrophoneInput([airPods, usb], order)).toBe(usb); |
| 82 | expect(preferredMicrophoneInput([airPods, carPlay], order)).toBe(airPods); |
| 83 | expect(preferredMicrophoneInput([airPods, iPhone], order)).toBe(iPhone); |
| 84 | const headset = { uid: "android:7:headset", name: "Headset", type: "BluetoothSCO" }; |
| 85 | expect(preferredMicrophoneInput([headset, iPhone], microphoneOrder([], "android"))).toBe( |
| 86 | headset, |
| 87 | ); |
| 88 | }); |
| 89 | }); |