forked from vergnet/application-amicale
Disable lint for test files
This commit is contained in:
parent
1e81b2cd7b
commit
4cc9c61d72
9 changed files with 1221 additions and 1112 deletions
|
@ -1,10 +1,12 @@
|
|||
jest.mock('react-native-keychain');
|
||||
/* eslint-disable */
|
||||
|
||||
import React from 'react';
|
||||
import ConnectionManager from "../../src/managers/ConnectionManager";
|
||||
import {ERROR_TYPE} from "../../src/utils/WebData";
|
||||
import ConnectionManager from '../../src/managers/ConnectionManager';
|
||||
import {ERROR_TYPE} from '../../src/utils/WebData';
|
||||
|
||||
let fetch = require('isomorphic-fetch'); // fetch is not implemented in nodeJS but in react-native
|
||||
jest.mock('react-native-keychain');
|
||||
|
||||
const fetch = require('isomorphic-fetch'); // fetch is not implemented in nodeJS but in react-native
|
||||
|
||||
const c = ConnectionManager.getInstance();
|
||||
|
||||
|
@ -13,132 +15,124 @@ afterEach(() => {
|
|||
});
|
||||
|
||||
test('isLoggedIn yes', () => {
|
||||
jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
|
||||
jest
|
||||
.spyOn(ConnectionManager.prototype, 'getToken')
|
||||
.mockImplementationOnce(() => {
|
||||
return 'token';
|
||||
});
|
||||
return expect(c.isLoggedIn()).toBe(true);
|
||||
});
|
||||
|
||||
test('isLoggedIn no', () => {
|
||||
jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
|
||||
jest
|
||||
.spyOn(ConnectionManager.prototype, 'getToken')
|
||||
.mockImplementationOnce(() => {
|
||||
return null;
|
||||
});
|
||||
return expect(c.isLoggedIn()).toBe(false);
|
||||
});
|
||||
|
||||
test("isConnectionResponseValid", () => {
|
||||
let json = {
|
||||
error: 0,
|
||||
data: {token: 'token'}
|
||||
};
|
||||
expect(c.isConnectionResponseValid(json)).toBeTrue();
|
||||
json = {
|
||||
error: 2,
|
||||
data: {}
|
||||
};
|
||||
expect(c.isConnectionResponseValid(json)).toBeTrue();
|
||||
json = {
|
||||
error: 0,
|
||||
data: {token: ''}
|
||||
};
|
||||
expect(c.isConnectionResponseValid(json)).toBeFalse();
|
||||
json = {
|
||||
error: 'prout',
|
||||
data: {token: ''}
|
||||
};
|
||||
expect(c.isConnectionResponseValid(json)).toBeFalse();
|
||||
});
|
||||
|
||||
test("connect bad credentials", () => {
|
||||
test('connect bad credentials', () => {
|
||||
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||
return Promise.resolve({
|
||||
json: () => {
|
||||
return {
|
||||
error: ERROR_TYPE.BAD_CREDENTIALS,
|
||||
data: {}
|
||||
data: {},
|
||||
};
|
||||
},
|
||||
})
|
||||
});
|
||||
return expect(c.connect('email', 'password'))
|
||||
.rejects.toBe(ERROR_TYPE.BAD_CREDENTIALS);
|
||||
});
|
||||
return expect(c.connect('email', 'password')).rejects.toBe(
|
||||
ERROR_TYPE.BAD_CREDENTIALS,
|
||||
);
|
||||
});
|
||||
|
||||
test("connect good credentials", () => {
|
||||
test('connect good credentials', () => {
|
||||
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||
return Promise.resolve({
|
||||
json: () => {
|
||||
return {
|
||||
error: ERROR_TYPE.SUCCESS,
|
||||
data: {token: 'token'}
|
||||
data: {token: 'token'},
|
||||
};
|
||||
},
|
||||
})
|
||||
});
|
||||
jest.spyOn(ConnectionManager.prototype, 'saveLogin').mockImplementationOnce(() => {
|
||||
});
|
||||
jest
|
||||
.spyOn(ConnectionManager.prototype, 'saveLogin')
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(true);
|
||||
});
|
||||
return expect(c.connect('email', 'password')).resolves.toBeTruthy();
|
||||
});
|
||||
|
||||
test("connect good credentials no consent", () => {
|
||||
test('connect good credentials no consent', () => {
|
||||
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||
return Promise.resolve({
|
||||
json: () => {
|
||||
return {
|
||||
error: ERROR_TYPE.NO_CONSENT,
|
||||
data: {}
|
||||
data: {},
|
||||
};
|
||||
},
|
||||
})
|
||||
});
|
||||
return expect(c.connect('email', 'password'))
|
||||
.rejects.toBe(ERROR_TYPE.NO_CONSENT);
|
||||
});
|
||||
return expect(c.connect('email', 'password')).rejects.toBe(
|
||||
ERROR_TYPE.NO_CONSENT,
|
||||
);
|
||||
});
|
||||
|
||||
test("connect good credentials, fail save token", () => {
|
||||
test('connect good credentials, fail save token', () => {
|
||||
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||
return Promise.resolve({
|
||||
json: () => {
|
||||
return {
|
||||
error: ERROR_TYPE.SUCCESS,
|
||||
data: {token: 'token'}
|
||||
data: {token: 'token'},
|
||||
};
|
||||
},
|
||||
})
|
||||
});
|
||||
jest.spyOn(ConnectionManager.prototype, 'saveLogin').mockImplementationOnce(() => {
|
||||
});
|
||||
jest
|
||||
.spyOn(ConnectionManager.prototype, 'saveLogin')
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.reject(false);
|
||||
});
|
||||
return expect(c.connect('email', 'password')).rejects.toBe(ERROR_TYPE.UNKNOWN);
|
||||
return expect(c.connect('email', 'password')).rejects.toBe(
|
||||
ERROR_TYPE.UNKNOWN,
|
||||
);
|
||||
});
|
||||
|
||||
test("connect connection error", () => {
|
||||
test('connect connection error', () => {
|
||||
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||
return Promise.reject();
|
||||
});
|
||||
return expect(c.connect('email', 'password'))
|
||||
.rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
|
||||
return expect(c.connect('email', 'password')).rejects.toBe(
|
||||
ERROR_TYPE.CONNECTION_ERROR,
|
||||
);
|
||||
});
|
||||
|
||||
test("connect bogus response 1", () => {
|
||||
test('connect bogus response 1', () => {
|
||||
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||
return Promise.resolve({
|
||||
json: () => {
|
||||
return {
|
||||
thing: true,
|
||||
wrong: '',
|
||||
}
|
||||
};
|
||||
},
|
||||
})
|
||||
});
|
||||
return expect(c.connect('email', 'password'))
|
||||
.rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
|
||||
});
|
||||
return expect(c.connect('email', 'password')).rejects.toBe(
|
||||
ERROR_TYPE.CONNECTION_ERROR,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
test("authenticatedRequest success", () => {
|
||||
jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
|
||||
test('authenticatedRequest success', () => {
|
||||
jest
|
||||
.spyOn(ConnectionManager.prototype, 'getToken')
|
||||
.mockImplementationOnce(() => {
|
||||
return 'token';
|
||||
});
|
||||
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||
|
@ -146,17 +140,20 @@ test("authenticatedRequest success", () => {
|
|||
json: () => {
|
||||
return {
|
||||
error: ERROR_TYPE.SUCCESS,
|
||||
data: {coucou: 'toi'}
|
||||
data: {coucou: 'toi'},
|
||||
};
|
||||
},
|
||||
})
|
||||
});
|
||||
return expect(c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'))
|
||||
.resolves.toStrictEqual({coucou: 'toi'});
|
||||
});
|
||||
return expect(
|
||||
c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'),
|
||||
).resolves.toStrictEqual({coucou: 'toi'});
|
||||
});
|
||||
|
||||
test("authenticatedRequest error wrong token", () => {
|
||||
jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
|
||||
test('authenticatedRequest error wrong token', () => {
|
||||
jest
|
||||
.spyOn(ConnectionManager.prototype, 'getToken')
|
||||
.mockImplementationOnce(() => {
|
||||
return 'token';
|
||||
});
|
||||
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||
|
@ -164,17 +161,20 @@ test("authenticatedRequest error wrong token", () => {
|
|||
json: () => {
|
||||
return {
|
||||
error: ERROR_TYPE.BAD_TOKEN,
|
||||
data: {}
|
||||
data: {},
|
||||
};
|
||||
},
|
||||
})
|
||||
});
|
||||
return expect(c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'))
|
||||
.rejects.toBe(ERROR_TYPE.BAD_TOKEN);
|
||||
});
|
||||
return expect(
|
||||
c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'),
|
||||
).rejects.toBe(ERROR_TYPE.BAD_TOKEN);
|
||||
});
|
||||
|
||||
test("authenticatedRequest error bogus response", () => {
|
||||
jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
|
||||
test('authenticatedRequest error bogus response', () => {
|
||||
jest
|
||||
.spyOn(ConnectionManager.prototype, 'getToken')
|
||||
.mockImplementationOnce(() => {
|
||||
return 'token';
|
||||
});
|
||||
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||
|
@ -184,27 +184,34 @@ test("authenticatedRequest error bogus response", () => {
|
|||
error: ERROR_TYPE.SUCCESS,
|
||||
};
|
||||
},
|
||||
})
|
||||
});
|
||||
return expect(c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'))
|
||||
.rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
|
||||
});
|
||||
return expect(
|
||||
c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'),
|
||||
).rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
|
||||
});
|
||||
|
||||
test("authenticatedRequest connection error", () => {
|
||||
jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
|
||||
test('authenticatedRequest connection error', () => {
|
||||
jest
|
||||
.spyOn(ConnectionManager.prototype, 'getToken')
|
||||
.mockImplementationOnce(() => {
|
||||
return 'token';
|
||||
});
|
||||
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||
return Promise.reject()
|
||||
return Promise.reject();
|
||||
});
|
||||
return expect(c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'))
|
||||
.rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
|
||||
return expect(
|
||||
c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'),
|
||||
).rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
|
||||
});
|
||||
|
||||
test("authenticatedRequest error no token", () => {
|
||||
jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
|
||||
test('authenticatedRequest error no token', () => {
|
||||
jest
|
||||
.spyOn(ConnectionManager.prototype, 'getToken')
|
||||
.mockImplementationOnce(() => {
|
||||
return null;
|
||||
});
|
||||
return expect(c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'))
|
||||
.rejects.toBe(ERROR_TYPE.UNKNOWN);
|
||||
return expect(
|
||||
c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'),
|
||||
).rejects.toBe(ERROR_TYPE.UNKNOWN);
|
||||
});
|
||||
|
|
|
@ -1,319 +1,345 @@
|
|||
/* eslint-disable */
|
||||
|
||||
import React from 'react';
|
||||
import * as EquipmentBooking from "../../src/utils/EquipmentBooking";
|
||||
import i18n from "i18n-js";
|
||||
import * as EquipmentBooking from '../../src/utils/EquipmentBooking';
|
||||
import i18n from 'i18n-js';
|
||||
|
||||
test('getISODate', () => {
|
||||
let date = new Date("2020-03-05 12:00");
|
||||
expect(EquipmentBooking.getISODate(date)).toBe("2020-03-05");
|
||||
date = new Date("2020-03-05");
|
||||
expect(EquipmentBooking.getISODate(date)).toBe("2020-03-05");
|
||||
date = new Date("2020-03-05 00:00"); // Treated as local time
|
||||
expect(EquipmentBooking.getISODate(date)).toBe("2020-03-04"); // Treated as UTC
|
||||
let date = new Date('2020-03-05 12:00');
|
||||
expect(EquipmentBooking.getISODate(date)).toBe('2020-03-05');
|
||||
date = new Date('2020-03-05');
|
||||
expect(EquipmentBooking.getISODate(date)).toBe('2020-03-05');
|
||||
date = new Date('2020-03-05 00:00'); // Treated as local time
|
||||
expect(EquipmentBooking.getISODate(date)).toBe('2020-03-04'); // Treated as UTC
|
||||
});
|
||||
|
||||
test('getCurrentDay', () => {
|
||||
jest.spyOn(Date, 'now')
|
||||
.mockImplementation(() =>
|
||||
new Date('2020-01-14 14:50:35').getTime()
|
||||
jest
|
||||
.spyOn(Date, 'now')
|
||||
.mockImplementation(() => new Date('2020-01-14 14:50:35').getTime());
|
||||
expect(EquipmentBooking.getCurrentDay().getTime()).toBe(
|
||||
new Date('2020-01-14').getTime(),
|
||||
);
|
||||
expect(EquipmentBooking.getCurrentDay().getTime()).toBe(new Date("2020-01-14").getTime());
|
||||
});
|
||||
|
||||
test('isEquipmentAvailable', () => {
|
||||
jest.spyOn(Date, 'now')
|
||||
.mockImplementation(() =>
|
||||
new Date('2020-07-09').getTime()
|
||||
);
|
||||
jest
|
||||
.spyOn(Date, 'now')
|
||||
.mockImplementation(() => new Date('2020-07-09').getTime());
|
||||
let testDevice = {
|
||||
id: 1,
|
||||
name: "Petit barbecue",
|
||||
name: 'Petit barbecue',
|
||||
caution: 100,
|
||||
booked_at: [{begin: "2020-07-07", end: "2020-07-10"}]
|
||||
booked_at: [{begin: '2020-07-07', end: '2020-07-10'}],
|
||||
};
|
||||
expect(EquipmentBooking.isEquipmentAvailable(testDevice)).toBeFalse();
|
||||
|
||||
testDevice.booked_at = [{begin: "2020-07-07", end: "2020-07-09"}];
|
||||
testDevice.booked_at = [{begin: '2020-07-07', end: '2020-07-09'}];
|
||||
expect(EquipmentBooking.isEquipmentAvailable(testDevice)).toBeFalse();
|
||||
|
||||
testDevice.booked_at = [{begin: "2020-07-09", end: "2020-07-10"}];
|
||||
testDevice.booked_at = [{begin: '2020-07-09', end: '2020-07-10'}];
|
||||
expect(EquipmentBooking.isEquipmentAvailable(testDevice)).toBeFalse();
|
||||
|
||||
testDevice.booked_at = [
|
||||
{begin: "2020-07-07", end: "2020-07-8"},
|
||||
{begin: "2020-07-10", end: "2020-07-12"},
|
||||
{begin: '2020-07-07', end: '2020-07-8'},
|
||||
{begin: '2020-07-10', end: '2020-07-12'},
|
||||
];
|
||||
expect(EquipmentBooking.isEquipmentAvailable(testDevice)).toBeTrue();
|
||||
});
|
||||
|
||||
test('getFirstEquipmentAvailability', () => {
|
||||
jest.spyOn(Date, 'now')
|
||||
.mockImplementation(() =>
|
||||
new Date('2020-07-09').getTime()
|
||||
);
|
||||
jest
|
||||
.spyOn(Date, 'now')
|
||||
.mockImplementation(() => new Date('2020-07-09').getTime());
|
||||
let testDevice = {
|
||||
id: 1,
|
||||
name: "Petit barbecue",
|
||||
name: 'Petit barbecue',
|
||||
caution: 100,
|
||||
booked_at: [{begin: "2020-07-07", end: "2020-07-10"}]
|
||||
booked_at: [{begin: '2020-07-07', end: '2020-07-10'}],
|
||||
};
|
||||
expect(EquipmentBooking.getFirstEquipmentAvailability(testDevice).getTime()).toBe(new Date("2020-07-11").getTime());
|
||||
testDevice.booked_at = [{begin: "2020-07-07", end: "2020-07-09"}];
|
||||
expect(EquipmentBooking.getFirstEquipmentAvailability(testDevice).getTime()).toBe(new Date("2020-07-10").getTime());
|
||||
expect(
|
||||
EquipmentBooking.getFirstEquipmentAvailability(testDevice).getTime(),
|
||||
).toBe(new Date('2020-07-11').getTime());
|
||||
testDevice.booked_at = [{begin: '2020-07-07', end: '2020-07-09'}];
|
||||
expect(
|
||||
EquipmentBooking.getFirstEquipmentAvailability(testDevice).getTime(),
|
||||
).toBe(new Date('2020-07-10').getTime());
|
||||
testDevice.booked_at = [
|
||||
{begin: "2020-07-07", end: "2020-07-09"},
|
||||
{begin: "2020-07-10", end: "2020-07-16"},
|
||||
{begin: '2020-07-07', end: '2020-07-09'},
|
||||
{begin: '2020-07-10', end: '2020-07-16'},
|
||||
];
|
||||
expect(EquipmentBooking.getFirstEquipmentAvailability(testDevice).getTime()).toBe(new Date("2020-07-17").getTime());
|
||||
expect(
|
||||
EquipmentBooking.getFirstEquipmentAvailability(testDevice).getTime(),
|
||||
).toBe(new Date('2020-07-17').getTime());
|
||||
testDevice.booked_at = [
|
||||
{begin: "2020-07-07", end: "2020-07-09"},
|
||||
{begin: "2020-07-10", end: "2020-07-12"},
|
||||
{begin: "2020-07-14", end: "2020-07-16"},
|
||||
{begin: '2020-07-07', end: '2020-07-09'},
|
||||
{begin: '2020-07-10', end: '2020-07-12'},
|
||||
{begin: '2020-07-14', end: '2020-07-16'},
|
||||
];
|
||||
expect(EquipmentBooking.getFirstEquipmentAvailability(testDevice).getTime()).toBe(new Date("2020-07-13").getTime());
|
||||
expect(
|
||||
EquipmentBooking.getFirstEquipmentAvailability(testDevice).getTime(),
|
||||
).toBe(new Date('2020-07-13').getTime());
|
||||
});
|
||||
|
||||
test('getRelativeDateString', () => {
|
||||
jest.spyOn(Date, 'now')
|
||||
.mockImplementation(() =>
|
||||
new Date('2020-07-09').getTime()
|
||||
jest
|
||||
.spyOn(Date, 'now')
|
||||
.mockImplementation(() => new Date('2020-07-09').getTime());
|
||||
jest.spyOn(i18n, 't').mockImplementation((translationString: string) => {
|
||||
const prefix = 'screens.equipment.';
|
||||
if (translationString === prefix + 'otherYear') return '0';
|
||||
else if (translationString === prefix + 'otherMonth') return '1';
|
||||
else if (translationString === prefix + 'thisMonth') return '2';
|
||||
else if (translationString === prefix + 'tomorrow') return '3';
|
||||
else if (translationString === prefix + 'today') return '4';
|
||||
else return null;
|
||||
});
|
||||
expect(EquipmentBooking.getRelativeDateString(new Date('2020-07-09'))).toBe(
|
||||
'4',
|
||||
);
|
||||
jest.spyOn(i18n, 't')
|
||||
.mockImplementation((translationString: string) => {
|
||||
const prefix = "screens.equipment.";
|
||||
if (translationString === prefix + "otherYear")
|
||||
return "0";
|
||||
else if (translationString === prefix + "otherMonth")
|
||||
return "1";
|
||||
else if (translationString === prefix + "thisMonth")
|
||||
return "2";
|
||||
else if (translationString === prefix + "tomorrow")
|
||||
return "3";
|
||||
else if (translationString === prefix + "today")
|
||||
return "4";
|
||||
else
|
||||
return null;
|
||||
}
|
||||
expect(EquipmentBooking.getRelativeDateString(new Date('2020-07-10'))).toBe(
|
||||
'3',
|
||||
);
|
||||
expect(EquipmentBooking.getRelativeDateString(new Date('2020-07-11'))).toBe(
|
||||
'2',
|
||||
);
|
||||
expect(EquipmentBooking.getRelativeDateString(new Date('2020-07-30'))).toBe(
|
||||
'2',
|
||||
);
|
||||
expect(EquipmentBooking.getRelativeDateString(new Date('2020-08-30'))).toBe(
|
||||
'1',
|
||||
);
|
||||
expect(EquipmentBooking.getRelativeDateString(new Date('2020-11-10'))).toBe(
|
||||
'1',
|
||||
);
|
||||
expect(EquipmentBooking.getRelativeDateString(new Date('2021-11-10'))).toBe(
|
||||
'0',
|
||||
);
|
||||
expect(EquipmentBooking.getRelativeDateString(new Date("2020-07-09"))).toBe("4");
|
||||
expect(EquipmentBooking.getRelativeDateString(new Date("2020-07-10"))).toBe("3");
|
||||
expect(EquipmentBooking.getRelativeDateString(new Date("2020-07-11"))).toBe("2");
|
||||
expect(EquipmentBooking.getRelativeDateString(new Date("2020-07-30"))).toBe("2");
|
||||
expect(EquipmentBooking.getRelativeDateString(new Date("2020-08-30"))).toBe("1");
|
||||
expect(EquipmentBooking.getRelativeDateString(new Date("2020-11-10"))).toBe("1");
|
||||
expect(EquipmentBooking.getRelativeDateString(new Date("2021-11-10"))).toBe("0");
|
||||
});
|
||||
|
||||
test('getValidRange', () => {
|
||||
let testDevice = {
|
||||
id: 1,
|
||||
name: "Petit barbecue",
|
||||
name: 'Petit barbecue',
|
||||
caution: 100,
|
||||
booked_at: [{begin: "2020-07-07", end: "2020-07-10"}]
|
||||
booked_at: [{begin: '2020-07-07', end: '2020-07-10'}],
|
||||
};
|
||||
let start = new Date("2020-07-11");
|
||||
let end = new Date("2020-07-15");
|
||||
let start = new Date('2020-07-11');
|
||||
let end = new Date('2020-07-15');
|
||||
let result = [
|
||||
"2020-07-11",
|
||||
"2020-07-12",
|
||||
"2020-07-13",
|
||||
"2020-07-14",
|
||||
"2020-07-15",
|
||||
'2020-07-11',
|
||||
'2020-07-12',
|
||||
'2020-07-13',
|
||||
'2020-07-14',
|
||||
'2020-07-15',
|
||||
];
|
||||
expect(EquipmentBooking.getValidRange(start, end, testDevice)).toStrictEqual(result);
|
||||
expect(EquipmentBooking.getValidRange(start, end, testDevice)).toStrictEqual(
|
||||
result,
|
||||
);
|
||||
testDevice.booked_at = [
|
||||
{begin: "2020-07-07", end: "2020-07-10"},
|
||||
{begin: "2020-07-13", end: "2020-07-15"},
|
||||
{begin: '2020-07-07', end: '2020-07-10'},
|
||||
{begin: '2020-07-13', end: '2020-07-15'},
|
||||
];
|
||||
result = [
|
||||
"2020-07-11",
|
||||
"2020-07-12",
|
||||
];
|
||||
expect(EquipmentBooking.getValidRange(start, end, testDevice)).toStrictEqual(result);
|
||||
result = ['2020-07-11', '2020-07-12'];
|
||||
expect(EquipmentBooking.getValidRange(start, end, testDevice)).toStrictEqual(
|
||||
result,
|
||||
);
|
||||
|
||||
testDevice.booked_at = [{begin: "2020-07-12", end: "2020-07-13"}];
|
||||
result = ["2020-07-11"];
|
||||
expect(EquipmentBooking.getValidRange(start, end, testDevice)).toStrictEqual(result);
|
||||
testDevice.booked_at = [{begin: "2020-07-07", end: "2020-07-12"},];
|
||||
result = [
|
||||
"2020-07-13",
|
||||
"2020-07-14",
|
||||
"2020-07-15",
|
||||
];
|
||||
expect(EquipmentBooking.getValidRange(end, start, testDevice)).toStrictEqual(result);
|
||||
start = new Date("2020-07-14");
|
||||
end = new Date("2020-07-14");
|
||||
result = [
|
||||
"2020-07-14",
|
||||
];
|
||||
expect(EquipmentBooking.getValidRange(start, start, testDevice)).toStrictEqual(result);
|
||||
expect(EquipmentBooking.getValidRange(end, start, testDevice)).toStrictEqual(result);
|
||||
expect(EquipmentBooking.getValidRange(start, end, null)).toStrictEqual(result);
|
||||
testDevice.booked_at = [{begin: '2020-07-12', end: '2020-07-13'}];
|
||||
result = ['2020-07-11'];
|
||||
expect(EquipmentBooking.getValidRange(start, end, testDevice)).toStrictEqual(
|
||||
result,
|
||||
);
|
||||
testDevice.booked_at = [{begin: '2020-07-07', end: '2020-07-12'}];
|
||||
result = ['2020-07-13', '2020-07-14', '2020-07-15'];
|
||||
expect(EquipmentBooking.getValidRange(end, start, testDevice)).toStrictEqual(
|
||||
result,
|
||||
);
|
||||
start = new Date('2020-07-14');
|
||||
end = new Date('2020-07-14');
|
||||
result = ['2020-07-14'];
|
||||
expect(
|
||||
EquipmentBooking.getValidRange(start, start, testDevice),
|
||||
).toStrictEqual(result);
|
||||
expect(EquipmentBooking.getValidRange(end, start, testDevice)).toStrictEqual(
|
||||
result,
|
||||
);
|
||||
expect(EquipmentBooking.getValidRange(start, end, null)).toStrictEqual(
|
||||
result,
|
||||
);
|
||||
|
||||
start = new Date("2020-07-14");
|
||||
end = new Date("2020-07-17");
|
||||
result = [
|
||||
"2020-07-14",
|
||||
"2020-07-15",
|
||||
"2020-07-16",
|
||||
"2020-07-17",
|
||||
];
|
||||
expect(EquipmentBooking.getValidRange(start, end, null)).toStrictEqual(result);
|
||||
start = new Date('2020-07-14');
|
||||
end = new Date('2020-07-17');
|
||||
result = ['2020-07-14', '2020-07-15', '2020-07-16', '2020-07-17'];
|
||||
expect(EquipmentBooking.getValidRange(start, end, null)).toStrictEqual(
|
||||
result,
|
||||
);
|
||||
|
||||
testDevice.booked_at = [{begin: "2020-07-17", end: "2020-07-17"}];
|
||||
result = [
|
||||
"2020-07-14",
|
||||
"2020-07-15",
|
||||
"2020-07-16",
|
||||
];
|
||||
expect(EquipmentBooking.getValidRange(start, end, testDevice)).toStrictEqual(result);
|
||||
testDevice.booked_at = [{begin: '2020-07-17', end: '2020-07-17'}];
|
||||
result = ['2020-07-14', '2020-07-15', '2020-07-16'];
|
||||
expect(EquipmentBooking.getValidRange(start, end, testDevice)).toStrictEqual(
|
||||
result,
|
||||
);
|
||||
|
||||
testDevice.booked_at = [
|
||||
{begin: "2020-07-12", end: "2020-07-13"},
|
||||
{begin: "2020-07-15", end: "2020-07-20"},
|
||||
{begin: '2020-07-12', end: '2020-07-13'},
|
||||
{begin: '2020-07-15', end: '2020-07-20'},
|
||||
];
|
||||
start = new Date("2020-07-11");
|
||||
end = new Date("2020-07-23");
|
||||
result = [
|
||||
"2020-07-21",
|
||||
"2020-07-22",
|
||||
"2020-07-23",
|
||||
];
|
||||
expect(EquipmentBooking.getValidRange(end, start, testDevice)).toStrictEqual(result);
|
||||
start = new Date('2020-07-11');
|
||||
end = new Date('2020-07-23');
|
||||
result = ['2020-07-21', '2020-07-22', '2020-07-23'];
|
||||
expect(EquipmentBooking.getValidRange(end, start, testDevice)).toStrictEqual(
|
||||
result,
|
||||
);
|
||||
});
|
||||
|
||||
test('generateMarkedDates', () => {
|
||||
let theme = {
|
||||
colors: {
|
||||
primary: "primary",
|
||||
danger: "primary",
|
||||
textDisabled: "primary",
|
||||
}
|
||||
}
|
||||
primary: 'primary',
|
||||
danger: 'primary',
|
||||
textDisabled: 'primary',
|
||||
},
|
||||
};
|
||||
let testDevice = {
|
||||
id: 1,
|
||||
name: "Petit barbecue",
|
||||
name: 'Petit barbecue',
|
||||
caution: 100,
|
||||
booked_at: [{begin: "2020-07-07", end: "2020-07-10"}]
|
||||
booked_at: [{begin: '2020-07-07', end: '2020-07-10'}],
|
||||
};
|
||||
let start = new Date("2020-07-11");
|
||||
let end = new Date("2020-07-13");
|
||||
let start = new Date('2020-07-11');
|
||||
let end = new Date('2020-07-13');
|
||||
let range = EquipmentBooking.getValidRange(start, end, testDevice);
|
||||
let result = {
|
||||
"2020-07-11": {
|
||||
'2020-07-11': {
|
||||
startingDay: true,
|
||||
endingDay: false,
|
||||
color: theme.colors.primary
|
||||
color: theme.colors.primary,
|
||||
},
|
||||
"2020-07-12": {
|
||||
'2020-07-12': {
|
||||
startingDay: false,
|
||||
endingDay: false,
|
||||
color: theme.colors.danger
|
||||
color: theme.colors.danger,
|
||||
},
|
||||
"2020-07-13": {
|
||||
'2020-07-13': {
|
||||
startingDay: false,
|
||||
endingDay: true,
|
||||
color: theme.colors.primary
|
||||
color: theme.colors.primary,
|
||||
},
|
||||
};
|
||||
expect(EquipmentBooking.generateMarkedDates(true, theme, range)).toStrictEqual(result);
|
||||
expect(
|
||||
EquipmentBooking.generateMarkedDates(true, theme, range),
|
||||
).toStrictEqual(result);
|
||||
result = {
|
||||
"2020-07-11": {
|
||||
'2020-07-11': {
|
||||
startingDay: true,
|
||||
endingDay: false,
|
||||
color: theme.colors.textDisabled
|
||||
color: theme.colors.textDisabled,
|
||||
},
|
||||
"2020-07-12": {
|
||||
'2020-07-12': {
|
||||
startingDay: false,
|
||||
endingDay: false,
|
||||
color: theme.colors.textDisabled
|
||||
color: theme.colors.textDisabled,
|
||||
},
|
||||
"2020-07-13": {
|
||||
'2020-07-13': {
|
||||
startingDay: false,
|
||||
endingDay: true,
|
||||
color: theme.colors.textDisabled
|
||||
color: theme.colors.textDisabled,
|
||||
},
|
||||
};
|
||||
expect(EquipmentBooking.generateMarkedDates(false, theme, range)).toStrictEqual(result);
|
||||
expect(
|
||||
EquipmentBooking.generateMarkedDates(false, theme, range),
|
||||
).toStrictEqual(result);
|
||||
result = {
|
||||
"2020-07-11": {
|
||||
'2020-07-11': {
|
||||
startingDay: true,
|
||||
endingDay: false,
|
||||
color: theme.colors.textDisabled
|
||||
color: theme.colors.textDisabled,
|
||||
},
|
||||
"2020-07-12": {
|
||||
'2020-07-12': {
|
||||
startingDay: false,
|
||||
endingDay: false,
|
||||
color: theme.colors.textDisabled
|
||||
color: theme.colors.textDisabled,
|
||||
},
|
||||
"2020-07-13": {
|
||||
'2020-07-13': {
|
||||
startingDay: false,
|
||||
endingDay: true,
|
||||
color: theme.colors.textDisabled
|
||||
color: theme.colors.textDisabled,
|
||||
},
|
||||
};
|
||||
range = EquipmentBooking.getValidRange(end, start, testDevice);
|
||||
expect(EquipmentBooking.generateMarkedDates(false, theme, range)).toStrictEqual(result);
|
||||
expect(
|
||||
EquipmentBooking.generateMarkedDates(false, theme, range),
|
||||
).toStrictEqual(result);
|
||||
|
||||
testDevice.booked_at = [{begin: "2020-07-13", end: "2020-07-15"},];
|
||||
testDevice.booked_at = [{begin: '2020-07-13', end: '2020-07-15'}];
|
||||
result = {
|
||||
"2020-07-11": {
|
||||
'2020-07-11': {
|
||||
startingDay: true,
|
||||
endingDay: false,
|
||||
color: theme.colors.primary
|
||||
color: theme.colors.primary,
|
||||
},
|
||||
"2020-07-12": {
|
||||
'2020-07-12': {
|
||||
startingDay: false,
|
||||
endingDay: true,
|
||||
color: theme.colors.primary
|
||||
color: theme.colors.primary,
|
||||
},
|
||||
};
|
||||
range = EquipmentBooking.getValidRange(start, end, testDevice);
|
||||
expect(EquipmentBooking.generateMarkedDates(true, theme, range)).toStrictEqual(result);
|
||||
expect(
|
||||
EquipmentBooking.generateMarkedDates(true, theme, range),
|
||||
).toStrictEqual(result);
|
||||
|
||||
testDevice.booked_at = [{begin: "2020-07-12", end: "2020-07-13"},];
|
||||
testDevice.booked_at = [{begin: '2020-07-12', end: '2020-07-13'}];
|
||||
result = {
|
||||
"2020-07-11": {
|
||||
'2020-07-11': {
|
||||
startingDay: true,
|
||||
endingDay: true,
|
||||
color: theme.colors.primary
|
||||
color: theme.colors.primary,
|
||||
},
|
||||
};
|
||||
range = EquipmentBooking.getValidRange(start, end, testDevice);
|
||||
expect(EquipmentBooking.generateMarkedDates(true, theme, range)).toStrictEqual(result);
|
||||
expect(
|
||||
EquipmentBooking.generateMarkedDates(true, theme, range),
|
||||
).toStrictEqual(result);
|
||||
|
||||
testDevice.booked_at = [
|
||||
{begin: "2020-07-12", end: "2020-07-13"},
|
||||
{begin: "2020-07-15", end: "2020-07-20"},
|
||||
{begin: '2020-07-12', end: '2020-07-13'},
|
||||
{begin: '2020-07-15', end: '2020-07-20'},
|
||||
];
|
||||
start = new Date("2020-07-11");
|
||||
end = new Date("2020-07-23");
|
||||
start = new Date('2020-07-11');
|
||||
end = new Date('2020-07-23');
|
||||
result = {
|
||||
"2020-07-11": {
|
||||
'2020-07-11': {
|
||||
startingDay: true,
|
||||
endingDay: true,
|
||||
color: theme.colors.primary
|
||||
color: theme.colors.primary,
|
||||
},
|
||||
};
|
||||
range = EquipmentBooking.getValidRange(start, end, testDevice);
|
||||
expect(EquipmentBooking.generateMarkedDates(true, theme, range)).toStrictEqual(result);
|
||||
expect(
|
||||
EquipmentBooking.generateMarkedDates(true, theme, range),
|
||||
).toStrictEqual(result);
|
||||
|
||||
result = {
|
||||
"2020-07-21": {
|
||||
'2020-07-21': {
|
||||
startingDay: true,
|
||||
endingDay: false,
|
||||
color: theme.colors.primary
|
||||
color: theme.colors.primary,
|
||||
},
|
||||
"2020-07-22": {
|
||||
'2020-07-22': {
|
||||
startingDay: false,
|
||||
endingDay: false,
|
||||
color: theme.colors.danger
|
||||
color: theme.colors.danger,
|
||||
},
|
||||
"2020-07-23": {
|
||||
'2020-07-23': {
|
||||
startingDay: false,
|
||||
endingDay: true,
|
||||
color: theme.colors.primary
|
||||
color: theme.colors.primary,
|
||||
},
|
||||
};
|
||||
range = EquipmentBooking.getValidRange(end, start, testDevice);
|
||||
expect(EquipmentBooking.generateMarkedDates(true, theme, range)).toStrictEqual(result);
|
||||
expect(
|
||||
EquipmentBooking.generateMarkedDates(true, theme, range),
|
||||
).toStrictEqual(result);
|
||||
});
|
||||
|
|
|
@ -1,35 +1,41 @@
|
|||
/* eslint-disable */
|
||||
|
||||
import React from 'react';
|
||||
import * as Planning from "../../src/utils/Planning";
|
||||
import * as Planning from '../../src/utils/Planning';
|
||||
|
||||
test('isDescriptionEmpty', () => {
|
||||
expect(Planning.isDescriptionEmpty("")).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty(" ")).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty('')).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty(' ')).toBeTrue();
|
||||
// noinspection CheckTagEmptyBody
|
||||
expect(Planning.isDescriptionEmpty("<p></p>")).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty("<p> </p>")).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty("<p><br></p>")).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty("<p><br></p><p><br></p>")).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty("<p><br><br><br></p>")).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty("<p><br>")).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty('<p></p>')).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty('<p> </p>')).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty('<p><br></p>')).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty('<p><br></p><p><br></p>')).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty('<p><br><br><br></p>')).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty('<p><br>')).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty(null)).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty(undefined)).toBeTrue();
|
||||
expect(Planning.isDescriptionEmpty("coucou")).toBeFalse();
|
||||
expect(Planning.isDescriptionEmpty("<p>coucou</p>")).toBeFalse();
|
||||
expect(Planning.isDescriptionEmpty('coucou')).toBeFalse();
|
||||
expect(Planning.isDescriptionEmpty('<p>coucou</p>')).toBeFalse();
|
||||
});
|
||||
|
||||
test('isEventDateStringFormatValid', () => {
|
||||
expect(Planning.isEventDateStringFormatValid("2020-03-21 09:00")).toBeTrue();
|
||||
expect(Planning.isEventDateStringFormatValid("3214-64-12 01:16")).toBeTrue();
|
||||
expect(Planning.isEventDateStringFormatValid('2020-03-21 09:00')).toBeTrue();
|
||||
expect(Planning.isEventDateStringFormatValid('3214-64-12 01:16')).toBeTrue();
|
||||
|
||||
expect(Planning.isEventDateStringFormatValid("3214-64-12 01:16:00")).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid("3214-64-12 1:16")).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid("3214-f4-12 01:16")).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid("sqdd 09:00")).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid("2020-03-21")).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid("2020-03-21 truc")).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid("3214-64-12 1:16:65")).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid("garbage")).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid("")).toBeFalse();
|
||||
expect(
|
||||
Planning.isEventDateStringFormatValid('3214-64-12 01:16:00'),
|
||||
).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid('3214-64-12 1:16')).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid('3214-f4-12 01:16')).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid('sqdd 09:00')).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid('2020-03-21')).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid('2020-03-21 truc')).toBeFalse();
|
||||
expect(
|
||||
Planning.isEventDateStringFormatValid('3214-64-12 1:16:65'),
|
||||
).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid('garbage')).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid('')).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid(undefined)).toBeFalse();
|
||||
expect(Planning.isEventDateStringFormatValid(null)).toBeFalse();
|
||||
});
|
||||
|
@ -37,136 +43,144 @@ test('isEventDateStringFormatValid', () => {
|
|||
test('stringToDate', () => {
|
||||
let testDate = new Date();
|
||||
expect(Planning.stringToDate(undefined)).toBeNull();
|
||||
expect(Planning.stringToDate("")).toBeNull();
|
||||
expect(Planning.stringToDate("garbage")).toBeNull();
|
||||
expect(Planning.stringToDate("2020-03-21")).toBeNull();
|
||||
expect(Planning.stringToDate("09:00:00")).toBeNull();
|
||||
expect(Planning.stringToDate("2020-03-21 09:g0")).toBeNull();
|
||||
expect(Planning.stringToDate("2020-03-21 09:g0:")).toBeNull();
|
||||
expect(Planning.stringToDate('')).toBeNull();
|
||||
expect(Planning.stringToDate('garbage')).toBeNull();
|
||||
expect(Planning.stringToDate('2020-03-21')).toBeNull();
|
||||
expect(Planning.stringToDate('09:00:00')).toBeNull();
|
||||
expect(Planning.stringToDate('2020-03-21 09:g0')).toBeNull();
|
||||
expect(Planning.stringToDate('2020-03-21 09:g0:')).toBeNull();
|
||||
testDate.setFullYear(2020, 2, 21);
|
||||
testDate.setHours(9, 0, 0, 0);
|
||||
expect(Planning.stringToDate("2020-03-21 09:00")).toEqual(testDate);
|
||||
expect(Planning.stringToDate('2020-03-21 09:00')).toEqual(testDate);
|
||||
testDate.setFullYear(2020, 0, 31);
|
||||
testDate.setHours(18, 30, 0, 0);
|
||||
expect(Planning.stringToDate("2020-01-31 18:30")).toEqual(testDate);
|
||||
expect(Planning.stringToDate('2020-01-31 18:30')).toEqual(testDate);
|
||||
testDate.setFullYear(2020, 50, 50);
|
||||
testDate.setHours(65, 65, 0, 0);
|
||||
expect(Planning.stringToDate("2020-51-50 65:65")).toEqual(testDate);
|
||||
expect(Planning.stringToDate('2020-51-50 65:65')).toEqual(testDate);
|
||||
});
|
||||
|
||||
test('getFormattedEventTime', () => {
|
||||
expect(Planning.getFormattedEventTime(null, null))
|
||||
.toBe('/ - /');
|
||||
expect(Planning.getFormattedEventTime(undefined, undefined))
|
||||
.toBe('/ - /');
|
||||
expect(Planning.getFormattedEventTime("20:30", "23:00"))
|
||||
.toBe('/ - /');
|
||||
expect(Planning.getFormattedEventTime("2020-03-30", "2020-03-31"))
|
||||
.toBe('/ - /');
|
||||
expect(Planning.getFormattedEventTime(null, null)).toBe('/ - /');
|
||||
expect(Planning.getFormattedEventTime(undefined, undefined)).toBe('/ - /');
|
||||
expect(Planning.getFormattedEventTime('20:30', '23:00')).toBe('/ - /');
|
||||
expect(Planning.getFormattedEventTime('2020-03-30', '2020-03-31')).toBe(
|
||||
'/ - /',
|
||||
);
|
||||
|
||||
|
||||
expect(Planning.getFormattedEventTime("2020-03-21 09:00", "2020-03-21 09:00"))
|
||||
.toBe('09:00');
|
||||
expect(Planning.getFormattedEventTime("2020-03-21 09:00", "2020-03-22 17:00"))
|
||||
.toBe('09:00 - 23:59');
|
||||
expect(Planning.getFormattedEventTime("2020-03-30 20:30", "2020-03-30 23:00"))
|
||||
.toBe('20:30 - 23:00');
|
||||
expect(
|
||||
Planning.getFormattedEventTime('2020-03-21 09:00', '2020-03-21 09:00'),
|
||||
).toBe('09:00');
|
||||
expect(
|
||||
Planning.getFormattedEventTime('2020-03-21 09:00', '2020-03-22 17:00'),
|
||||
).toBe('09:00 - 23:59');
|
||||
expect(
|
||||
Planning.getFormattedEventTime('2020-03-30 20:30', '2020-03-30 23:00'),
|
||||
).toBe('20:30 - 23:00');
|
||||
});
|
||||
|
||||
test('getDateOnlyString', () => {
|
||||
expect(Planning.getDateOnlyString("2020-03-21 09:00")).toBe("2020-03-21");
|
||||
expect(Planning.getDateOnlyString("2021-12-15 09:00")).toBe("2021-12-15");
|
||||
expect(Planning.getDateOnlyString("2021-12-o5 09:00")).toBeNull();
|
||||
expect(Planning.getDateOnlyString("2021-12-15 09:")).toBeNull();
|
||||
expect(Planning.getDateOnlyString("2021-12-15")).toBeNull();
|
||||
expect(Planning.getDateOnlyString("garbage")).toBeNull();
|
||||
expect(Planning.getDateOnlyString('2020-03-21 09:00')).toBe('2020-03-21');
|
||||
expect(Planning.getDateOnlyString('2021-12-15 09:00')).toBe('2021-12-15');
|
||||
expect(Planning.getDateOnlyString('2021-12-o5 09:00')).toBeNull();
|
||||
expect(Planning.getDateOnlyString('2021-12-15 09:')).toBeNull();
|
||||
expect(Planning.getDateOnlyString('2021-12-15')).toBeNull();
|
||||
expect(Planning.getDateOnlyString('garbage')).toBeNull();
|
||||
});
|
||||
|
||||
test('isEventBefore', () => {
|
||||
expect(Planning.isEventBefore(
|
||||
"2020-03-21 09:00", "2020-03-21 10:00")).toBeTrue();
|
||||
expect(Planning.isEventBefore(
|
||||
"2020-03-21 10:00", "2020-03-21 10:15")).toBeTrue();
|
||||
expect(Planning.isEventBefore(
|
||||
"2020-03-21 10:15", "2021-03-21 10:15")).toBeTrue();
|
||||
expect(Planning.isEventBefore(
|
||||
"2020-03-21 10:15", "2020-05-21 10:15")).toBeTrue();
|
||||
expect(Planning.isEventBefore(
|
||||
"2020-03-21 10:15", "2020-03-30 10:15")).toBeTrue();
|
||||
expect(
|
||||
Planning.isEventBefore('2020-03-21 09:00', '2020-03-21 10:00'),
|
||||
).toBeTrue();
|
||||
expect(
|
||||
Planning.isEventBefore('2020-03-21 10:00', '2020-03-21 10:15'),
|
||||
).toBeTrue();
|
||||
expect(
|
||||
Planning.isEventBefore('2020-03-21 10:15', '2021-03-21 10:15'),
|
||||
).toBeTrue();
|
||||
expect(
|
||||
Planning.isEventBefore('2020-03-21 10:15', '2020-05-21 10:15'),
|
||||
).toBeTrue();
|
||||
expect(
|
||||
Planning.isEventBefore('2020-03-21 10:15', '2020-03-30 10:15'),
|
||||
).toBeTrue();
|
||||
|
||||
expect(Planning.isEventBefore(
|
||||
"2020-03-21 10:00", "2020-03-21 10:00")).toBeFalse();
|
||||
expect(Planning.isEventBefore(
|
||||
"2020-03-21 10:00", "2020-03-21 09:00")).toBeFalse();
|
||||
expect(Planning.isEventBefore(
|
||||
"2020-03-21 10:15", "2020-03-21 10:00")).toBeFalse();
|
||||
expect(Planning.isEventBefore(
|
||||
"2021-03-21 10:15", "2020-03-21 10:15")).toBeFalse();
|
||||
expect(Planning.isEventBefore(
|
||||
"2020-05-21 10:15", "2020-03-21 10:15")).toBeFalse();
|
||||
expect(Planning.isEventBefore(
|
||||
"2020-03-30 10:15", "2020-03-21 10:15")).toBeFalse();
|
||||
expect(
|
||||
Planning.isEventBefore('2020-03-21 10:00', '2020-03-21 10:00'),
|
||||
).toBeFalse();
|
||||
expect(
|
||||
Planning.isEventBefore('2020-03-21 10:00', '2020-03-21 09:00'),
|
||||
).toBeFalse();
|
||||
expect(
|
||||
Planning.isEventBefore('2020-03-21 10:15', '2020-03-21 10:00'),
|
||||
).toBeFalse();
|
||||
expect(
|
||||
Planning.isEventBefore('2021-03-21 10:15', '2020-03-21 10:15'),
|
||||
).toBeFalse();
|
||||
expect(
|
||||
Planning.isEventBefore('2020-05-21 10:15', '2020-03-21 10:15'),
|
||||
).toBeFalse();
|
||||
expect(
|
||||
Planning.isEventBefore('2020-03-30 10:15', '2020-03-21 10:15'),
|
||||
).toBeFalse();
|
||||
|
||||
expect(Planning.isEventBefore(
|
||||
"garbage", "2020-03-21 10:15")).toBeFalse();
|
||||
expect(Planning.isEventBefore(
|
||||
undefined, undefined)).toBeFalse();
|
||||
expect(Planning.isEventBefore('garbage', '2020-03-21 10:15')).toBeFalse();
|
||||
expect(Planning.isEventBefore(undefined, undefined)).toBeFalse();
|
||||
});
|
||||
|
||||
test('dateToString', () => {
|
||||
let testDate = new Date();
|
||||
testDate.setFullYear(2020, 2, 21);
|
||||
testDate.setHours(9, 0, 0, 0);
|
||||
expect(Planning.dateToString(testDate)).toBe("2020-03-21 09:00");
|
||||
expect(Planning.dateToString(testDate)).toBe('2020-03-21 09:00');
|
||||
testDate.setFullYear(2021, 0, 12);
|
||||
testDate.setHours(9, 10, 0, 0);
|
||||
expect(Planning.dateToString(testDate)).toBe("2021-01-12 09:10");
|
||||
expect(Planning.dateToString(testDate)).toBe('2021-01-12 09:10');
|
||||
testDate.setFullYear(2022, 11, 31);
|
||||
testDate.setHours(9, 10, 15, 0);
|
||||
expect(Planning.dateToString(testDate)).toBe("2022-12-31 09:10");
|
||||
expect(Planning.dateToString(testDate)).toBe('2022-12-31 09:10');
|
||||
});
|
||||
|
||||
test('generateEmptyCalendar', () => {
|
||||
jest.spyOn(Date, 'now')
|
||||
.mockImplementation(() =>
|
||||
new Date('2020-01-14T00:00:00.000Z').getTime()
|
||||
);
|
||||
jest
|
||||
.spyOn(Date, 'now')
|
||||
.mockImplementation(() => new Date('2020-01-14T00:00:00.000Z').getTime());
|
||||
let calendar = Planning.generateEmptyCalendar(1);
|
||||
expect(calendar).toHaveProperty("2020-01-14");
|
||||
expect(calendar).toHaveProperty("2020-01-20");
|
||||
expect(calendar).toHaveProperty("2020-02-10");
|
||||
expect(calendar).toHaveProperty('2020-01-14');
|
||||
expect(calendar).toHaveProperty('2020-01-20');
|
||||
expect(calendar).toHaveProperty('2020-02-10');
|
||||
expect(Object.keys(calendar).length).toBe(32);
|
||||
calendar = Planning.generateEmptyCalendar(3);
|
||||
expect(calendar).toHaveProperty("2020-01-14");
|
||||
expect(calendar).toHaveProperty("2020-01-20");
|
||||
expect(calendar).toHaveProperty("2020-02-10");
|
||||
expect(calendar).toHaveProperty("2020-02-14");
|
||||
expect(calendar).toHaveProperty("2020-03-20");
|
||||
expect(calendar).toHaveProperty("2020-04-12");
|
||||
expect(calendar).toHaveProperty('2020-01-14');
|
||||
expect(calendar).toHaveProperty('2020-01-20');
|
||||
expect(calendar).toHaveProperty('2020-02-10');
|
||||
expect(calendar).toHaveProperty('2020-02-14');
|
||||
expect(calendar).toHaveProperty('2020-03-20');
|
||||
expect(calendar).toHaveProperty('2020-04-12');
|
||||
expect(Object.keys(calendar).length).toBe(92);
|
||||
});
|
||||
|
||||
test('pushEventInOrder', () => {
|
||||
let eventArray = [];
|
||||
let event1 = {date_begin: "2020-01-14 09:15"};
|
||||
let event1 = {date_begin: '2020-01-14 09:15'};
|
||||
Planning.pushEventInOrder(eventArray, event1);
|
||||
expect(eventArray.length).toBe(1);
|
||||
expect(eventArray[0]).toBe(event1);
|
||||
|
||||
let event2 = {date_begin: "2020-01-14 10:15"};
|
||||
let event2 = {date_begin: '2020-01-14 10:15'};
|
||||
Planning.pushEventInOrder(eventArray, event2);
|
||||
expect(eventArray.length).toBe(2);
|
||||
expect(eventArray[0]).toBe(event1);
|
||||
expect(eventArray[1]).toBe(event2);
|
||||
|
||||
let event3 = {date_begin: "2020-01-14 10:15", title: "garbage"};
|
||||
let event3 = {date_begin: '2020-01-14 10:15', title: 'garbage'};
|
||||
Planning.pushEventInOrder(eventArray, event3);
|
||||
expect(eventArray.length).toBe(3);
|
||||
expect(eventArray[0]).toBe(event1);
|
||||
expect(eventArray[1]).toBe(event2);
|
||||
expect(eventArray[2]).toBe(event3);
|
||||
|
||||
let event4 = {date_begin: "2020-01-13 09:00"};
|
||||
let event4 = {date_begin: '2020-01-13 09:00'};
|
||||
Planning.pushEventInOrder(eventArray, event4);
|
||||
expect(eventArray.length).toBe(4);
|
||||
expect(eventArray[0]).toBe(event4);
|
||||
|
@ -176,31 +190,29 @@ test('pushEventInOrder', () => {
|
|||
});
|
||||
|
||||
test('generateEventAgenda', () => {
|
||||
jest.spyOn(Date, 'now')
|
||||
.mockImplementation(() =>
|
||||
new Date('2020-01-14T00:00:00.000Z').getTime()
|
||||
);
|
||||
jest
|
||||
.spyOn(Date, 'now')
|
||||
.mockImplementation(() => new Date('2020-01-14T00:00:00.000Z').getTime());
|
||||
let eventList = [
|
||||
{date_begin: "2020-01-14 09:15"},
|
||||
{date_begin: "2020-02-01 09:15"},
|
||||
{date_begin: "2020-01-15 09:15"},
|
||||
{date_begin: "2020-02-01 09:30"},
|
||||
{date_begin: "2020-02-01 08:30"},
|
||||
{date_begin: '2020-01-14 09:15'},
|
||||
{date_begin: '2020-02-01 09:15'},
|
||||
{date_begin: '2020-01-15 09:15'},
|
||||
{date_begin: '2020-02-01 09:30'},
|
||||
{date_begin: '2020-02-01 08:30'},
|
||||
];
|
||||
const calendar = Planning.generateEventAgenda(eventList, 2);
|
||||
expect(calendar["2020-01-14"].length).toBe(1);
|
||||
expect(calendar["2020-01-14"][0]).toBe(eventList[0]);
|
||||
expect(calendar["2020-01-15"].length).toBe(1);
|
||||
expect(calendar["2020-01-15"][0]).toBe(eventList[2]);
|
||||
expect(calendar["2020-02-01"].length).toBe(3);
|
||||
expect(calendar["2020-02-01"][0]).toBe(eventList[4]);
|
||||
expect(calendar["2020-02-01"][1]).toBe(eventList[1]);
|
||||
expect(calendar["2020-02-01"][2]).toBe(eventList[3]);
|
||||
expect(calendar['2020-01-14'].length).toBe(1);
|
||||
expect(calendar['2020-01-14'][0]).toBe(eventList[0]);
|
||||
expect(calendar['2020-01-15'].length).toBe(1);
|
||||
expect(calendar['2020-01-15'][0]).toBe(eventList[2]);
|
||||
expect(calendar['2020-02-01'].length).toBe(3);
|
||||
expect(calendar['2020-02-01'][0]).toBe(eventList[4]);
|
||||
expect(calendar['2020-02-01'][1]).toBe(eventList[1]);
|
||||
expect(calendar['2020-02-01'][2]).toBe(eventList[3]);
|
||||
});
|
||||
|
||||
test('getCurrentDateString', () => {
|
||||
jest.spyOn(Date, 'now')
|
||||
.mockImplementation(() => {
|
||||
jest.spyOn(Date, 'now').mockImplementation(() => {
|
||||
let date = new Date();
|
||||
date.setFullYear(2020, 0, 14);
|
||||
date.setHours(15, 30, 54, 65);
|
||||
|
|
|
@ -1,142 +1,167 @@
|
|||
/* eslint-disable */
|
||||
|
||||
import React from 'react';
|
||||
import {getCleanedMachineWatched, getMachineEndDate, getMachineOfId, isMachineWatched} from "../../src/utils/Proxiwash";
|
||||
import {
|
||||
getCleanedMachineWatched,
|
||||
getMachineEndDate,
|
||||
getMachineOfId,
|
||||
isMachineWatched,
|
||||
} from '../../src/utils/Proxiwash';
|
||||
|
||||
test('getMachineEndDate', () => {
|
||||
jest.spyOn(Date, 'now')
|
||||
.mockImplementation(() =>
|
||||
new Date('2020-01-14T15:00:00.000Z').getTime()
|
||||
);
|
||||
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());
|
||||
expect(getMachineEndDate({endTime: '23:10'}).getTime()).toBe(
|
||||
expectDate.getTime(),
|
||||
);
|
||||
|
||||
expectDate.setHours(16);
|
||||
expectDate.setMinutes(30);
|
||||
expect(getMachineEndDate({endTime: "16:30"}).getTime()).toBe(expectDate.getTime());
|
||||
|
||||
expect(getMachineEndDate({endTime: "15:30"})).toBeNull();
|
||||
|
||||
expect(getMachineEndDate({endTime: "13:10"})).toBeNull();
|
||||
|
||||
jest.spyOn(Date, 'now')
|
||||
.mockImplementation(() =>
|
||||
new Date('2020-01-14T23:00:00.000Z').getTime()
|
||||
expect(getMachineEndDate({endTime: '16:30'}).getTime()).toBe(
|
||||
expectDate.getTime(),
|
||||
);
|
||||
|
||||
expect(getMachineEndDate({endTime: '15:30'})).toBeNull();
|
||||
|
||||
expect(getMachineEndDate({endTime: '13:10'})).toBeNull();
|
||||
|
||||
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());
|
||||
expect(getMachineEndDate({endTime: '00:30'}).getTime()).toBe(
|
||||
expectDate.getTime(),
|
||||
);
|
||||
});
|
||||
|
||||
test('isMachineWatched', () => {
|
||||
let machineList = [
|
||||
{
|
||||
number: "0",
|
||||
endTime: "23:30",
|
||||
number: '0',
|
||||
endTime: '23:30',
|
||||
},
|
||||
{
|
||||
number: "1",
|
||||
endTime: "20: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();
|
||||
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();
|
||||
});
|
||||
|
||||
test('getMachineOfId', () => {
|
||||
let machineList = [
|
||||
{
|
||||
number: "0",
|
||||
number: '0',
|
||||
},
|
||||
{
|
||||
number: "1",
|
||||
number: '1',
|
||||
},
|
||||
];
|
||||
expect(getMachineOfId("0", machineList)).toStrictEqual({number: "0"});
|
||||
expect(getMachineOfId("1", machineList)).toStrictEqual({number: "1"});
|
||||
expect(getMachineOfId("3", machineList)).toBeNull();
|
||||
expect(getMachineOfId('0', machineList)).toStrictEqual({number: '0'});
|
||||
expect(getMachineOfId('1', machineList)).toStrictEqual({number: '1'});
|
||||
expect(getMachineOfId('3', machineList)).toBeNull();
|
||||
});
|
||||
|
||||
test('getCleanedMachineWatched', () => {
|
||||
let machineList = [
|
||||
{
|
||||
number: "0",
|
||||
endTime: "23:30",
|
||||
number: '0',
|
||||
endTime: '23:30',
|
||||
},
|
||||
{
|
||||
number: "1",
|
||||
endTime: "20:30",
|
||||
number: '1',
|
||||
endTime: '20:30',
|
||||
},
|
||||
{
|
||||
number: "2",
|
||||
endTime: "",
|
||||
number: '2',
|
||||
endTime: '',
|
||||
},
|
||||
];
|
||||
let watchList = [
|
||||
{
|
||||
number: "0",
|
||||
endTime: "23:30",
|
||||
number: '0',
|
||||
endTime: '23:30',
|
||||
},
|
||||
{
|
||||
number: "1",
|
||||
endTime: "20:30",
|
||||
number: '1',
|
||||
endTime: '20:30',
|
||||
},
|
||||
{
|
||||
number: "2",
|
||||
endTime: "",
|
||||
number: '2',
|
||||
endTime: '',
|
||||
},
|
||||
];
|
||||
let cleanedList = watchList;
|
||||
expect(getCleanedMachineWatched(watchList, machineList)).toStrictEqual(cleanedList);
|
||||
expect(getCleanedMachineWatched(watchList, machineList)).toStrictEqual(
|
||||
cleanedList,
|
||||
);
|
||||
|
||||
watchList = [
|
||||
{
|
||||
number: "0",
|
||||
endTime: "23:30",
|
||||
number: '0',
|
||||
endTime: '23:30',
|
||||
},
|
||||
{
|
||||
number: "1",
|
||||
endTime: "20:30",
|
||||
number: '1',
|
||||
endTime: '20:30',
|
||||
},
|
||||
{
|
||||
number: "2",
|
||||
endTime: "15:30",
|
||||
number: '2',
|
||||
endTime: '15:30',
|
||||
},
|
||||
];
|
||||
cleanedList = [
|
||||
{
|
||||
number: "0",
|
||||
endTime: "23:30",
|
||||
number: '0',
|
||||
endTime: '23:30',
|
||||
},
|
||||
{
|
||||
number: "1",
|
||||
endTime: "20:30",
|
||||
number: '1',
|
||||
endTime: '20:30',
|
||||
},
|
||||
];
|
||||
expect(getCleanedMachineWatched(watchList, machineList)).toStrictEqual(cleanedList);
|
||||
expect(getCleanedMachineWatched(watchList, machineList)).toStrictEqual(
|
||||
cleanedList,
|
||||
);
|
||||
|
||||
watchList = [
|
||||
{
|
||||
number: "0",
|
||||
endTime: "23:30",
|
||||
number: '0',
|
||||
endTime: '23:30',
|
||||
},
|
||||
{
|
||||
number: "1",
|
||||
endTime: "20:31",
|
||||
number: '1',
|
||||
endTime: '20:31',
|
||||
},
|
||||
{
|
||||
number: "3",
|
||||
endTime: "15:30",
|
||||
number: '3',
|
||||
endTime: '15:30',
|
||||
},
|
||||
];
|
||||
cleanedList = [
|
||||
{
|
||||
number: "0",
|
||||
endTime: "23:30",
|
||||
number: '0',
|
||||
endTime: '23:30',
|
||||
},
|
||||
];
|
||||
expect(getCleanedMachineWatched(watchList, machineList)).toStrictEqual(cleanedList);
|
||||
expect(getCleanedMachineWatched(watchList, machineList)).toStrictEqual(
|
||||
cleanedList,
|
||||
);
|
||||
});
|
|
@ -1,45 +1,47 @@
|
|||
import React from 'react';
|
||||
import {isResponseValid} from "../../src/utils/WebData";
|
||||
/* eslint-disable */
|
||||
|
||||
let fetch = require('isomorphic-fetch'); // fetch is not implemented in nodeJS but in react-native
|
||||
import React from 'react';
|
||||
import {isApiResponseValid} from '../../src/utils/WebData';
|
||||
|
||||
const fetch = require('isomorphic-fetch'); // fetch is not implemented in nodeJS but in react-native
|
||||
|
||||
test('isRequestResponseValid', () => {
|
||||
let json = {
|
||||
error: 0,
|
||||
data: {}
|
||||
data: {},
|
||||
};
|
||||
expect(isResponseValid(json)).toBeTrue();
|
||||
expect(isApiResponseValid(json)).toBeTrue();
|
||||
json = {
|
||||
error: 1,
|
||||
data: {}
|
||||
data: {},
|
||||
};
|
||||
expect(isResponseValid(json)).toBeTrue();
|
||||
expect(isApiResponseValid(json)).toBeTrue();
|
||||
json = {
|
||||
error: 50,
|
||||
data: {}
|
||||
data: {},
|
||||
};
|
||||
expect(isResponseValid(json)).toBeTrue();
|
||||
expect(isApiResponseValid(json)).toBeTrue();
|
||||
json = {
|
||||
error: 50,
|
||||
data: {truc: 'machin'}
|
||||
data: {truc: 'machin'},
|
||||
};
|
||||
expect(isResponseValid(json)).toBeTrue();
|
||||
expect(isApiResponseValid(json)).toBeTrue();
|
||||
json = {
|
||||
message: 'coucou'
|
||||
message: 'coucou',
|
||||
};
|
||||
expect(isResponseValid(json)).toBeFalse();
|
||||
expect(isApiResponseValid(json)).toBeFalse();
|
||||
json = {
|
||||
error: 'coucou',
|
||||
data: {truc: 'machin'}
|
||||
data: {truc: 'machin'},
|
||||
};
|
||||
expect(isResponseValid(json)).toBeFalse();
|
||||
expect(isApiResponseValid(json)).toBeFalse();
|
||||
json = {
|
||||
error: 0,
|
||||
data: 'coucou'
|
||||
data: 'coucou',
|
||||
};
|
||||
expect(isResponseValid(json)).toBeFalse();
|
||||
expect(isApiResponseValid(json)).toBeFalse();
|
||||
json = {
|
||||
error: 0,
|
||||
};
|
||||
expect(isResponseValid(json)).toBeFalse();
|
||||
expect(isApiResponseValid(json)).toBeFalse();
|
||||
});
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
/* eslint-disable */
|
||||
|
||||
import React from 'react';
|
||||
import GridManager from "../logic/GridManager";
|
||||
import ScoreManager from "../logic/ScoreManager";
|
||||
import Piece from "../logic/Piece";
|
||||
import GridManager from '../logic/GridManager';
|
||||
import ScoreManager from '../logic/ScoreManager';
|
||||
import Piece from '../logic/Piece';
|
||||
|
||||
let colors = {
|
||||
tetrisBackground: "#000002"
|
||||
tetrisBackground: '#000002',
|
||||
};
|
||||
|
||||
jest.mock("../ScoreManager");
|
||||
jest.mock('../ScoreManager');
|
||||
|
||||
afterAll(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
|
||||
test('getEmptyLine', () => {
|
||||
let g = new GridManager(2, 2, colors);
|
||||
expect(g.getEmptyLine(2)).toStrictEqual([
|
||||
|
@ -89,9 +90,11 @@ test('clearLines', () => {
|
|||
|
||||
test('freezeTetromino', () => {
|
||||
let g = new GridManager(2, 2, colors);
|
||||
let spy1 = jest.spyOn(GridManager.prototype, 'getLinesToClear')
|
||||
let spy1 = jest
|
||||
.spyOn(GridManager.prototype, 'getLinesToClear')
|
||||
.mockImplementation(() => {});
|
||||
let spy2 = jest.spyOn(GridManager.prototype, 'clearLines')
|
||||
let spy2 = jest
|
||||
.spyOn(GridManager.prototype, 'clearLines')
|
||||
.mockImplementation(() => {});
|
||||
g.freezeTetromino(new Piece({}), null);
|
||||
|
||||
|
|
|
@ -1,17 +1,22 @@
|
|||
/* eslint-disable */
|
||||
|
||||
import React from 'react';
|
||||
import Piece from "../logic/Piece";
|
||||
import ShapeI from "../Shapes/ShapeI";
|
||||
import Piece from '../logic/Piece';
|
||||
import ShapeI from '../Shapes/ShapeI';
|
||||
|
||||
let colors = {
|
||||
tetrisI: "#000001",
|
||||
tetrisBackground: "#000002"
|
||||
tetrisI: '#000001',
|
||||
tetrisBackground: '#000002',
|
||||
};
|
||||
|
||||
jest.mock("../Shapes/ShapeI");
|
||||
jest.mock('../Shapes/ShapeI');
|
||||
|
||||
beforeAll(() => {
|
||||
jest.spyOn(Piece.prototype, 'getRandomShape')
|
||||
.mockImplementation((colors: Object) => {return new ShapeI(colors);});
|
||||
jest
|
||||
.spyOn(Piece.prototype, 'getRandomShape')
|
||||
.mockImplementation((colors: Object) => {
|
||||
return new ShapeI(colors);
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
|
@ -21,8 +26,11 @@ afterAll(() => {
|
|||
test('isPositionValid', () => {
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
let spy = jest.spyOn(ShapeI.prototype, 'getCellsCoordinates')
|
||||
.mockImplementation(() => {return [{x: x, y: y}];});
|
||||
let spy = jest
|
||||
.spyOn(ShapeI.prototype, 'getCellsCoordinates')
|
||||
.mockImplementation(() => {
|
||||
return [{x: x, y: y}];
|
||||
});
|
||||
let grid = [
|
||||
[{isEmpty: true}, {isEmpty: true}],
|
||||
[{isEmpty: true}, {isEmpty: false}],
|
||||
|
@ -31,19 +39,26 @@ test('isPositionValid', () => {
|
|||
|
||||
let p = new Piece(colors);
|
||||
expect(p.isPositionValid(grid, size, size)).toBeTrue();
|
||||
x = 1; y = 0;
|
||||
x = 1;
|
||||
y = 0;
|
||||
expect(p.isPositionValid(grid, size, size)).toBeTrue();
|
||||
x = 0; y = 1;
|
||||
x = 0;
|
||||
y = 1;
|
||||
expect(p.isPositionValid(grid, size, size)).toBeTrue();
|
||||
x = 1; y = 1;
|
||||
x = 1;
|
||||
y = 1;
|
||||
expect(p.isPositionValid(grid, size, size)).toBeFalse();
|
||||
x = 2; y = 0;
|
||||
x = 2;
|
||||
y = 0;
|
||||
expect(p.isPositionValid(grid, size, size)).toBeFalse();
|
||||
x = -1; y = 0;
|
||||
x = -1;
|
||||
y = 0;
|
||||
expect(p.isPositionValid(grid, size, size)).toBeFalse();
|
||||
x = 0; y = 2;
|
||||
x = 0;
|
||||
y = 2;
|
||||
expect(p.isPositionValid(grid, size, size)).toBeFalse();
|
||||
x = 0; y = -1;
|
||||
x = 0;
|
||||
y = -1;
|
||||
expect(p.isPositionValid(grid, size, size)).toBeFalse();
|
||||
|
||||
spy.mockRestore();
|
||||
|
@ -53,12 +68,15 @@ test('tryMove', () => {
|
|||
let p = new Piece(colors);
|
||||
const callbackMock = jest.fn();
|
||||
let isValid = true;
|
||||
let spy1 = jest.spyOn(Piece.prototype, 'isPositionValid')
|
||||
.mockImplementation(() => {return isValid;});
|
||||
let spy2 = jest.spyOn(Piece.prototype, 'removeFromGrid')
|
||||
.mockImplementation(() => {});
|
||||
let spy3 = jest.spyOn(Piece.prototype, 'toGrid')
|
||||
let spy1 = jest
|
||||
.spyOn(Piece.prototype, 'isPositionValid')
|
||||
.mockImplementation(() => {
|
||||
return isValid;
|
||||
});
|
||||
let spy2 = jest
|
||||
.spyOn(Piece.prototype, 'removeFromGrid')
|
||||
.mockImplementation(() => {});
|
||||
let spy3 = jest.spyOn(Piece.prototype, 'toGrid').mockImplementation(() => {});
|
||||
|
||||
expect(p.tryMove(-1, 0, null, null, null, callbackMock)).toBeTrue();
|
||||
isValid = false;
|
||||
|
@ -82,12 +100,15 @@ test('tryMove', () => {
|
|||
test('tryRotate', () => {
|
||||
let p = new Piece(colors);
|
||||
let isValid = true;
|
||||
let spy1 = jest.spyOn(Piece.prototype, 'isPositionValid')
|
||||
.mockImplementation(() => {return isValid;});
|
||||
let spy2 = jest.spyOn(Piece.prototype, 'removeFromGrid')
|
||||
.mockImplementation(() => {});
|
||||
let spy3 = jest.spyOn(Piece.prototype, 'toGrid')
|
||||
let spy1 = jest
|
||||
.spyOn(Piece.prototype, 'isPositionValid')
|
||||
.mockImplementation(() => {
|
||||
return isValid;
|
||||
});
|
||||
let spy2 = jest
|
||||
.spyOn(Piece.prototype, 'removeFromGrid')
|
||||
.mockImplementation(() => {});
|
||||
let spy3 = jest.spyOn(Piece.prototype, 'toGrid').mockImplementation(() => {});
|
||||
|
||||
expect(p.tryRotate(null, null, null)).toBeTrue();
|
||||
isValid = false;
|
||||
|
@ -101,14 +122,17 @@ test('tryRotate', () => {
|
|||
spy3.mockRestore();
|
||||
});
|
||||
|
||||
|
||||
test('toGrid', () => {
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
let spy1 = jest.spyOn(ShapeI.prototype, 'getCellsCoordinates')
|
||||
.mockImplementation(() => {return [{x: x, y: y}];});
|
||||
let spy2 = jest.spyOn(ShapeI.prototype, 'getColor')
|
||||
.mockImplementation(() => {return colors.tetrisI;});
|
||||
let spy1 = jest
|
||||
.spyOn(ShapeI.prototype, 'getCellsCoordinates')
|
||||
.mockImplementation(() => {
|
||||
return [{x: x, y: y}];
|
||||
});
|
||||
let spy2 = jest.spyOn(ShapeI.prototype, 'getColor').mockImplementation(() => {
|
||||
return colors.tetrisI;
|
||||
});
|
||||
let grid = [
|
||||
[{isEmpty: true}, {isEmpty: true}],
|
||||
[{isEmpty: true}, {isEmpty: true}],
|
||||
|
@ -141,11 +165,18 @@ test('removeFromGrid', () => {
|
|||
{color: colors.tetrisBackground, isEmpty: true},
|
||||
],
|
||||
];
|
||||
let oldCoord = [{x: 0, y: 0}, {x: 1, y: 0}];
|
||||
let spy1 = jest.spyOn(ShapeI.prototype, 'getCellsCoordinates')
|
||||
.mockImplementation(() => {return oldCoord;});
|
||||
let spy2 = jest.spyOn(ShapeI.prototype, 'getColor')
|
||||
.mockImplementation(() => {return colors.tetrisI;});
|
||||
let oldCoord = [
|
||||
{x: 0, y: 0},
|
||||
{x: 1, y: 0},
|
||||
];
|
||||
let spy1 = jest
|
||||
.spyOn(ShapeI.prototype, 'getCellsCoordinates')
|
||||
.mockImplementation(() => {
|
||||
return oldCoord;
|
||||
});
|
||||
let spy2 = jest.spyOn(ShapeI.prototype, 'getColor').mockImplementation(() => {
|
||||
return colors.tetrisI;
|
||||
});
|
||||
let p = new Piece(colors);
|
||||
p.removeFromGrid(gridOld);
|
||||
expect(gridOld).toStrictEqual(gridNew);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import React from 'react';
|
||||
import ScoreManager from "../logic/ScoreManager";
|
||||
/* eslint-disable */
|
||||
|
||||
import React from 'react';
|
||||
import ScoreManager from '../logic/ScoreManager';
|
||||
|
||||
test('incrementScore', () => {
|
||||
let scoreManager = new ScoreManager();
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
/* eslint-disable */
|
||||
|
||||
import React from 'react';
|
||||
import BaseShape from "../Shapes/BaseShape";
|
||||
import ShapeI from "../Shapes/ShapeI";
|
||||
import BaseShape from '../Shapes/BaseShape';
|
||||
import ShapeI from '../Shapes/ShapeI';
|
||||
|
||||
const colors = {
|
||||
tetrisI: '#000001',
|
||||
|
@ -22,7 +24,7 @@ test('constructor', () => {
|
|||
expect(T.getColor()).toBe(colors.tetrisI);
|
||||
});
|
||||
|
||||
test("move", () => {
|
||||
test('move', () => {
|
||||
let T = new ShapeI(colors);
|
||||
T.move(0, 1);
|
||||
expect(T.position.x).toBe(3);
|
||||
|
|
Loading…
Reference in a new issue