Skip to content

Commit

Permalink
fixed tests related to accessibility updates
Browse files Browse the repository at this point in the history
Jira ticket: CAMS-428

Co-authored-by: Arthur Morrow <[email protected]>
Co-authored-by: James Brooks <[email protected]>
  • Loading branch information
3 people committed Sep 17, 2024
1 parent 0f8018d commit 89687e9
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 16 deletions.
60 changes: 52 additions & 8 deletions user-interface/src/case-detail/CaseDetailScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { formatDate } from '@/lib/utils/datetime';
import { CaseDetail } from '@common/cams/cases';
import { Debtor, DebtorAttorney } from '@common/cams/parties';
import { MockAttorneys } from '@common/cams/test-utilities/attorneys.mock';
import * as detailHeader from './panels/CaseDetailHeader';

const caseId = '101-23-12345';

Expand All @@ -31,13 +32,57 @@ describe('Case Detail screen tests', () => {

type MaybeString = string | undefined;

beforeAll(() => {
beforeEach(() => {
vi.restoreAllMocks();
process.env = {
...env,
CAMS_PA11Y: 'true',
};
});

test('should render CaseDetailHeader', async () => {
const testCaseDetail: CaseDetail = {
caseId: caseId,
dxtrId: '123',
chapter: '15',
regionId: '02',
officeName: 'New York',
officeCode: '000',
caseTitle: 'The Beach Boys',
dateFiled: '01-04-1962',
judgeName: rickBHartName,
courtId: '01',
courtName: 'Court of Law',
courtDivisionName: 'Manhattan',
courtDivisionCode: '081',
debtorTypeLabel: 'Corporate Business',
petitionLabel: 'Voluntary',
closedDate: '01-08-1963',
dismissedDate: '01-08-1964',
assignments: [brianWilson, carlWilson],
debtor: {
name: 'Roger Rabbit',
address1: '123 Rabbithole Lane',
address2: 'Apt 117',
address3: 'Suite C',
cityStateZipCountry: 'Ciudad Obregón GR 25443, MX',
},
debtorAttorney,
groupDesignator: '01',
regionName: 'Test Region',
};
const headerSpy = vi.spyOn(detailHeader, 'default');

render(
<BrowserRouter>
<CaseDetailScreen caseDetail={testCaseDetail} />
</BrowserRouter>,
);
await waitFor(() => {
expect(headerSpy).toHaveBeenCalled();
});
});

test('should display case title, case number, dates, assignees, judge name, and debtor for the case', async () => {
const testCaseDetail: CaseDetail = {
caseId: caseId,
Expand Down Expand Up @@ -78,10 +123,11 @@ describe('Case Detail screen tests', () => {
await waitFor(
async () => {
const title = screen.getByTestId('case-detail-heading-title');
expect(title.innerHTML).toEqual('The Beach Boys');
const expectedTitle = ` - ${testCaseDetail.caseTitle}`;
expect(title.innerHTML).toEqual(expectedTitle);

const caseNumber = document.querySelector('.case-number');
expect(caseNumber?.innerHTML).toEqual(getCaseNumber(caseId));
expect(caseNumber?.innerHTML).toEqual(caseId);

const dateFiled = screen.getByTestId('case-detail-filed-date');
expect(dateFiled).toHaveTextContent('Filed');
Expand All @@ -99,9 +145,7 @@ describe('Case Detail screen tests', () => {
expect(chapter.innerHTML).toEqual('Voluntary Chapter&nbsp;15');

const courtName = screen.getByTestId('court-name-and-district');
expect(courtName.innerHTML).toEqual(
`Court of Law - Manhattan (${testCaseDetail.courtDivisionCode})`,
);
expect(courtName.innerHTML).toEqual(`Court of Law (${testCaseDetail.courtDivisionName})`);

const region = screen.getByTestId('case-detail-region-id');
expect(region.innerHTML).toEqual('Region 2 - New York Office');
Expand Down Expand Up @@ -607,11 +651,11 @@ describe('Case Detail screen tests', () => {
<CaseDetailScreen caseDetail={testCaseDetail} />
</BrowserRouter>,
);

const expectedTitle = ` - ${testCaseDetail.caseTitle}`;
await waitFor(
async () => {
const title = screen.getByTestId('case-detail-heading-title');
expect(title.innerHTML).toEqual('The Beach Boys');
expect(title.innerHTML).toEqual(expectedTitle);

const unassignedElement = document.querySelector('.unassigned-placeholder');
expect(unassignedElement).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe('audit history tests', () => {
render(<CaseDetailAuditHistory caseId={caseId} />);

const emptyAssignments = await screen.findByTestId('empty-assignments-test-id');
expect(emptyAssignments).toHaveTextContent('There are no assignments in the case history.');
expect(emptyAssignments).toHaveTextContent('No changes have been made to this case');

const historyTable = screen.queryByTestId('history-table');
expect(historyTable).not.toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ describe('Case Detail Header tests', () => {
const app = await screen.findByTestId('app-component-test-id');
await waitFor(
async () => {
const heading = await screen.findByTestId('case-detail-heading');
expect(heading.innerHTML).toEqual('Case Detail');
const heading = await screen.findByTestId('case-detail-heading-title');
expect(heading.innerHTML).toEqual(` - ${testCaseDetail.caseTitle}`);
},
{ timeout: 1000 },
);
await waitFor(async () => {
const title = await screen.findByTestId('case-detail-heading-title');
expect(title.innerHTML).toEqual(testCaseDetail.caseTitle);
expect(title.innerHTML).toEqual(` - ${testCaseDetail.caseTitle}`);
});

let normalHeader = await screen.findByTestId('case-detail-header');
Expand Down
6 changes: 5 additions & 1 deletion user-interface/src/my-cases/MyCasesScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ describe('MyCasesScreen', () => {
});
vi.spyOn(LocalStorage, 'getSession').mockReturnValue(MockData.getCamsSession({ user }));

render(<MyCasesScreen></MyCasesScreen>);
render(
<BrowserRouter>
<MyCasesScreen></MyCasesScreen>
</BrowserRouter>,
);

const body = document.querySelector('body');
expect(body).toHaveTextContent('Invalid user expectation');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Api2 from '@/lib/models/api2';
import testingUtilities from '@/lib/testing/testing-utilities';
import { SearchResultsProps } from '@/search-results/SearchResults';
import { CamsRole } from '@common/cams/roles';
import { BrowserRouter } from 'react-router-dom';

describe('StaffAssignmentScreen', () => {
test('should render a list of cases assigned to a case assignment manager', async () => {
Expand Down Expand Up @@ -39,7 +40,11 @@ describe('StaffAssignmentScreen', () => {
.spyOn(staffAssignmentRow, 'StaffAssignmentRow')
.mockReturnValue(<></>);

render(<StaffAssignmentScreen></StaffAssignmentScreen>);
render(
<BrowserRouter>
<StaffAssignmentScreen></StaffAssignmentScreen>
</BrowserRouter>,
);

expect(SearchResults).toHaveBeenCalledWith(
{
Expand All @@ -62,7 +67,11 @@ describe('StaffAssignmentScreen', () => {
test('should render permission invalid error when CaseAssignmentManager is not found in user roles', async () => {
testingUtilities.setUserWithRoles([]);
const alertSpy = testingUtilities.spyOnGlobalAlert();
render(<StaffAssignmentScreen></StaffAssignmentScreen>);
render(
<BrowserRouter>
<StaffAssignmentScreen></StaffAssignmentScreen>
</BrowserRouter>,
);

expect(alertSpy.error).toHaveBeenCalledWith('Invalid Permissions');
});
Expand All @@ -71,7 +80,11 @@ describe('StaffAssignmentScreen', () => {
testingUtilities.setUser({ offices: undefined, roles: [CamsRole.CaseAssignmentManager] });
const SearchResults = vi.spyOn(searchResultsModule, 'SearchResults');

render(<StaffAssignmentScreen></StaffAssignmentScreen>);
render(
<BrowserRouter>
<StaffAssignmentScreen></StaffAssignmentScreen>
</BrowserRouter>,
);

expect(SearchResults).toHaveBeenCalledWith(
{
Expand Down

0 comments on commit 89687e9

Please sign in to comment.