Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed type blocked reservations to not have cooldown #320

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Moment from 'moment';
import { extendMoment } from 'moment-range';

import { slotSize, slotWidth, slotMargin } from 'constants/SlotConstants';
import constants from '../../../../constants/AppConstants';

const moment = extendMoment(Moment);

Expand Down Expand Up @@ -130,7 +131,11 @@ function addSelectionData(selection, resource, items) {

function getCooldownRanges(reservations, cooldown) {
if (reservations && cooldown && cooldown !== '00:00:00') {
return reservations.map(reservation => moment.range(
// type blocked reservations don't have cooldown
const filteredReservations = reservations.filter(
reservation => reservation.type !== constants.RESERVATION_TYPE.BLOCKED_VALUE);

return filteredReservations.map(reservation => moment.range(
moment(reservation.begin).subtract(moment.duration(cooldown)),
moment(reservation.end).add(moment.duration(cooldown))
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import mockDate from 'mockdate';
import moment from 'moment';

import utils from './utils';
import constants from '../../../../constants/AppConstants';

describe('shared/availability-view/utils', () => {
describe('getTimeSlotWidth', () => {
Expand Down Expand Up @@ -499,6 +500,9 @@ describe('shared/availability-view/utils', () => {
test.each([true, false])('returns slots and reservations correctly when there is cooldown and hasStaffRights is %p', hasRights => {
const timeRestrictions2 = { cooldown: '01:00:00', minPeriod: '00:30:00', maxPeriod: '01:00:00' };
const reservations = [
{
id: 10, begin: '2016-01-01T01:30:00', end: '2016-01-01T02:00:00', type: constants.RESERVATION_TYPE.BLOCKED_VALUE
},
{ id: 11, begin: '2016-01-01T02:00:00', end: '2016-01-01T10:00:00' },
{ id: 12, begin: '2016-01-01T12:30:00', end: '2016-01-01T20:00:00' },
{ id: 13, begin: '2016-01-01T20:00:00', end: '2016-01-01T20:30:00' },
Expand Down Expand Up @@ -549,19 +553,10 @@ describe('shared/availability-view/utils', () => {
},
{
key: '3',
type: 'reservation-slot',
data: {
begin: moment('2016-01-01T01:30:00').format(),
end: moment('2016-01-01T02:00:00').format(),
resourceId: '1',
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: !hasRights,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
type: 'reservation',
data: reservations[0],
},
{ key: '4', type: 'reservation', data: reservations[0] },
{ key: '4', type: 'reservation', data: reservations[1] },
{
key: '5',
type: 'reservation-slot',
Expand Down Expand Up @@ -632,8 +627,8 @@ describe('shared/availability-view/utils', () => {
maxPeriod: timeRestrictions2.maxPeriod,
},
},
{ key: '10', type: 'reservation', data: reservations[1] },
{ key: '11', type: 'reservation', data: reservations[2] },
{ key: '10', type: 'reservation', data: reservations[2] },
{ key: '11', type: 'reservation', data: reservations[3] },
{
key: '12',
type: 'reservation-slot',
Expand Down
23 changes: 23 additions & 0 deletions app/utils/__tests__/timeUtils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,29 @@ describe('Utils: timeUtils', () => {
expect(slots[3].onCooldown).toBe(false);
expect(slots[4].onCooldown).toBe(false);
});

test('is false when reservation is type blocked', () => {
const cooldown = '1:00:00';
twoReservations = [
{
begin: '2015-10-09T08:00:00+03:00',
end: '2015-10-09T09:00:00+03:00',
isOwn: false,
},
{
begin: '2015-10-09T12:00:00+03:00',
end: '2015-10-09T13:00:00+03:00',
isOwn: true,
type: constants.RESERVATION_TYPE.BLOCKED_VALUE,
}
];
const slots = getTimeSlots(start, end, period, twoReservations, [], cooldown);
expect(slots[0].onCooldown).toBe(false);
expect(slots[1].onCooldown).toBe(true);
expect(slots[2].onCooldown).toBe(false);
expect(slots[3].onCooldown).toBe(false); // would be on cooldown if not blocked
expect(slots[4].onCooldown).toBe(false);
});
});
});

Expand Down
6 changes: 5 additions & 1 deletion app/utils/timeUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import forEach from 'lodash/forEach';
import map from 'lodash/map';
import filter from 'lodash/filter';
import Moment from 'moment';
import { extendMoment } from 'moment-range';

Expand Down Expand Up @@ -111,11 +112,14 @@ function getTimeSlots(
)
);

// type blocked reservations don't have cooldown
const filteredReservations = filter(reservations,
reservation => reservation.type !== constants.RESERVATION_TYPE.BLOCKED_VALUE);
/*
reservation cooldown range is calculated in the following way:
cooldown range = from (begin time - cooldown) to (end time + cooldown)
*/
const cooldownRanges = map(reservations, reservation => moment.range(
const cooldownRanges = map(filteredReservations, reservation => moment.range(
moment(reservation.begin).subtract(moment.duration(cooldown)),
moment(reservation.end).add(moment.duration(cooldown))
));
Expand Down
Loading