Skip to content

Commit a67cc3b

Browse files
committed
delivery custom
Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
1 parent 2ac7e96 commit a67cc3b

File tree

3 files changed

+222
-4
lines changed

3 files changed

+222
-4
lines changed

packages/rmf-dashboard-framework/src/components/tasks/types/delivery-custom.test.tsx

Lines changed: 213 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,46 @@
1-
import { describe, expect, it } from 'vitest';
1+
import { fireEvent, render, screen, within } from '@testing-library/react';
2+
import { describe, expect, it, vi } from 'vitest';
23

34
import {
5+
DeliveryAreaPickupTaskDefinition,
46
deliveryCustomInsertCartId,
57
deliveryCustomInsertDropoff,
68
deliveryCustomInsertOnCancel,
79
deliveryCustomInsertPickup,
810
DeliveryCustomTaskDescription,
11+
DeliveryCustomTaskForm,
912
deliveryInsertCartId,
1013
deliveryInsertDropoff,
1114
deliveryInsertOnCancel,
1215
deliveryInsertPickup,
16+
DeliveryPickupTaskDefinition,
1317
DeliveryPickupTaskDescription,
18+
DeliveryPickupTaskForm,
19+
DeliverySequentialLotPickupTaskDefinition,
20+
isDeliveryCustomTaskDescriptionValid,
21+
isDeliveryPickupTaskDescriptionValid,
1422
makeDefaultDeliveryCustomTaskDescription,
1523
makeDefaultDeliveryPickupTaskDescription,
24+
makeDeliveryCustomTaskBookingLabel,
25+
makeDeliveryCustomTaskShortDescription,
26+
makeDeliveryPickupTaskBookingLabel,
27+
makeDeliveryPickupTaskShortDescription,
1628
} from '.';
1729

30+
const mockPickupPoints = {
31+
pickup_1: 'handler_1',
32+
pickup_2: 'handler_2',
33+
};
34+
const mockCartIds = ['cart_1', 'cart_2', 'cart_3'];
35+
const mockDropoffPoints = {
36+
dropoff_1: 'handler_3',
37+
dropoff_2: 'handler_4',
38+
};
39+
const mockPickupZones = {
40+
pickup_1: 'zone_1',
41+
pickup_2: 'zone_2',
42+
};
43+
1844
describe('Custom deliveries', () => {
1945
it('delivery pickup', () => {
2046
let deliveryPickupTaskDescription: DeliveryPickupTaskDescription | null = null;
@@ -133,6 +159,89 @@ describe('Custom deliveries', () => {
133159
expect(deliveryPickupTaskDescription).toEqual(description);
134160
});
135161

162+
it('delivery pickup task form renders, changes and validates', async () => {
163+
const onChange = vi.fn();
164+
const onValidate = vi.fn();
165+
166+
render(
167+
<DeliveryPickupTaskForm
168+
taskDesc={makeDefaultDeliveryPickupTaskDescription()}
169+
pickupPoints={mockPickupPoints}
170+
cartIds={mockCartIds}
171+
dropoffPoints={mockDropoffPoints}
172+
onChange={onChange}
173+
onValidate={onValidate}
174+
/>,
175+
);
176+
177+
let triggerCount = 1;
178+
179+
const pickupPlace = screen.getByTestId('pickup-location');
180+
let input = within(pickupPlace).getByLabelText(/pickup location/i);
181+
pickupPlace.focus();
182+
fireEvent.change(input, { target: { value: 'a' } });
183+
fireEvent.keyDown(pickupPlace, { key: 'ArrowDown' });
184+
fireEvent.keyDown(pickupPlace, { key: 'Enter' });
185+
expect(onChange).toHaveBeenCalledTimes(triggerCount);
186+
expect(onValidate).toHaveBeenCalledTimes(triggerCount);
187+
triggerCount += 1;
188+
189+
const cartId = screen.getByTestId('cart-id');
190+
cartId.focus();
191+
input = within(cartId).getByLabelText(/cart id/i);
192+
fireEvent.change(input, { target: { value: 'a' } });
193+
fireEvent.keyDown(pickupPlace, { key: 'ArrowDown' });
194+
fireEvent.keyDown(pickupPlace, { key: 'Enter' });
195+
expect(onChange).toHaveBeenCalledTimes(triggerCount);
196+
expect(onValidate).toHaveBeenCalledTimes(triggerCount);
197+
triggerCount += 1;
198+
199+
const dropoffPlace = screen.getByTestId('dropoff-location');
200+
dropoffPlace.focus();
201+
input = within(dropoffPlace).getByLabelText(/dropoff location/i);
202+
fireEvent.change(input, { target: { value: 'a' } });
203+
fireEvent.keyDown(dropoffPlace, { key: 'ArrowDown' });
204+
fireEvent.keyDown(dropoffPlace, { key: 'Enter' });
205+
expect(onChange).toHaveBeenCalledTimes(triggerCount);
206+
expect(onValidate).toHaveBeenCalledTimes(triggerCount);
207+
triggerCount += 1;
208+
});
209+
210+
it('delivery pickup booking label', () => {
211+
let desc = makeDefaultDeliveryPickupTaskDescription();
212+
desc = deliveryInsertPickup(desc, 'test_place', 'test_lot');
213+
desc = deliveryInsertCartId(desc, 'test_cart_id');
214+
desc = deliveryInsertDropoff(desc, 'test_dropoff');
215+
const label = makeDeliveryPickupTaskBookingLabel(desc);
216+
expect(label.task_definition_id).toBe(DeliveryPickupTaskDefinition.taskDefinitionId);
217+
expect(label.pickup).toBe('test_lot');
218+
expect(label.destination).toBe('test_dropoff');
219+
expect(label.cart_id).toBe('test_cart_id');
220+
});
221+
222+
it('delivery pickup validity', () => {
223+
let desc = makeDefaultDeliveryPickupTaskDescription();
224+
expect(
225+
isDeliveryPickupTaskDescriptionValid(desc, mockPickupPoints, mockDropoffPoints),
226+
).not.toBeTruthy();
227+
desc = deliveryInsertPickup(desc, 'pickup_1', 'handler_1');
228+
desc = deliveryInsertCartId(desc, 'cart_1');
229+
desc = deliveryInsertDropoff(desc, 'dropoff_1');
230+
expect(
231+
isDeliveryPickupTaskDescriptionValid(desc, mockPickupPoints, mockDropoffPoints),
232+
).toBeTruthy();
233+
});
234+
235+
it('delivery pickup short description', () => {
236+
let desc = makeDefaultDeliveryPickupTaskDescription();
237+
desc = deliveryInsertPickup(desc, 'pickup_1', 'handler_1');
238+
desc = deliveryInsertCartId(desc, 'cart_1');
239+
desc = deliveryInsertDropoff(desc, 'dropoff_1');
240+
expect(makeDeliveryPickupTaskShortDescription(desc, undefined)).toBe(
241+
'[Delivery - 1:1] payload [cart_1] from [pickup_1] to [dropoff_1]',
242+
);
243+
});
244+
136245
it('delivery_sequential_lot_pickup', () => {
137246
let deliveryCustomTaskDescription: DeliveryCustomTaskDescription | null = null;
138247
try {
@@ -369,4 +478,107 @@ describe('Custom deliveries', () => {
369478
]);
370479
expect(deliveryCustomTaskDescription).toEqual(description);
371480
});
481+
482+
it('delivery custom task form renders, changes and validates', async () => {
483+
const onChange = vi.fn();
484+
const onValidate = vi.fn();
485+
486+
render(
487+
<DeliveryCustomTaskForm
488+
taskDesc={makeDefaultDeliveryCustomTaskDescription('delivery_sequential_lot_pickup')}
489+
pickupZones={Object.keys(mockPickupZones)}
490+
cartIds={mockCartIds}
491+
dropoffPoints={Object.keys(mockDropoffPoints)}
492+
onChange={onChange}
493+
onValidate={onValidate}
494+
/>,
495+
);
496+
497+
let triggerCount = 1;
498+
499+
const pickupPlace = screen.getByTestId('pickup-zone');
500+
let input = within(pickupPlace).getByLabelText(/pickup zone/i);
501+
pickupPlace.focus();
502+
fireEvent.change(input, { target: { value: 'a' } });
503+
fireEvent.keyDown(pickupPlace, { key: 'ArrowDown' });
504+
fireEvent.keyDown(pickupPlace, { key: 'Enter' });
505+
expect(onChange).toHaveBeenCalledTimes(triggerCount);
506+
expect(onValidate).toHaveBeenCalledTimes(triggerCount);
507+
triggerCount += 1;
508+
509+
const cartId = screen.getByTestId('cart-id');
510+
cartId.focus();
511+
input = within(cartId).getByLabelText(/cart id/i);
512+
fireEvent.change(input, { target: { value: 'a' } });
513+
fireEvent.keyDown(pickupPlace, { key: 'ArrowDown' });
514+
fireEvent.keyDown(pickupPlace, { key: 'Enter' });
515+
expect(onChange).toHaveBeenCalledTimes(triggerCount);
516+
expect(onValidate).toHaveBeenCalledTimes(triggerCount);
517+
triggerCount += 1;
518+
519+
const dropoffPlace = screen.getByTestId('dropoff-location');
520+
dropoffPlace.focus();
521+
input = within(dropoffPlace).getByLabelText(/dropoff location/i);
522+
fireEvent.change(input, { target: { value: 'a' } });
523+
fireEvent.keyDown(dropoffPlace, { key: 'ArrowDown' });
524+
fireEvent.keyDown(dropoffPlace, { key: 'Enter' });
525+
expect(onChange).toHaveBeenCalledTimes(triggerCount);
526+
expect(onValidate).toHaveBeenCalledTimes(triggerCount);
527+
triggerCount += 1;
528+
});
529+
530+
it('delivery custom booking label', () => {
531+
let desc = makeDefaultDeliveryCustomTaskDescription('delivery_sequential_lot_pickup');
532+
desc = deliveryCustomInsertPickup(desc, 'test_place', 'test_lot');
533+
desc = deliveryCustomInsertCartId(desc, 'test_cart_id');
534+
desc = deliveryCustomInsertDropoff(desc, 'test_dropoff');
535+
let label = makeDeliveryCustomTaskBookingLabel(desc);
536+
expect(label.task_definition_id).toBe(
537+
DeliverySequentialLotPickupTaskDefinition.taskDefinitionId,
538+
);
539+
expect(label.pickup).toBe('test_lot');
540+
expect(label.destination).toBe('test_dropoff');
541+
expect(label.cart_id).toBe('test_cart_id');
542+
543+
desc = makeDefaultDeliveryCustomTaskDescription('delivery_area_pickup');
544+
desc = deliveryCustomInsertPickup(desc, 'test_place', 'test_lot');
545+
desc = deliveryCustomInsertCartId(desc, 'test_cart_id');
546+
desc = deliveryCustomInsertDropoff(desc, 'test_dropoff');
547+
label = makeDeliveryCustomTaskBookingLabel(desc);
548+
expect(label.task_definition_id).toBe(DeliveryAreaPickupTaskDefinition.taskDefinitionId);
549+
expect(label.pickup).toBe('test_lot');
550+
expect(label.destination).toBe('test_dropoff');
551+
expect(label.cart_id).toBe('test_cart_id');
552+
});
553+
554+
it('delivery custom validity', () => {
555+
let desc = makeDefaultDeliveryCustomTaskDescription('delivery_sequential_lot_pickup');
556+
expect(
557+
isDeliveryCustomTaskDescriptionValid(
558+
desc,
559+
Object.values(mockPickupZones),
560+
Object.keys(mockDropoffPoints),
561+
),
562+
).not.toBeTruthy();
563+
desc = deliveryCustomInsertPickup(desc, 'pickup_1', 'zone_1');
564+
desc = deliveryCustomInsertCartId(desc, 'cart_1');
565+
desc = deliveryCustomInsertDropoff(desc, 'dropoff_1');
566+
expect(
567+
isDeliveryCustomTaskDescriptionValid(
568+
desc,
569+
Object.values(mockPickupZones),
570+
Object.keys(mockDropoffPoints),
571+
),
572+
).toBeTruthy();
573+
});
574+
575+
it('delivery custom short description', () => {
576+
let desc = makeDefaultDeliveryCustomTaskDescription('delivery_sequential_lot_pickup');
577+
desc = deliveryCustomInsertPickup(desc, 'pickup_1', 'zone_1');
578+
desc = deliveryCustomInsertCartId(desc, 'cart_1');
579+
desc = deliveryCustomInsertDropoff(desc, 'dropoff_1');
580+
expect(makeDeliveryCustomTaskShortDescription(desc, undefined)).toBe(
581+
'[Delivery - Sequential lot pick up] payload [cart_1] from [pickup_1] to [dropoff_1]',
582+
);
583+
});
372584
});

packages/rmf-dashboard-framework/src/components/tasks/types/delivery-custom.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export function makeDeliveryCustomTaskShortDescription(
237237
return '[Unknown] delivery pickup task';
238238
}
239239

240-
const isDeliveryPickupTaskDescriptionValid = (
240+
export const isDeliveryPickupTaskDescriptionValid = (
241241
taskDescription: DeliveryPickupTaskDescription,
242242
pickupPoints: Record<string, string>,
243243
dropoffPoints: Record<string, string>,
@@ -255,7 +255,7 @@ const isDeliveryPickupTaskDescriptionValid = (
255255
);
256256
};
257257

258-
const isDeliveryCustomTaskDescriptionValid = (
258+
export const isDeliveryCustomTaskDescriptionValid = (
259259
taskDescription: DeliveryCustomTaskDescription,
260260
pickupZones: string[],
261261
dropoffPoints: string[],
@@ -365,6 +365,7 @@ export function DeliveryPickupTaskForm({
365365
<Grid item xs={8}>
366366
<Autocomplete
367367
id="pickup-location"
368+
data-testid="pickup-location"
368369
freeSolo
369370
fullWidth
370371
options={Object.keys(pickupPoints).sort()}
@@ -406,6 +407,7 @@ export function DeliveryPickupTaskForm({
406407
<Grid item xs={4}>
407408
<Autocomplete
408409
id="cart_id"
410+
data-testid="cart-id"
409411
freeSolo
410412
fullWidth
411413
options={cartIds}
@@ -446,6 +448,7 @@ export function DeliveryPickupTaskForm({
446448
<Grid item xs={8}>
447449
<Autocomplete
448450
id="dropoff-location"
451+
data-testid="dropoff-location"
449452
freeSolo
450453
fullWidth
451454
options={Object.keys(dropoffPoints).sort()}
@@ -577,6 +580,7 @@ export function DeliveryCustomTaskForm({
577580
<Grid item xs={8}>
578581
<Autocomplete
579582
id="pickup-zone"
583+
data-testid="pickup-zone"
580584
freeSolo
581585
fullWidth
582586
options={pickupZones.sort()}
@@ -616,6 +620,7 @@ export function DeliveryCustomTaskForm({
616620
<Grid item xs={4}>
617621
<Autocomplete
618622
id="cart-id"
623+
data-testid="cart-id"
619624
freeSolo
620625
fullWidth
621626
options={cartIds}
@@ -659,6 +664,7 @@ export function DeliveryCustomTaskForm({
659664
<Grid item xs={8}>
660665
<Autocomplete
661666
id="dropoff-location"
667+
data-testid="dropoff-location"
662668
freeSolo
663669
fullWidth
664670
options={dropoffPoints.sort()}

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)