Skip to content

Commit 36e81f3

Browse files
Thomas FinkThomas Fink
Thomas Fink
authored and
Thomas Fink
committed
fix(ZMS-3466): add more tests
1 parent 2f92832 commit 36e81f3

File tree

2 files changed

+191
-3
lines changed

2 files changed

+191
-3
lines changed

zmsadmin/js/page/availabilityDay/form/datepicker.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AvailabilityDatePicker extends Component
2222
availabilityList: this.props.attributes.availabilitylist,
2323
minDate: moment.unix(this.props.attributes.availability.startDate).toDate(),
2424
minTime: setHours(setMinutes(new Date(), 1), 0),
25-
maxTime: setHours(setMinutes(new Date(), 59), 23),
25+
maxTime: setHours(setMinutes(new Date(), 59), 22),
2626
datePickerIsOpen: false,
2727
timPickerIsOpen: false
2828
}
@@ -126,10 +126,10 @@ class AvailabilityDatePicker extends Component
126126
}
127127
var times = [];
128128

129-
// Add maintenance window times (23:00-01:00)
129+
// Add maintenance window times (22:00-01:00)
130130
const selectedDate = moment(this.state.selectedDate);
131131
for (let minute = 1; minute < 60; minute++) {
132-
times.push(selectedDate.clone().hour(23).minute(minute).toDate());
132+
times.push(selectedDate.clone().hour(22).minute(minute).toDate());
133133
}
134134
for (let minute = 0; minute < 59; minute++) {
135135
times.push(selectedDate.clone().hour(0).minute(minute).toDate());

zmsentities/tests/Zmsentities/AvailabilityTest.php

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,158 @@ public function testConflicts()
956956

957957
}
958958

959+
public function testPartialOverlaps()
960+
{
961+
$entity1 = new Availability([
962+
'id' => '1',
963+
'weekday' => ['monday' => '2'],
964+
'startDate' => strtotime('2024-01-15'),
965+
'endDate' => strtotime('2024-01-15'),
966+
'startTime' => '08:00:00',
967+
'endTime' => '12:00:00',
968+
'type' => 'appointment',
969+
'scope' => ['id' => '141', 'dayoff' => []]
970+
]);
971+
972+
// Test overlap at start
973+
$entity2 = new Availability([
974+
'id' => '2',
975+
'weekday' => ['monday' => '2'],
976+
'startDate' => strtotime('2024-01-15'),
977+
'endDate' => strtotime('2024-01-15'),
978+
'startTime' => '07:00:00',
979+
'endTime' => '09:00:00',
980+
'type' => 'appointment',
981+
'scope' => ['id' => '141', 'dayoff' => []]
982+
]);
983+
984+
// Test overlap at end
985+
$entity3 = new Availability([
986+
'id' => '3',
987+
'weekday' => ['monday' => '2'],
988+
'startDate' => strtotime('2024-01-15'),
989+
'endDate' => strtotime('2024-01-15'),
990+
'startTime' => '11:00:00',
991+
'endTime' => '13:00:00',
992+
'type' => 'appointment',
993+
'scope' => ['id' => '141', 'dayoff' => []]
994+
]);
995+
996+
// Test completely contained
997+
$entity4 = new Availability([
998+
'id' => '4',
999+
'weekday' => ['monday' => '2'],
1000+
'startDate' => strtotime('2024-01-15'),
1001+
'endDate' => strtotime('2024-01-15'),
1002+
'startTime' => '09:00:00',
1003+
'endTime' => '11:00:00',
1004+
'type' => 'appointment',
1005+
'scope' => ['id' => '141', 'dayoff' => []]
1006+
]);
1007+
1008+
$list = new AvailabilityList([$entity1, $entity2, $entity3, $entity4]);
1009+
$conflicts = $list->checkAllVsExistingConflicts(
1010+
new \DateTimeImmutable('2024-01-15 00:00:00'),
1011+
new \DateTimeImmutable('2024-01-15 23:59:59')
1012+
);
1013+
1014+
$this->assertEquals(6, $conflicts->count(), "Should detect all overlaps bidirectionally");
1015+
}
1016+
1017+
public function testEdgeCaseOverlaps()
1018+
{
1019+
// Test back-to-back times
1020+
$entity1 = new Availability([
1021+
'id' => '1',
1022+
'weekday' => ['monday' => '2'],
1023+
'startDate' => strtotime('2024-01-15'),
1024+
'endDate' => strtotime('2024-01-15'),
1025+
'startTime' => '08:00:00',
1026+
'endTime' => '12:00:00',
1027+
'type' => 'appointment',
1028+
'scope' => ['id' => '141', 'dayoff' => []]
1029+
]);
1030+
1031+
$entity2 = new Availability([
1032+
'id' => '2',
1033+
'weekday' => ['monday' => '2'],
1034+
'startDate' => strtotime('2024-01-15'),
1035+
'endDate' => strtotime('2024-01-15'),
1036+
'startTime' => '12:00:00',
1037+
'endTime' => '16:00:00',
1038+
'type' => 'appointment',
1039+
'scope' => ['id' => '141', 'dayoff' => []]
1040+
]);
1041+
1042+
// Test overlap across midnight
1043+
$entity3 = new Availability([
1044+
'id' => '3',
1045+
'weekday' => ['monday' => '2'],
1046+
'startDate' => strtotime('2024-01-15'),
1047+
'endDate' => strtotime('2024-01-16'),
1048+
'startTime' => '23:00:00',
1049+
'endTime' => '01:00:00',
1050+
'type' => 'appointment',
1051+
'scope' => ['id' => '141', 'dayoff' => []]
1052+
]);
1053+
1054+
$list = new AvailabilityList([$entity1, $entity2, $entity3]);
1055+
$conflicts = $list->checkAllVsExistingConflicts(
1056+
new \DateTimeImmutable('2024-01-15 00:00:00'),
1057+
new \DateTimeImmutable('2024-01-16 23:59:59')
1058+
);
1059+
1060+
$this->assertEquals(0, $conflicts->count(), "Back-to-back times should not be considered overlapping");
1061+
}
1062+
1063+
public function testWeekdayOverlaps()
1064+
{
1065+
// Test same weekday, different weeks
1066+
$entity1 = new Availability([
1067+
'id' => '1',
1068+
'weekday' => ['monday' => '2'],
1069+
'startDate' => strtotime('2024-01-15'),
1070+
'endDate' => strtotime('2024-01-15'),
1071+
'startTime' => '08:00:00',
1072+
'endTime' => '12:00:00',
1073+
'type' => 'appointment',
1074+
'scope' => ['id' => '141', 'dayoff' => []],
1075+
'repeat' => ['afterWeeks' => '1']
1076+
]);
1077+
1078+
$entity2 = new Availability([
1079+
'id' => '2',
1080+
'weekday' => ['monday' => '2'],
1081+
'startDate' => strtotime('2024-01-22'),
1082+
'endDate' => strtotime('2024-01-22'),
1083+
'startTime' => '08:00:00',
1084+
'endTime' => '12:00:00',
1085+
'type' => 'appointment',
1086+
'scope' => ['id' => '141', 'dayoff' => []],
1087+
'repeat' => ['afterWeeks' => '2']
1088+
]);
1089+
1090+
// Test different weekdays, same times
1091+
$entity3 = new Availability([
1092+
'id' => '3',
1093+
'weekday' => ['tuesday' => '3'],
1094+
'startDate' => strtotime('2024-01-15'),
1095+
'endDate' => strtotime('2024-01-15'),
1096+
'startTime' => '08:00:00',
1097+
'endTime' => '12:00:00',
1098+
'type' => 'appointment',
1099+
'scope' => ['id' => '141', 'dayoff' => []]
1100+
]);
1101+
1102+
$list = new AvailabilityList([$entity1, $entity2, $entity3]);
1103+
$conflicts = $list->checkAllVsExistingConflicts(
1104+
new \DateTimeImmutable('2024-01-15 00:00:00'),
1105+
new \DateTimeImmutable('2024-01-22 23:59:59')
1106+
);
1107+
1108+
$this->assertEquals(0, $conflicts->count(), "Different weeks or weekdays should not conflict");
1109+
}
1110+
9591111
protected function getExampleWithTypeOpeningHours(\DateTimeImmutable $time)
9601112
{
9611113
return new $this->entityclass(
@@ -1239,4 +1391,40 @@ public function testValidateTypeAllowedValues()
12391391
$this->assertCount(0, $errors, "Type '$type' should be valid");
12401392
}
12411393
}
1394+
1395+
public function testGetSummerizedSlotCount()
1396+
{
1397+
$availability1 = new Availability([
1398+
'id' => '1',
1399+
'type' => 'appointment',
1400+
'startTime' => '09:00:00',
1401+
'endTime' => '10:00:00',
1402+
'slotTimeInMinutes' => 10,
1403+
'workstationCount' => ['intern' => 1, 'public' => 1],
1404+
'weekday' => ['monday' => '2'],
1405+
'startDate' => strtotime('2024-01-15'),
1406+
'endDate' => strtotime('2024-01-15'),
1407+
'scope' => ['id' => '141', 'dayoff' => []]
1408+
]);
1409+
1410+
$availability2 = new Availability([
1411+
'id' => '2',
1412+
'type' => 'appointment',
1413+
'startTime' => '10:00:00',
1414+
'endTime' => '11:00:00',
1415+
'slotTimeInMinutes' => 10,
1416+
'workstationCount' => ['intern' => 1, 'public' => 1],
1417+
'weekday' => ['monday' => '2'],
1418+
'startDate' => strtotime('2024-01-15'),
1419+
'endDate' => strtotime('2024-01-15'),
1420+
'scope' => ['id' => '141', 'dayoff' => []]
1421+
]);
1422+
1423+
$list = new AvailabilityList([$availability1, $availability2]);
1424+
$slotCounts = $list->getSummerizedSlotCount();
1425+
1426+
$this->assertEquals(6, $slotCounts['1'], "First availability should have 6 slots");
1427+
$this->assertEquals(6, $slotCounts['2'], "Second availability should have 6 slots");
1428+
}
1429+
12421430
}

0 commit comments

Comments
 (0)