From 91d1e0c5c0a586afb0ce7903235f4088fdf5a323 Mon Sep 17 00:00:00 2001 From: TyFonDev Date: Thu, 11 Jan 2024 09:13:20 -0300 Subject: [PATCH] feat: some refactor + clean code + tests --- .eslintrc.js | 1 + README.md | 72 +- .../@react-native-firebase/remote-config.js | 22 +- jest.config.ts | 2 + package.json | 5 +- src/domain/const/index.ts | 5 + src/domain/repositories/LineDetail.ts | 2 +- src/domain/services/BusStopInfoService.ts | 6 +- src/infraestructure/api/clients/AuthAPI.ts | 12 +- src/infraestructure/api/clients/DevicesAPI.ts | 7 +- .../api/clients/response-devices-mock.json | 292 +- src/infraestructure/consts/urls.ts | 3 +- .../hooks/__mocks__/mockResponse.json | 508 ++++ .../hooks/__tests__/useDevices.spec.ts | 64 +- .../hooks/__tests__/useRemoteconfig.spec.ts | 67 + src/infraestructure/hooks/useDevices.ts | 36 +- src/infraestructure/hooks/useRemoteConfig.ts | 8 +- src/presentation/components/BusList.tsx | 25 +- src/presentation/components/Table.tsx | 12 +- .../__snapshots__/BusList.spec.tsx.snap | 19 +- .../screens/BusStopInfoScreen.tsx | 23 +- .../screens/__tests__/App.spec.tsx | 7 + .../__tests__/BusStopInfoScreen.spec.tsx | 615 ++++ .../BusStopInfoScreen.spec.tsx.snap | 2581 +++++++++++++++++ yarn.lock | 11 +- 25 files changed, 4157 insertions(+), 248 deletions(-) create mode 100644 src/domain/const/index.ts create mode 100644 src/infraestructure/hooks/__mocks__/mockResponse.json create mode 100644 src/infraestructure/hooks/__tests__/useRemoteconfig.spec.ts create mode 100644 src/presentation/screens/__tests__/App.spec.tsx create mode 100644 src/presentation/screens/__tests__/BusStopInfoScreen.spec.tsx create mode 100644 src/presentation/screens/__tests__/__snapshots__/BusStopInfoScreen.spec.tsx.snap diff --git a/.eslintrc.js b/.eslintrc.js index c5b30ca..364d45c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,4 +9,5 @@ module.exports = { 'react/jsx-uses-react': 'off', 'react/react-in-jsx-scope': 'off', }, + ignorePatterns: ['coverage'], }; diff --git a/README.md b/README.md index 12470c3..5ef2bfd 100644 --- a/README.md +++ b/README.md @@ -1,69 +1,31 @@ -This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli). - # Getting Started ->**Note**: Make sure you have completed the [React Native - Environment Setup](https://reactnative.dev/docs/environment-setup) instructions till "Creating a new application" step, before proceeding. +> **Note**: Make sure you have completed the [React Native - Environment Setup](https://reactnative.dev/docs/environment-setup) instructions till "Creating a new application" step, before proceeding. -## Step 1: Start the Metro Server - -First, you will need to start **Metro**, the JavaScript _bundler_ that ships _with_ React Native. - -To start Metro, run the following command from the _root_ of your React Native project: +## Step 1: Install dependencies ```bash -# using npm -npm start - -# OR using Yarn -yarn start +yarn install ``` ## Step 2: Start your Application -Let Metro Bundler run in its _own_ terminal. Open a _new_ terminal from the _root_ of your React Native project. Run the following command to start your _Android_ or _iOS_ app: - ### For Android ```bash -# using npm -npm run android - -# OR using Yarn yarn android ``` ### For iOS ```bash -# using npm -npm run ios - -# OR using Yarn yarn ios ``` -If everything is set up _correctly_, you should see your new app running in your _Android Emulator_ or _iOS Simulator_ shortly provided you have set up your emulator/simulator correctly. +If everything is set up _correctly_, you should see your new app running in your Android Emulator or iOS Simulator shortly provided you have set up your emulator/simulator correctly. This is one way to run your app — you can also run it directly from within Android Studio and Xcode respectively. -## Step 3: Modifying your App - -Now that you have successfully run the app, let's modify it. - -1. Open `App.tsx` in your text editor of choice and edit some lines. -2. For **Android**: Press the R key twice or select **"Reload"** from the **Developer Menu** (Ctrl + M (on Window and Linux) or Cmd ⌘ + M (on macOS)) to see your changes! - - For **iOS**: Hit Cmd ⌘ + R in your iOS Simulator to reload the app and see your changes! - -## Congratulations! :tada: - -You've successfully run and modified your React Native App. :partying_face: - -### Now what? - -- If you want to add this new React Native code to an existing application, check out the [Integration guide](https://reactnative.dev/docs/integration-with-existing-apps). -- If you're curious to learn more about React Native, check out the [Introduction to React Native](https://reactnative.dev/docs/getting-started). - # Troubleshooting If you can't get this to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page. @@ -77,3 +39,29 @@ To learn more about React Native, take a look at the following resources: - [Learn the Basics](https://reactnative.dev/docs/getting-started) - a **guided tour** of the React Native **basics**. - [Blog](https://reactnative.dev/blog) - read the latest official React Native **Blog** posts. - [`@facebook/react-native`](https://github.com/facebook/react-native) - the Open Source; GitHub **repository** for React Native. + +## Utility scripts + +### Start metro server + +```bash +yarn start +``` + +### Linting code + +```bash +yarn lint +``` + +### Run tests + +```bash +yarn test +``` + +### Create a release apk + +```bash +yarn build:apk:release +``` diff --git a/__mocks__/@react-native-firebase/remote-config.js b/__mocks__/@react-native-firebase/remote-config.js index 3a3d777..caedb00 100644 --- a/__mocks__/@react-native-firebase/remote-config.js +++ b/__mocks__/@react-native-firebase/remote-config.js @@ -1,11 +1,19 @@ +export const fetchAndActivate = jest.fn(); +export const setConfigSettings = jest.fn(); +export const setDefaults = jest.fn(); +export const getValue = jest.fn(); +export const getAll = jest.fn(); +export const getString = jest.fn(); +export const getNumber = jest.fn(); + const remoteConfig = () => ({ - fetchAndActivate: jest.fn(() => Promise.resolve(true)), - setConfigSettings: jest.fn(), - setDefaults: jest.fn(), - getValue: jest.fn(), - getAll: jest.fn(), - getString: jest.fn(), - getNumber: jest.fn(), + fetchAndActivate, + setConfigSettings, + setDefaults, + getValue, + getAll, + getString, + getNumber, }); export default remoteConfig; diff --git a/jest.config.ts b/jest.config.ts index a892760..db68114 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -6,5 +6,7 @@ const esModules = [ export default { preset: 'react-native', + collectCoverage: true, + collectCoverageFrom: ['src/**/*.{ts,tsx}'], transformIgnorePatterns: [`node_modules/(?!${esModules})`], }; diff --git a/package.json b/package.json index c186c93..0068c18 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,12 @@ "private": true, "scripts": { "prepare": "husky install", + "start": "react-native start", "android": "react-native run-android", "ios": "react-native run-ios", "lint": "eslint .", - "start": "react-native start", - "test": "jest" + "test": "jest", + "build:apk:release": "cd android;./gradlew assembleRelease;open app/build/outputs/apk/release;cd .." }, "dependencies": { "@react-native-firebase/app": "^18.7.3", diff --git a/src/domain/const/index.ts b/src/domain/const/index.ts new file mode 100644 index 0000000..7c02825 --- /dev/null +++ b/src/domain/const/index.ts @@ -0,0 +1,5 @@ +const COLUMNS = 3; +const ROWS = 7; +const BUSES_BY_PAGE = COLUMNS * ROWS; + +export {COLUMNS, ROWS, BUSES_BY_PAGE}; diff --git a/src/domain/repositories/LineDetail.ts b/src/domain/repositories/LineDetail.ts index ef5110d..e7376ce 100644 --- a/src/domain/repositories/LineDetail.ts +++ b/src/domain/repositories/LineDetail.ts @@ -3,7 +3,7 @@ import Arrival from './Arrival'; interface LineDetail { lineNumber: string; description: string; - locomotionType: number; + locomotionType: string; backgroundColor: string; letterColor: string; lineMessage: string; diff --git a/src/domain/services/BusStopInfoService.ts b/src/domain/services/BusStopInfoService.ts index 69beef0..17f0f6e 100644 --- a/src/domain/services/BusStopInfoService.ts +++ b/src/domain/services/BusStopInfoService.ts @@ -3,7 +3,6 @@ import LineDetail from '../repositories/LineDetail'; import {getHours, getMinutes, getSeconds} from '../../utils/DateUtils'; import Arrival from '../repositories/Arrival'; -// TODO: Change to a better name or split ? class BusStopInfoService { private lines: LineDetail[]; @@ -31,11 +30,12 @@ class BusStopInfoService { } getNextArraival(lineNumber: string): Arrival { - const currentTime = moment(); + const currentTime = moment().local(); const nextArraival = this.getLinesByNumber(lineNumber).arrivals.find( arrival => { - const compareTime = moment(); + const compareTime = moment().local(); + compareTime.set('hour', getHours(arrival.estimatedGPS)); compareTime.set('minute', getMinutes(arrival.estimatedGPS)); compareTime.set('second', getSeconds(arrival.estimatedGPS)); diff --git a/src/infraestructure/api/clients/AuthAPI.ts b/src/infraestructure/api/clients/AuthAPI.ts index be414aa..3c7310b 100644 --- a/src/infraestructure/api/clients/AuthAPI.ts +++ b/src/infraestructure/api/clients/AuthAPI.ts @@ -1,6 +1,7 @@ import axios from 'axios'; import AuthResponse from '../models/AuthResponse'; import AuthRequest from '../models/AuthRequest'; +import {LOGIN_METHOD} from '../../consts/urls'; class AuthAPI { private baseURL: string; @@ -18,10 +19,13 @@ class AuthAPI { throw new Error('password is required'); } - const {data} = await axios.post(`${this.baseURL}/api/auth/`, { - username, - password, - }); + const {data} = await axios.post( + `${this.baseURL}${LOGIN_METHOD}`, + { + username, + password, + }, + ); return data; } diff --git a/src/infraestructure/api/clients/DevicesAPI.ts b/src/infraestructure/api/clients/DevicesAPI.ts index da8865f..d8bb99c 100644 --- a/src/infraestructure/api/clients/DevicesAPI.ts +++ b/src/infraestructure/api/clients/DevicesAPI.ts @@ -2,7 +2,8 @@ import axios from 'axios'; import DeviceRequest from '../models/DeviceRequest'; import {GetInfoDeviceResponse} from '../models/GetInfoDeviceResponse'; import WhoamiResponse from '../models/WhoamiResponse'; -import responseDevicesMock from './response-devices-mock.json'; +import {INFO_DEVICE_METHOD, WHOAMI_METHOD} from '../../consts/urls'; +// import responseDevicesMock from './response-devices-mock.json'; const KEYAUTORIZACION = 'token'; @@ -22,7 +23,7 @@ class DevicesAPI { throw new Error('deviceId is required'); } const {data} = await axios.post( - `${this.baseURL}/api/dispositivos/whoami/`, + `${this.baseURL}${WHOAMI_METHOD}`, { whoami: {idDispositivo: deviceId, KeyAuthorizacion: KEYAUTORIZACION}, }, @@ -49,7 +50,7 @@ class DevicesAPI { } const {data} = await axios.post( - `${this.baseURL}/api/dispositivos/getInfoDevice/`, + `${this.baseURL}${INFO_DEVICE_METHOD}`, { GetInfoDevice: { idDispositivo: deviceId, diff --git a/src/infraestructure/api/clients/response-devices-mock.json b/src/infraestructure/api/clients/response-devices-mock.json index ef4cb7c..81a34f8 100644 --- a/src/infraestructure/api/clients/response-devices-mock.json +++ b/src/infraestructure/api/clients/response-devices-mock.json @@ -11,14 +11,14 @@ { "patente": "RW8962", "Planificada": null, - "EstimadaGPS": "21:16:25", + "EstimadaGPS": "01:16:25", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "DKSZ83", "Planificada": null, - "EstimadaGPS": "21:28:58", + "EstimadaGPS": "01:28:58", "DistanciaGPS": null, "Mensajelinea": null } @@ -34,28 +34,28 @@ { "patente": "GCJW93", "Planificada": null, - "EstimadaGPS": "20:56:01", + "EstimadaGPS": "00:56:01", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "KLJL34", "Planificada": null, - "EstimadaGPS": "21:10:21", + "EstimadaGPS": "01:10:21", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "CWCK88", "Planificada": null, - "EstimadaGPS": "21:30:40", + "EstimadaGPS": "01:30:40", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "XF4036", "Planificada": null, - "EstimadaGPS": "21:36:28", + "EstimadaGPS": "01:36:28", "DistanciaGPS": null, "Mensajelinea": null } @@ -71,7 +71,7 @@ { "patente": "DRFP53", "Planificada": null, - "EstimadaGPS": "21:20:34", + "EstimadaGPS": "01:20:34", "DistanciaGPS": null, "Mensajelinea": null } @@ -87,49 +87,49 @@ { "patente": "CPFC27", "Planificada": null, - "EstimadaGPS": "20:36:30", + "EstimadaGPS": "00:36:30", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "HFXZ79", "Planificada": null, - "EstimadaGPS": "20:37:46", + "EstimadaGPS": "00:37:46", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FWJX76", "Planificada": null, - "EstimadaGPS": "20:43:33", + "EstimadaGPS": "00:43:33", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "DPZZ52", "Planificada": null, - "EstimadaGPS": "21:13:25", + "EstimadaGPS": "01:13:25", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "DYFY38", "Planificada": null, - "EstimadaGPS": "21:30:33", + "EstimadaGPS": "01:30:33", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "HYYX77", "Planificada": null, - "EstimadaGPS": "21:37:31", + "EstimadaGPS": "01:37:31", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "RW9475", "Planificada": null, - "EstimadaGPS": "21:39:04", + "EstimadaGPS": "01:39:04", "DistanciaGPS": null, "Mensajelinea": null } @@ -145,21 +145,21 @@ { "patente": "JCHL93", "Planificada": null, - "EstimadaGPS": "20:45:13", + "EstimadaGPS": "00:45:13", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "XU2768", "Planificada": null, - "EstimadaGPS": "21:17:44", + "EstimadaGPS": "01:17:44", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "CSYZ74", "Planificada": null, - "EstimadaGPS": "21:33:02", + "EstimadaGPS": "01:33:02", "DistanciaGPS": null, "Mensajelinea": null } @@ -175,14 +175,14 @@ { "patente": "BTST46", "Planificada": null, - "EstimadaGPS": "20:38:33", + "EstimadaGPS": "00:38:33", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "RLKB76", "Planificada": null, - "EstimadaGPS": "21:27:15", + "EstimadaGPS": "01:27:15", "DistanciaGPS": null, "Mensajelinea": null } @@ -198,21 +198,21 @@ { "patente": "LJKK86", "Planificada": null, - "EstimadaGPS": "21:06:21", + "EstimadaGPS": "01:06:21", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "XW8423", "Planificada": null, - "EstimadaGPS": "21:11:44", + "EstimadaGPS": "01:11:44", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "HZRP10", "Planificada": null, - "EstimadaGPS": "21:22:11", + "EstimadaGPS": "01:22:11", "DistanciaGPS": null, "Mensajelinea": null } @@ -228,28 +228,28 @@ { "patente": "CSYR79", "Planificada": null, - "EstimadaGPS": "20:55:10", + "EstimadaGPS": "00:55:10", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "BZLY10", "Planificada": null, - "EstimadaGPS": "21:10:58", + "EstimadaGPS": "01:10:58", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "RYHY66", "Planificada": null, - "EstimadaGPS": "21:18:11", + "EstimadaGPS": "01:18:11", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "XZ9717", "Planificada": null, - "EstimadaGPS": "21:30:42", + "EstimadaGPS": "01:30:42", "DistanciaGPS": null, "Mensajelinea": null } @@ -265,70 +265,70 @@ { "patente": "FSYW10", "Planificada": null, - "EstimadaGPS": "20:38:24", + "EstimadaGPS": "00:38:24", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FYDV68", "Planificada": null, - "EstimadaGPS": "20:38:34", + "EstimadaGPS": "00:38:34", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "HHBP53", "Planificada": null, - "EstimadaGPS": "20:39:30", + "EstimadaGPS": "00:39:30", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "LHWX56", "Planificada": null, - "EstimadaGPS": "20:40:11", + "EstimadaGPS": "00:40:11", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FDCB32", "Planificada": null, - "EstimadaGPS": "20:47:29", + "EstimadaGPS": "00:47:29", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "WV6705", "Planificada": null, - "EstimadaGPS": "20:56:02", + "EstimadaGPS": "00:56:02", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "CVTG93", "Planificada": null, - "EstimadaGPS": "21:02:20", + "EstimadaGPS": "01:02:20", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "DPZZ21", "Planificada": null, - "EstimadaGPS": "21:18:02", + "EstimadaGPS": "01:18:02", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "HYCZ31", "Planificada": null, - "EstimadaGPS": "21:19:13", + "EstimadaGPS": "01:19:13", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FZWC15", "Planificada": null, - "EstimadaGPS": "21:21:56", + "EstimadaGPS": "01:21:56", "DistanciaGPS": null, "Mensajelinea": null } @@ -344,28 +344,28 @@ { "patente": "FCBR88", "Planificada": null, - "EstimadaGPS": "20:38:25", + "EstimadaGPS": "00:38:25", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "DRTH95", "Planificada": null, - "EstimadaGPS": "20:55:26", + "EstimadaGPS": "00:55:26", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "DCRD27", "Planificada": null, - "EstimadaGPS": "21:09:13", + "EstimadaGPS": "01:09:13", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "CPHW48", "Planificada": null, - "EstimadaGPS": "21:25:39", + "EstimadaGPS": "01:25:39", "DistanciaGPS": null, "Mensajelinea": null } @@ -381,28 +381,28 @@ { "patente": "FDBY83", "Planificada": null, - "EstimadaGPS": "20:36:31", + "EstimadaGPS": "00:36:31", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "HFLS53", "Planificada": null, - "EstimadaGPS": "20:37:14", + "EstimadaGPS": "00:37:14", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FFVP21", "Planificada": null, - "EstimadaGPS": "20:39:44", + "EstimadaGPS": "00:39:44", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FKLS63", "Planificada": null, - "EstimadaGPS": "20:40:00", + "EstimadaGPS": "00:40:00", "DistanciaGPS": null, "Mensajelinea": null } @@ -418,35 +418,35 @@ { "patente": "BPDS42", "Planificada": null, - "EstimadaGPS": "20:38:51", + "EstimadaGPS": "00:38:51", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "BJFK98", "Planificada": null, - "EstimadaGPS": "21:02:49", + "EstimadaGPS": "01:02:49", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "GWZC19", "Planificada": null, - "EstimadaGPS": "21:10:52", + "EstimadaGPS": "01:10:52", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "BHZY40", "Planificada": null, - "EstimadaGPS": "21:18:39", + "EstimadaGPS": "01:18:39", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "CZBW17", "Planificada": null, - "EstimadaGPS": "21:32:02", + "EstimadaGPS": "01:32:02", "DistanciaGPS": null, "Mensajelinea": null } @@ -462,14 +462,14 @@ { "patente": "WK4163", "Planificada": null, - "EstimadaGPS": "20:48:11", + "EstimadaGPS": "00:48:11", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "ZV6766", "Planificada": null, - "EstimadaGPS": "21:17:45", + "EstimadaGPS": "01:17:45", "DistanciaGPS": null, "Mensajelinea": null } @@ -485,14 +485,14 @@ { "patente": "DRTS98", "Planificada": null, - "EstimadaGPS": "20:43:30", + "EstimadaGPS": "00:43:30", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "YG6214", "Planificada": null, - "EstimadaGPS": "21:13:28", + "EstimadaGPS": "01:13:28", "DistanciaGPS": null, "Mensajelinea": null } @@ -508,42 +508,42 @@ { "patente": "HYCZ71", "Planificada": null, - "EstimadaGPS": "20:36:23", + "EstimadaGPS": "00:36:23", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "JXFY79", "Planificada": null, - "EstimadaGPS": "20:47:02", + "EstimadaGPS": "00:47:02", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "JHHJ90", "Planificada": null, - "EstimadaGPS": "20:51:20", + "EstimadaGPS": "00:51:20", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "GWZC84", "Planificada": null, - "EstimadaGPS": "21:18:00", + "EstimadaGPS": "01:18:00", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FVDC88", "Planificada": null, - "EstimadaGPS": "21:18:39", + "EstimadaGPS": "01:18:39", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "LGVH69", "Planificada": null, - "EstimadaGPS": "21:19:37", + "EstimadaGPS": "01:19:37", "DistanciaGPS": null, "Mensajelinea": null } @@ -559,42 +559,42 @@ { "patente": "DYSZ71", "Planificada": null, - "EstimadaGPS": "20:35:52", + "EstimadaGPS": "00:35:52", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FCHP83", "Planificada": null, - "EstimadaGPS": "20:50:21", + "EstimadaGPS": "00:50:21", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "BBGF22", "Planificada": null, - "EstimadaGPS": "20:52:25", + "EstimadaGPS": "00:52:25", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FFVP27", "Planificada": null, - "EstimadaGPS": "20:52:31", + "EstimadaGPS": "00:52:31", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "BBGL85", "Planificada": null, - "EstimadaGPS": "20:56:31", + "EstimadaGPS": "00:56:31", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "HYZD26", "Planificada": null, - "EstimadaGPS": "21:02:00", + "EstimadaGPS": "01:02:00", "DistanciaGPS": null, "Mensajelinea": null } @@ -610,7 +610,7 @@ { "patente": "LZZG48", "Planificada": null, - "EstimadaGPS": "20:51:14", + "EstimadaGPS": "00:51:14", "DistanciaGPS": null, "Mensajelinea": null } @@ -618,7 +618,7 @@ }, { "Linea": "Nueva Llacolén 20A - Boca Sur", - "Descripcion": "20A", + "Descripcion": "23A", "TipoLocomocion": null, "colorFondo": "0071ca", "colorLetra": "ffffff", @@ -626,21 +626,21 @@ { "patente": "HYYX24", "Planificada": null, - "EstimadaGPS": "20:40:00", + "EstimadaGPS": "00:40:00", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "ZY4652", "Planificada": null, - "EstimadaGPS": "21:00:25", + "EstimadaGPS": "01:00:25", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FPKV41", "Planificada": null, - "EstimadaGPS": "21:20:51", + "EstimadaGPS": "01:20:51", "DistanciaGPS": null, "Mensajelinea": null } @@ -648,7 +648,7 @@ }, { "Linea": "Nueva Llacolén 20M - San Pedro Costa", - "Descripcion": "20M", + "Descripcion": "23M", "TipoLocomocion": null, "colorFondo": "b10086", "colorLetra": "ffffff", @@ -656,21 +656,21 @@ { "patente": "FXRL56", "Planificada": null, - "EstimadaGPS": "20:45:32", + "EstimadaGPS": "00:45:32", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "RXFF50", "Planificada": null, - "EstimadaGPS": "21:08:55", + "EstimadaGPS": "01:08:55", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "ZY3567", "Planificada": null, - "EstimadaGPS": "21:14:25", + "EstimadaGPS": "01:14:25", "DistanciaGPS": null, "Mensajelinea": null } @@ -678,7 +678,7 @@ }, { "Linea": "Riviera Biobío 21B - Candelaria", - "Descripcion": "21B", + "Descripcion": "00B", "TipoLocomocion": null, "colorFondo": "ce5504", "colorLetra": "ffffff", @@ -686,21 +686,21 @@ { "patente": "KHSX95", "Planificada": null, - "EstimadaGPS": "20:35:51", + "EstimadaGPS": "00:35:51", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "HYVR34", "Planificada": null, - "EstimadaGPS": "20:40:49", + "EstimadaGPS": "00:40:49", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "YT2138", "Planificada": null, - "EstimadaGPS": "20:43:01", + "EstimadaGPS": "00:43:01", "DistanciaGPS": null, "Mensajelinea": null } @@ -716,14 +716,14 @@ { "patente": "FYDV31", "Planificada": null, - "EstimadaGPS": "20:49:24", + "EstimadaGPS": "00:49:24", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "YR2002", "Planificada": null, - "EstimadaGPS": "20:56:26", + "EstimadaGPS": "00:56:26", "DistanciaGPS": null, "Mensajelinea": null } @@ -739,28 +739,28 @@ { "patente": "ZT1825", "Planificada": null, - "EstimadaGPS": "20:38:58", + "EstimadaGPS": "00:38:58", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "DCGT36", "Planificada": null, - "EstimadaGPS": "20:52:56", + "EstimadaGPS": "00:52:56", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "DJBB52", "Planificada": null, - "EstimadaGPS": "21:17:48", + "EstimadaGPS": "01:17:48", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "CJVG74", "Planificada": null, - "EstimadaGPS": "21:27:27", + "EstimadaGPS": "01:27:27", "DistanciaGPS": null, "Mensajelinea": null } @@ -776,28 +776,28 @@ { "patente": "DPZY91", "Planificada": null, - "EstimadaGPS": "20:38:37", + "EstimadaGPS": "00:38:37", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "HXKL13", "Planificada": null, - "EstimadaGPS": "20:45:06", + "EstimadaGPS": "00:45:06", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "JWXV66", "Planificada": null, - "EstimadaGPS": "21:03:46", + "EstimadaGPS": "01:03:46", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "JRZZ67", "Planificada": null, - "EstimadaGPS": "21:23:56", + "EstimadaGPS": "01:23:56", "DistanciaGPS": null, "Mensajelinea": null } @@ -813,21 +813,21 @@ { "patente": "CFTD78", "Planificada": null, - "EstimadaGPS": "20:39:41", + "EstimadaGPS": "00:39:41", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "CLFX61", "Planificada": null, - "EstimadaGPS": "20:44:07", + "EstimadaGPS": "00:44:07", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "DDVZ66", "Planificada": null, - "EstimadaGPS": "21:20:41", + "EstimadaGPS": "01:20:41", "DistanciaGPS": null, "Mensajelinea": null } @@ -843,21 +843,21 @@ { "patente": "CTDG26", "Planificada": null, - "EstimadaGPS": "20:41:14", + "EstimadaGPS": "00:41:14", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FFTL50", "Planificada": null, - "EstimadaGPS": "21:17:51", + "EstimadaGPS": "01:17:51", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "CFWC16", "Planificada": null, - "EstimadaGPS": "21:36:01", + "EstimadaGPS": "01:36:01", "DistanciaGPS": null, "Mensajelinea": null } @@ -873,21 +873,21 @@ { "patente": "HFBC38", "Planificada": null, - "EstimadaGPS": "20:36:34", + "EstimadaGPS": "00:36:34", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FYBB73", "Planificada": null, - "EstimadaGPS": "20:58:20", + "EstimadaGPS": "00:58:20", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "BZPT67", "Planificada": null, - "EstimadaGPS": "21:29:34", + "EstimadaGPS": "01:29:34", "DistanciaGPS": null, "Mensajelinea": null } @@ -903,28 +903,28 @@ { "patente": "DWHG74", "Planificada": null, - "EstimadaGPS": "20:36:34", + "EstimadaGPS": "00:36:34", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "BLDT29", "Planificada": null, - "EstimadaGPS": "20:42:28", + "EstimadaGPS": "00:42:28", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "JVTK78", "Planificada": null, - "EstimadaGPS": "21:06:34", + "EstimadaGPS": "01:06:34", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FXRL49", "Planificada": null, - "EstimadaGPS": "21:19:39", + "EstimadaGPS": "01:19:39", "DistanciaGPS": null, "Mensajelinea": null } @@ -940,28 +940,28 @@ { "patente": "RLLV59", "Planificada": null, - "EstimadaGPS": "20:38:15", + "EstimadaGPS": "00:38:15", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "BBVC71", "Planificada": null, - "EstimadaGPS": "20:51:04", + "EstimadaGPS": "00:51:04", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "WK7487", "Planificada": null, - "EstimadaGPS": "21:09:43", + "EstimadaGPS": "01:09:43", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FWTT75", "Planificada": null, - "EstimadaGPS": "21:27:19", + "EstimadaGPS": "01:27:19", "DistanciaGPS": null, "Mensajelinea": null } @@ -977,21 +977,21 @@ { "patente": "HZRP11", "Planificada": null, - "EstimadaGPS": "20:38:06", + "EstimadaGPS": "00:38:06", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "WW4900", "Planificada": null, - "EstimadaGPS": "20:38:53", + "EstimadaGPS": "00:38:53", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "KCFB59", "Planificada": null, - "EstimadaGPS": "20:53:02", + "EstimadaGPS": "00:53:02", "DistanciaGPS": null, "Mensajelinea": null } @@ -1007,14 +1007,14 @@ { "patente": "DBHL17", "Planificada": null, - "EstimadaGPS": "20:56:20", + "EstimadaGPS": "00:56:20", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FCJS56", "Planificada": null, - "EstimadaGPS": "21:13:07", + "EstimadaGPS": "01:13:07", "DistanciaGPS": null, "Mensajelinea": null } @@ -1030,14 +1030,14 @@ { "patente": "HZGX71", "Planificada": null, - "EstimadaGPS": "20:38:39", + "EstimadaGPS": "00:38:39", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FFVP83", "Planificada": null, - "EstimadaGPS": "20:43:41", + "EstimadaGPS": "00:43:41", "DistanciaGPS": null, "Mensajelinea": null } @@ -1053,35 +1053,35 @@ { "patente": "JRZZ56", "Planificada": null, - "EstimadaGPS": "20:36:42", + "EstimadaGPS": "00:36:42", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "JXJG49", "Planificada": null, - "EstimadaGPS": "20:50:09", + "EstimadaGPS": "00:50:09", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FHZB99", "Planificada": null, - "EstimadaGPS": "20:52:19", + "EstimadaGPS": "00:52:19", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "KFTK39", "Planificada": null, - "EstimadaGPS": "20:53:14", + "EstimadaGPS": "00:53:14", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "KVJC80", "Planificada": null, - "EstimadaGPS": "21:14:24", + "EstimadaGPS": "01:14:24", "DistanciaGPS": null, "Mensajelinea": null } @@ -1097,21 +1097,21 @@ { "patente": "RTZT30", "Planificada": null, - "EstimadaGPS": "20:44:12", + "EstimadaGPS": "00:44:12", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "CXSS25", "Planificada": null, - "EstimadaGPS": "20:50:43", + "EstimadaGPS": "00:50:43", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "DPZY99", "Planificada": null, - "EstimadaGPS": "20:52:14", + "EstimadaGPS": "00:52:14", "DistanciaGPS": null, "Mensajelinea": null } @@ -1127,7 +1127,7 @@ { "patente": "BKKS46", "Planificada": null, - "EstimadaGPS": "20:56:25", + "EstimadaGPS": "00:56:25", "DistanciaGPS": null, "Mensajelinea": null } @@ -1143,14 +1143,14 @@ { "patente": "RLVZ65", "Planificada": null, - "EstimadaGPS": "20:38:25", + "EstimadaGPS": "00:38:25", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "RVWC96", "Planificada": null, - "EstimadaGPS": "20:56:36", + "EstimadaGPS": "00:56:36", "DistanciaGPS": null, "Mensajelinea": null } @@ -1166,28 +1166,28 @@ { "patente": "GJLW52", "Planificada": null, - "EstimadaGPS": "20:39:25", + "EstimadaGPS": "00:39:25", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "DLDW43", "Planificada": null, - "EstimadaGPS": "20:49:45", + "EstimadaGPS": "00:49:45", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "HFLR38", "Planificada": null, - "EstimadaGPS": "21:11:22", + "EstimadaGPS": "01:11:22", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "HYCZ20", "Planificada": null, - "EstimadaGPS": "21:26:46", + "EstimadaGPS": "01:26:46", "DistanciaGPS": null, "Mensajelinea": null } @@ -1203,28 +1203,28 @@ { "patente": "DKYR64", "Planificada": null, - "EstimadaGPS": "20:38:06", + "EstimadaGPS": "00:38:06", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "GYGK16", "Planificada": null, - "EstimadaGPS": "20:40:37", + "EstimadaGPS": "00:40:37", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "JSBB39", "Planificada": null, - "EstimadaGPS": "20:59:11", + "EstimadaGPS": "00:59:11", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "HJXW59", "Planificada": null, - "EstimadaGPS": "21:17:13", + "EstimadaGPS": "01:17:13", "DistanciaGPS": null, "Mensajelinea": null } @@ -1240,56 +1240,56 @@ { "patente": "GSRZ32", "Planificada": null, - "EstimadaGPS": "20:40:04", + "EstimadaGPS": "00:40:04", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FLVX57", "Planificada": null, - "EstimadaGPS": "20:41:04", + "EstimadaGPS": "00:41:04", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "DJJH69", "Planificada": null, - "EstimadaGPS": "20:49:17", + "EstimadaGPS": "00:49:17", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "HJXW56", "Planificada": null, - "EstimadaGPS": "20:54:41", + "EstimadaGPS": "00:54:41", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "RFDS28", "Planificada": null, - "EstimadaGPS": "21:08:28", + "EstimadaGPS": "01:08:28", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "DPGK78", "Planificada": null, - "EstimadaGPS": "21:10:49", + "EstimadaGPS": "01:10:49", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "DPGK86", "Planificada": null, - "EstimadaGPS": "21:23:49", + "EstimadaGPS": "01:23:49", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "FTPC75", "Planificada": null, - "EstimadaGPS": "21:30:39", + "EstimadaGPS": "01:30:39", "DistanciaGPS": null, "Mensajelinea": null } @@ -1305,28 +1305,28 @@ { "patente": "YE3093", "Planificada": null, - "EstimadaGPS": "20:40:10", + "EstimadaGPS": "00:40:10", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "JVXY87", "Planificada": null, - "EstimadaGPS": "20:45:13", + "EstimadaGPS": "00:45:13", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "JPRY91", "Planificada": null, - "EstimadaGPS": "20:49:49", + "EstimadaGPS": "00:49:49", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "HVLT12", "Planificada": null, - "EstimadaGPS": "20:53:22", + "EstimadaGPS": "00:53:22", "DistanciaGPS": null, "Mensajelinea": null } @@ -1342,21 +1342,21 @@ { "patente": "KHXV29", "Planificada": null, - "EstimadaGPS": "20:43:11", + "EstimadaGPS": "00:43:11", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "WF1304", "Planificada": null, - "EstimadaGPS": "21:02:10", + "EstimadaGPS": "01:02:10", "DistanciaGPS": null, "Mensajelinea": null }, { "patente": "STJZ94", "Planificada": null, - "EstimadaGPS": "21:15:00", + "EstimadaGPS": "01:15:00", "DistanciaGPS": null, "Mensajelinea": null } diff --git a/src/infraestructure/consts/urls.ts b/src/infraestructure/consts/urls.ts index c8eda4e..993fc73 100644 --- a/src/infraestructure/consts/urls.ts +++ b/src/infraestructure/consts/urls.ts @@ -1,6 +1,5 @@ -const BASE_URL = 'https://transporte.hz.kursor.cl'; const LOGIN_METHOD = '/api/auth/'; const WHOAMI_METHOD = '/api/dispositivos/whoami/'; const INFO_DEVICE_METHOD = '/api/dispositivos/getInfoDevice/'; -export {BASE_URL, LOGIN_METHOD, WHOAMI_METHOD, INFO_DEVICE_METHOD}; +export {LOGIN_METHOD, WHOAMI_METHOD, INFO_DEVICE_METHOD}; diff --git a/src/infraestructure/hooks/__mocks__/mockResponse.json b/src/infraestructure/hooks/__mocks__/mockResponse.json new file mode 100644 index 0000000..e8c2652 --- /dev/null +++ b/src/infraestructure/hooks/__mocks__/mockResponse.json @@ -0,0 +1,508 @@ +{ + "lineDetails": [ + { + "lineNumber": "Vía Láctea 10K - Leonera", + "description": "10K", + "locomotionType": null, + "backgroundColor": "0071ca", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "01:16:25", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:28:58", "distanceGPS": null} + ] + }, + { + "lineNumber": "Vía Láctea 10L - Los Bloques", + "description": "10L", + "locomotionType": null, + "backgroundColor": "4e0963", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:56:01", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:10:21", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:30:40", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:36:28", "distanceGPS": null} + ] + }, + { + "lineNumber": "Vía Láctea 10M - Los Bloques", + "description": "10M", + "locomotionType": null, + "backgroundColor": "ad0101", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "01:20:34", "distanceGPS": null} + ] + }, + { + "lineNumber": "Vía Láctea 10N - Los Bloques", + "description": "10N", + "locomotionType": null, + "backgroundColor": "b10086", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:36:30", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:37:46", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:43:33", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:13:25", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:30:33", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:37:31", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:39:04", "distanceGPS": null} + ] + }, + { + "lineNumber": "Vía Láctea 10O - Pobl. Porvenir", + "description": "10O", + "locomotionType": null, + "backgroundColor": "0d7215", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:45:13", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:17:44", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:33:02", "distanceGPS": null} + ] + }, + { + "lineNumber": "Vía Láctea 10P - Leonera", + "description": "10P", + "locomotionType": null, + "backgroundColor": "0071ca", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:38:33", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:27:15", "distanceGPS": null} + ] + }, + { + "lineNumber": "Vía Futuro 11Q - Los Bloques", + "description": "11Q", + "locomotionType": null, + "backgroundColor": "ad0101", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "01:06:21", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:11:44", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:22:11", "distanceGPS": null} + ] + }, + { + "lineNumber": "Vía Futuro 11R - Porvenir", + "description": "11R", + "locomotionType": null, + "backgroundColor": "b10086", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:55:10", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:10:58", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:18:11", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:30:42", "distanceGPS": null} + ] + }, + { + "lineNumber": "Vía Siglo XXI 13S - Leonera", + "description": "13S", + "locomotionType": null, + "backgroundColor": "ce5504", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:38:24", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:38:34", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:39:30", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:40:11", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:47:29", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:56:02", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:02:20", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:18:02", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:19:13", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:21:56", "distanceGPS": null} + ] + }, + { + "lineNumber": "Chiguayante Sur 14T - Coquimbo", + "description": "14T", + "locomotionType": null, + "backgroundColor": "ce5504", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:38:25", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:55:26", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:09:13", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:25:39", "distanceGPS": null} + ] + }, + { + "lineNumber": "Chiguayante Sur 14U - Los Altos", + "description": "14U", + "locomotionType": null, + "backgroundColor": "cc9b00", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:36:31", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:37:14", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:39:44", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:40:00", "distanceGPS": null} + ] + }, + { + "lineNumber": "Vía Universo 16K - Leonera", + "description": "16K", + "locomotionType": null, + "backgroundColor": "ce5504", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:38:51", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:02:49", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:10:52", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:18:39", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:32:02", "distanceGPS": null} + ] + }, + { + "lineNumber": "Vía Universo 16V - Leonera", + "description": "16V", + "locomotionType": null, + "backgroundColor": "ad0101", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:48:11", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:17:45", "distanceGPS": null} + ] + }, + { + "lineNumber": "Expresos Chiguayante 17C - Leonera", + "description": "17C", + "locomotionType": null, + "backgroundColor": "0071ca", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:43:30", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:13:28", "distanceGPS": null} + ] + }, + { + "lineNumber": "Expresos Chiguayante 17W - Leonera", + "description": "17W", + "locomotionType": null, + "backgroundColor": "0d7215", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:36:23", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:47:02", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:51:20", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:18:00", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:18:39", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:19:37", "distanceGPS": null} + ] + }, + { + "lineNumber": "Expresos Chiguayante 17X - Leonera", + "description": "17X", + "locomotionType": null, + "backgroundColor": "ce5504", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:35:52", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:50:21", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:52:25", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:52:31", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:56:31", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:02:00", "distanceGPS": null} + ] + }, + { + "lineNumber": "Buses Palomares 18Y - Hualqui", + "description": "18Y", + "locomotionType": null, + "backgroundColor": "0071ca", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:51:14", "distanceGPS": null} + ] + }, + { + "lineNumber": "Nueva Llacolén 20A - Boca Sur", + "description": "23A", + "locomotionType": null, + "backgroundColor": "0071ca", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:40:00", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:00:25", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:20:51", "distanceGPS": null} + ] + }, + { + "lineNumber": "Nueva Llacolén 20M - San Pedro Costa", + "description": "23M", + "locomotionType": null, + "backgroundColor": "b10086", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:45:32", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:08:55", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:14:25", "distanceGPS": null} + ] + }, + { + "lineNumber": "Riviera Biobío 21B - Candelaria", + "description": "00B", + "locomotionType": null, + "backgroundColor": "ce5504", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:35:51", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:40:49", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:43:01", "distanceGPS": null} + ] + }, + { + "lineNumber": "Buses San Pedro 22D - Michaihue", + "description": "22D", + "locomotionType": null, + "backgroundColor": "b38800", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:49:24", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:56:26", "distanceGPS": null} + ] + }, + { + "lineNumber": "Ruta Las Playas 30Q - Higueras", + "description": "30Q", + "locomotionType": null, + "backgroundColor": "0d7215", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:38:58", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:52:56", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:17:48", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:27:27", "distanceGPS": null} + ] + }, + { + "lineNumber": "Ruta Las Playas 30R - Higueras", + "description": "30R", + "locomotionType": null, + "backgroundColor": "049684", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:38:37", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:45:06", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:03:46", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:23:56", "distanceGPS": null} + ] + }, + { + "lineNumber": "Ruta del Mar 31D - Lobos Viejos", + "description": "31D", + "locomotionType": null, + "backgroundColor": "ad0101", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:39:41", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:44:07", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:20:41", "distanceGPS": null} + ] + }, + { + "lineNumber": "Ruta del Mar 32E - Lobos Viejos", + "description": "32E", + "locomotionType": null, + "backgroundColor": "b10086", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:41:14", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:17:51", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:36:01", "distanceGPS": null} + ] + }, + { + "lineNumber": "Ruta del Mar 32J - Lobos Viejos", + "description": "32J", + "locomotionType": null, + "backgroundColor": "598200", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:36:34", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:58:20", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:29:34", "distanceGPS": null} + ] + }, + { + "lineNumber": "Las Golondrinas 40G - Candelaria", + "description": "40G", + "locomotionType": null, + "backgroundColor": "ad0101", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:36:34", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:42:28", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:06:34", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:19:39", "distanceGPS": null} + ] + }, + { + "lineNumber": "Buses Hualpencillo 42F - Concepción", + "description": "42F", + "locomotionType": null, + "backgroundColor": "ce5504", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:38:15", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:51:04", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:09:43", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:27:19", "distanceGPS": null} + ] + }, + { + "lineNumber": "Base Naval 56O - Pta. Los Leones", + "description": "56O", + "locomotionType": null, + "backgroundColor": "0071ca", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:38:06", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:38:53", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:53:02", "distanceGPS": null} + ] + }, + { + "lineNumber": "Denavi Sur 57Y - Cosmito", + "description": "57Y", + "locomotionType": null, + "backgroundColor": "ce5504", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:56:20", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:13:07", "distanceGPS": null} + ] + }, + { + "lineNumber": "Mi Expreso 62M - San Vicente", + "description": "62M", + "locomotionType": null, + "backgroundColor": "0071ca", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:38:39", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:43:41", "distanceGPS": null} + ] + }, + { + "lineNumber": "Las Bahías 70I - Centinela", + "description": "70I", + "locomotionType": null, + "backgroundColor": "613FA6", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:36:42", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:50:09", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:52:19", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:53:14", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:14:24", "distanceGPS": null} + ] + }, + { + "lineNumber": "Las Bahías 70J - Los Copihues", + "description": "70J", + "locomotionType": null, + "backgroundColor": "b38800", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:44:12", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:50:43", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:52:14", "distanceGPS": null} + ] + }, + { + "lineNumber": "Las Bahías 70K - Los Copihues", + "description": "70K", + "locomotionType": null, + "backgroundColor": "0d7215", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:56:25", "distanceGPS": null} + ] + }, + { + "lineNumber": "Pedro de Valdivia 72K - Lonco", + "description": "72K", + "locomotionType": null, + "backgroundColor": "0071ca", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:38:25", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:56:36", "distanceGPS": null} + ] + }, + { + "lineNumber": "Las Galaxias 80H - Hualqui", + "description": "80H", + "locomotionType": null, + "backgroundColor": "0071ca", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:39:25", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:49:45", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:11:22", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:26:46", "distanceGPS": null} + ] + }, + { + "lineNumber": "Las Galaxias 80Q - Hualqui", + "description": "80Q", + "locomotionType": null, + "backgroundColor": "ce5504", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:38:06", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:40:37", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:59:11", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:17:13", "distanceGPS": null} + ] + }, + { + "lineNumber": "Las Galaxias 80Z - Valle Piedra", + "description": "80Z", + "locomotionType": null, + "backgroundColor": "0d7215", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:40:04", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:41:04", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:49:17", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:54:41", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:08:28", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:10:49", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:23:49", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:30:39", "distanceGPS": null} + ] + }, + { + "lineNumber": "Nueva Sol Yet 90X - Parque Central", + "description": "90X", + "locomotionType": null, + "backgroundColor": "ad0101", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:40:10", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:45:13", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:49:49", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "00:53:22", "distanceGPS": null} + ] + }, + { + "lineNumber": "Biobús B02 - Centro Concepción", + "description": "B02", + "locomotionType": null, + "backgroundColor": "0d7215", + "letterColor": "ffffff", + "arrivals": [ + {"planned": null, "estimatedGPS": "00:43:11", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:02:10", "distanceGPS": null}, + {"planned": null, "estimatedGPS": "01:15:00", "distanceGPS": null} + ] + } + ], + "stopMessage": "No considerar, uso futuro" +} diff --git a/src/infraestructure/hooks/__tests__/useDevices.spec.ts b/src/infraestructure/hooks/__tests__/useDevices.spec.ts index 163c8eb..200439f 100644 --- a/src/infraestructure/hooks/__tests__/useDevices.spec.ts +++ b/src/infraestructure/hooks/__tests__/useDevices.spec.ts @@ -1,10 +1,20 @@ -import {renderHook, waitFor} from '@testing-library/react-native'; +import {act, renderHook, waitFor} from '@testing-library/react-native'; import useDevices from '../useDevices'; import AuthRepositoryImpl from '../../repositories/AuthRepositoryImpl'; import DevicesRepositoryImpl from '../../repositories/DevicesRepositoryImpl'; +import mockResponse from '../__mocks__/mockResponse.json'; +import {getNumber} from '../../../../__mocks__/@react-native-firebase/remote-config'; -jest.useFakeTimers(); describe('useDevices tests', () => { + beforeEach(() => { + jest.clearAllMocks(); + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + }); + beforeAll(() => { jest.spyOn(AuthRepositoryImpl.prototype, 'auth').mockResolvedValue('token'); jest @@ -74,6 +84,8 @@ describe('useDevices tests', () => { stopNumber: '37477', stopName: "O'Higgins - entre Angol y Salas", }); + + getNumber.mockReturnValue(20000).mockReturnValue(60000); }); it('should be defined', () => { @@ -96,7 +108,9 @@ describe('useDevices tests', () => { it('should return a list of devices', async () => { const mockDate = new Date('2023-01-01T14:00:00Z'); const spy = jest.spyOn(global, 'Date').mockImplementation(() => mockDate); + const {result} = renderHook(() => useDevices()); + await waitFor(() => { expect(result.current.state.lines).toMatchObject([ { @@ -160,4 +174,50 @@ describe('useDevices tests', () => { spy.mockRestore(); }); + + it('should refresh devices list after 20000 miliseconds', async () => { + const mockDate = new Date('2023-01-01T00:01:00Z'); + const spy = jest.spyOn(global, 'Date').mockImplementation(() => mockDate); + jest + .spyOn(DevicesRepositoryImpl.prototype, 'getDeviceInfo') + .mockResolvedValue(mockResponse as any); + + const {result} = renderHook(() => useDevices()); + + await waitFor(() => { + expect(result.current.state.currentIndex).toBe(0); + }); + + jest.advanceTimersByTime(20000); + + await waitFor(() => { + expect(result.current.state.currentIndex).toBe(22); + }); + + spy.mockRestore(); + }); + + it('should refresh devices list after 60000 miliseconds', async () => { + const mockDate = new Date('2023-01-01T00:01:00Z'); + const spy = jest.spyOn(global, 'Date').mockImplementation(() => mockDate); + const spp = jest.spyOn(DevicesRepositoryImpl.prototype, 'getDeviceInfo'); + + const {result} = renderHook(() => useDevices()); + + expect(result.current.state.status).toBe(0); + + await waitFor(() => { + expect(spp).toHaveBeenCalledTimes(1); + }); + + act(() => { + jest.advanceTimersByTime(60000); + }); + + await waitFor(() => { + expect(spp).toHaveBeenCalledTimes(2); + }); + + spy.mockRestore(); + }); }); diff --git a/src/infraestructure/hooks/__tests__/useRemoteconfig.spec.ts b/src/infraestructure/hooks/__tests__/useRemoteconfig.spec.ts new file mode 100644 index 0000000..6e5cf33 --- /dev/null +++ b/src/infraestructure/hooks/__tests__/useRemoteconfig.spec.ts @@ -0,0 +1,67 @@ +import {renderHook, waitFor} from '@testing-library/react-native'; +import useRemoteConfig from '../useRemoteConfig'; +import Status from '../../../utils/Status'; +import { + setConfigSettings, + setDefaults, + fetchAndActivate, + getString, +} from '../../../../__mocks__/@react-native-firebase/remote-config'; + +describe('useRemoteconfig tests', () => { + it('should be defined', async () => { + expect(useRemoteConfig).toBeDefined(); + }); + + describe('on init hook', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('should load remote config data succesfully', async () => { + fetchAndActivate.mockResolvedValueOnce(true); + + const {result} = renderHook(() => useRemoteConfig()); + + expect(result.current.status).toBe(Status.LOADING); + + await waitFor(() => { + expect(result.current.status).toBe(Status.SUCCESS); + expect(setConfigSettings).toHaveBeenCalledTimes(1); + expect(setDefaults).toHaveBeenCalledTimes(1); + expect(fetchAndActivate).toHaveBeenCalledTimes(1); + }); + }); + + it('should fail to load remote config data', async () => { + setConfigSettings.mockRejectedValueOnce(new Error('Error')); + + const {result} = renderHook(() => useRemoteConfig()); + + expect(result.current.status).toBe(Status.LOADING); + + await waitFor(() => { + expect(result.current.status).toBe(Status.ERROR); + expect(setConfigSettings).toHaveBeenCalledTimes(1); + expect(fetchAndActivate).toHaveBeenCalledTimes(0); + expect(setDefaults).toHaveBeenCalledTimes(0); + }); + }); + }); + + describe('get string', () => { + it('should be defined', async () => { + const {result} = renderHook(() => useRemoteConfig()); + + expect(result.current.getString).toBeDefined(); + }); + + it('should return a value', async () => { + getString.mockReturnValueOnce('someValue'); + + const {result} = renderHook(() => useRemoteConfig()); + + expect(result.current.getString('someKey')).toStrictEqual('someValue'); + }); + }); +}); diff --git a/src/infraestructure/hooks/useDevices.ts b/src/infraestructure/hooks/useDevices.ts index 32acce2..e3fc7d3 100644 --- a/src/infraestructure/hooks/useDevices.ts +++ b/src/infraestructure/hooks/useDevices.ts @@ -10,8 +10,9 @@ import BusStopInfoService from '../../domain/services/BusStopInfoService'; import RemoteConfigKeys from '../../utils/RemoteConfigKeys'; import {Line} from '../../presentation/components/Table'; import Status from '../../utils/Status'; +import {BUSES_BY_PAGE} from '../../domain/const'; -interface State { +export interface State { status: Status; lines: LineDetail[]; displayedLines: Line[]; @@ -77,7 +78,7 @@ const useDevices = () => { busStopInfoService = new BusStopInfoService(linesWithArrivals); const linesToDisplay: Line[] = busStopInfoService - .pruneBusList(state.currentIndex, 21) // result 7 rows * 3 columns + .pruneBusList(state.currentIndex, BUSES_BY_PAGE) .map(line => { try { const nextArraival = busStopInfoService.getNextArraival( @@ -140,9 +141,17 @@ const useDevices = () => { ); useEffect(() => { + let timeout: NodeJS.Timeout; + const init = async () => { try { + setState((prevState: State) => ({ + ...prevState, + status: Status.LOADING, + })); + const token = await authRepository.auth({username, password}); + const {lineDetails, stopMessage} = await devicesRepository.getDeviceInfo({ deviceId: DEVICE_ID, @@ -177,14 +186,14 @@ const useDevices = () => { status: Status.ERROR, })); } + + timeout = setTimeout(init, updateBusesListInterval); }; init(); - const interval = setInterval(init, updateBusesListInterval); - return () => { - clearInterval(interval); + clearTimeout(timeout); }; }, [ authRepository, @@ -199,22 +208,29 @@ const useDevices = () => { }, [setDisplayedLines, state.lines, state.stopMessage, state.stopName]); useEffect(() => { - const interval = setInterval(() => { + let timeout: NodeJS.Timeout; + + const init = () => { setState(prevState => { const isGreatherThanLinesLength = - (prevState.currentIndex || 1) + 21 >= state.lines.length; + (prevState.currentIndex || 1) + BUSES_BY_PAGE >= state.lines.length; return { ...prevState, currentIndex: isGreatherThanLinesLength ? 0 - : (prevState.currentIndex || 1 + 21) % state.lines.length, + : (prevState.currentIndex || 1 + BUSES_BY_PAGE) % + state.lines.length, }; }); - }, changePageInterval); + + setTimeout(init, changePageInterval); + }; + + init(); return () => { - clearInterval(interval); + clearTimeout(timeout); }; }, [state.lines, state.status, changePageInterval]); diff --git a/src/infraestructure/hooks/useRemoteConfig.ts b/src/infraestructure/hooks/useRemoteConfig.ts index f276ced..58476fe 100644 --- a/src/infraestructure/hooks/useRemoteConfig.ts +++ b/src/infraestructure/hooks/useRemoteConfig.ts @@ -2,6 +2,8 @@ import {useCallback, useEffect, useState} from 'react'; import remoteConfig from '@react-native-firebase/remote-config'; import Status from '../../utils/Status'; +const ONE_HOUR = 3600000; + const useRemoteConfig = () => { const [status, setStatus] = useState(Status.LOADING); @@ -14,7 +16,7 @@ const useRemoteConfig = () => { const init = async () => { try { await remoteConfig().setConfigSettings({ - minimumFetchIntervalMillis: 3600000, + minimumFetchIntervalMillis: ONE_HOUR, }); // TODO: Add default values for remote config @@ -23,8 +25,8 @@ const useRemoteConfig = () => { HEADER_IMAGE_URL: '', USER: '', PASS: '', - CHANGE_PAGE_INTERVAL: 0, - UPDATE_BUSES_LIST_INTERVAL: 0, + CHANGE_PAGE_INTERVAL: 0, // in miliseconds + UPDATE_BUSES_LIST_INTERVAL: 0, // in miliseconds }); const isActivated = await remoteConfig().fetchAndActivate(); diff --git a/src/presentation/components/BusList.tsx b/src/presentation/components/BusList.tsx index 30431c7..6f1f018 100644 --- a/src/presentation/components/BusList.tsx +++ b/src/presentation/components/BusList.tsx @@ -1,4 +1,10 @@ -import {View, ActivityIndicator, StyleProp} from 'react-native'; +import { + View, + ActivityIndicator, + StyleProp, + Text, + StyleSheet, +} from 'react-native'; import {ViewStyle} from 'react-native'; import Table, {Line} from './Table'; import Status from '../../utils/Status'; @@ -9,11 +15,18 @@ interface BusListProps { style?: StyleProp; } +const ERROR_MESSAGE = 'Ha ocurrido un error'; +const EMPTY_MESSAGE = 'No buses available'; + const BusList = ({buses, status, style}: BusListProps) => { return ( - {status === Status.LOADING ? ( - + {status === Status.LOADING && } + {status === Status.ERROR && ( + {ERROR_MESSAGE} + )} + {status === Status.SUCCESS && buses.length === 0 ? ( + {EMPTY_MESSAGE} ) : ( )} @@ -21,4 +34,10 @@ const BusList = ({buses, status, style}: BusListProps) => { ); }; +const styles = StyleSheet.create({ + text: { + textAlign: 'center', + }, +}); + export default BusList; diff --git a/src/presentation/components/Table.tsx b/src/presentation/components/Table.tsx index 908e480..6c183fe 100644 --- a/src/presentation/components/Table.tsx +++ b/src/presentation/components/Table.tsx @@ -1,4 +1,5 @@ import {View, Text, StyleSheet} from 'react-native'; +import {COLUMNS, ROWS} from '../../domain/const'; export interface Line { lineNumber: string; @@ -14,11 +15,8 @@ export interface TableProps { } const Table = ({data}: TableProps) => { - const rows = 7; - const columns = 3; - - const baseTableData: Line[][] = Array.from({length: rows}, () => - new Array(columns).fill({ + const baseTableData: Line[][] = Array.from({length: ROWS}, () => + new Array(COLUMNS).fill({ lineNumber: '', lineLetter: '', letterColor: '', @@ -28,8 +26,8 @@ const Table = ({data}: TableProps) => { ); data.map((item, index) => { - const row = Math.floor(index / columns); - const column = index % columns; + const row = Math.floor(index / COLUMNS); + const column = index % COLUMNS; baseTableData[row][column] = item; }); diff --git a/src/presentation/components/__tests__/__snapshots__/BusList.spec.tsx.snap b/src/presentation/components/__tests__/__snapshots__/BusList.spec.tsx.snap index b0ae955..2f67b45 100644 --- a/src/presentation/components/__tests__/__snapshots__/BusList.spec.tsx.snap +++ b/src/presentation/components/__tests__/__snapshots__/BusList.spec.tsx.snap @@ -5,11 +5,6 @@ exports[`BusList tests should render correctly with status LOADING 1`] = ` - -`; - -exports[`BusList tests should render correctly with status SUCCESS 1`] = ` - `; + +exports[`BusList tests should render correctly with status SUCCESS 1`] = ` + + + No buses available + + +`; diff --git a/src/presentation/screens/BusStopInfoScreen.tsx b/src/presentation/screens/BusStopInfoScreen.tsx index 18a2e7a..f691518 100644 --- a/src/presentation/screens/BusStopInfoScreen.tsx +++ b/src/presentation/screens/BusStopInfoScreen.tsx @@ -1,4 +1,4 @@ -import {ActivityIndicator, StyleSheet, View} from 'react-native'; +import {ActivityIndicator, StyleSheet, Text, View} from 'react-native'; import Container from '../components/Container'; import Header from '../components/Header'; import useDevices from '../../infraestructure/hooks/useDevices'; @@ -9,9 +9,12 @@ import useRemoteConfig from '../../infraestructure/hooks/useRemoteConfig'; import Status from '../../utils/Status'; const BANNER_TEXT = 'Buses que se detienen en esta parada'; +const ERROR_MESSAGE = 'Ha ocurrido un error'; const BusStopInfoScreen = () => { - const {status, displayedLines, stopName} = useDevices().state; + const { + state: {status, displayedLines, stopName}, + } = useDevices(); const {status: remoteConfigStatus, getString} = useRemoteConfig(); const image = getString(RemoteConfigKeys.HEADER_IMAGE_URL); @@ -21,12 +24,20 @@ const BusStopInfoScreen = () => { if (remoteConfigStatus === Status.LOADING) { return ( - + ); } + if (remoteConfigStatus === Status.ERROR) { + return ( + + {ERROR_MESSAGE} + + ); + } + return (
{ status={status} /> - {/* {TODO implement footer} */} + {/* {TODO: implement footer} */} ); @@ -52,6 +63,10 @@ const styles = StyleSheet.create({ container: { justifyContent: 'center', }, + containerCenter: { + justifyContent: 'center', + alignItems: 'center', + }, headerContainer: { flex: 1.5, backgroundColor: 'orange', diff --git a/src/presentation/screens/__tests__/App.spec.tsx b/src/presentation/screens/__tests__/App.spec.tsx new file mode 100644 index 0000000..d687654 --- /dev/null +++ b/src/presentation/screens/__tests__/App.spec.tsx @@ -0,0 +1,7 @@ +import App from '../App'; + +describe('App tests', () => { + it('should be defined', () => { + expect(App).toBeDefined(); + }); +}); diff --git a/src/presentation/screens/__tests__/BusStopInfoScreen.spec.tsx b/src/presentation/screens/__tests__/BusStopInfoScreen.spec.tsx new file mode 100644 index 0000000..cd39fb3 --- /dev/null +++ b/src/presentation/screens/__tests__/BusStopInfoScreen.spec.tsx @@ -0,0 +1,615 @@ +import {render} from '@testing-library/react-native'; +import BusStopInfoScreen from '../BusStopInfoScreen'; +import * as useDevices from '../../../infraestructure/hooks/useDevices'; +import * as useRemoteConfig from '../../../infraestructure/hooks/useRemoteConfig'; + +const mockState: useDevices.State = { + status: 1, + currentIndex: 0, + stopMessage: 'No considerar, uso futuro', + displayedLines: [ + { + backgroundColor: 'b10086', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'N', + lineNumber: '10', + lineDescription: 'Vía Láctea - Los Bloques', + letterColor: '', + }, + { + backgroundColor: '0071ca', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'P', + lineNumber: '10', + lineDescription: 'Vía Láctea - Leonera', + letterColor: '', + }, + { + backgroundColor: '4e0963', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'L', + lineNumber: '10', + lineDescription: 'Vía Láctea - Los Bloques', + letterColor: '', + }, + { + backgroundColor: 'ad0101', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'Q', + lineNumber: '11', + lineDescription: 'Vía Futuro - Los Bloques', + letterColor: '', + }, + { + backgroundColor: 'b10086', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'R', + lineNumber: '11', + lineDescription: 'Vía Futuro - Porvenir', + letterColor: '', + }, + { + backgroundColor: 'ce5504', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'S', + lineNumber: '13', + lineDescription: 'Vía Siglo XXI - Leonera', + letterColor: '', + }, + { + backgroundColor: 'ce5504', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'T', + lineNumber: '14', + lineDescription: 'Chiguayante Sur - Coquimbo', + letterColor: '', + }, + { + backgroundColor: 'cc9b00', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'U', + lineNumber: '14', + lineDescription: 'Chiguayante Sur - Los Altos', + letterColor: '', + }, + { + backgroundColor: 'ce5504', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'K', + lineNumber: '16', + lineDescription: 'Vía Universo - Leonera', + letterColor: '', + }, + { + backgroundColor: 'ad0101', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'V', + lineNumber: '16', + lineDescription: 'Vía Universo - Leonera', + letterColor: '', + }, + { + backgroundColor: '0d7215', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'W', + lineNumber: '17', + lineDescription: 'Expresos Chiguayante - Leonera', + letterColor: '', + }, + { + backgroundColor: 'ce5504', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'X', + lineNumber: '17', + lineDescription: 'Expresos Chiguayante - Leonera', + letterColor: '', + }, + { + backgroundColor: '0071ca', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'Y', + lineNumber: '18', + lineDescription: 'Buses Palomares - Hualqui', + letterColor: '', + }, + { + backgroundColor: 'b10086', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'M', + lineNumber: '20', + lineDescription: 'Nueva Llacolén - San Pedro Costa', + letterColor: '', + }, + { + backgroundColor: '0071ca', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'A', + lineNumber: '20', + lineDescription: 'Nueva Llacolén - Boca Sur', + letterColor: '', + }, + { + backgroundColor: '0071ca', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'F', + lineNumber: '24', + lineDescription: 'San Remo - Candelaria', + letterColor: '', + }, + { + backgroundColor: '0d7215', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'Q', + lineNumber: '30', + lineDescription: 'Ruta Las Playas - Higueras', + letterColor: '', + }, + { + backgroundColor: '049684', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'R', + lineNumber: '30', + lineDescription: 'Ruta Las Playas - Higueras', + letterColor: '', + }, + { + backgroundColor: 'ce5504', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'P', + lineNumber: '57', + lineDescription: 'Denavi Sur - San Vicente', + letterColor: '', + }, + { + backgroundColor: 'ad0101', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'D', + lineNumber: '31', + lineDescription: 'Ruta del Mar - Lobos Viejos', + letterColor: '', + }, + { + backgroundColor: 'ad0101', + estimatedArrivalTimeInMinutes: 'Más de 10 minutos', + lineLetter: 'G', + lineNumber: '40', + lineDescription: 'Las Golondrinas - Candelaria', + letterColor: '', + }, + ], + lines: [ + { + lineNumber: 'Vía Láctea 10N - Los Bloques', + description: '10N', + locomotionType: 'Autobús', + backgroundColor: 'b10086', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '21:57:47', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:11:13', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Vía Láctea 10P - Leonera', + description: '10P', + locomotionType: 'Autobús', + backgroundColor: '0071ca', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:11:15', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Vía Láctea 10L - Los Bloques', + description: '10L', + locomotionType: 'Autobús', + backgroundColor: '4e0963', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:11:15', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Vía Futuro 11Q - Los Bloques', + description: '11Q', + locomotionType: 'Autobús', + backgroundColor: 'ad0101', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:03:18', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Vía Futuro 11R - Porvenir', + description: '11R', + locomotionType: 'Autobús', + backgroundColor: 'b10086', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:10:32', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '21:58:25', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Vía Siglo XXI 13S - Leonera', + description: '13S', + locomotionType: 'Autobús', + backgroundColor: 'ce5504', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:05:47', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:03:29', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Chiguayante Sur 14T - Coquimbo', + description: '14T', + locomotionType: 'Autobús', + backgroundColor: 'ce5504', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:03:07', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:10:34', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Chiguayante Sur 14U - Los Altos', + description: '14U', + locomotionType: 'Autobús', + backgroundColor: 'cc9b00', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '21:58:12', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Vía Universo 16K - Leonera', + description: '16K', + locomotionType: 'Autobús', + backgroundColor: 'ce5504', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '21:56:07', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:03:34', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Vía Universo 16V - Leonera', + description: '16V', + locomotionType: 'Autobús', + backgroundColor: 'ad0101', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '21:55:51', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:03:50', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '21:51:59', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:11:13', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Expresos Chiguayante 17W - Leonera', + description: '17W', + locomotionType: 'Autobús', + backgroundColor: '0d7215', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:10:43', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Expresos Chiguayante 17X - Leonera', + description: '17X', + locomotionType: 'Autobús', + backgroundColor: 'ce5504', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '21:57:13', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:05:42', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '21:54:55', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Buses Palomares 18Y - Hualqui', + description: '18Y', + locomotionType: 'Autobús', + backgroundColor: '0071ca', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:10:11', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Nueva Llacolén 20M - San Pedro Costa', + description: '20M', + locomotionType: 'Autobús', + backgroundColor: 'b10086', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:08:19', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Nueva Llacolén 20A - Boca Sur', + description: '20A', + locomotionType: 'Autobús', + backgroundColor: '0071ca', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '21:55:19', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:09:49', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'San Remo 24F - Candelaria', + description: '24F', + locomotionType: 'Autobús', + backgroundColor: '0071ca', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '21:51:14', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '21:43:17', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Ruta Las Playas 30Q - Higueras', + description: '30Q', + locomotionType: 'Autobús', + backgroundColor: '0d7215', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:00:38', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Ruta Las Playas 30R - Higueras', + description: '30R', + locomotionType: 'Autobús', + backgroundColor: '049684', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '21:50:33', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Denavi Sur 57P - San Vicente', + description: '57P', + locomotionType: 'Autobús', + backgroundColor: 'ce5504', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:06:08', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Ruta del Mar 31D - Lobos Viejos', + description: '31D', + locomotionType: 'Autobús', + backgroundColor: 'ad0101', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:10:32', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:10:34', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:06:41', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Las Golondrinas 40G - Candelaria', + description: '40G', + locomotionType: 'Autobús', + backgroundColor: 'ad0101', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '21:48:36', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Buses Hualpencillo 42F - Concepción', + description: '42F', + locomotionType: 'Autobús', + backgroundColor: 'ce5504', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '21:19:33', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Mi Expreso 62M - San Vicente', + description: '62M', + locomotionType: 'Autobús', + backgroundColor: '0071ca', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:02:34', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Pedro de Valdivia 72K - Lonco', + description: '72K', + locomotionType: 'Autobús', + backgroundColor: '0071ca', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '21:17:38', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '21:26:45', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Nueva Sol Yet 90X - Parque Central', + description: '90X', + locomotionType: 'Autobús', + backgroundColor: 'ad0101', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '21:39:48', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '21:47:30', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '21:52:24', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Biobús B02 - Centro Concepción', + description: 'B02', + locomotionType: 'Autobús', + backgroundColor: '0d7215', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '21:37:33', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Las Bahías 70I - Centinela', + description: '70I', + locomotionType: 'Autobús', + backgroundColor: '613FA6', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:05:39', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:09:26', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Las Bahías 70J - Los Copihues', + description: '70J', + locomotionType: 'Autobús', + backgroundColor: 'b38800', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:01:24', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Las Galaxias 80Q - Hualqui', + description: '80Q', + locomotionType: 'Autobús', + backgroundColor: 'ce5504', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:10:28', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:10:54', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:11:01', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Las Galaxias 80H - Hualqui', + description: '80H', + locomotionType: 'Autobús', + backgroundColor: '0071ca', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:10:23', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:10:32', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Las Galaxias 80Z - Valle Piedra', + description: '80Z', + locomotionType: 'Autobús', + backgroundColor: '0d7215', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:06:08', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:10:02', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:11:02', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '21:54:16', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:01:17', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Ruta del Mar 32E - Lobos Viejos', + description: '32E', + locomotionType: 'Autobús', + backgroundColor: 'b10086', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:05:08', distanceGPS: '', carPlate: ''}, + {planned: '', estimatedGPS: '22:10:28', distanceGPS: '', carPlate: ''}, + ], + }, + { + lineNumber: 'Ruta del Mar 32J - Lobos Viejos', + description: '32J', + locomotionType: 'Autobús', + backgroundColor: '598200', + letterColor: '', + lineMessage: '', + arrivals: [ + {planned: '', estimatedGPS: '22:09:44', distanceGPS: '', carPlate: ''}, + ], + }, + ], + stopName: "O'Higgins -esq. Salas", +}; + +describe('BusStopInfoScreen tests', () => { + beforeAll(() => { + jest.spyOn(useDevices, 'default').mockReturnValue({ + state: mockState, + }); + }); + + it('should be defined', () => { + expect(BusStopInfoScreen).toBeDefined(); + }); + + it('should render the screen with status loading', () => { + jest.spyOn(useRemoteConfig, 'default').mockReturnValue({ + status: 0, + getString: () => 'https://www.google.com', + }); + const {toJSON} = render(); + + expect(toJSON()).toMatchSnapshot(); + }); + + it('should render the screen with status error', () => { + jest.spyOn(useRemoteConfig, 'default').mockReturnValue({ + status: 2, + getString: () => 'https://www.google.com', + }); + + const {toJSON} = render(); + + expect(toJSON()).toMatchSnapshot(); + }); + + it('should render the screen with status success', () => { + jest.spyOn(useRemoteConfig, 'default').mockReturnValue({ + status: 1, + getString: () => 'https://www.google.com', + }); + const {toJSON} = render(); + + expect(toJSON()).toMatchSnapshot(); + }); +}); diff --git a/src/presentation/screens/__tests__/__snapshots__/BusStopInfoScreen.spec.tsx.snap b/src/presentation/screens/__tests__/__snapshots__/BusStopInfoScreen.spec.tsx.snap new file mode 100644 index 0000000..642d858 --- /dev/null +++ b/src/presentation/screens/__tests__/__snapshots__/BusStopInfoScreen.spec.tsx.snap @@ -0,0 +1,2581 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`BusStopInfoScreen tests should render the screen with status error 1`] = ` + + + Ha ocurrido un error + + +`; + +exports[`BusStopInfoScreen tests should render the screen with status loading 1`] = ` + + + +`; + +exports[`BusStopInfoScreen tests should render the screen with status success 1`] = ` + + + + + + + + + O'Higgins + + + esq. Salas + + + + + + + Buses que se detienen en esta parada + + + + + + + + + 10 + + + + N + + + + + + Vía Láctea + + + Los Bloques + + + Más de 10 minutos + + + + + + + 10 + + + + P + + + + + + Vía Láctea + + + Leonera + + + Más de 10 minutos + + + + + + + 10 + + + + L + + + + + + Vía Láctea + + + Los Bloques + + + Más de 10 minutos + + + + + + + + + 11 + + + + Q + + + + + + Vía Futuro + + + Los Bloques + + + Más de 10 minutos + + + + + + + 11 + + + + R + + + + + + Vía Futuro + + + Porvenir + + + Más de 10 minutos + + + + + + + 13 + + + + S + + + + + + Vía Siglo XXI + + + Leonera + + + Más de 10 minutos + + + + + + + + + 14 + + + + T + + + + + + Chiguayante Sur + + + Coquimbo + + + Más de 10 minutos + + + + + + + 14 + + + + U + + + + + + Chiguayante Sur + + + Los Altos + + + Más de 10 minutos + + + + + + + 16 + + + + K + + + + + + Vía Universo + + + Leonera + + + Más de 10 minutos + + + + + + + + + 16 + + + + V + + + + + + Vía Universo + + + Leonera + + + Más de 10 minutos + + + + + + + 17 + + + + W + + + + + + Expresos Chiguayante + + + Leonera + + + Más de 10 minutos + + + + + + + 17 + + + + X + + + + + + Expresos Chiguayante + + + Leonera + + + Más de 10 minutos + + + + + + + + + 18 + + + + Y + + + + + + Buses Palomares + + + Hualqui + + + Más de 10 minutos + + + + + + + 20 + + + + M + + + + + + Nueva Llacolén + + + San Pedro Costa + + + Más de 10 minutos + + + + + + + 20 + + + + A + + + + + + Nueva Llacolén + + + Boca Sur + + + Más de 10 minutos + + + + + + + + + 24 + + + + F + + + + + + San Remo + + + Candelaria + + + Más de 10 minutos + + + + + + + 30 + + + + Q + + + + + + Ruta Las Playas + + + Higueras + + + Más de 10 minutos + + + + + + + 30 + + + + R + + + + + + Ruta Las Playas + + + Higueras + + + Más de 10 minutos + + + + + + + + + 57 + + + + P + + + + + + Denavi Sur + + + San Vicente + + + Más de 10 minutos + + + + + + + 31 + + + + D + + + + + + Ruta del Mar + + + Lobos Viejos + + + Más de 10 minutos + + + + + + + 40 + + + + G + + + + + + Las Golondrinas + + + Candelaria + + + Más de 10 minutos + + + + + + + + +`; diff --git a/yarn.lock b/yarn.lock index 793b367..06f50ae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1908,13 +1908,16 @@ integrity sha512-Im93xRJuHHxb1wniGhBMsxLwcfzdYreSZVQGDoMJgkd6+Iky61LInGEHnQCTN0fKNYF1Dvcofb4uMmE1RQHXHQ== "@react-native/codegen@^0.72.7": - version "0.72.7" - resolved "https://registry.yarnpkg.com/@react-native/codegen/-/codegen-0.72.7.tgz#b6832ce631ac63143024ea094a6b5480a780e589" - integrity sha512-O7xNcGeXGbY+VoqBGNlZ3O05gxfATlwE1Q1qQf5E38dK+tXn5BY4u0jaQ9DPjfE8pBba8g/BYI1N44lynidMtg== + version "0.72.8" + resolved "https://registry.yarnpkg.com/@react-native/codegen/-/codegen-0.72.8.tgz#0593f628e1310f430450a9479fbb4be35e7b63d6" + integrity sha512-jQCcBlXV7B7ap5VlHhwIPieYz89yiRgwd2FPUBu+unz+kcJ6pAiB2U8RdLDmyIs8fiWd+Vq1xxaWs4TR329/ng== dependencies: "@babel/parser" "^7.20.0" flow-parser "^0.206.0" + glob "^7.1.1" + invariant "^2.2.4" jscodeshift "^0.14.0" + mkdirp "^0.5.1" nullthrows "^1.1.1" "@react-native/eslint-config@^0.72.2": @@ -4007,7 +4010,7 @@ glob-parent@^6.0.2: dependencies: is-glob "^4.0.3" -glob@^7.1.3, glob@^7.1.4: +glob@^7.1.1, glob@^7.1.3, glob@^7.1.4: version "7.2.3" resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b" integrity sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==