|
| 1 | +/** |
| 2 | + * Copyright 2024 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import type { |
| 18 | + MapViewController, |
| 19 | + NavigationCallbacks, |
| 20 | + NavigationController, |
| 21 | + NavigationInitErrorCode, |
| 22 | +} from '@googlemaps/react-native-navigation-sdk'; |
| 23 | + |
| 24 | +interface TestTools { |
| 25 | + navigationController: NavigationController; |
| 26 | + mapViewController: MapViewController | null; |
| 27 | + addListeners: (listeners: Partial<NavigationCallbacks>) => void; |
| 28 | + removeListeners: (listeners: Partial<NavigationCallbacks>) => void; |
| 29 | + passTest: () => void; |
| 30 | + failTest: (message: string) => void; |
| 31 | + setDetoxStep: (stepNumber: number) => void; |
| 32 | + expectFalseError: (expectation: string) => void; |
| 33 | + expectTrueError: (expectation: string) => void; |
| 34 | +} |
| 35 | + |
| 36 | +export const testNavigationSessionInitialization = async ( |
| 37 | + testTools: TestTools |
| 38 | +) => { |
| 39 | + const { |
| 40 | + navigationController, |
| 41 | + addListeners, |
| 42 | + passTest, |
| 43 | + failTest, |
| 44 | + setDetoxStep, |
| 45 | + expectFalseError, |
| 46 | + } = testTools; |
| 47 | + |
| 48 | + const checkDefaults = async () => { |
| 49 | + if (!(await navigationController.areTermsAccepted())) { |
| 50 | + return expectFalseError('navigationController.areTermsAccepted()'); |
| 51 | + } |
| 52 | + passTest(); |
| 53 | + }; |
| 54 | + |
| 55 | + addListeners({ |
| 56 | + onNavigationReady: () => { |
| 57 | + checkDefaults(); |
| 58 | + }, |
| 59 | + onNavigationInitError: (errorCode: NavigationInitErrorCode) => { |
| 60 | + console.log(errorCode); |
| 61 | + failTest('onNavigatonInitError'); |
| 62 | + }, |
| 63 | + }); |
| 64 | + try { |
| 65 | + await navigationController.init(); |
| 66 | + } catch (error) { |
| 67 | + console.error('Error initializing navigator', error); |
| 68 | + failTest('navigationController.init() exception'); |
| 69 | + } |
| 70 | + // Tell detox to prepare to execute step 1: (confirm t&c dialog) |
| 71 | + setDetoxStep(1); |
| 72 | +}; |
| 73 | + |
| 74 | +const expectFalseMessage = (expectation: string) => { |
| 75 | + return `Expected ${expectation} to be false but it was true`; |
| 76 | +}; |
| 77 | + |
| 78 | +export const testMapInitialization = async (testTools: TestTools) => { |
| 79 | + const { mapViewController, passTest, failTest, expectFalseError } = testTools; |
| 80 | + if (!mapViewController) { |
| 81 | + return failTest('mapViewController was expected to exist'); |
| 82 | + } |
| 83 | + if ((await mapViewController.getUiSettings()).isCompassEnabled) { |
| 84 | + return expectFalseError( |
| 85 | + 'mapViewController.getUiSettings()).isCompassEnabled' |
| 86 | + ); |
| 87 | + } |
| 88 | + if ((await mapViewController.getUiSettings()).isMapToolbarEnabled) { |
| 89 | + return failTest( |
| 90 | + expectFalseMessage( |
| 91 | + 'mapViewController.getUiSettings()).isMapToolbarEnabled' |
| 92 | + ) |
| 93 | + ); |
| 94 | + } |
| 95 | + if (!(await mapViewController.getUiSettings()).isIndoorLevelPickerEnabled) { |
| 96 | + return failTest( |
| 97 | + expectFalseMessage( |
| 98 | + 'mapViewController.getUiSettings()).isIndoorLevelPickerEnabled' |
| 99 | + ) |
| 100 | + ); |
| 101 | + } |
| 102 | + if ((await mapViewController.getUiSettings()).isMapToolbarEnabled) { |
| 103 | + return expectFalseError( |
| 104 | + 'mapViewController.getUiSettings()).isMapToolbarEnabled' |
| 105 | + ); |
| 106 | + } |
| 107 | + if (!(await mapViewController.getUiSettings()).isRotateGesturesEnabled) { |
| 108 | + return expectFalseError( |
| 109 | + 'mapViewController.getUiSettings()).isRotateGesturesEnabled' |
| 110 | + ); |
| 111 | + } |
| 112 | + if (!(await mapViewController.getUiSettings()).isScrollGesturesEnabled) { |
| 113 | + return expectFalseError( |
| 114 | + 'mapViewController.getUiSettings()).isScrollGesturesEnabled' |
| 115 | + ); |
| 116 | + } |
| 117 | + if ( |
| 118 | + !(await mapViewController.getUiSettings()) |
| 119 | + .isScrollGesturesEnabledDuringRotateOrZoom |
| 120 | + ) { |
| 121 | + return expectFalseError( |
| 122 | + 'mapViewController.getUiSettings()).isScrollGesturesEnabledDuringRotateOrZoom' |
| 123 | + ); |
| 124 | + } |
| 125 | + if (!(await mapViewController.getUiSettings()).isTiltGesturesEnabled) { |
| 126 | + return expectFalseError( |
| 127 | + 'mapViewController.getUiSettings()).isTiltGesturesEnabled' |
| 128 | + ); |
| 129 | + } |
| 130 | + if ((await mapViewController.getUiSettings()).isZoomControlsEnabled) { |
| 131 | + return expectFalseError( |
| 132 | + 'mapViewController.getUiSettings()).isZoomControlsEnabled' |
| 133 | + ); |
| 134 | + } |
| 135 | + if (!(await mapViewController.getUiSettings()).isZoomGesturesEnabled) { |
| 136 | + return expectFalseError( |
| 137 | + 'mapViewController.getUiSettings()).isZoomGesturesEnabled' |
| 138 | + ); |
| 139 | + } |
| 140 | + |
| 141 | + passTest(); |
| 142 | +}; |
| 143 | + |
| 144 | +export const runTest3 = async () => {}; |
0 commit comments