Skip to content

Colota - Android GPS Location tracker

refactor(share): hand the setup link to the system sharesheet (#860)

Max Dietrich70e596ab30b0
diff --git a/apps/docs/docs/guides/deep-link-setup.md b/apps/docs/docs/guides/deep-link-setup.md
index d964ca07..5738818f 100644
--- a/apps/docs/docs/guides/deep-link-setup.md
+++ b/apps/docs/docs/guides/deep-link-setup.md
@@ -16,11 +16,11 @@ Fill in the settings you want to configure. Only the fields you set will be incl
## Sharing From the App
-You can also generate a setup link straight from an existing installation, without the browser generator. Open **Settings → Share Setup**, tick which categories to include - Tracking, Sync, API, Geofences, Tracking profiles and Credentials - and tap **Share** to send the `colota://setup` link through any app.
+You can also generate a setup link straight from an existing installation, without the browser generator. Open **Settings → Share setup**, tick which categories to include - Tracking, Sync, API, Geofences, Tracking profiles and Credentials - and tap **Share** to send the `colota://setup` link through any app.
Credentials are off by default. Enabling them puts your username, password, bearer token or custom headers into the link in plain text, so only share it over a trusted channel.
-Geofences and tracking profiles can also be shared on their own from the [Geofences](geofencing.md#sharing-zones) and Tracking Profiles screens.
+Geofences and tracking profiles can also be shared on their own from the [Geofences](geofencing.md#sharing-zones) and Tracking profiles screens.
## How It Works
@@ -63,7 +63,7 @@ The `config` parameter is a base64-encoded JSON object. Only include the setting
| `auth.bearerToken` | string | Token for Bearer Auth |
| `customHeaders` | object | Custom HTTP headers (e.g. Cloudflare Access) |
| `geofences` | array | Pause zone definitions (see [Geofences](#geofences)) |
-| `profiles` | array | Tracking profile definitions (see [Tracking Profiles](#tracking-profiles)) |
+| `profiles` | array | Tracking profile definitions (see [Tracking profiles](#tracking-profiles)) |
### Geofences
@@ -75,7 +75,6 @@ Each entry in the `geofences` array describes one pause zone. `name`, `lat`, `lo
| `lat` | number | (required) | Latitude in decimal degrees |
| `lon` | number | (required) | Longitude in decimal degrees |
| `radius` | number | (required) | Radius in meters, must be > 0 |
-| `enabled` | boolean | `true` | Zone is active on import |
| `pauseTracking` | boolean | `false` | Stop saving locations inside the zone |
| `pauseOnWifi` | boolean | `false` | Also stop GPS while connected to Wi-Fi or Ethernet |
| `pauseOnMotionless` | boolean | `false` | Also stop GPS after no motion for `motionlessTimeoutMinutes` |
@@ -87,7 +86,7 @@ Imported geofences are appended by default. The import confirmation screen has a
You can build links with geofences using the in-browser generator above, the Node.js or Python snippets below, or by sharing zones directly from the Geofences screen in the app (see the [Geofencing](geofencing.md#sharing-zones) guide).
-### Tracking Profiles
+### Tracking profiles
Each entry in the `profiles` array describes one [tracking profile](tracking-profiles.md). `name`, `interval`, `distance`, `syncInterval` and `condition` are required. Other fields fall back to safe defaults. `id` and `createdAt` are ignored on import - the receiving device always creates fresh rows.
@@ -102,11 +101,10 @@ Each entry in the `profiles` array describes one [tracking profile](tracking-pro
| `priority` | number | `10` | Higher value wins when multiple profiles match |
| `activationDelay` | number | `0` (stationary: `60`) | Seconds the condition must keep matching before the profile is applied (0 = immediate). For `stationary`, how long the device must be still before activating |
| `deactivationDelay` | number | `60` (stationary: `0`) | Seconds to keep the profile active after the condition stops matching. Stationary resumes via the motion sensor instead |
-| `enabled` | boolean | `true` | Profile is active on import |
Imported profiles are appended by default. When both profiles and geofences are present the same "Replace ... with the same name" toggle on the import screen also deletes existing profiles whose names match before creating the incoming ones.
-You can build links with profiles using the in-browser generator above, the Node.js or Python snippets below, or by sharing profiles directly from the Tracking Profiles screen in the app.
+You can build links with profiles using the in-browser generator above, the Node.js or Python snippets below, or by sharing profiles directly from the Tracking profiles screen in the app.
## Generating Links Programmatically
diff --git a/apps/mobile/src/screens/SetupImportScreen.tsx b/apps/mobile/src/screens/SetupImportScreen.tsx
index 9d42b050..46463e02 100644
--- a/apps/mobile/src/screens/SetupImportScreen.tsx
+++ b/apps/mobile/src/screens/SetupImportScreen.tsx
@@ -4,18 +4,30 @@
*/
import React, { useState, useMemo } from "react"
-import { View, Text, ScrollView, StyleSheet, Switch } from "react-native"
+import { View, Text, ScrollView, StyleSheet, DeviceEventEmitter } from "react-native"
import { useTheme } from "../hooks/useTheme"
import { useTracking } from "../contexts/TrackingProvider"
-import { Container, Card, Button, SectionTitle } from "../components"
-import { fonts } from "../styles/typography"
-import { CircleAlert, CircleCheck, Import } from "lucide-react-native"
+import {
+ Button,
+ Card,
+ Container,
+ Divider,
+ EmptyState,
+ FieldMessage,
+ SectionTitle,
+ SettingRow,
+ StatRow,
+ Toggle
+} from "../components"
+import { fontSizes, fonts, lineHeights } from "../styles/typography"
+import { Check, CircleAlert } from "lucide-react-native"
import NativeLocationService from "../services/NativeLocationService"
import { showAlert } from "../services/modalService"
import { logger } from "../utils/logger"
import { type Settings } from "../types/global"
import { validateConfig, detectPreset, type ConfigEntry, type ValidationResult } from "../utils/setupConfig"
import { decodeConfig } from "../utils/setupLink"
+import { space } from "../constants"
export function SetupImportScreen({ route, navigation }: any) {
const { colors } = useTheme()
@@ -95,6 +107,7 @@ export function SetupImportScreen({ route, navigation }: any) {
}
await NativeLocationService.createGeofence(g)
}
+ DeviceEventEmitter.emit("geofenceUpdated")
}
if (result.config.profiles.length > 0) {
@@ -129,30 +142,25 @@ export function SetupImportScreen({ route, navigation }: any) {
<SectionTitle>{title}</SectionTitle>
<Card>
{entries.map((entry, i) => (
- <View
- key={entry.label}
- style={[
- styles.settingRow,
- i < entries.length - 1 && styles.settingRowBorder,
- i < entries.length - 1 && { borderBottomColor: colors.border }
- ]}
- >
- <Text style={[styles.settingLabel, { color: entry.rejected ? colors.error : colors.textSecondary }]}>
- {entry.label}
- </Text>
- <Text
- style={[styles.settingValue, { color: entry.rejected ? colors.error : colors.text }]}
- numberOfLines={1}
- >
- {entry.value}
- </Text>
- </View>
+ <React.Fragment key={entry.label}>
+ {i > 0 && <Divider tight />}
+ {/* A rejected entry carries a reason where a value would be, so it gets both. */}
+ <StatRow label={entry.label} value={entry.rejected ? "Not applied" : entry.value} />
+ {entry.rejected && <FieldMessage variant="error">{entry.value}</FieldMessage>}
+ </React.Fragment>
))}
</Card>
</View>
)
}
+ const replaceLabel =
+ geofenceEntries.length > 0 && profileEntries.length > 0
+ ? "Replace zones and profiles with the same name"
+ : profileEntries.length > 0
+ ? "Replace profiles with the same name"
+ : "Replace zones with the same name"
+
const handleCancel = () => {
navigation.navigate("Dashboard")
}
@@ -162,16 +170,8 @@ export function SetupImportScreen({ route, navigation }: any) {
return (
<Container>
<ScrollView contentContainerStyle={styles.content}>
- <Card style={styles.headerCard}>
- <View style={styles.headerRow}>
- <CircleAlert size={28} color={colors.error} />
- <View style={styles.headerText}>
- <Text style={[styles.title, { color: colors.text }]}>Invalid Configuration</Text>
- <Text style={[styles.subtitle, { color: colors.textSecondary }]}>{result.error}</Text>
- </View>
- </View>
- </Card>
- <Button title="Go Back" onPress={handleCancel} variant="primary" />
+ <EmptyState icon={CircleAlert} title="Invalid configuration" hint={result.error} />
+ <Button title="Go back" onPress={handleCancel} variant="primary" />
</ScrollView>
</Container>
)
@@ -181,52 +181,37 @@ export function SetupImportScreen({ route, navigation }: any) {
return (
<Container>
<ScrollView contentContainerStyle={styles.content}>
- <Card style={styles.headerCard}>
- <View style={styles.headerRow}>
- <Import size={28} color={colors.primary} />
- <View style={styles.headerText}>
- <Text style={[styles.title, { color: colors.text }]}>Import Configuration</Text>
- <Text style={[styles.subtitle, { color: colors.textSecondary }]}>
- A setup link wants to apply {result.entries.length} setting{result.entries.length !== 1 ? "s" : ""}
- </Text>
- </View>
- </View>
- </Card>
+ <Text style={[styles.subtitle, { color: colors.textSecondary }]}>
+ A setup link wants to apply {result.entries.length} setting{result.entries.length !== 1 ? "s" : ""}
+ </Text>
- {renderSection("TRACKING", trackingEntries)}
+ {renderSection("Tracking", trackingEntries)}
{renderSection("API", apiEntries)}
- {renderSection("AUTHENTICATION", authEntries)}
- {renderSection("GEOFENCES", geofenceEntries)}
- {renderSection("TRACKING PROFILES", profileEntries)}
+ {renderSection("Authentication", authEntries)}
+ {renderSection("Geofences", geofenceEntries)}
+ {renderSection("Tracking profiles", profileEntries)}
{(geofenceEntries.length > 0 || profileEntries.length > 0) && (
<View style={styles.section}>
- <Card>
- <View style={styles.toggleRow}>
- <View style={styles.toggleText}>
- <Text style={[styles.toggleLabel, { color: colors.text }]}>
- {geofenceEntries.length > 0 && profileEntries.length > 0
- ? "Replace zones and profiles with the same name"
- : profileEntries.length > 0
- ? "Replace profiles with the same name"
- : "Replace zones with the same name"}
- </Text>
- <Text style={[styles.toggleHint, { color: colors.textSecondary }]}>
- Off: imports are added as new entries
- </Text>
- </View>
- <Switch testID="replace-imports-switch" value={replaceByName} onValueChange={setReplaceByName} />
- </View>
+ <Card rows>
+ <SettingRow label={replaceLabel} hint="Off: imports are added as new entries">
+ <Toggle
+ accessibilityLabel={replaceLabel}
+ testID="replace-imports-switch"
+ value={replaceByName}
+ onValueChange={setReplaceByName}
+ />
+ </SettingRow>
</Card>
</View>
)}
<View style={styles.actions}>
<Button
- title="Apply Configuration"
+ title="Apply configuration"
onPress={handleApply}
variant="primary"
- icon={CircleCheck}
+ icon={Check}
loading={applying}
disabled={applying}
/>
@@ -239,70 +224,20 @@ export function SetupImportScreen({ route, navigation }: any) {
const styles = StyleSheet.create({
content: {
- padding: 16,
- paddingBottom: 40
- },
- headerCard: {
- marginBottom: 16
- },
- headerRow: {
- flexDirection: "row",
- alignItems: "center",
- gap: 12
- },
- headerText: {
- flex: 1
- },
- title: {
- fontSize: 18,
- ...fonts.bold
+ paddingHorizontal: space.lg,
+ paddingTop: space.lg,
+ paddingBottom: space.xxl
},
subtitle: {
- fontSize: 13,
+ fontSize: fontSizes.body,
...fonts.regular,
- marginTop: 2
+ lineHeight: lineHeights.body,
+ marginBottom: space.lg
},
section: {
- marginTop: 8
- },
- settingRow: {
- flexDirection: "row",
- justifyContent: "space-between",
- alignItems: "center",
- paddingVertical: 10
- },
- settingRowBorder: {
- borderBottomWidth: StyleSheet.hairlineWidth
- },
- settingLabel: {
- fontSize: 13,
- ...fonts.semiBold
- },
- toggleRow: {
- flexDirection: "row",
- alignItems: "center",
- paddingVertical: 6,
- gap: 12
- },
- toggleText: {
- flex: 1
- },
- toggleLabel: {
- fontSize: 13,
- ...fonts.semiBold
- },
- toggleHint: {
- fontSize: 12,
- ...fonts.regular,
- marginTop: 2
- },
- settingValue: {
- fontSize: 13,
- ...fonts.regular,
- maxWidth: "60%",
- textAlign: "right"
+ marginTop: space.xl
},
actions: {
- marginTop: 24
+ marginTop: space.xl
}
})
diff --git a/apps/mobile/src/screens/ShareSetupScreen.tsx b/apps/mobile/src/screens/ShareSetupScreen.tsx
index 302a69a4..33211c8f 100644
--- a/apps/mobile/src/screens/ShareSetupScreen.tsx
+++ b/apps/mobile/src/screens/ShareSetupScreen.tsx
@@ -4,17 +4,18 @@
*/
import React, { useCallback, useEffect, useMemo, useState } from "react"
-import { View, Text, ScrollView, StyleSheet, Switch, Share } from "react-native"
+import { View, Text, ScrollView, StyleSheet, Share } from "react-native"
import { useTheme } from "../hooks/useTheme"
import { useTracking } from "../contexts/TrackingProvider"
-import { Container, Card, Button, SectionTitle } from "../components"
-import { fonts } from "../styles/typography"
+import { Button, Card, Container, Divider, SectionTitle, SettingRow, Toggle } from "../components"
+import { fontSizes, fonts, lineHeights } from "../styles/typography"
import { Share2, TriangleAlert } from "lucide-react-native"
import NativeLocationService from "../services/NativeLocationService"
import { showAlert } from "../services/modalService"
import { logger } from "../utils/logger"
import { buildSetupConfig, buildSetupLink, type SetupShareParts, type SetupShareSelection } from "../utils/setupLink"
import { DEFAULT_AUTH_CONFIG, type AuthConfig, type Geofence, type TrackingProfile } from "../types/global"
+import { size, space } from "../constants"
type ShareCategory = keyof SetupShareSelection
@@ -122,53 +123,36 @@ export function ShareSetupScreen() {
return (
<Container>
<ScrollView contentContainerStyle={styles.content}>
- <Card style={styles.headerCard}>
- <View style={styles.headerRow}>
- <Share2 size={28} color={colors.primary} />
- <View style={styles.headerText}>
- <Text style={[styles.title, { color: colors.text }]}>Share Setup</Text>
- <Text style={[styles.subtitle, { color: colors.textSecondary }]}>
- Choose what to bundle into a setup link, then share it. The recipient opens it to apply the same
- configuration.
- </Text>
- </View>
- </View>
- </Card>
+ <Text style={[styles.intro, { color: colors.textSecondary }]}>
+ Choose what to bundle into a setup link, then share it. The recipient opens it to apply the same
+ configuration.
+ </Text>
<View style={styles.section}>
- <SectionTitle>INCLUDE</SectionTitle>
- <Card>
+ <SectionTitle>Include</SectionTitle>
+ <Card rows>
{rows.map((row, i) => (
- <View
- key={row.key}
- style={[
- styles.row,
- i < rows.length - 1 && styles.rowBorder,
- i < rows.length - 1 && { borderBottomColor: colors.border }
- ]}
- >
- <View style={styles.rowText}>
- <Text style={[styles.rowLabel, { color: row.disabled ? colors.textSecondary : colors.text }]}>
- {row.label}
- </Text>
- <Text style={[styles.rowSub, { color: colors.textSecondary }]}>{row.sub}</Text>
- </View>
- <Switch
- testID={`share-${row.key}`}
- value={selection[row.key] && !row.disabled}
- onValueChange={() => toggle(row.key)}
- disabled={row.disabled}
- />
- </View>
+ <React.Fragment key={row.key}>
+ {i > 0 && <Divider tight />}
+ <SettingRow label={row.label} hint={row.sub} disabled={row.disabled}>
+ <Toggle
+ accessibilityLabel={row.label}
+ testID={`share-${row.key}`}
+ value={selection[row.key] && !row.disabled}
+ onValueChange={() => toggle(row.key)}
+ disabled={row.disabled}
+ />
+ </SettingRow>
+ </React.Fragment>
))}
</Card>
</View>
{selection.credentials && hasCredentials && credentialFields.length > 0 && (
<View style={styles.section}>
- <Card style={[styles.warningCard, { borderColor: colors.error }]}>
+ <Card danger>
<View style={styles.headerRow}>
- <TriangleAlert size={20} color={colors.error} />
+ <TriangleAlert size={size.icon.md} color={colors.error} />
<Text style={[styles.warningText, { color: colors.text }]}>
This link will contain your {credentialFields.join(", ")} in plain text. Anyone who sees the link can
read them - only share it over a trusted channel.
@@ -193,70 +177,36 @@ export function ShareSetupScreen() {
const styles = StyleSheet.create({
content: {
- padding: 16,
- paddingBottom: 40
- },
- headerCard: {
- marginBottom: 16
+ padding: space.lg,
+ paddingBottom: space.xxl
},
headerRow: {
flexDirection: "row",
alignItems: "center",
- gap: 12
- },
- headerText: {
- flex: 1
+ gap: space.md
},
- title: {
- fontSize: 18,
- ...fonts.bold
- },
- subtitle: {
- fontSize: 13,
+ intro: {
+ fontSize: fontSizes.body,
...fonts.regular,
- marginTop: 2
+ lineHeight: lineHeights.body,
+ marginBottom: space.md
},
section: {
- marginTop: 8
- },
- row: {
- flexDirection: "row",
- justifyContent: "space-between",
- alignItems: "center",
- paddingVertical: 12,
- gap: 12
- },
- rowBorder: {
- borderBottomWidth: StyleSheet.hairlineWidth
- },
- rowText: {
- flex: 1
- },
- rowLabel: {
- fontSize: 14,
- ...fonts.semiBold
- },
- rowSub: {
- fontSize: 12,
- ...fonts.regular,
- marginTop: 2
- },
- warningCard: {
- borderWidth: StyleSheet.hairlineWidth
+ marginTop: space.sm
},
warningText: {
flex: 1,
- fontSize: 12,
+ fontSize: fontSizes.caption,
...fonts.regular,
- lineHeight: 17
+ lineHeight: lineHeights.caption
},
actions: {
- marginTop: 24
+ marginTop: space.xl
},
emptyHint: {
- fontSize: 12,
+ fontSize: fontSizes.caption,
...fonts.regular,
textAlign: "center",
- marginTop: 8
+ marginTop: space.sm
}
})
diff --git a/apps/mobile/src/screens/__tests__/SetupImportScreen.test.tsx b/apps/mobile/src/screens/__tests__/SetupImportScreen.test.tsx
index 428858ce..ce52afae 100644
--- a/apps/mobile/src/screens/__tests__/SetupImportScreen.test.tsx
+++ b/apps/mobile/src/screens/__tests__/SetupImportScreen.test.tsx
@@ -58,8 +58,7 @@ jest.mock("../../hooks/useTheme", () => ({
error: "#ef4444",
card: "#fff",
textOnPrimary: "#fff",
- textDisabled: "#d1d5db",
- borderRadius: 12
+ textDisabled: "#d1d5db"
}
})
}))
@@ -68,9 +67,32 @@ jest.mock("../../components", () => {
const R = require("react")
const { View, Text, Pressable } = require("react-native")
return {
+ Toggle: function (props: any) {
+ return require("react").createElement(require("react-native").Switch, {
+ testID: props.testID,
+ value: props.value,
+ onValueChange: props.onValueChange,
+ disabled: props.disabled,
+ accessibilityLabel: props.accessibilityLabel
+ })
+ },
Container: ({ children }: any) => R.createElement(View, null, children),
Card: ({ children }: any) => R.createElement(View, null, children),
SectionTitle: ({ children }: any) => R.createElement(Text, null, children),
+ Divider: () => R.createElement(View, null),
+ StatRow: ({ label, value }: any) =>
+ R.createElement(View, null, R.createElement(Text, null, label), R.createElement(Text, null, value)),
+ FieldMessage: ({ children }: any) => R.createElement(Text, null, children),
+ EmptyState: ({ title, hint }: any) =>
+ R.createElement(View, null, R.createElement(Text, null, title), hint ? R.createElement(Text, null, hint) : null),
+ SettingRow: ({ label, hint, children }: any) =>
+ R.createElement(
+ View,
+ null,
+ R.createElement(Text, null, label),
+ hint ? R.createElement(Text, null, hint) : null,
+ children
+ ),
Button: ({ title, onPress, disabled }: any) =>
R.createElement(Pressable, { onPress, disabled, accessibilityRole: "button" }, R.createElement(Text, null, title))
}
@@ -107,29 +129,28 @@ describe("SetupImportScreen", () => {
describe("parsing and validation", () => {
it("shows error when no config param is provided", () => {
const { getByText } = renderScreen()
- expect(getByText("Invalid Configuration")).toBeTruthy()
+ expect(getByText("Invalid configuration")).toBeTruthy()
expect(getByText("No configuration data in URL")).toBeTruthy()
})
it("shows error for invalid base64", () => {
const { getByText } = renderScreen("!!!not-base64!!!")
- expect(getByText("Invalid Configuration")).toBeTruthy()
+ expect(getByText("Invalid configuration")).toBeTruthy()
})
it("shows error for valid base64 but invalid JSON", () => {
const { getByText } = renderScreen(btoa("not json"))
- expect(getByText("Invalid Configuration")).toBeTruthy()
+ expect(getByText("Invalid configuration")).toBeTruthy()
})
it("shows error when config has no valid settings", () => {
const { getByText } = renderScreen(encode({ unknownKey: "value" }))
- expect(getByText("Invalid Configuration")).toBeTruthy()
+ expect(getByText("Invalid configuration")).toBeTruthy()
expect(getByText("No valid settings found in configuration")).toBeTruthy()
})
it("parses valid endpoint config", () => {
const { getByText } = renderScreen(encode({ endpoint: "https://my-server.com/api" }))
- expect(getByText("Import Configuration")).toBeTruthy()
expect(getByText("Endpoint")).toBeTruthy()
expect(getByText("https://my-server.com/api")).toBeTruthy()
})
@@ -161,17 +182,17 @@ describe("SetupImportScreen", () => {
it("rejects invalid interval (negative)", () => {
const { getByText } = renderScreen(encode({ interval: -5 }))
- expect(getByText("Invalid Configuration")).toBeTruthy()
+ expect(getByText("Invalid configuration")).toBeTruthy()
})
it("rejects invalid auth type", () => {
const { getByText } = renderScreen(encode({ auth: { type: "oauth" } }))
- expect(getByText("Invalid Configuration")).toBeTruthy()
+ expect(getByText("Invalid configuration")).toBeTruthy()
})
it("rejects invalid API template", () => {
const { getByText } = renderScreen(encode({ apiTemplate: "invalid" }))
- expect(getByText("Invalid Configuration")).toBeTruthy()
+ expect(getByText("Invalid configuration")).toBeTruthy()
})
it("counts settings correctly in subtitle", () => {
@@ -192,7 +213,7 @@ describe("SetupImportScreen", () => {
const config = { endpoint: "https://test.com", interval: 15 }
const { getByText } = renderScreen(encode(config))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockShowAlert).toHaveBeenCalledWith(
@@ -212,7 +233,7 @@ describe("SetupImportScreen", () => {
const config = { endpoint: "https://test.com", auth: { type: "bearer", bearerToken: "mytoken" } }
const { getByText } = renderScreen(encode(config))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockSaveAuthConfig).toHaveBeenCalledWith(
@@ -224,7 +245,7 @@ describe("SetupImportScreen", () => {
it("marks hasCompletedSetup as true", async () => {
const { getByText } = renderScreen(encode({ endpoint: "https://test.com" }))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockSetSettings).toHaveBeenCalledWith(expect.objectContaining({ hasCompletedSetup: true }))
@@ -235,7 +256,7 @@ describe("SetupImportScreen", () => {
const config = { interval: 15, distance: 3, syncInterval: 120 }
const { getByText } = renderScreen(encode(config))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockSetSettings).toHaveBeenCalledWith(expect.objectContaining({ syncPreset: "custom" }))
@@ -252,7 +273,7 @@ describe("SetupImportScreen", () => {
}
const { getByText } = renderScreen(encode(config))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockSetSettings).toHaveBeenCalledWith(expect.objectContaining({ syncPreset: "balanced" }))
@@ -263,7 +284,7 @@ describe("SetupImportScreen", () => {
mockSetSettings.mockRejectedValueOnce(new Error("fail"))
const { getByText } = renderScreen(encode({ endpoint: "https://test.com" }))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockShowAlert).toHaveBeenCalledWith("Error", "Failed to apply configuration. Please try again.", "error")
@@ -280,7 +301,7 @@ describe("SetupImportScreen", () => {
it("navigates to Dashboard on Go Back (error state)", () => {
const { getByText } = renderScreen()
- fireEvent.press(getByText("Go Back"))
+ fireEvent.press(getByText("Go back"))
expect(mockNavigate).toHaveBeenCalledWith("Dashboard")
})
})
@@ -288,21 +309,21 @@ describe("SetupImportScreen", () => {
describe("geofences", () => {
const validGeofence = { name: "Home", lat: 52.5, lon: 13.4, radius: 100 }
- it("parses a valid geofence and shows it under GEOFENCES", () => {
+ it("parses a valid geofence and shows it under Geofences", () => {
const { getByText } = renderScreen(encode({ geofences: [validGeofence] }))
- expect(getByText("GEOFENCES")).toBeTruthy()
+ expect(getByText("Geofences")).toBeTruthy()
expect(getByText("Home")).toBeTruthy()
expect(getByText("100m")).toBeTruthy()
})
it("rejects a geofence missing required fields", () => {
const { getByText } = renderScreen(encode({ geofences: [{ name: "X", lat: 52.5 }] }))
- expect(getByText("Invalid Configuration")).toBeTruthy()
+ expect(getByText("Invalid configuration")).toBeTruthy()
})
it("rejects a geofence with non-positive radius", () => {
const { getByText } = renderScreen(encode({ geofences: [{ ...validGeofence, radius: 0 }] }))
- expect(getByText("Invalid Configuration")).toBeTruthy()
+ expect(getByText("Invalid configuration")).toBeTruthy()
})
it("skips invalid entries but keeps valid ones", () => {
@@ -317,7 +338,7 @@ describe("SetupImportScreen", () => {
it("calls createGeofence on apply with defaults filled in", async () => {
const { getByText } = renderScreen(encode({ geofences: [validGeofence] }))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockCreateGeofence).toHaveBeenCalledTimes(1)
@@ -354,7 +375,7 @@ describe("SetupImportScreen", () => {
}
const { getByText } = renderScreen(encode(config))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockCreateGeofence).toHaveBeenCalledTimes(1)
@@ -381,7 +402,7 @@ describe("SetupImportScreen", () => {
}
const { getByText } = renderScreen(encode(config))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockCreateGeofence).toHaveBeenCalledTimes(2)
@@ -390,10 +411,22 @@ describe("SetupImportScreen", () => {
expect(mockCreateGeofence.mock.calls[1][0].name).toBe("Office")
})
+ it("tells the geofence screens to reload once the zones are written, as the editor does", async () => {
+ const { DeviceEventEmitter } = require("react-native")
+ const emit = jest.spyOn(DeviceEventEmitter, "emit")
+ const { getByText } = renderScreen(encode({ geofences: [validGeofence] }))
+
+ fireEvent.press(getByText("Apply configuration"))
+
+ await waitFor(() => expect(mockCreateGeofence).toHaveBeenCalledTimes(1))
+ expect(emit).toHaveBeenCalledWith("geofenceUpdated")
+ emit.mockRestore()
+ })
+
it("does not call createGeofence when no geofences in config", async () => {
const { getByText } = renderScreen(encode({ endpoint: "https://test.com" }))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockShowAlert).toHaveBeenCalledWith("Configuration Applied", expect.any(String), "success")
@@ -426,7 +459,7 @@ describe("SetupImportScreen", () => {
mockGetGeofences.mockResolvedValueOnce([{ id: 7, name: "Home", lat: 0, lon: 0, radius: 50, enabled: true }])
const { getByText } = renderScreen(encode({ geofences: [validGeofence] }))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockCreateGeofence).toHaveBeenCalledTimes(1)
@@ -443,7 +476,7 @@ describe("SetupImportScreen", () => {
const { getByText, getByTestId } = renderScreen(encode({ geofences: [validGeofence] }))
fireEvent(getByTestId("replace-imports-switch"), "valueChange", true)
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockCreateGeofence).toHaveBeenCalledTimes(1)
@@ -457,7 +490,7 @@ describe("SetupImportScreen", () => {
const { getByText, getByTestId } = renderScreen(encode({ geofences: [validGeofence] }))
fireEvent(getByTestId("replace-imports-switch"), "valueChange", true)
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockCreateGeofence).toHaveBeenCalledTimes(1)
@@ -479,7 +512,7 @@ describe("SetupImportScreen", () => {
const { getByText, getByTestId } = renderScreen(encode(config))
fireEvent(getByTestId("replace-imports-switch"), "valueChange", true)
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockCreateGeofence).toHaveBeenCalledTimes(2)
@@ -511,27 +544,27 @@ describe("SetupImportScreen", () => {
mockCreateProfile.mockResolvedValue(1)
})
- it("parses a valid profile and shows it under TRACKING PROFILES", () => {
+ it("parses a valid profile and shows it under Tracking profiles", () => {
const { getByText } = renderScreen(encode({ profiles: [validProfile] }))
- expect(getByText("TRACKING PROFILES")).toBeTruthy()
+ expect(getByText("Tracking profiles")).toBeTruthy()
expect(getByText("Driving")).toBeTruthy()
})
it("rejects a profile missing name", () => {
const { getByText } = renderScreen(encode({ profiles: [{ ...validProfile, name: "" }] }))
- expect(getByText("Invalid Configuration")).toBeTruthy()
+ expect(getByText("Invalid configuration")).toBeTruthy()
})
it("rejects a profile with unknown condition type", () => {
const config = { profiles: [{ ...validProfile, condition: { type: "bogus" } }] }
const { getByText } = renderScreen(encode(config))
- expect(getByText("Invalid Configuration")).toBeTruthy()
+ expect(getByText("Invalid configuration")).toBeTruthy()
})
it("rejects a speed profile missing speedThreshold", () => {
const config = { profiles: [{ ...validProfile, condition: { type: "speed_above" } }] }
const { getByText } = renderScreen(encode(config))
- expect(getByText("Invalid Configuration")).toBeTruthy()
+ expect(getByText("Invalid configuration")).toBeTruthy()
})
it("accepts a non-speed condition without speedThreshold", () => {
@@ -544,13 +577,13 @@ describe("SetupImportScreen", () => {
it("rejects a profile with interval < 1", () => {
const { getByText } = renderScreen(encode({ profiles: [{ ...validProfile, interval: 0 }] }))
- expect(getByText("Invalid Configuration")).toBeTruthy()
+ expect(getByText("Invalid configuration")).toBeTruthy()
})
it("calls createProfile on apply with all fields", async () => {
const { getByText } = renderScreen(encode({ profiles: [validProfile] }))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockCreateProfile).toHaveBeenCalledTimes(1)
@@ -578,7 +611,7 @@ describe("SetupImportScreen", () => {
}
const { getByText } = renderScreen(encode({ profiles: [minimal] }))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockCreateProfile).toHaveBeenCalledTimes(1)
@@ -609,7 +642,7 @@ describe("SetupImportScreen", () => {
}
const { getByText } = renderScreen(encode(config))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockCreateProfile).toHaveBeenCalledTimes(1)
@@ -631,7 +664,7 @@ describe("SetupImportScreen", () => {
}
const { getByText } = renderScreen(encode(config))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockCreateProfile).toHaveBeenCalledTimes(1)
@@ -645,7 +678,7 @@ describe("SetupImportScreen", () => {
}
const { getByText } = renderScreen(encode(config))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockCreateProfile).toHaveBeenCalledTimes(2)
@@ -657,7 +690,7 @@ describe("SetupImportScreen", () => {
it("does not call createProfile when no profiles in config", async () => {
const { getByText } = renderScreen(encode({ endpoint: "https://test.com" }))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockShowAlert).toHaveBeenCalledWith("Configuration Applied", expect.any(String), "success")
@@ -693,7 +726,7 @@ describe("SetupImportScreen", () => {
const { getByText, getByTestId } = renderScreen(encode({ profiles: [validProfile] }))
fireEvent(getByTestId("replace-imports-switch"), "valueChange", true)
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockCreateProfile).toHaveBeenCalledTimes(1)
@@ -718,7 +751,7 @@ describe("SetupImportScreen", () => {
])
const { getByText } = renderScreen(encode({ profiles: [validProfile] }))
- fireEvent.press(getByText("Apply Configuration"))
+ fireEvent.press(getByText("Apply configuration"))
await waitFor(() => {
expect(mockCreateProfile).toHaveBeenCalledTimes(1)
@@ -727,4 +760,14 @@ describe("SetupImportScreen", () => {
expect(mockDeleteProfile).not.toHaveBeenCalled()
})
})
+
+ describe("rejected entries", () => {
+ it("says the setting was not applied and why, instead of only turning the row red", () => {
+ const { getByText } = renderScreen(encode({ endpoint: "notaurl", interval: 10 }))
+
+ // The value column carries a reason for a rejected entry, so it cannot double as the value.
+ expect(getByText("Not applied")).toBeTruthy()
+ expect(getByText("HTTP not allowed for public hosts")).toBeTruthy()
+ })
+ })
})
diff --git a/apps/mobile/src/screens/__tests__/ShareSetupScreen.test.tsx b/apps/mobile/src/screens/__tests__/ShareSetupScreen.test.tsx
index 8a92cfff..6723b875 100644
--- a/apps/mobile/src/screens/__tests__/ShareSetupScreen.test.tsx
+++ b/apps/mobile/src/screens/__tests__/ShareSetupScreen.test.tsx
@@ -41,7 +41,6 @@ jest.mock("../../hooks/useTheme", () => ({
background: "#fff",
backgroundElevated: "#f9fafb",
border: "#e5e7eb",
- borderRadius: 12,
success: "#22c55e",
warning: "#f59e0b",
info: "#3b82f6",
@@ -92,6 +91,7 @@ jest.mock("../../services/NativeLocationService", () => ({
jest.mock("../../services/modalService", () => ({ showAlert: jest.fn() }))
import { ShareSetupScreen } from "../ShareSetupScreen"
+import { Card } from "../../components"
const NO_AUTH = { authType: "none", username: "", password: "", bearerToken: "", customHeaders: {} }
const BASIC_AUTH = { authType: "basic", username: "user", password: "secret", bearerToken: "", customHeaders: {} }
@@ -111,6 +111,18 @@ describe("ShareSetupScreen", () => {
afterEach(() => shareSpy.mockRestore())
+ it("warns through the Card danger variant rather than a border drawn by hand", async () => {
+ mockGetAuthConfig.mockResolvedValue(BASIC_AUTH)
+ const { getByTestId, UNSAFE_getAllByType } = render(<ShareSetupScreen />)
+ await waitFor(() => expect(mockGetAuthConfig).toHaveBeenCalled())
+
+ fireEvent(getByTestId("share-credentials"), "valueChange", true)
+
+ const warning = await waitFor(() => UNSAFE_getAllByType(Card).find((c) => c.props.danger))
+ expect(warning).toBeTruthy()
+ expect(warning!.props.style).toBeUndefined()
+ })
+
it("shares nothing until a category is toggled on", async () => {
const { getByText } = render(<ShareSetupScreen />)
await waitFor(() => expect(mockGetAuthConfig).toHaveBeenCalled())