| 1 | import type { RelayClientDeviceRecord } from "@t3tools/contracts/relay"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { |
| 5 | mobileClientNotificationDetail, |
| 6 | mobileClientPlatformLabel, |
| 7 | mobileClientUpdatedAtLabel, |
| 8 | } from "./MobileClientsUserProfilePage.logic"; |
| 9 | |
| 10 | function device(overrides: Partial<RelayClientDeviceRecord> = {}): RelayClientDeviceRecord { |
| 11 | return { |
| 12 | deviceId: "device-1", |
| 13 | label: "Julius’s iPhone", |
| 14 | platform: "ios", |
| 15 | iosMajorVersion: 18, |
| 16 | appVersion: "1.2.3", |
| 17 | notifications: { |
| 18 | enabled: true, |
| 19 | notifyOnApproval: true, |
| 20 | notifyOnInput: false, |
| 21 | notifyOnCompletion: true, |
| 22 | notifyOnFailure: false, |
| 23 | }, |
| 24 | liveActivities: { enabled: true }, |
| 25 | updatedAt: "2026-06-21T12:00:00.000Z", |
| 26 | ...overrides, |
| 27 | }; |
| 28 | } |
| 29 | |
| 30 | describe("mobile client presentation", () => { |
| 31 | it("describes the client platform and enabled notification events", () => { |
| 32 | const client = device(); |
| 33 | |
| 34 | expect(mobileClientPlatformLabel(client)).toBe("iOS 18 · The Knife 1.2.3"); |
| 35 | expect(mobileClientNotificationDetail(client)).toBe( |
| 36 | "Alerts enabled for approvals, completions.", |
| 37 | ); |
| 38 | }); |
| 39 | |
| 40 | it("labels Android devices without displaying an iOS version", () => { |
| 41 | expect( |
| 42 | mobileClientPlatformLabel( |
| 43 | device({ platform: "android", iosMajorVersion: null, androidApiLevel: 36 }), |
| 44 | ), |
| 45 | ).toBe("Android · The Knife 1.2.3"); |
| 46 | }); |
| 47 | |
| 48 | it("distinguishes disabled notifications from an empty event selection", () => { |
| 49 | expect( |
| 50 | mobileClientNotificationDetail( |
| 51 | device({ notifications: { ...device().notifications, enabled: false } }), |
| 52 | ), |
| 53 | ).toBe("Push notifications are disabled on this device."); |
| 54 | expect( |
| 55 | mobileClientNotificationDetail( |
| 56 | device({ |
| 57 | notifications: { |
| 58 | enabled: true, |
| 59 | notifyOnApproval: false, |
| 60 | notifyOnInput: false, |
| 61 | notifyOnCompletion: false, |
| 62 | notifyOnFailure: false, |
| 63 | }, |
| 64 | }), |
| 65 | ), |
| 66 | ).toBe("Push notifications are enabled, but no alert types are selected."); |
| 67 | }); |
| 68 | |
| 69 | it("handles missing app versions and invalid update timestamps", () => { |
| 70 | expect(mobileClientPlatformLabel(device({ iosMajorVersion: null }))).toBe( |
| 71 | "iOS · The Knife 1.2.3", |
| 72 | ); |
| 73 | expect(mobileClientPlatformLabel(device({ appVersion: null }))).toBe("iOS 18"); |
| 74 | expect(mobileClientUpdatedAtLabel("not-a-date")).toBe("Update time unavailable"); |
| 75 | }); |
| 76 | }); |