-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Aaron Chong <[email protected]>
- Loading branch information
1 parent
bca4188
commit a24458b
Showing
4 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
packages/rmf-dashboard-framework/src/components/tasks/types/delivery.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { DeliveryTaskForm, makeDefaultDeliveryTaskDescription } from './delivery'; | ||
|
||
export default { | ||
title: 'Tasks/DeliveryTaskForm', | ||
component: DeliveryTaskForm, | ||
} satisfies Meta; | ||
|
||
type Story = StoryObj<typeof DeliveryTaskForm>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
taskDesc: makeDefaultDeliveryTaskDescription(), | ||
pickupPoints: { pickup_1: 'handler_1', pickup_2: 'handler_2' }, | ||
dropoffPoints: { dropoff_1: 'handler_3', dropoff_2: 'handler_4' }, | ||
onChange: () => {}, | ||
onValidate: () => {}, | ||
}, | ||
}; |
118 changes: 118 additions & 0 deletions
118
packages/rmf-dashboard-framework/src/components/tasks/types/delivery.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { fireEvent, render, screen, within } from '@testing-library/react'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
|
||
import { | ||
DeliveryTaskDefinition, | ||
DeliveryTaskForm, | ||
isDeliveryTaskDescriptionValid, | ||
makeDefaultDeliveryTaskDescription, | ||
makeDeliveryTaskBookingLabel, | ||
makeDeliveryTaskShortDescription, | ||
} from './delivery'; | ||
|
||
const mockPickupPoints = { | ||
pickup_1: 'handler_1', | ||
pickup_2: 'handler_2', | ||
}; | ||
const mockDropoffPoints = { | ||
dropoff_1: 'handler_3', | ||
dropoff_2: 'handler_4', | ||
}; | ||
|
||
describe('Delivery task form', () => { | ||
it('Delivery task form renders, changes and validates', async () => { | ||
const onChange = vi.fn(); | ||
const onValidate = vi.fn(); | ||
|
||
render( | ||
<DeliveryTaskForm | ||
taskDesc={makeDefaultDeliveryTaskDescription()} | ||
pickupPoints={mockPickupPoints} | ||
dropoffPoints={mockDropoffPoints} | ||
onChange={onChange} | ||
onValidate={onValidate} | ||
/>, | ||
); | ||
|
||
const autocomplete = screen.getByTestId('pickup-location'); | ||
const input = within(autocomplete).getByLabelText(/pickup location/i); | ||
autocomplete.focus(); | ||
fireEvent.change(input, { target: { value: 'a' } }); | ||
fireEvent.keyDown(autocomplete, { key: 'ArrowDown' }); | ||
fireEvent.keyDown(autocomplete, { key: 'Enter' }); | ||
|
||
expect(onChange).toHaveBeenCalled(); | ||
expect(onValidate).toHaveBeenCalled(); | ||
}); | ||
|
||
it('booking label', () => { | ||
const desc = makeDefaultDeliveryTaskDescription(); | ||
desc.pickup = { | ||
handler: 'handler_1', | ||
place: 'pickup_1', | ||
payload: { | ||
sku: 'coke', | ||
quantity: 1, | ||
}, | ||
}; | ||
desc.dropoff = { | ||
handler: 'handler_3', | ||
place: 'dropoff_1', | ||
payload: { | ||
sku: 'coke', | ||
quantity: 1, | ||
}, | ||
}; | ||
const label = makeDeliveryTaskBookingLabel(desc); | ||
expect(label.task_definition_id).toBe(DeliveryTaskDefinition.taskDefinitionId); | ||
expect(label.pickup).toBe('pickup_1'); | ||
expect(label.destination).toBe('dropoff_1'); | ||
expect(label.payload).toBe('coke'); | ||
}); | ||
|
||
it('validity', () => { | ||
const desc = makeDefaultDeliveryTaskDescription(); | ||
expect(isDeliveryTaskDescriptionValid(desc)).not.toBeTruthy(); | ||
|
||
desc.pickup = { | ||
handler: 'handler_1', | ||
place: 'pickup_1', | ||
payload: { | ||
sku: 'coke', | ||
quantity: 1, | ||
}, | ||
}; | ||
desc.dropoff = { | ||
handler: 'handler_3', | ||
place: 'dropoff_1', | ||
payload: { | ||
sku: 'coke', | ||
quantity: 1, | ||
}, | ||
}; | ||
expect(isDeliveryTaskDescriptionValid(desc)).toBeTruthy(); | ||
}); | ||
|
||
it('short description', () => { | ||
const desc = makeDefaultDeliveryTaskDescription(); | ||
desc.pickup = { | ||
handler: 'handler_1', | ||
place: 'pickup_1', | ||
payload: { | ||
sku: 'coke', | ||
quantity: 1, | ||
}, | ||
}; | ||
desc.dropoff = { | ||
handler: 'handler_3', | ||
place: 'dropoff_1', | ||
payload: { | ||
sku: 'coke', | ||
quantity: 1, | ||
}, | ||
}; | ||
expect(makeDeliveryTaskShortDescription(desc, undefined)).toBe( | ||
'[Delivery] Pickup [coke] from [pickup_1], dropoff [coke] at [dropoff_1]', | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters