Skip to content

Commit

Permalink
door-summary, tests, clean up unused opmode
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Chong <[email protected]>
  • Loading branch information
aaronchongth committed Nov 26, 2024
1 parent 2329251 commit 26d7bcf
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function BeaconDataGridTable({ beacons }: BeaconDataGridTableProps): JSX.
headerName: 'Level',
width: 150,
editable: false,
valueGetter: (params: GridValueGetterParams) => params.row.level ?? 'N/A',
valueGetter: (params: GridValueGetterParams) => params.row.level ?? 'n/a',
flex: 1,
filterable: true,
},
Expand All @@ -99,7 +99,7 @@ export function BeaconDataGridTable({ beacons }: BeaconDataGridTableProps): JSX.
headerName: 'Type',
width: 150,
editable: false,
valueGetter: (params: GridValueGetterParams) => params.row.category ?? 'N/A',
valueGetter: (params: GridValueGetterParams) => params.row.category ?? 'n/a',
flex: 1,
filterable: true,
},
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { DoorState } from 'api-client';
import React, { act } from 'react';
import { Door as RmfDoor } from 'rmf-models/ros/rmf_building_map_msgs/msg';
import { DoorMode as RmfDoorMode } from 'rmf-models/ros/rmf_door_msgs/msg';
import { describe, expect, it, vi } from 'vitest';

import { RmfApiProvider } from '../../hooks';
import { MockRmfApi, render, TestProviders } from '../../utils/test-utils.test';
import { DoorSummary } from './door-summary';
import { makeDoor } from './test-utils.test';

describe('DoorSummary', () => {
const mockDoor: RmfDoor = makeDoor({ name: 'test_door' });

const rmfApi = new MockRmfApi();
const Base = (props: React.PropsWithChildren<{}>) => {
return (
<TestProviders>
<RmfApiProvider value={rmfApi}>{props.children}</RmfApiProvider>
</TestProviders>
);
};

it('renders door summary correctly', async () => {
const onCloseMock = vi.fn();
const root = render(
<Base>
<DoorSummary onClose={onCloseMock} door={mockDoor} doorLevelName="L1" />
</Base>,
);

// Create the subject for the door
const doorStateObs = rmfApi.getDoorStateObs('test_door');
let emittedDoorState: DoorState | undefined;
doorStateObs.subscribe((doorState) => {
emittedDoorState = doorState;
});

const mockDoorState: DoorState = {
door_time: { sec: 0, nanosec: 0 },
door_name: 'test_door',
current_mode: { value: RmfDoorMode.MODE_OPEN },
};
act(() => {
rmfApi.doorStateObsStore['test_door'].next(mockDoorState);
});

expect(emittedDoorState).toEqual(mockDoorState);
expect(emittedDoorState?.current_mode.value).toEqual(RmfDoorMode.MODE_OPEN);

expect(root.getByText('Name')).toBeTruthy();
expect(root.getByText('Current Floor')).toBeTruthy();
expect(root.getByText('Type')).toBeTruthy();
expect(root.getByText('State')).toBeTruthy();

expect(root.getByText('test_door')).toBeTruthy();
expect(root.getByText('L1')).toBeTruthy();
expect(root.getByText('Single Swing')).toBeTruthy();
expect(root.getByText('OPEN')).toBeTruthy();

userEvent.keyboard('{Escape}');
await waitFor(() => expect(onCloseMock).toHaveBeenCalledTimes(1));
});
});
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import { Dialog, DialogContent, DialogTitle, Divider, TextField, useTheme } from '@mui/material';
import { Level } from 'api-client';
import React from 'react';
import { Door as DoorModel } from 'rmf-models/ros/rmf_building_map_msgs/msg';

import { useRmfApi } from '../../hooks';
import { getApiErrorMessage } from '../../utils/api';
import { doorModeToOpModeString, DoorTableData } from './door-table-datagrid';
import { DoorTableData } from './door-table-datagrid';
import { doorModeToString, doorTypeToString } from './door-utils';

interface DoorSummaryProps {
onClose: () => void;
door: DoorModel;
level: Level;
doorLevelName: string;
}

export const DoorSummary = ({ onClose, door, level }: DoorSummaryProps): JSX.Element => {
export const DoorSummary = ({ onClose, door, doorLevelName }: DoorSummaryProps): JSX.Element => {
const rmfApi = useRmfApi();
const [doorData, setDoorData] = React.useState<DoorTableData>({
index: 0,
doorName: '',
levelName: '',
doorType: 0,
doorName: door.name,
levelName: doorLevelName,
doorType: door.door_type,
doorState: undefined,
});

Expand All @@ -31,7 +30,7 @@ export const DoorSummary = ({ onClose, door, level }: DoorSummaryProps): JSX.Ele
setDoorData({
index: 0,
doorName: door.name,
levelName: level.name,
levelName: doorLevelName,
doorType: door.door_type,
doorState: doorState,
});
Expand All @@ -43,7 +42,7 @@ export const DoorSummary = ({ onClose, door, level }: DoorSummaryProps): JSX.Ele
};

fetchDataForDoor();
}, [rmfApi, level, door]);
}, [rmfApi, doorLevelName, door]);

const [isOpen, setIsOpen] = React.useState(true);

Expand All @@ -70,18 +69,14 @@ export const DoorSummary = ({ onClose, door, level }: DoorSummaryProps): JSX.Ele
<DialogContent>
{Object.entries(doorData).map(([key, value]) => {
if (key === 'index') {
return <></>;
return <div key={doorData.doorName + key} />;
}
let displayValue = value;
let displayLabel = key;
switch (key) {
case 'doorName':
displayLabel = 'Name';
break;
case 'opMode':
displayValue = doorModeToOpModeString(value.current_mode);
displayLabel = 'Op. Mode';
break;
case 'levelName':
displayLabel = 'Current Floor';
break;
Expand All @@ -90,7 +85,9 @@ export const DoorSummary = ({ onClose, door, level }: DoorSummaryProps): JSX.Ele
displayLabel = 'Type';
break;
case 'doorState':
displayValue = value ? doorModeToString(value.current_mode.value) : -1;
displayValue = value
? doorModeToString(value.current_mode.value)
: doorModeToString(undefined);
displayLabel = 'State';
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface DoorData {

export function doorModeToString(doorMode?: number): string {
if (doorMode === undefined) {
return 'N/A';
return 'n/a';
}
switch (doorMode) {
case RmfDoorMode.MODE_OPEN:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './door-card';
export * from './door-summary';
export * from './doors-table';
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export function LiftDataGridTable({ lifts, onLiftClick }: LiftDataGridTableProps
width: 150,
editable: false,
valueGetter: (params: GridValueGetterParams) =>
params.row.currentFloor ? params.row.currentFloor : 'N/A',
params.row.currentFloor ? params.row.currentFloor : 'n/a',
flex: 1,
filterable: true,
},
Expand All @@ -210,7 +210,7 @@ export function LiftDataGridTable({ lifts, onLiftClick }: LiftDataGridTableProps
width: 150,
editable: false,
valueGetter: (params: GridValueGetterParams) =>
params.row.destinationFloor ? params.row.destinationFloor : 'N/A',
params.row.destinationFloor ? params.row.destinationFloor : 'n/a',
flex: 1,
filterable: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ export const Map = styled((props: MapProps) => {
<DoorSummary
onClose={() => setOpenDoorSummary(false)}
door={selectedDoor}
level={currentLevel}
doorLevelName={currentLevel.name}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const RobotsTable = () => {
status: robot.status || undefined,
estFinishTime: estFinishTime || undefined,
lastUpdateTime: robot.unix_millis_time ? robot.unix_millis_time : undefined,
level: robot.location?.map || 'N/A',
level: robot.location?.map || 'n/a',
commission: robot.commission || undefined,
};
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export function dispenserModeToString(mode: number): string {
case RmfDispenserState.OFFLINE:
return 'OFFLINE';
default:
return 'N/A';
return 'n/a';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ describe('Workcell table', () => {
expect(root.getByLabelText('test3')).toBeTruthy();

// check if state unknown dispenser state is handled
expect(root.getAllByText('N/A').length).toEqual(1);
expect(root.getAllByText('n/a').length).toEqual(1);
});
});

0 comments on commit 26d7bcf

Please sign in to comment.