Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HaztrakProfile for managing Remote signer access #637

Merged
merged 11 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,10 @@ repos:
\.vscode\/.*|
)$
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.251'
rev: 'v0.1.3'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/ambv/black
rev: '23.1.0'
hooks:
- id: black
language_version: python3.11
- repo: local
hooks:
- id: pre-commit-django-migrations
Expand Down
6 changes: 4 additions & 2 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import React, { ReactElement, useEffect } from 'react';
import { RouterProvider, useNavigate } from 'react-router-dom';
import { router } from 'routes';
import { useAppDispatch, useAppSelector } from 'store';
import { getProfile, selectRcraProfile } from 'store/rcraProfileSlice';
import { getRcraProfile, selectRcraProfile } from 'store/profileSlice';
import { getHaztrakProfile } from 'store/profileSlice/profile.slice';
import { selectUserName } from 'store/userSlice';
import { getHaztrakUser } from 'store/userSlice/user.slice';
import './App.scss';
Expand All @@ -15,8 +16,9 @@ function App(): ReactElement {

useEffect(() => {
if (userName) {
dispatch(getProfile());
dispatch(getRcraProfile());
dispatch(getHaztrakUser());
dispatch(getHaztrakProfile());
}
}, [profile.user]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ describe('QuickerSignModalBtn', () => {
{
// Redux store state with an API user is required for this button to be active
preloadedState: {
rcraProfile: {
profile: {
user: 'username',
phoneNumber: '1231231234',
apiUser: true,
rcrainfoProfile: {
user: 'username',
phoneNumber: '1231231234',
apiUser: true,
},
},
},
}
Expand All @@ -74,10 +77,13 @@ describe('QuickerSignModalBtn', () => {
{
// Redux store state with an API user is required for this button to be active
preloadedState: {
rcraProfile: {
profile: {
user: 'username',
phoneNumber: '1231231234',
apiUser: false,
rcrainfoProfile: {
user: 'username',
phoneNumber: '1231231234',
apiUser: false,
},
},
},
}
Expand Down
31 changes: 17 additions & 14 deletions client/src/components/Manifest/SiteSelect/SiteSelect.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { SiteSelect } from 'components/Manifest/SiteSelect/SiteSelect';
import React, { useState } from 'react';
import { useForm } from 'react-hook-form';
import { renderWithProviders } from 'test-utils';
import { createMockSite } from 'test-utils/fixtures';
import { createMockPermission } from 'test-utils/fixtures/mockHandler';
import { createMockRcrainfoSite } from 'test-utils/fixtures';
import { createMockRcrainfoPermissions } from 'test-utils/fixtures/mockHandler';
import { describe, expect, test } from 'vitest';

function TestComponent() {
Expand All @@ -16,21 +16,24 @@ function TestComponent() {

describe('SiteSelect', () => {
test('renders', () => {
const mySite = createMockSite();
const mySite = createMockRcrainfoSite();
renderWithProviders(<TestComponent />, {
preloadedState: {
rcraProfile: {
profile: {
user: 'username',
phoneNumber: '1231231234',
apiUser: false,
rcraSites: {
VATESTGEN001: {
site: mySite,
permissions: createMockPermission(),
},
VATEST00001: {
site: mySite,
permissions: createMockPermission(),
rcrainfoProfile: {
user: 'username',
phoneNumber: '1231231234',
apiUser: false,
rcraSites: {
VATESTGEN001: {
epaSiteId: 'VATESTGEN001',
permissions: createMockRcrainfoPermissions(),
},
VATEST00001: {
epaSiteId: 'VATEST00001',
permissions: createMockRcrainfoPermissions(),
},
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/Manifest/SiteSelect/SiteSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import { Control, Controller } from 'react-hook-form';
import Select from 'react-select';
import { useAppSelector } from 'store';
import { userRcraSitesSelector } from 'store/rcraProfileSlice/rcraProfile.slice';
import { selectHaztrakSites, selectRcrainfoSites } from 'store/profileSlice/profile.slice';

interface SiteSelectProps<T> {
control: Control;
Expand All @@ -17,8 +17,8 @@ export function SiteSelect({
value,
handleChange,
}: SiteSelectProps<RcraSite | undefined | null>) {
const userRcraSites = useAppSelector(userRcraSitesSelector);
const siteOptions = userRcraSites?.map((site) => site.site.handler);
const userSites = useAppSelector(selectHaztrakSites);
const siteOptions = userSites?.map((site) => site.handler);
return (
<>
<HtForm.Label htmlFor="site">Site</HtForm.Label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ describe('RcraApiUserBtn', () => {
test('is disabled when apiUser=false', () => {
renderWithProviders(<RcraApiUserBtn>Click Me</RcraApiUserBtn>, {
preloadedState: {
rcraProfile: {
profile: {
user: 'username',
phoneNumber: '1231231234',
apiUser: false,
rcrainfoProfile: {
user: 'username',
phoneNumber: '1231231234',
apiUser: false,
},
},
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, ButtonProps } from 'react-bootstrap';
import { useAppSelector } from 'store';
import { selectRcraProfile } from 'store/rcraProfileSlice';
import { selectRcraProfile } from 'store/profileSlice';

interface HtApiUserBtnProps extends ButtonProps {}

Expand All @@ -14,9 +14,7 @@ interface HtApiUserBtnProps extends ButtonProps {}
export function RcraApiUserBtn(props: HtApiUserBtnProps) {
const profile = useAppSelector(selectRcraProfile);
let { children, ...btnProps } = props;
// In order for the button to be active,
// the disabled prop needs to be falsy AND the user needs to be an API user
const active = !btnProps.disabled && profile.apiUser;
const active = !btnProps.disabled && profile.rcrainfoProfile?.apiUser;

return (
<Button {...btnProps} disabled={!active}>
Expand Down
4 changes: 2 additions & 2 deletions client/src/features/SiteList/SiteList.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { rest } from 'msw';
import { setupServer } from 'msw/node';
import React from 'react';
import { cleanup, renderWithProviders, screen } from 'test-utils';
import { createMockHandler, createMockSite } from 'test-utils/fixtures/mockHandler';
import { createMockHandler, createMockRcrainfoSite } from 'test-utils/fixtures/mockHandler';
import { API_BASE_URL } from 'test-utils/mock/handlers';
import { afterAll, afterEach, beforeAll, describe, expect, test, vi } from 'vitest';

const mockSites = [createMockSite(), createMockSite()];
const mockSites = [createMockRcrainfoSite(), createMockRcrainfoSite()];
const server = setupServer(
rest.get(`${API_BASE_URL}/api/site`, (req, res, ctx) => {
return res(ctx.status(200), ctx.json(mockSites));
Expand Down
4 changes: 2 additions & 2 deletions client/src/features/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Accordion, Button, Col, Container, Row } from 'react-bootstrap';
import { Link } from 'react-router-dom';
import { useAppDispatch, useAppSelector } from 'store';
import { launchExampleTask } from 'store/notificationSlice/notification.slice';
import { getProfile } from 'store/rcraProfileSlice';
import { getRcraProfile } from 'store/profileSlice';
import { selectUserName } from 'store/userSlice/user.slice';

/**
Expand All @@ -22,7 +22,7 @@ export function Home(): ReactElement {

useEffect(() => {
// get user profile information when the user changes
dispatch(getProfile());
dispatch(getRcraProfile());
}, [userName]);

return (
Expand Down
49 changes: 0 additions & 49 deletions client/src/features/manifestList/NewManifest.spec.tsx

This file was deleted.

94 changes: 94 additions & 0 deletions client/src/features/newManifest/NewManifest.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';
import { NewManifest } from 'features/newManifest/NewManifest';
import React from 'react';
import { renderWithProviders, screen } from 'test-utils';
import {
createMockRcrainfoPermissions,
createMockRcrainfoSite,
} from 'test-utils/fixtures/mockHandler';
import { describe, expect, test } from 'vitest';

describe('NewManifest', () => {
test('renders', () => {
const mySiteId = 'VATESTGEN001';
const mySiteName = 'My Site';
const mySite = createMockRcrainfoSite({
name: mySiteName,
// @ts-ignore
handler: { epaSiteId: mySiteId, siteType: 'Tsdf' },
});
renderWithProviders(<NewManifest />, {
preloadedState: {
profile: {
user: 'testuser1',
sites: { VATESTGEN001: { ...mySite, permissions: { eManifest: 'viewer' } } },
rcrainfoProfile: {
user: 'username',
phoneNumber: '1231231234',
apiUser: false,
rcraSites: {
VATESTGEN001: {
epaSiteId: mySiteId,
permissions: createMockRcrainfoPermissions(),
},
},
},
},
},
});
expect(screen.getByRole('combobox', { name: /site Role/i })).toBeInTheDocument();
});
test('site type is initially disabled', () => {
const mySiteId = 'VATESTGEN001';
const mySiteName = 'My Site';
const mySite = createMockRcrainfoSite({
name: mySiteName,
// @ts-ignore
handler: { epaSiteId: mySiteId, siteType: 'Tsdf' },
});
renderWithProviders(<NewManifest />, {
preloadedState: {
profile: {
user: 'testuser1',
rcrainfoProfile: {
user: 'username',
phoneNumber: '1231231234',
apiUser: false,
rcraSites: {
VATESTGEN001: {
epaSiteId: mySiteId,
permissions: createMockRcrainfoPermissions(),
},
},
},
},
},
});
const siteRole = screen.getByRole('combobox', { name: /site Role/i });
expect(siteRole).toBeDisabled();
});
test('site type is not disabled after selecting a site', async () => {
const mySiteId = 'VATESTGEN001';
const mySiteName = 'My Site';
const mySite = createMockRcrainfoSite({
name: mySiteName,
// @ts-ignore
handler: { epaSiteId: mySiteId, siteType: 'Tsdf' },
});
renderWithProviders(<NewManifest />, {
preloadedState: {
profile: {
user: 'testuser1',
sites: { VATESTGEN001: { ...mySite, permissions: { eManifest: 'viewer' } } },
},
},
});
const siteSelection = screen.getByRole('combobox', { name: /site select/i });
await userEvent.click(siteSelection);
await userEvent.keyboard('{enter}');
expect(screen.getByText(new RegExp(`${mySiteId} --`, 'i'))).toBeInTheDocument();
const siteRole = screen.getByRole('combobox', { name: /site Role/i });
expect(siteRole).not.toBeDisabled();
});
});
5 changes: 2 additions & 3 deletions client/src/features/newManifest/NewManifest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Form } from 'react-bootstrap';
import { useForm } from 'react-hook-form';
import { useParams } from 'react-router-dom';
import { useAppSelector } from 'store';
import { siteByEpaIdSelector } from 'store/rcraProfileSlice/rcraProfile.slice';
import { siteByEpaIdSelector } from 'store/profileSlice/profile.slice';

/**
* NewManifest component allows a user to create a new electronic manifest.
Expand Down Expand Up @@ -40,8 +40,7 @@ export function NewManifest() {
};

if (!selectedSiteType || !manifestingSite) {
// If the site that needs to start a manifest, or its role on the manifest
// can't be determined, ask the user.
// If the manifesting site's role on the manifest can't be automatically determined, ask the user.
return (
<HtCard>
<HtCard.Body>
Expand Down
7 changes: 4 additions & 3 deletions client/src/features/profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useTitle } from 'hooks';
import React, { ReactElement, useEffect } from 'react';
import { Col, Container, Row } from 'react-bootstrap';
import { useAppDispatch, useAppSelector } from 'store';
import { getProfile, selectRcraProfile } from 'store/rcraProfileSlice';
import { getRcraProfile, selectRcraProfile } from 'store/profileSlice';

/**
* Display user profile
Expand All @@ -23,7 +23,7 @@ export function Profile(): ReactElement {
}

useEffect(() => {
dispatch(getProfile());
dispatch(getRcraProfile());
}, [profile.user]);

return (
Expand All @@ -43,7 +43,8 @@ export function Profile(): ReactElement {
<HtCard>
<HtCard.Header title="RCRAInfo Profile" />
<HtCard.Body>
<RcraProfile profile={profile} />
{/*ToDo extend RcraProfile component accept undefined*/}
{profile.rcrainfoProfile && <RcraProfile profile={profile.rcrainfoProfile} />}
</HtCard.Body>
</HtCard>
</Col>
Expand Down
Loading
Loading