Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const AccessAssignmentTable = (props: IProps) => {
onClick={() => props.showDetails(data.row.original)}
/>
),
header: ' '
header: 'Details'
},
{
header: 'Assignment',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('Access Container', () => {

const headerRecord = container.querySelector('.table-row').textContent;
expect(headerRecord).toBe(
' NameNumber of AssignmentsAssigned ToFirst ExpirationActions'
'DetailsNameNumber of AssignmentsAssigned ToFirst ExpirationActions'
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const AccessDetailContainer = (props: IProps) => {
</div>
</div>
{tags.length > 0 && (
<div className='flex flex-wrap gap-2' aria-label='Access tags'>
<div className='flex flex-wrap gap-2' role='group' aria-label='Access tags'>
{tags.map(tag => (
<span
key={tag}
Expand Down
12 changes: 8 additions & 4 deletions Keas.Mvc/ClientApp/src/components/Access/AccessEditValues.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AssetSummary } from '../Shared/AssetSummary';
import { LinkIcon } from '@heroicons/react/24/outline';
import { useId } from 'react';
import { Button, FormFeedback, FormGroup, Input, Label } from 'reactstrap';
import { IAccess } from '../../models/Access';
import { IValidationError } from '../../models/Shared';
Expand All @@ -15,6 +16,7 @@ interface IProps {
}

const AccessEditValues = (props: IProps) => {
const formId = useId();
if (!props.disableEditing && !props.onAccessUpdate) {
throw new Error(
'If the access is editable then a callback must be provided'
Expand Down Expand Up @@ -45,8 +47,9 @@ const AccessEditValues = (props: IProps) => {
</div>
<div className='grid min-w-0 grid-cols-1 gap-x-6 gap-y-5 sm:grid-cols-2 lg:grid-cols-3 [&>div]:min-w-0 [&>div]:mb-0 [&_label]:mb-2 [&_label]:inline-block [&_label]:text-sm [&_label]:font-semibold [&>div:has(textarea)]:col-span-full'>
<FormGroup>
<Label for='name'>Name</Label>
<Label for={`${formId}-name`}>Name</Label>
<Input
id={`${formId}-name`}
type='text'
className='input w-full'
readOnly={props.disableEditing}
Expand All @@ -65,8 +68,9 @@ const AccessEditValues = (props: IProps) => {
</FormFeedback>
</FormGroup>
<FormGroup>
<Label>Notes</Label>
<Label for={`${formId}-notes`}>Notes</Label>
<Input
id={`${formId}-notes`}
type='textarea'
className='textarea min-h-28 w-full'
readOnly={props.disableEditing}
Expand All @@ -83,7 +87,7 @@ const AccessEditValues = (props: IProps) => {
</FormFeedback>
</FormGroup>
<FormGroup>
<Label for='searchTags'>Tags</Label>
<Label for={`${formId}-tags`}>Tags</Label>
<SearchDefinedOptions
definedOptions={props.tags}
disabled={props.disableEditing}
Expand All @@ -96,7 +100,7 @@ const AccessEditValues = (props: IProps) => {
props.onAccessUpdate({ ...access, tags: e.join(',') });
}}
placeholder='Search for Tags'
id='searchTags'
id={`${formId}-tags`}
/>
<FormFeedback>
{error && error.path === 'tags' && error.message}
Expand Down
4 changes: 2 additions & 2 deletions Keas.Mvc/ClientApp/src/components/Access/AccessList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const AccessAssignmentList = (props: IProps) => {
const access =
!props.accessAssignments || props.accessAssignments.length < 1 ? (
<tr>
<td colSpan={5}>No Accesses Found</td>
<td colSpan={6}>No Accesses Found</td>
</tr>
) : (
props.accessAssignments.map(x => (
Expand All @@ -34,7 +34,7 @@ const AccessAssignmentList = (props: IProps) => {
<table className='table'>
<thead>
<tr>
<th />
<th scope='col'>Details</th>
<th>Name</th>
<th>Assigned?</th>
<th>Number of Assignments</th>
Expand Down
2 changes: 1 addition & 1 deletion Keas.Mvc/ClientApp/src/components/Access/AccessTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const AccessTable = (props: IProps) => {
onClick={() => props.showDetails(data.row.original)}
/>
),
header: ' '
header: 'Details'
},
{
header: 'Name',
Expand Down
7 changes: 4 additions & 3 deletions Keas.Mvc/ClientApp/src/components/Access/SearchAccess.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PlusIcon } from '@heroicons/react/24/outline';
import { useContext, useState } from 'react';
import { useContext, useId, useState } from 'react';
import { Highlighter } from '../Shared/SearchCombobox';
import { toast } from 'react-toastify';
import { Button } from 'reactstrap';
Expand All @@ -15,17 +15,18 @@ interface IProps {

// Search for existing access then send selection back to parent
const SearchAccess = (props: IProps) => {
const inputId = useId();
const [accesses, setAccesses] = useState<IAccess[]>([]);
const [isSearchLoading, setIsSearchLoading] = useState<boolean>(false);
const context = useContext(Context);

const renderSelectAccess = () => {
return (
<div>
<label>Pick an access to assign</label>
<label htmlFor={inputId}>Pick an access to assign</label>
<div>
<SearchAsyncOptions
id='searchAccesses' // for accessibility
id={inputId}
isLoading={isSearchLoading}
minLength={3}
placeholder='Search for access by name or by serial number'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const EquipmentAttributes = (props: IProps) => {
<div>
<label>Attributes</label> <span />{' '}
<a
aria-label='About equipment attributes'
href='https://computing.caes.ucdavis.edu/documentation/peaks/equipment-attribute-keys'
target='blank'
rel='noopener noreferrer'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ISpace } from '../../models/Spaces';
import { fakeEquipment } from '../specs/mockData/Equipment';
import { routes } from '../../pages/assets/routes';
import EquipmentContainer from '../Equipment/EquipmentContainer';
import EquipmentManagedSystemSearchId from './EquipmentManagedSystemSearchId';

let container: HTMLElement = null;

Expand All @@ -20,6 +21,51 @@ beforeEach(() => {
document.body.appendChild(container);
});

describe('Managed-system search accessibility', () => {
it('labels the input and pending action while preserving result selection', async () => {
let resolveSearch: (value: unknown) => void;
const fetch = vi.fn(() => new Promise(resolve => { resolveSearch = resolve; }));
const select = vi.fn();
render(
<Context.Provider value={{ fetch, permissions: [], team: { id: 1, name: 'Team', slug: 'team' }, tags: [] }}>
<EquipmentManagedSystemSearchId addManagedSystemId={select} />
</Context.Provider>,
{ container }
);

fireEvent.click(screen.getByRole('button', { name: 'Look Up' }));
const dialog = await screen.findByRole('dialog', { name: 'Search by Computer Property' });
const property = within(dialog).getByRole('textbox', { name: 'Computer Property' });
const status = within(dialog).getByRole('status');
expect(status).toBeEmptyDOMElement();
expect(within(dialog).getByLabelText('Computer Property')).toBe(property);
fireEvent.change(property, { target: { value: 'Research' } });
fireEvent.click(within(dialog).getByRole('button', { name: 'Search!' }));

const pending = within(dialog).getByRole('button', { name: 'Searching…' });
expect(pending).toBeDisabled();
expect(pending).toHaveAttribute('aria-busy', 'true');
expect(status).toHaveTextContent('Searching…');
expect(fetch).toHaveBeenCalledExactlyOnceWith('/api/team/equipment/GetComputersBySearch?value=Research');

await act(async () => resolveSearch({ result: [{
hardware_u_bigfix_id: '123',
hardware_display_name: 'Research laptop',
hardware_u_device_name: 'LAB-01'
}] }));
expect(within(dialog).getByRole('button', { name: 'Search!' })).toBeEnabled();
expect(status).toHaveTextContent('1 computer found.');
fireEvent.click(within(dialog).getByRole('button', { name: 'Research laptop (LAB-01)' }));
expect(select).toHaveBeenCalledExactlyOnceWith('systemManagementId', '123');

fireEvent.click(within(dialog).getByRole('button', { name: 'Search!' }));
expect(status).toHaveTextContent('Searching…');
await act(async () => resolveSearch({ result: [] }));
expect(within(dialog).getByRole('status')).toBe(status);
expect(status).toHaveTextContent('No results found for the search term.');
});
});

describe('Equipment duplication', () => {
beforeEach(() => {
// The date picker measures text with canvas, which jsdom does not implement.
Expand Down Expand Up @@ -126,7 +172,7 @@ describe('Equipment duplication', () => {

const saveCopy = () => fireEvent.click(screen.getByRole('button', { name: 'Save' }));
const selectOtherPerson = async (name: string) => {
fireEvent.change(screen.getByRole('combobox', { name: 'Search for person by name or email' }), { target: { value: name } });
fireEvent.change(screen.getByRole('combobox', { name: 'Assign to' }), { target: { value: name } });
fireEvent.click(await screen.findByRole('option', { name: new RegExp(name) }));
};

Expand All @@ -141,7 +187,7 @@ describe('Equipment duplication', () => {
expect(screen.getByLabelText('Make')).toHaveValue(state.source.make);
expect(screen.getByLabelText('Model')).toHaveValue(state.source.model);
expect(screen.getByLabelText('Attribute value 1')).toHaveValue('5');
expect(screen.getByRole('combobox', { name: 'Search for person by name or email' })).toHaveValue('');
expect(screen.getByRole('combobox', { name: 'Assign to' })).toHaveValue('');
fireEvent.change(screen.getByLabelText('Name'), { target: { value: 'New laptop' } });
fireEvent.change(screen.getByLabelText('Serial Number / Identifier'), { target: { value: 'NEW-SERIAL' } });
fireEvent.change(screen.getByLabelText('Attribute value 1'), { target: { value: '6' } });
Expand Down Expand Up @@ -182,7 +228,7 @@ describe('Equipment duplication', () => {

it('prevents Enter in a pending person search from submitting a new equipment record', async () => {
const state = await setup();
const personSearch = screen.getByRole('combobox', { name: 'Search for person by name or email' });
const personSearch = screen.getByRole('combobox', { name: 'Assign to' });
fireEvent.change(personSearch, { target: { value: 'Searching' } });
expect(fireEvent.keyDown(personSearch, { key: 'Enter', code: 'Enter' })).toBe(false);
expect(state.duplicate).not.toHaveBeenCalled();
Expand Down Expand Up @@ -228,7 +274,7 @@ describe('Equipment duplication', () => {

expect(await screen.findByRole('alert')).toHaveTextContent('assignment could not be confirmed');
expect(state.assetInUseUpdated).not.toHaveBeenCalled();
fireEvent.change(screen.getByRole('combobox', { name: 'Search for person by name or email' }), { target: { value: '' } });
fireEvent.change(screen.getByRole('combobox', { name: 'Assign to' }), { target: { value: '' } });
fireEvent.click(screen.getByRole('button', { name: 'Save assignment' }));

expect(await screen.findByRole('alert')).toHaveTextContent(`already assigned to ${state.otherPerson.name}`);
Expand Down Expand Up @@ -263,7 +309,7 @@ describe('Equipment duplication', () => {
saveCopy();

expect(await screen.findByRole('alert')).toHaveTextContent('assignment could not be confirmed');
fireEvent.change(screen.getByRole('combobox', { name: 'Search for person by name or email' }), { target: { value: '' } });
fireEvent.change(screen.getByRole('combobox', { name: 'Assign to' }), { target: { value: '' } });
fireEvent.click(screen.getByRole('button', { name: 'Save assignment' }));

await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
Expand All @@ -283,7 +329,7 @@ describe('Equipment duplication', () => {

expect(await screen.findByRole('alert')).toHaveTextContent('assignment could not be confirmed');
state.details.mockRejectedValueOnce(new Error('Details unavailable'));
fireEvent.change(screen.getByRole('combobox', { name: 'Search for person by name or email' }), { target: { value: '' } });
fireEvent.change(screen.getByRole('combobox', { name: 'Assign to' }), { target: { value: '' } });
fireEvent.click(screen.getByRole('button', { name: 'Save assignment' }));

expect(await screen.findByRole('alert')).toHaveTextContent('Unable to verify the saved assignment');
Expand All @@ -297,7 +343,7 @@ describe('Equipment duplication', () => {

it('allows changing the person from a person page without adding the copy to the original person', async () => {
const state = await setup({ view: 'person' });
expect(screen.getByRole('combobox', { name: 'Search for person by name or email' })).toHaveValue(`${state.person.name} (${state.person.email})`);
expect(screen.getByRole('combobox', { name: 'Assign to' })).toHaveValue(`${state.person.name} (${state.person.email})`);
await selectOtherPerson(state.otherPerson.name);
fireEvent.change(screen.getByLabelText('Name'), { target: { value: 'Other person copy' } });
saveCopy();
Expand All @@ -311,7 +357,7 @@ describe('Equipment duplication', () => {

it('allows clearing the person and saves unassigned outside that person’s list', async () => {
const state = await setup({ view: 'person' });
fireEvent.change(screen.getByRole('combobox', { name: 'Search for person by name or email' }), { target: { value: '' } });
fireEvent.change(screen.getByRole('combobox', { name: 'Assign to' }), { target: { value: '' } });
fireEvent.change(screen.getByLabelText('Name'), { target: { value: 'Unassigned copy' } });
saveCopy();

Expand All @@ -323,7 +369,7 @@ describe('Equipment duplication', () => {

it('excludes a copy from the space page when its room is cleared', async () => {
const state = await setup({ view: 'space' });
const spaceInput = screen.getByRole('combobox', { name: 'Search for space' });
const spaceInput = screen.getByRole('combobox', { name: 'Room' });
fireEvent.click(within(spaceInput.parentElement).getByRole('button', { name: 'Clear selection' }));
fireEvent.change(screen.getByLabelText('Name'), { target: { value: 'Roomless copy' } });
saveCopy();
Expand Down Expand Up @@ -383,7 +429,7 @@ describe('Equipment Container', () => {
});

const headerRecord = container.querySelector('.table-row').textContent;
expect(headerRecord).toBe(' Serial NumberNameAssigned ToExpirationActions');
expect(headerRecord).toBe('DetailsSerial NumberNameAssigned ToExpirationActions');
});

it('Shows Add Button', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const EquipmentDetails = (props: IProps) => {
)}
</dl>
{tags.length > 0 && (
<div className='mt-5 flex flex-wrap gap-2' aria-label='Tags'>
<div className='mt-5 flex flex-wrap gap-2' role='group' aria-label='Tags'>
{tags.map(tag => <span key={tag} className='badge badge-asset badge-soft'>{tag}</span>)}
</div>
)}
Expand Down
Loading
Loading