-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: [PE-917] CGN
WebviewComponent
additional test (#6651)
## 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
1 parent
665fc75
commit bf82569
Showing
3 changed files
with
59 additions
and
8 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -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(); | ||
}); | ||
}); |
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