Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/mobile/app/providers/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ export const ImportOnly: ProviderCardStory = {
},
};

export const GarminDumpImport: ProviderCardStory = {
args: {
provider: {
id: "garmin-dump",
label: "Garmin Dump",
enabled: false,
authStatus: "connected",
authType: "none",
lastSyncAt: null,
importOnly: true,
pushOnly: false,
},
onImport: () => {},
},
};

export const AppleHealthImportOnly: ProviderCardStory = {
args: {
provider: {
Expand Down
140 changes: 139 additions & 1 deletion packages/mobile/app/providers/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ const mockReplace = vi.fn();
const mockUseLocalSearchParams = vi.fn().mockReturnValue({});
const mockSyncMutateAsync = vi.fn();
const mockImportSharedFile = vi.fn();
const mockGetDocumentAsync = vi.fn();

vi.mock("react-native", () => ({
View: ({ children, ...props }: { children?: React.ReactNode } & Record<string, unknown>) => {
const {
style: _s,
style,
contentContainerStyle: _cs,
activeOpacity: _ao,
numberOfLines: _nl,
Expand All @@ -25,6 +26,7 @@ vi.mock("react-native", () => ({
"div",
{
...(testID ? { "data-testid": testID } : {}),
...(testID && style ? { "data-style": JSON.stringify(style) } : {}),
...rest,
},
children,
Expand Down Expand Up @@ -189,6 +191,10 @@ vi.mock("expo-web-browser", () => ({
openBrowserAsync: vi.fn().mockResolvedValue({ type: "cancel" }),
}));

vi.mock("expo-document-picker", () => ({
getDocumentAsync: (...args: unknown[]) => mockGetDocumentAsync(...args),
}));

vi.mock("../../lib/share-import", () => ({
importSharedFile: (...args: unknown[]) => mockImportSharedFile(...args),
}));
Expand Down Expand Up @@ -242,12 +248,14 @@ const mockStatsQuery = vi.fn();
const mockLogsQuery = vi.fn();
const mockDataHealthQuery = vi.fn();
const mockActiveSyncsQuery = vi.fn();
const mockActiveImportsQuery = vi.fn();
const mockInvalidate = vi.fn();
const mockInvalidateProviders = vi.fn();
const mockInvalidateProviderStats = vi.fn();
const mockInvalidateLogs = vi.fn();
const mockInvalidateDataHealth = vi.fn();
const mockInvalidateActiveSyncs = vi.fn();
const mockInvalidateActiveImports = vi.fn();
const mockSyncStatusFetch = vi.fn();
const mockCredentialSignIn = vi.fn();
const mockGarminSignIn = vi.fn();
Expand All @@ -273,6 +281,7 @@ vi.mock("../../lib/trpc", () => ({
dataHealth: { useQuery: (...args: unknown[]) => mockDataHealthQuery(...args) },
triggerSync: { useMutation: () => ({ mutateAsync: mockSyncMutateAsync }) },
activeSyncs: { useQuery: (...args: unknown[]) => mockActiveSyncsQuery(...args) },
activeImports: { useQuery: (...args: unknown[]) => mockActiveImportsQuery(...args) },
},
credentialAuth: {
signIn: { useMutation: () => ({ mutateAsync: mockCredentialSignIn }) },
Expand Down Expand Up @@ -304,6 +313,7 @@ vi.mock("../../lib/trpc", () => ({
logs: { invalidate: mockInvalidateLogs },
dataHealth: { invalidate: mockInvalidateDataHealth },
activeSyncs: { invalidate: mockInvalidateActiveSyncs },
activeImports: { invalidate: mockInvalidateActiveImports },
syncStatus: { fetch: mockSyncStatusFetch },
},
}),
Expand Down Expand Up @@ -366,6 +376,7 @@ function setupDefaultMocks() {
mockLogsQuery.mockReturnValue({ data: [], isLoading: false, error: null });
mockDataHealthQuery.mockReturnValue({ data: undefined, isLoading: false, error: null });
mockActiveSyncsQuery.mockReturnValue({ data: [] });
mockActiveImportsQuery.mockReturnValue({ data: [], error: null });
}

function makeProvider(
Expand Down Expand Up @@ -718,17 +729,20 @@ describe("ProvidersScreen", () => {
mockUseLocalSearchParams.mockReturnValue({});
mockSyncMutateAsync.mockReset();
mockImportSharedFile.mockReset();
mockGetDocumentAsync.mockReset();
mockProvidersQuery.mockReset();
mockStatsQuery.mockReset();
mockLogsQuery.mockReset();
mockDataHealthQuery.mockReset();
mockActiveSyncsQuery.mockReset();
mockActiveImportsQuery.mockReset();
mockInvalidate.mockReset();
mockInvalidateProviders.mockReset();
mockInvalidateProviderStats.mockReset();
mockInvalidateLogs.mockReset();
mockInvalidateDataHealth.mockReset();
mockInvalidateActiveSyncs.mockReset();
mockInvalidateActiveImports.mockReset();
mockSyncStatusFetch.mockReset();
mockUseRefresh.mockClear();
mockCredentialSignIn.mockReset();
Expand Down Expand Up @@ -1212,6 +1226,107 @@ describe("ProvidersScreen", () => {
});
});

it("selects and imports a Garmin dump ZIP from the Garmin card", async () => {
mockProvidersQuery.mockReturnValue({
data: [
{
id: "garmin-dump",
name: "Garmin Dump",
authType: "none",
authorized: true,
importOnly: true,
lastSyncedAt: null,
},
],
isLoading: false,
error: null,
});
mockGetDocumentAsync.mockResolvedValue({
canceled: false,
assets: [
{
uri: "file:///tmp/garmin-export.zip",
name: "garmin-export.zip",
mimeType: "application/zip",
},
],
});
mockImportSharedFile.mockResolvedValue({ providerId: "garmin-dump", jobId: "job-garmin" });

await renderProvidersScreen();

const garminCard = within(screen.getByTestId("provider-card-garmin-dump"));
fireEvent.click(garminCard.getByText("Import file"));

await waitFor(() => {
expect(mockGetDocumentAsync).toHaveBeenCalledWith({
copyToCacheDirectory: true,
multiple: false,
type: ["application/zip", "application/x-zip-compressed"],
});
expect(mockImportSharedFile).toHaveBeenCalledWith(
expect.objectContaining({
fileUri: "file:///tmp/garmin-export.zip",
providerId: "garmin-dump",
serverUrl: "https://test.example.com",
sessionToken: "test-token",
}),
expect.objectContaining({ readBlob: expect.any(Function) }),
);
});
});

it("shows resumable progress for an in-flight Garmin import", async () => {
mockProvidersQuery.mockReturnValue({
data: [
{
id: "garmin-dump",
name: "Garmin Dump",
authType: "none",
authorized: true,
importOnly: true,
lastSyncedAt: null,
},
],
isLoading: false,
error: null,
});
mockActiveImportsQuery.mockReturnValue({
data: [
{
jobId: "job-garmin",
providerId: "garmin-dump",
progress: 64,
message: "Importing activities",
},
],
error: null,
});

await renderProvidersScreen();

const garminCard = within(screen.getByTestId("provider-card-garmin-dump"));
expect(garminCard.getByText("Importing activities")).toBeTruthy();
expect(garminCard.getByText("Loading...")).toBeTruthy();
expect(
screen.getByTestId("provider-card-garmin-dump-progress-fill").getAttribute("data-style"),
).toContain('"width":"64%"');
expect(garminCard.queryByText("Import only")).toBeNull();
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

it("shows the server error when active import progress cannot load", async () => {
mockActiveImportsQuery.mockReturnValue({
data: undefined,
error: new Error("Unable to check import progress because the queue service is unavailable."),
});

await renderProvidersScreen();

expect(
screen.getByText("Unable to check import progress because the queue service is unavailable."),
).toBeTruthy();
});

it("shows shared import progress while providers are still loading", async () => {
mockProvidersQuery.mockReturnValue({
data: undefined,
Expand Down Expand Up @@ -1612,6 +1727,29 @@ describe("ProvidersScreen", () => {
expect(screen.getByText("Apple Health")).toBeTruthy();
});

it("shows resumable progress for an in-flight Apple Health import", async () => {
mockActiveImportsQuery.mockReturnValue({
data: [
{
jobId: "job-apple-health",
providerId: "apple_health",
progress: 42,
message: "Importing Apple Health data",
},
],
error: null,
});

await renderProvidersScreen();

const appleCard = within(screen.getByTestId("provider-card-apple_health"));
expect(appleCard.getByText("Importing Apple Health data")).toBeTruthy();
expect(appleCard.getByText("Loading...")).toBeTruthy();
expect(
screen.getByTestId("provider-card-apple_health-progress-fill").getAttribute("data-style"),
).toContain('"width":"42%"');
});

it("triggers HealthKit sync with syncRangeDays: 7 when Sync is clicked", async () => {
await renderProvidersScreen();

Expand Down
Loading
Loading