-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Carta Giovani Nazionale): [#179282600] Integrates CGN Merchant L…
…anding page discount option (#3316) * [#179282600] Integrates CGN Merchant Landing page discount option * [#179282600] Adds missing localized string * [#179282600] Implements common webview component with error and loading handlers * [#179282600] Adds snapshot testing on new common component Co-authored-by: pietro909 <[email protected]>
- Loading branch information
1 parent
1390e0b
commit 25f7bfa
Showing
12 changed files
with
327 additions
and
14 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
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,46 @@ | ||
import * as React from "react"; | ||
import WebView from "react-native-webview"; | ||
import { useState } from "react"; | ||
import { WebViewSource } from "react-native-webview/lib/WebViewTypes"; | ||
import GenericErrorComponent from "./screens/GenericErrorComponent"; | ||
import LoadingSpinnerOverlay from "./LoadingSpinnerOverlay"; | ||
import { IOStyles } from "./core/variables/IOStyles"; | ||
|
||
type Props = { | ||
source: WebViewSource; | ||
}; | ||
|
||
const WebviewComponent = (props: Props) => { | ||
const [loading, setLoading] = useState(true); | ||
const [hasError, setHasError] = useState(false); | ||
|
||
const ref = React.createRef<WebView>(); | ||
|
||
const handleReload = () => { | ||
setHasError(false); | ||
setLoading(true); | ||
if (ref.current) { | ||
ref.current.reload(); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
{hasError ? ( | ||
<GenericErrorComponent onRetry={handleReload} /> | ||
) : ( | ||
<LoadingSpinnerOverlay isLoading={loading}> | ||
<WebView | ||
style={IOStyles.flex} | ||
ref={ref} | ||
onLoadEnd={() => setLoading(false)} | ||
onError={() => setHasError(true)} | ||
source={props.source} | ||
/> | ||
</LoadingSpinnerOverlay> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default WebviewComponent; |
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,12 @@ | ||
import { render } from "@testing-library/react-native"; | ||
import React from "react"; | ||
import WebviewComponent from "../WebviewComponent"; | ||
|
||
describe("WebviewComponent tests", () => { | ||
it("snapshot for component", () => { | ||
const component = render( | ||
<WebviewComponent source={{ uri: "https://google.com" }} /> | ||
); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); |
134 changes: 134 additions & 0 deletions
134
ts/components/__tests__/__snapshots__/WebviewComponent.test.tsx.snap
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,134 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`WebviewComponent tests snapshot for component 1`] = ` | ||
<View | ||
style={ | ||
Object { | ||
"flex": 1, | ||
} | ||
} | ||
testID="overlayComponent" | ||
> | ||
<View | ||
style={ | ||
Array [ | ||
Object { | ||
"backgroundColor": "#fff", | ||
"bottom": 0, | ||
"justifyContent": "center", | ||
"left": 0, | ||
"position": "absolute", | ||
"right": 0, | ||
"top": 0, | ||
"zIndex": 1, | ||
}, | ||
Object { | ||
"backgroundColor": "rgba(255,255,255,0.7)", | ||
"opacity": 1, | ||
}, | ||
] | ||
} | ||
> | ||
<View | ||
style={ | ||
Array [ | ||
Object { | ||
"alignItems": "center", | ||
"flex": 1, | ||
"height": 100, | ||
"justifyContent": "center", | ||
}, | ||
undefined, | ||
] | ||
} | ||
> | ||
<ActivityIndicator | ||
animating={true} | ||
color="#999999" | ||
hidesWhenStopped={true} | ||
size="large" | ||
/> | ||
<Text | ||
accessible={true} | ||
alignCenter={true} | ||
style={ | ||
Array [ | ||
Object { | ||
"color": "#000", | ||
"fontFamily": "System", | ||
"fontSize": 16, | ||
}, | ||
Object { | ||
"padding": 24, | ||
}, | ||
] | ||
} | ||
> | ||
Wait a few seconds.. | ||
</Text> | ||
</View> | ||
</View> | ||
<View | ||
style={ | ||
Array [ | ||
Object { | ||
"flex": 1, | ||
}, | ||
Object { | ||
"zIndex": 0, | ||
}, | ||
] | ||
} | ||
> | ||
<View | ||
style={ | ||
Array [ | ||
Object { | ||
"flex": 1, | ||
"overflow": "hidden", | ||
}, | ||
undefined, | ||
] | ||
} | ||
> | ||
<RNCWebView | ||
cacheEnabled={true} | ||
injectedJavaScriptBeforeContentLoadedForMainFrameOnly={true} | ||
injectedJavaScriptForMainFrameOnly={true} | ||
javaScriptEnabled={true} | ||
messagingEnabled={false} | ||
onContentProcessDidTerminate={[Function]} | ||
onError={[Function]} | ||
onHttpError={[Function]} | ||
onLoadEnd={[Function]} | ||
onLoadingError={[Function]} | ||
onLoadingFinish={[Function]} | ||
onLoadingProgress={[Function]} | ||
onLoadingStart={[Function]} | ||
onMessage={[Function]} | ||
onShouldStartLoadWithRequest={[Function]} | ||
source={ | ||
Object { | ||
"uri": "https://google.com", | ||
} | ||
} | ||
style={ | ||
Array [ | ||
Object { | ||
"flex": 1, | ||
"overflow": "hidden", | ||
}, | ||
Object { | ||
"backgroundColor": "#ffffff", | ||
}, | ||
Object { | ||
"flex": 1, | ||
}, | ||
] | ||
} | ||
useSharedProcessPool={true} | ||
/> | ||
</View> | ||
</View> | ||
</View> | ||
`; |
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
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
Oops, something went wrong.