mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-06-22 14:38:49 -04:00
* Convert web view components to typescript * Basic tests for URL handling in FullPageWebView * Allowlist of domains in FullPageWebView * Open links in browser in most situations * Allow FullPageWebView to handle mailto links * Throw errors if FullPageWebView is about to leak a JWT * Restore FullPageWebView functionality to signup screens Closes #1803 Closes #1934
63 lines
2.7 KiB
JavaScript
63 lines
2.7 KiB
JavaScript
import {
|
|
ALLOWED_DOMAINS,
|
|
onShouldStartLoadWithRequest
|
|
} from "components/FullPageWebView/FullPageWebView.tsx";
|
|
import { Linking } from "react-native";
|
|
|
|
describe( "FullPageWebView", ( ) => {
|
|
describe( "onShouldStartLoadWithRequest", ( ) => {
|
|
it( "should approve a request for the source url", ( ) => {
|
|
const url = "https://www.inaturalist.org";
|
|
const request = { url };
|
|
const source = { uri: url };
|
|
const routeParams = { initialUrl: url };
|
|
expect( onShouldStartLoadWithRequest( request, source, routeParams ) ).toBeTruthy();
|
|
} );
|
|
|
|
it( "should approve a request for an anchor on the source url", ( ) => {
|
|
const url = "https://www.inaturalist.org";
|
|
const request = { url: `${url}#something` };
|
|
const source = { uri: url };
|
|
const routeParams = { initialUrl: url };
|
|
expect( onShouldStartLoadWithRequest( request, source, routeParams ) ).toBeTruthy();
|
|
} );
|
|
|
|
describe( "external browser", ( ) => {
|
|
beforeEach( ( ) => {
|
|
Linking.openURL.mockImplementation( jest.fn( _url => Promise.resolve() ) );
|
|
} );
|
|
|
|
afterEach( ( ) => Linking.openURL.mockReset( ) );
|
|
|
|
it( "should try to open for any domain not on the allowlist", ( ) => {
|
|
const url = "https://www.inaturalist.org";
|
|
const request = { url: "https://www.ebird.org" };
|
|
expect( ALLOWED_DOMAINS ).not.toContain( "ebird.org" );
|
|
const source = { uri: url };
|
|
const routeParams = { initialUrl: url };
|
|
expect( onShouldStartLoadWithRequest( request, source, routeParams ) ).toBeFalsy();
|
|
expect( Linking.openURL ).toHaveBeenCalledWith( request.url );
|
|
} );
|
|
|
|
it( "should not try to open for any domain on the allowlist if requested", ( ) => {
|
|
const url = "https://www.inaturalist.org";
|
|
const request = { url: "https://www.inaturalist.org/users/edit" };
|
|
expect( ALLOWED_DOMAINS ).toContain( "inaturalist.org" );
|
|
const source = { uri: url };
|
|
const routeParams = { initialUrl: url, handleLinksForAllowedDomains: true };
|
|
expect( onShouldStartLoadWithRequest( request, source, routeParams ) ).toBeTruthy();
|
|
expect( Linking.openURL ).not.toHaveBeenCalled( );
|
|
} );
|
|
|
|
it( "should try to open for any domain on the allowlist for clicks", ( ) => {
|
|
const url = "https://www.inaturalist.org";
|
|
const request = { url: "https://www.inaturalist.org/users/edit", navigationType: "click" };
|
|
const source = { uri: url };
|
|
const routeParams = { initialUrl: url };
|
|
expect( onShouldStartLoadWithRequest( request, source, routeParams ) ).toBeFalsy();
|
|
expect( Linking.openURL ).toHaveBeenCalledWith( request.url );
|
|
} );
|
|
} );
|
|
} );
|
|
} );
|