Skip to content

Commit

Permalink
Increase testing (#1036)
Browse files Browse the repository at this point in the history
* beacon-table

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Ignore .stories.tsx and .js files

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* role-list-page

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* user-list-page

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* user-profile-page

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Ignore index.ts files

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* door-summary, tests, clean up unused opmode

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* doors-table, door-utils

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* lift-summary, removed lift-card

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* lifts-table

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* doors-table, lifts-table

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* remove delivery-alert-store

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* map, basic empty render test, cleanup map directory

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* map, test with office map

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* camera-control

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Revert resize observer import, using a mock resize observer for testing, address comments

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

---------

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth authored Dec 3, 2024
1 parent 6e62967 commit 1a9d593
Show file tree
Hide file tree
Showing 35 changed files with 658 additions and 939 deletions.
4 changes: 4 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ coverage:
status:
project: false
patch: false
ignore:
- packages/rmf-dashboard-framework/examples
- "**/*.js"
- "**/*.stories.tsx"
flags:
dashboard:
paths:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { waitFor } from '@testing-library/react';
import React from 'react';
import { describe, expect, it } from 'vitest';

import { RmfApiProvider } from '../../hooks';
import { RmfApi } from '../../services';
import { MockRmfApi, render, TestProviders } from '../../utils/test-utils.test';
import { RoleListPage } from './role-list-page';

describe('Role List Page', () => {
const Base = (props: React.PropsWithChildren<{}>) => {
const rmfApi = React.useMemo<RmfApi>(() => {
const mockRmfApi = new MockRmfApi();
// mock out some api calls so they never resolves
mockRmfApi.adminApi.getRolesAdminRolesGet = () => new Promise(() => {});
mockRmfApi.adminApi.createRoleAdminRolesPost = () => new Promise(() => {});
mockRmfApi.adminApi.deleteRoleAdminRolesRoleDelete = () => new Promise(() => {});
mockRmfApi.adminApi.getRolePermissionsAdminRolesRolePermissionsGet = () =>
new Promise(() => {});
mockRmfApi.adminApi.addRolePermissionAdminRolesRolePermissionsPost = () =>
new Promise(() => {});
mockRmfApi.adminApi.removeRolePermissionAdminRolesRolePermissionsRemovePost = () =>
new Promise(() => {});
return mockRmfApi;
}, []);
return (
<TestProviders>
<RmfApiProvider value={rmfApi}>{props.children}</RmfApiProvider>
</TestProviders>
);
};

it('renders role list page', async () => {
await expect(
waitFor(() =>
render(
<Base>
<RoleListPage />
</Base>,
),
),
).resolves.not.toThrow();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { render as render_, waitFor } from '@testing-library/react';
import React from 'react';
import { MemoryRouter } from 'react-router';
import { describe, expect, it } from 'vitest';

import { AppControllerProvider, RmfApiProvider } from '../../hooks';
import { RmfApi } from '../../services';
import { makeMockAppController, MockRmfApi, TestProviders } from '../../utils/test-utils.test';
import { UserListPage } from './user-list-page';

const render = (ui: React.ReactNode) =>
render_(<AppControllerProvider value={makeMockAppController()}>{ui}</AppControllerProvider>);

describe('UserListPage', () => {
const Base = (props: React.PropsWithChildren<{}>) => {
const rmfApi = React.useMemo<RmfApi>(() => {
const mockRmfApi = new MockRmfApi();
// mock out some api calls so they never resolves
mockRmfApi.adminApi.getUsersAdminUsersGet = () => new Promise(() => {});
mockRmfApi.adminApi.deleteUserAdminUsersUsernameDelete = () => new Promise(() => {});
mockRmfApi.adminApi.createUserAdminUsersPost = () => new Promise(() => {});
return mockRmfApi;
}, []);
return (
<TestProviders>
<RmfApiProvider value={rmfApi}>{props.children}</RmfApiProvider>
</TestProviders>
);
};

it('renders user list page', async () => {
await expect(
waitFor(() =>
render(
<Base>
<MemoryRouter>
<UserListPage />
</MemoryRouter>
</Base>,
),
),
).resolves.not.toThrow();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { render as render_, waitFor } from '@testing-library/react';
import React from 'react';
import { describe, expect, it } from 'vitest';

import { AppControllerProvider, RmfApiProvider } from '../../hooks';
import { RmfApi } from '../../services';
import { makeMockAppController, MockRmfApi, TestProviders } from '../../utils/test-utils.test';
import { UserProfilePage } from './user-profile-page';

const render = (ui: React.ReactNode) =>
render_(<AppControllerProvider value={makeMockAppController()}>{ui}</AppControllerProvider>);

describe('UserProfilePage', () => {
const Base = (props: React.PropsWithChildren<{}>) => {
const rmfApi = React.useMemo<RmfApi>(() => {
const mockRmfApi = new MockRmfApi();
// mock out some api calls so they never resolves
mockRmfApi.adminApi.getUserAdminUsersUsernameGet = () => new Promise(() => {});
mockRmfApi.adminApi.makeAdminAdminUsersUsernameMakeAdminPost = () => new Promise(() => {});
mockRmfApi.adminApi.getRolesAdminRolesGet = () => new Promise(() => {});
mockRmfApi.adminApi.setUserRolesAdminUsersUsernameRolesPut = () => new Promise(() => {});
return mockRmfApi;
}, []);
return (
<TestProviders>
<RmfApiProvider value={rmfApi}>{props.children}</RmfApiProvider>
</TestProviders>
);
};

it('renders user profile page', async () => {
await expect(
waitFor(() =>
render(
<Base>
<UserProfilePage />
</Base>,
),
),
).resolves.not.toThrow();
});
});
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import { describe, expect, it } from 'vitest';

import { RmfApiProvider } from '../../hooks';
import { RmfApi } from '../../services';
import { MockRmfApi, render, TestProviders } from '../../utils/test-utils.test';
import { BeaconsTable } from './beacons-table';

describe('BeaconsTable', () => {
const Base = (props: React.PropsWithChildren<{}>) => {
const rmfApi = React.useMemo<RmfApi>(() => {
const mockRmfApi = new MockRmfApi();
// mock out some api calls so they never resolves
mockRmfApi.beaconsApi.getBeaconsBeaconsGet = () => new Promise(() => {});
return mockRmfApi;
}, []);
return (
<TestProviders>
<RmfApiProvider value={rmfApi}>{props.children}</RmfApiProvider>
</TestProviders>
);
};

it('renders with beacons table', () => {
const root = render(
<Base>
<BeaconsTable />
</Base>,
);
expect(root.getByText('Name')).toBeTruthy();
expect(root.getByText('Op. Mode')).toBeTruthy();
expect(root.getByText('Level')).toBeTruthy();
expect(root.getByText('Type')).toBeTruthy();
expect(root.getByText('Beacon State')).toBeTruthy();
});
});
Loading

0 comments on commit 1a9d593

Please sign in to comment.