Skip to content

Commit

Permalink
test: [PE-917] CGN WebviewComponent additional test (#6651)
Browse files Browse the repository at this point in the history
## Short description
This pull request updates the test suite for `WebviewComponent` to cover
additional missing test cases.

## List of changes proposed in this pull request
- Added `testID` attributes to the `OperationResultScreenContent` and
`WebView` components to facilitate targeted testing
- Adding new test cases for error handling

## How to test
Make sure the new test suite runs successfully without failures and that
the test coverage has increased
  • Loading branch information
LeleDallas authored Jan 31, 2025
1 parent 665fc75 commit bf82569
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 8 deletions.
2 changes: 2 additions & 0 deletions ts/components/WebviewComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const WebviewComponent = (props: Props) => {
<>
{hasError ? (
<OperationResultScreenContent
testID="webview-error"
pictogram="umbrellaNew"
title={I18n.t("wallet.errors.GENERIC_ERROR")}
isHeaderVisible
Expand All @@ -54,6 +55,7 @@ const WebviewComponent = (props: Props) => {
) : (
<LoadingSpinnerOverlay isLoading={loading}>
<WebView
testID="webview"
androidCameraAccessDisabled={true}
androidMicrophoneAccessDisabled={true}
allowsInlineMediaPlayback={true}
Expand Down
64 changes: 56 additions & 8 deletions ts/components/__tests__/WebviewComponent.test.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,76 @@
import { render } from "@testing-library/react-native";
import { fireEvent, render } from "@testing-library/react-native";
import { Provider } from "react-redux";
import configureMockStore from "redux-mock-store";
import WebviewComponent from "../WebviewComponent";
import { appReducer } from "../../store/reducers";
import I18n from "../../i18n";
import { applicationChangeState } from "../../store/actions/application";
import { appReducer } from "../../store/reducers";
import { GlobalState } from "../../store/reducers/types";

import WebviewComponent from "../WebviewComponent";
describe("WebviewComponent tests", () => {
const globalState = appReducer(undefined, applicationChangeState("active"));
const mockStore = configureMockStore<GlobalState>();
const store: ReturnType<typeof mockStore> = mockStore(globalState);

it("snapshot for component", () => {
const globalState = appReducer(undefined, applicationChangeState("active"));
const enrichedState = {
...globalState,
persistedPreferences: {
...globalState.persistedPreferences,
isDesignSystemEnabled: false
}
};
const mockStore = configureMockStore<GlobalState>();
const store: ReturnType<typeof mockStore> = mockStore(enrichedState);
const enrichedStore: ReturnType<typeof mockStore> =
mockStore(enrichedState);
const component = render(
<Provider store={store}>
<Provider store={enrichedStore}>
<WebviewComponent source={{ uri: "https://google.com" }} />
</Provider>
);
expect(component).toMatchSnapshot();
});

it("should display error screen on error", () => {
const { getByText, getByTestId } = render(
<Provider store={store}>
<WebviewComponent source={{ uri: "https://google.com" }} />
</Provider>
);

fireEvent(getByTestId("webview"), "onError", {
nativeEvent: { description: "Network error" }
});

expect(getByText(I18n.t("wallet.errors.GENERIC_ERROR"))).toBeTruthy();
expect(getByText(I18n.t("global.buttons.retry"))).toBeTruthy();
});

it("should reload on retry", () => {
const { getByText, getByTestId } = render(
<Provider store={store}>
<WebviewComponent source={{ uri: "https://google.com" }} />
</Provider>
);

fireEvent(getByTestId("webview"), "onError", {
nativeEvent: { description: "Network error" }
});

fireEvent.press(getByText(I18n.t("global.buttons.retry")));

expect(getByTestId("webview")).toBeTruthy();
});

it("should call handleError on WebView error", () => {
const { getByTestId } = render(
<Provider store={store}>
<WebviewComponent source={{ uri: "wrong uri" }} />
</Provider>
);

fireEvent(getByTestId("webview"), "onError", {
nativeEvent: { description: "Network error" }
});

expect(getByTestId("webview-error")).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ exports[`WebviewComponent tests snapshot for component 1`] = `
},
]
}
testID="webview"
textInteractionEnabled={true}
useSharedProcessPool={true}
/>
Expand Down

0 comments on commit bf82569

Please sign in to comment.