| 1 | import { EnvironmentId } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { |
| 5 | resolveAgentAwarenessPlatformPresentation, |
| 6 | resolveAutoSettleReferenceEnvironmentId, |
| 7 | } from "./SettingsRouteScreen.logic"; |
| 8 | |
| 9 | describe("resolveAutoSettleReferenceEnvironmentId", () => { |
| 10 | const firstId = EnvironmentId.make("first"); |
| 11 | const secondId = EnvironmentId.make("second"); |
| 12 | |
| 13 | it("waits for an earlier grant before exposing a later writable reference", () => { |
| 14 | const second = { environmentId: secondId, canWriteSettings: true }; |
| 15 | expect( |
| 16 | resolveAutoSettleReferenceEnvironmentId([ |
| 17 | { environmentId: firstId, canWriteSettings: null }, |
| 18 | second, |
| 19 | ]), |
| 20 | ).toBeNull(); |
| 21 | expect( |
| 22 | resolveAutoSettleReferenceEnvironmentId([ |
| 23 | { environmentId: firstId, canWriteSettings: false }, |
| 24 | second, |
| 25 | ]), |
| 26 | ).toBe(secondId); |
| 27 | expect( |
| 28 | resolveAutoSettleReferenceEnvironmentId([ |
| 29 | { environmentId: firstId, canWriteSettings: true }, |
| 30 | second, |
| 31 | ]), |
| 32 | ).toBe(firstId); |
| 33 | }); |
| 34 | |
| 35 | it("does not wait for later grants after finding the first writable reference", () => { |
| 36 | expect( |
| 37 | resolveAutoSettleReferenceEnvironmentId([ |
| 38 | { environmentId: firstId, canWriteSettings: true }, |
| 39 | { environmentId: secondId, canWriteSettings: null }, |
| 40 | ]), |
| 41 | ).toBe(firstId); |
| 42 | }); |
| 43 | |
| 44 | it("waits before showing a read-only fallback until all grants are resolved", () => { |
| 45 | expect( |
| 46 | resolveAutoSettleReferenceEnvironmentId([ |
| 47 | { environmentId: firstId, canWriteSettings: false }, |
| 48 | { environmentId: secondId, canWriteSettings: null }, |
| 49 | ]), |
| 50 | ).toBeNull(); |
| 51 | expect( |
| 52 | resolveAutoSettleReferenceEnvironmentId([ |
| 53 | { environmentId: firstId, canWriteSettings: false }, |
| 54 | { environmentId: secondId, canWriteSettings: false }, |
| 55 | ]), |
| 56 | ).toBe(firstId); |
| 57 | }); |
| 58 | |
| 59 | it("has no reference when no environment supports synchronization", () => { |
| 60 | expect(resolveAutoSettleReferenceEnvironmentId([])).toBeNull(); |
| 61 | }); |
| 62 | }); |
| 63 | |
| 64 | describe("resolveAgentAwarenessPlatformPresentation", () => { |
| 65 | it("supports agent awareness settings on Android", () => { |
| 66 | expect(resolveAgentAwarenessPlatformPresentation("android")).toEqual({ |
| 67 | supported: true, |
| 68 | subtitle: undefined, |
| 69 | }); |
| 70 | }); |
| 71 | |
| 72 | it("leaves supported iOS settings unchanged", () => { |
| 73 | expect(resolveAgentAwarenessPlatformPresentation("ios")).toEqual({ |
| 74 | supported: true, |
| 75 | subtitle: undefined, |
| 76 | }); |
| 77 | }); |
| 78 | }); |