2020-08-05 21:09:04 +02:00
|
|
|
/* eslint-disable */
|
|
|
|
|
2020-04-30 22:16:35 +02:00
|
|
|
import React from 'react';
|
2020-08-05 21:09:04 +02:00
|
|
|
import {
|
|
|
|
getCleanedMachineWatched,
|
|
|
|
getMachineEndDate,
|
|
|
|
getMachineOfId,
|
|
|
|
isMachineWatched,
|
|
|
|
} from '../../src/utils/Proxiwash';
|
2020-04-30 22:16:35 +02:00
|
|
|
|
|
|
|
test('getMachineEndDate', () => {
|
2020-08-05 21:09:04 +02:00
|
|
|
jest
|
|
|
|
.spyOn(Date, 'now')
|
|
|
|
.mockImplementation(() => new Date('2020-01-14T15:00:00.000Z').getTime());
|
|
|
|
let expectDate = new Date('2020-01-14T15:00:00.000Z');
|
|
|
|
expectDate.setHours(23);
|
|
|
|
expectDate.setMinutes(10);
|
|
|
|
expect(getMachineEndDate({endTime: '23:10'}).getTime()).toBe(
|
|
|
|
expectDate.getTime(),
|
|
|
|
);
|
2020-04-30 22:16:35 +02:00
|
|
|
|
2020-08-05 21:09:04 +02:00
|
|
|
expectDate.setHours(16);
|
|
|
|
expectDate.setMinutes(30);
|
|
|
|
expect(getMachineEndDate({endTime: '16:30'}).getTime()).toBe(
|
|
|
|
expectDate.getTime(),
|
|
|
|
);
|
2020-04-30 22:16:35 +02:00
|
|
|
|
2020-08-05 21:09:04 +02:00
|
|
|
expect(getMachineEndDate({endTime: '15:30'})).toBeNull();
|
2020-04-30 22:38:33 +02:00
|
|
|
|
2020-08-05 21:09:04 +02:00
|
|
|
expect(getMachineEndDate({endTime: '13:10'})).toBeNull();
|
2020-04-30 22:38:33 +02:00
|
|
|
|
2020-08-05 21:09:04 +02:00
|
|
|
jest
|
|
|
|
.spyOn(Date, 'now')
|
|
|
|
.mockImplementation(() => new Date('2020-01-14T23:00:00.000Z').getTime());
|
|
|
|
expectDate = new Date('2020-01-14T23:00:00.000Z');
|
|
|
|
expectDate.setHours(0);
|
|
|
|
expectDate.setMinutes(30);
|
|
|
|
expect(getMachineEndDate({endTime: '00:30'}).getTime()).toBe(
|
|
|
|
expectDate.getTime(),
|
|
|
|
);
|
2020-04-30 22:16:35 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('isMachineWatched', () => {
|
2020-08-05 21:09:04 +02:00
|
|
|
let machineList = [
|
|
|
|
{
|
|
|
|
number: '0',
|
|
|
|
endTime: '23:30',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
number: '1',
|
|
|
|
endTime: '20:30',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
expect(
|
|
|
|
isMachineWatched({number: '0', endTime: '23:30'}, machineList),
|
|
|
|
).toBeTrue();
|
|
|
|
expect(
|
|
|
|
isMachineWatched({number: '1', endTime: '20:30'}, machineList),
|
|
|
|
).toBeTrue();
|
|
|
|
expect(
|
|
|
|
isMachineWatched({number: '3', endTime: '20:30'}, machineList),
|
|
|
|
).toBeFalse();
|
|
|
|
expect(
|
|
|
|
isMachineWatched({number: '1', endTime: '23:30'}, machineList),
|
|
|
|
).toBeFalse();
|
2020-04-30 22:16:35 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('getMachineOfId', () => {
|
2020-08-05 21:09:04 +02:00
|
|
|
let machineList = [
|
|
|
|
{
|
|
|
|
number: '0',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
number: '1',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
expect(getMachineOfId('0', machineList)).toStrictEqual({number: '0'});
|
|
|
|
expect(getMachineOfId('1', machineList)).toStrictEqual({number: '1'});
|
|
|
|
expect(getMachineOfId('3', machineList)).toBeNull();
|
2020-04-30 22:16:35 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('getCleanedMachineWatched', () => {
|
2020-08-05 21:09:04 +02:00
|
|
|
let machineList = [
|
|
|
|
{
|
|
|
|
number: '0',
|
|
|
|
endTime: '23:30',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
number: '1',
|
|
|
|
endTime: '20:30',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
number: '2',
|
|
|
|
endTime: '',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
let watchList = [
|
|
|
|
{
|
|
|
|
number: '0',
|
|
|
|
endTime: '23:30',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
number: '1',
|
|
|
|
endTime: '20:30',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
number: '2',
|
|
|
|
endTime: '',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
let cleanedList = watchList;
|
|
|
|
expect(getCleanedMachineWatched(watchList, machineList)).toStrictEqual(
|
|
|
|
cleanedList,
|
|
|
|
);
|
2020-04-30 22:16:35 +02:00
|
|
|
|
2020-08-05 21:09:04 +02:00
|
|
|
watchList = [
|
|
|
|
{
|
|
|
|
number: '0',
|
|
|
|
endTime: '23:30',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
number: '1',
|
|
|
|
endTime: '20:30',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
number: '2',
|
|
|
|
endTime: '15:30',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
cleanedList = [
|
|
|
|
{
|
|
|
|
number: '0',
|
|
|
|
endTime: '23:30',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
number: '1',
|
|
|
|
endTime: '20:30',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
expect(getCleanedMachineWatched(watchList, machineList)).toStrictEqual(
|
|
|
|
cleanedList,
|
|
|
|
);
|
2020-04-30 22:16:35 +02:00
|
|
|
|
2020-08-05 21:09:04 +02:00
|
|
|
watchList = [
|
|
|
|
{
|
|
|
|
number: '0',
|
|
|
|
endTime: '23:30',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
number: '1',
|
|
|
|
endTime: '20:31',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
number: '3',
|
|
|
|
endTime: '15:30',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
cleanedList = [
|
|
|
|
{
|
|
|
|
number: '0',
|
|
|
|
endTime: '23:30',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
expect(getCleanedMachineWatched(watchList, machineList)).toStrictEqual(
|
|
|
|
cleanedList,
|
|
|
|
);
|
|
|
|
});
|