SmartStopAPK/src/infraestructure/hooks/__tests__/useDevices.spec.ts

164 lines
4.7 KiB
TypeScript
Raw Normal View History

2023-12-22 22:40:24 -03:00
import {renderHook, waitFor} from '@testing-library/react-native';
import useDevices from '../useDevices';
import AuthRepositoryImpl from '../../repositories/AuthRepositoryImpl';
import DevicesRepositoryImpl from '../../repositories/DevicesRepositoryImpl';
jest.useFakeTimers();
describe('useDevices tests', () => {
2023-12-22 22:40:24 -03:00
beforeAll(() => {
jest.spyOn(AuthRepositoryImpl.prototype, 'auth').mockResolvedValue('token');
jest
.spyOn(DevicesRepositoryImpl.prototype, 'getDeviceInfo')
.mockResolvedValue({
lineDetails: [
{
lineNumber: '803010',
description: 'Tucapel',
locomotionType: 1,
backgroundColor: 'Hexadecimal',
letterColor: 'Hexadecimal',
lineMessage: '',
arrivals: [
{
carPlate: 'RPDA-98',
planned: '',
estimatedGPS: '15:08',
distanceGPS: '1.0 KM',
},
{
carPlate: 'WYXYZ-22',
planned: '',
estimatedGPS: '15:42',
distanceGPS: '5.0 KM',
},
{
carPlate: 'ABCA-65',
planned: '',
estimatedGPS: '16:18',
distanceGPS: '13.4 KM',
},
],
},
{
lineNumber: '5487',
description: 'Centauro',
locomotionType: 1,
backgroundColor: 'Hexadecimal',
letterColor: 'Hexadecimal',
lineMessage: 'Sin info. GPS, la informacion es estimada',
arrivals: [
{
carPlate: 'PLKJ-32',
planned: '15:13',
estimatedGPS: '',
distanceGPS: '',
},
{
carPlate: 'GHLK-11',
planned: '15:39',
estimatedGPS: '',
distanceGPS: '',
},
{
carPlate: 'DFQW-55',
planned: '16:22',
estimatedGPS: '',
distanceGPS: '',
},
],
},
],
stopMessage: 'No considerar, uso futuro',
});
jest.spyOn(DevicesRepositoryImpl.prototype, 'whoAmI').mockResolvedValue({
stopNumber: '37477',
stopName: "O'Higgins - entre Angol y Salas",
});
});
it('should be defined', () => {
expect(true).toBeTruthy();
});
2023-12-22 22:40:24 -03:00
it('should return stop information', async () => {
const {result} = renderHook(() => useDevices());
await waitFor(() => {
expect(result.current.state.stopName).toStrictEqual(
"O'Higgins - entre Angol y Salas",
);
expect(result.current.state.stopMessage).toStrictEqual(
'No considerar, uso futuro',
);
});
});
2023-12-22 22:40:24 -03:00
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([
{
arrivals: [
{
carPlate: 'RPDA-98',
distanceGPS: '1.0 KM',
estimatedGPS: '15:08',
planned: '',
},
{
carPlate: 'WYXYZ-22',
distanceGPS: '5.0 KM',
estimatedGPS: '15:42',
planned: '',
},
{
carPlate: 'ABCA-65',
distanceGPS: '13.4 KM',
estimatedGPS: '16:18',
planned: '',
},
],
backgroundColor: 'Hexadecimal',
description: 'Tucapel',
letterColor: 'Hexadecimal',
lineMessage: '',
lineNumber: '803010',
locomotionType: 1,
},
{
arrivals: [
{
carPlate: 'PLKJ-32',
distanceGPS: '',
estimatedGPS: '',
planned: '15:13',
},
{
carPlate: 'GHLK-11',
distanceGPS: '',
estimatedGPS: '',
planned: '15:39',
},
{
carPlate: 'DFQW-55',
distanceGPS: '',
estimatedGPS: '',
planned: '16:22',
},
],
backgroundColor: 'Hexadecimal',
description: 'Centauro',
letterColor: 'Hexadecimal',
lineMessage: 'Sin info. GPS, la informacion es estimada',
lineNumber: '5487',
locomotionType: 1,
},
]);
});
spy.mockRestore();
});
});