Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [IOPID-2547] Fix unhandled error on Linking.openUrl #6554

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 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
1 change: 1 addition & 0 deletions locales/en/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ authentication:
title: We can't find the CieID app
description: To login, you must have the app installed on your device.
primary_action_label: Get the app
link_error: We could not direct you to the store. Open it manually and search for CieID
cie:
genericTitle: Login with CIE
cie: CIE
Expand Down
1 change: 1 addition & 0 deletions locales/it/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ authentication:
title: Non riusciamo a trovare l'app CieID
description: Per accedere, devi avere l'app installata sul tuo dispositivo.
primary_action_label: Scarica CieID
link_error: Non siamo riusciti a indirizzarti allo store. Aprilo manualmente e cerca CieID
cie:
genericTitle: Entra con CIE
cie: CIE
Expand Down
23 changes: 13 additions & 10 deletions ts/features/cie/__tests__/CieIdNotInstalled.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { Linking, Platform } from "react-native";
import { Platform } from "react-native";
import { fireEvent, render } from "@testing-library/react-native";
import React from "react";
import CieIdNotInstalled, {
CIE_ID_ANDROID_COLL_LINK,
CIE_ID_ANDROID_LINK,
CIE_ID_IOS_LINK
} from "../components/CieIdNotInstalled";
import * as urlUtils from "../../../utils/url";

const UAT_ENV_ENABLE_STATES = [true, false];

const mockPopToTop = jest.fn();
const mockOpenUrl = jest.spyOn(urlUtils, "openWebUrl");
const anyFunction = expect.any(Function);

jest.mock("@react-navigation/native", () => ({
...jest.requireActual("@react-navigation/native"),
Expand All @@ -28,15 +31,13 @@ describe(CieIdNotInstalled, () => {

describe("Behavior on iOS", () => {
UAT_ENV_ENABLE_STATES.forEach(uatState => {
it("Should open CIE_ID_IOS_LINK", () => {
it("Should open CIE_ID_IOS_LINK", async () => {
const { getByTestId } = render(<CieIdNotInstalled isUat={uatState} />);

const openStore = getByTestId("cie-id-not-installed-open-store");
fireEvent.press(openStore);

expect(jest.spyOn(Linking, "openURL")).toHaveBeenCalledWith(
CIE_ID_IOS_LINK
);
expect(mockOpenUrl).toHaveBeenCalledWith(CIE_ID_IOS_LINK, anyFunction);
expect(mockPopToTop).not.toHaveBeenCalled();
});
});
Expand All @@ -50,8 +51,9 @@ describe(CieIdNotInstalled, () => {
const openStore = getByTestId("cie-id-not-installed-open-store");
fireEvent.press(openStore);

expect(jest.spyOn(Linking, "openURL")).toHaveBeenCalledWith(
CIE_ID_ANDROID_LINK
expect(mockOpenUrl).toHaveBeenCalledWith(
CIE_ID_ANDROID_LINK,
anyFunction
);
expect(mockPopToTop).not.toHaveBeenCalled();
});
Expand All @@ -63,8 +65,9 @@ describe(CieIdNotInstalled, () => {
const openStore = getByTestId("cie-id-not-installed-open-store");
fireEvent.press(openStore);

expect(jest.spyOn(Linking, "openURL")).toHaveBeenCalledWith(
CIE_ID_ANDROID_COLL_LINK
expect(mockOpenUrl).toHaveBeenCalledWith(
CIE_ID_ANDROID_COLL_LINK,
anyFunction
);
expect(mockPopToTop).not.toHaveBeenCalled();
});
Expand All @@ -76,7 +79,7 @@ describe(CieIdNotInstalled, () => {
const popToTop = getByTestId("cie-id-not-installed-pop-to-top");
fireEvent.press(popToTop);

expect(jest.spyOn(Linking, "openURL")).not.toHaveBeenCalled();
expect(mockOpenUrl).not.toHaveBeenCalled();
expect(mockPopToTop).toHaveBeenCalledTimes(1);
});
});
Expand Down
14 changes: 11 additions & 3 deletions ts/features/cie/components/CieIdNotInstalled.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from "react";
import { Linking, Platform } from "react-native";
import { Platform } from "react-native";
import { useIOToast } from "@pagopa/io-app-design-system";
import { OperationResultScreenContent } from "../../../components/screens/OperationResultScreenContent";
import { useIONavigation } from "../../../navigation/params/AppParamsList";
import I18n from "../../../i18n";
import { trackCieIdNotInstalledDownloadAction } from "../analytics";
import { openWebUrl } from "../../../utils/url";

export const CIE_ID_IOS_LINK =
"https://apps.apple.com/it/app/cieid/id1504644677";
Expand All @@ -17,6 +19,7 @@ export type CieIdNotInstalledProps = {

const CieIdNotInstalled = ({ isUat }: CieIdNotInstalledProps) => {
const { popToTop } = useIONavigation();
const { error } = useIOToast();

return (
<OperationResultScreenContent
Expand All @@ -30,12 +33,17 @@ const CieIdNotInstalled = ({ isUat }: CieIdNotInstalledProps) => {
),
onPress: () => {
void trackCieIdNotInstalledDownloadAction();
void Linking.openURL(
openWebUrl(
Platform.select({
ios: CIE_ID_IOS_LINK,
android: isUat ? CIE_ID_ANDROID_COLL_LINK : CIE_ID_ANDROID_LINK,
default: ""
})
}),
() => {
error(
I18n.t("authentication.cie_id.cie_not_installed.link_error")
);
}
);
}
}}
Expand Down
Loading