-
Notifications
You must be signed in to change notification settings - Fork 41
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 <aaronchongth@gmail.com>
- Loading branch information
1 parent
f38fb48
commit bca4188
Showing
5 changed files
with
145 additions
and
7 deletions.
There are no files selected for viewing
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
19 changes: 19 additions & 0 deletions
19
packages/rmf-dashboard-framework/src/components/tasks/types/patrol.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,19 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { makeDefaultPatrolTaskDescription, PatrolTaskForm } from './patrol'; | ||
|
||
export default { | ||
title: 'Tasks/PatrolTaskForm', | ||
component: PatrolTaskForm, | ||
} satisfies Meta; | ||
|
||
type Story = StoryObj<typeof PatrolTaskForm>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
taskDesc: makeDefaultPatrolTaskDescription(), | ||
patrolWaypoints: ['waypoint_1', 'waypoint_2', 'waypoint_3'], | ||
onChange: () => {}, | ||
onValidate: () => {}, | ||
}, | ||
}; |
89 changes: 89 additions & 0 deletions
89
packages/rmf-dashboard-framework/src/components/tasks/types/patrol.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,89 @@ | ||
import { fireEvent, render, screen, within } from '@testing-library/react'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
|
||
import { | ||
addPlaceToPatrolTaskDescription, | ||
isPatrolTaskDescriptionValid, | ||
makeDefaultPatrolTaskDescription, | ||
makePatrolTaskBookingLabel, | ||
makePatrolTaskShortDescription, | ||
PatrolTaskDefinition, | ||
PatrolTaskForm, | ||
} from './patrol'; | ||
|
||
const mockWaypoints = ['waypoint_1', 'waypoint_2', 'waypoint_3']; | ||
|
||
describe('Patrol task form', () => { | ||
it('PatrolTaskForm renders, changes and validates', async () => { | ||
const onChange = vi.fn(); | ||
const onValidate = vi.fn(); | ||
|
||
render( | ||
<PatrolTaskForm | ||
taskDesc={makeDefaultPatrolTaskDescription()} | ||
patrolWaypoints={mockWaypoints} | ||
onChange={onChange} | ||
onValidate={onValidate} | ||
/>, | ||
); | ||
|
||
const autocomplete = screen.getByTestId('place-name'); | ||
const input = within(autocomplete).getByLabelText(/place name/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('PatrolTaskForm renders and has places', async () => { | ||
const onChange = vi.fn(); | ||
const onValidate = vi.fn(); | ||
|
||
const desc = makeDefaultPatrolTaskDescription(); | ||
const updatedDesc = addPlaceToPatrolTaskDescription(desc, 'waypoint_1'); | ||
|
||
const root = render( | ||
<PatrolTaskForm | ||
taskDesc={updatedDesc} | ||
patrolWaypoints={mockWaypoints} | ||
onChange={onChange} | ||
onValidate={onValidate} | ||
/>, | ||
); | ||
|
||
expect(root.getByText(/waypoint_1/i)); | ||
}); | ||
|
||
it('booking label', () => { | ||
let desc = makeDefaultPatrolTaskDescription(); | ||
desc = addPlaceToPatrolTaskDescription(desc, 'waypoint_1'); | ||
let label = makePatrolTaskBookingLabel(desc); | ||
expect(label.task_definition_id).toBe(PatrolTaskDefinition.taskDefinitionId); | ||
expect(label.destination).toBe('waypoint_1'); | ||
|
||
desc = addPlaceToPatrolTaskDescription(desc, 'waypoint_2'); | ||
label = makePatrolTaskBookingLabel(desc); | ||
expect(label.task_definition_id).toBe(PatrolTaskDefinition.taskDefinitionId); | ||
expect(label.destination).toBe('waypoint_2'); | ||
}); | ||
|
||
it('validity', () => { | ||
let desc = makeDefaultPatrolTaskDescription(); | ||
expect(isPatrolTaskDescriptionValid(desc)).not.toBeTruthy(); | ||
|
||
desc = addPlaceToPatrolTaskDescription(desc, 'waypoint_1'); | ||
expect(isPatrolTaskDescriptionValid(desc)).toBeTruthy(); | ||
}); | ||
|
||
it('short description', () => { | ||
let desc = makeDefaultPatrolTaskDescription(); | ||
desc = addPlaceToPatrolTaskDescription(desc, 'waypoint_1'); | ||
desc = addPlaceToPatrolTaskDescription(desc, 'waypoint_2'); | ||
expect(makePatrolTaskShortDescription(desc, undefined)).toBe( | ||
'[Patrol] [1] round/s, along [waypoint_1], [waypoint_2]', | ||
); | ||
}); | ||
}); |
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