1 parent
97d0785c71
commit
a2d1993bee
3 files changed
+28
-16
No files matched your search
@@ -14,13 +14,15 @@ test("opens the app listing directly in Google Play without invoking a generic U
|
||||
const openedUrls: string[] = [];
|
||||
|
||||
const result = await openMobileInstallUpdateSource(googlePlay, {
|
||||
linking: {
|
||||
openURL: async (url) => {
|
||||
openedUrls.push(url);
|
||||
},
|
||||
},
|
||||
openGooglePlayDetails: (applicationId) => {
|
||||
openedApplicationIds.push(applicationId);
|
||||
return "opened";
|
||||
},
|
||||
openUrl: async (url) => {
|
||||
openedUrls.push(url);
|
||||
},
|
||||
});
|
||||
|
||||
expect(openedApplicationIds).toEqual(["org.edgeever.mobile"]);
|
||||
@@ -32,10 +34,12 @@ test("reports that Google Play is not installed without opening a browser automa
|
||||
const openedUrls: string[] = [];
|
||||
|
||||
const result = await openMobileInstallUpdateSource(googlePlay, {
|
||||
openGooglePlayDetails: () => "not-installed",
|
||||
openUrl: async (url) => {
|
||||
openedUrls.push(url);
|
||||
linking: {
|
||||
openURL: async (url) => {
|
||||
openedUrls.push(url);
|
||||
},
|
||||
},
|
||||
openGooglePlayDetails: () => "not-installed",
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
@@ -47,8 +51,8 @@ test("reports that Google Play is not installed without opening a browser automa
|
||||
|
||||
test("preserves the disabled Google Play reason", async () => {
|
||||
const result = await openMobileInstallUpdateSource(googlePlay, {
|
||||
linking: { openURL: async () => undefined },
|
||||
openGooglePlayDetails: () => "disabled",
|
||||
openUrl: async () => undefined,
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
@@ -62,12 +66,14 @@ test("reports Google Play as unavailable when the native launch fails unexpected
|
||||
const openedUrls: string[] = [];
|
||||
|
||||
const result = await openMobileInstallUpdateSource(googlePlay, {
|
||||
linking: {
|
||||
openURL: async (url) => {
|
||||
openedUrls.push(url);
|
||||
},
|
||||
},
|
||||
openGooglePlayDetails: () => {
|
||||
throw new Error("native module unavailable");
|
||||
},
|
||||
openUrl: async (url) => {
|
||||
openedUrls.push(url);
|
||||
},
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
@@ -80,14 +86,18 @@ test("reports Google Play as unavailable when the native launch fails unexpected
|
||||
|
||||
test("opens GitHub through the regular URL handler", async () => {
|
||||
const openedUrls: string[] = [];
|
||||
const linking = {
|
||||
async openURL(url: string) {
|
||||
expect(this).toBe(linking);
|
||||
openedUrls.push(url);
|
||||
},
|
||||
};
|
||||
|
||||
const result = await openMobileInstallUpdateSource(github, {
|
||||
linking,
|
||||
openGooglePlayDetails: () => {
|
||||
throw new Error("Google Play should not be called");
|
||||
},
|
||||
openUrl: async (url) => {
|
||||
openedUrls.push(url);
|
||||
},
|
||||
});
|
||||
|
||||
expect(openedUrls).toEqual([github.url]);
|
||||
|
||||
@@ -2,8 +2,10 @@ import type { MobileInstallUpdateSource } from "./mobile-release";
|
||||
import type { GooglePlayOpenResult } from "../../modules/edgeever-app-store";
|
||||
|
||||
type MobileUpdateDestinationDependencies = {
|
||||
linking: {
|
||||
openURL: (url: string) => Promise<unknown>;
|
||||
};
|
||||
openGooglePlayDetails: (applicationId: string) => GooglePlayOpenResult | Promise<GooglePlayOpenResult>;
|
||||
openUrl: (url: string) => Promise<unknown>;
|
||||
};
|
||||
|
||||
type GooglePlayOpenFailure = Exclude<GooglePlayOpenResult, "opened">;
|
||||
@@ -47,6 +49,6 @@ export const openMobileInstallUpdateSource = async (
|
||||
};
|
||||
}
|
||||
|
||||
await dependencies.openUrl(source.url);
|
||||
await dependencies.linking.openURL(source.url);
|
||||
return { status: "opened" };
|
||||
};
|
||||
@@ -59,8 +59,8 @@ export const MobileUpdateProvider = ({ children }: { children: ReactNode }) => {
|
||||
|
||||
const openManualUpdateSource = useCallback((source: MobileInstallUpdateSource) => {
|
||||
void openMobileInstallUpdateSource(source, {
|
||||
linking: Linking,
|
||||
openGooglePlayDetails,
|
||||
openUrl: Linking.openURL,
|
||||
}).then((result) => {
|
||||
if (result.status !== "google-play-unavailable") {
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user