Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladirico committed May 10, 2024
1 parent 72d65b0 commit 1ff0a76
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 0 deletions.
72 changes: 72 additions & 0 deletions ts/screens/authentication/cie/__test__/AuthErrorScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from "react";
import { fireEvent, render } from "@testing-library/react-native";
import AuthErrorScreen from "../components/AuthErrorScreen";
import I18n from "../../../../i18n";

describe("AuthErrorScreen", () => {
test("renders correctly with default error code", () => {
const onRetryMock = jest.fn();
const onCancelMock = jest.fn();

const { getByText } = render(
<AuthErrorScreen onRetry={onRetryMock} onCancel={onCancelMock} />
);

expect(
getByText(I18n.t("authentication.cie_errors.generic.title"))
).toBeDefined();
expect(
getByText(I18n.t("authentication.cie_errors.generic.subtitle"))
).toBeDefined();
fireEvent.press(getByText(I18n.t("global.buttons.retry")));
fireEvent.press(getByText(I18n.t("global.buttons.close")));
expect(onRetryMock).toHaveBeenCalled();
expect(onCancelMock).toHaveBeenCalled();
});

test('renders correctly with error code "22"', () => {
const onRetryMock = jest.fn();
const onCancelMock = jest.fn();

const { getByText } = render(
<AuthErrorScreen
errorCode="22"
onRetry={onRetryMock}
onCancel={onCancelMock}
/>
);

expect(
getByText(I18n.t("authentication.cie_errors.error_22.title"))
).toBeDefined();
expect(
getByText(I18n.t("authentication.cie_errors.error_22.subtitle"))
).toBeDefined();
fireEvent.press(getByText(I18n.t("global.buttons.retry")));
fireEvent.press(getByText(I18n.t("global.buttons.close")));
expect(onRetryMock).toHaveBeenCalled();
expect(onCancelMock).toHaveBeenCalled();
});

test('renders correctly with error code "1001"', () => {
const onRetryMock = jest.fn();
const onCancelMock = jest.fn();

const { getByText } = render(
<AuthErrorScreen
errorCode="1001"
onRetry={onRetryMock}
onCancel={onCancelMock}
/>
);

expect(
getByText(I18n.t("authentication.cie_errors.error_1001.title"))
).toBeDefined();
expect(
getByText(I18n.t("authentication.cie_errors.error_1001.subtitle"))
).toBeDefined();
fireEvent.press(getByText(I18n.t("global.buttons.retry")));
expect(onRetryMock).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React from "react";
import { render } from "@testing-library/react-native";
import { NavigationContainer } from "@react-navigation/native";
import CieConsentDataUsageRenderComponent from "../components/CieConsentDataUsageRenderComponent";
import ROUTES from "../../../../navigation/routes";
import I18n from "../../../../i18n";

describe("CieConsentDataUsageRenderComponent", () => {
test("renders LoaderComponent when isLoginSuccess is true", () => {
const LoaderComponent = jest.fn().mockReturnValue(null);
const props = {
isLoginSuccess: true,
LoaderComponent,
hasError: false,
cieConsentUri: "some-uri",
originSchemasWhiteList: [],
handleShouldStartLoading: jest.fn(),
handleWebViewError: jest.fn(),
handleHttpError: jest.fn(),
onRetry: jest.fn(),
onCancel: jest.fn()
};

render(<CieConsentDataUsageRenderComponent {...props} />);

expect(LoaderComponent).toHaveBeenCalled();
});

test('renders AuthErrorScreen when hasError is true and errorCode is not "1002"', () => {
const props = {
isLoginSuccess: false,
LoaderComponent: jest.fn().mockReturnValue(null),
hasError: true,
errorCode: "200",
cieConsentUri: "some-uri",
originSchemasWhiteList: [],
handleShouldStartLoading: jest.fn(),
handleWebViewError: jest.fn(),
handleHttpError: jest.fn(),
onRetry: jest.fn(),
onCancel: jest.fn()
};

const { getByText } = render(
<NavigationContainer
initialState={{
routes: [{ name: ROUTES.CIE_CONSENT_DATA_USAGE }],
index: 0
}}
>
<CieConsentDataUsageRenderComponent {...props} />
</NavigationContainer>
);
expect(
getByText(I18n.t("authentication.cie_errors.generic.title"))
).toBeTruthy();
});

test("renders WebView when hasError is false", () => {
const props = {
isLoginSuccess: false,
LoaderComponent: jest.fn().mockReturnValue(null),
hasError: false,
cieConsentUri: "some-uri",
originSchemasWhiteList: [],
handleShouldStartLoading: jest.fn(),
handleWebViewError: jest.fn(),
handleHttpError: jest.fn(),
onRetry: jest.fn(),
onCancel: jest.fn()
};

const { getByTestId } = render(
<CieConsentDataUsageRenderComponent {...props} />
);

expect(getByTestId("webview-cie-test")).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const CieConsentDataUsageRenderComponent = ({
} else {
return (
<WebView
testID="webview-cie-test"
androidCameraAccessDisabled={true}
androidMicrophoneAccessDisabled={true}
textZoom={100}
Expand Down

0 comments on commit 1ff0a76

Please sign in to comment.