-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
ts/screens/authentication/cie/__test__/AuthErrorScreen.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
79 changes: 79 additions & 0 deletions
79
ts/screens/authentication/cie/__test__/CieConsentDataUsageRenderComponent.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters