Skip to content

Commit cf73300

Browse files
committed
fix: improve accessible queries
1 parent 2bd48e6 commit cf73300

File tree

4 files changed

+42
-56
lines changed

4 files changed

+42
-56
lines changed

src/components/Assessment/EditableAssessment/AssessmentActions.test.jsx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jest.mock(
2525
}) => (
2626
<button
2727
type="button"
28-
data-testid={`action-button-${variant}`}
28+
aria-label={`Action Button ${variant}`}
2929
onClick={onClick}
3030
{...props}
3131
>
@@ -39,7 +39,7 @@ jest.mock(
3939
() => ({ title, onConfirm, ...props }) => (
4040
<button
4141
type="button"
42-
data-testid={`confirm-dialog-${title}`}
42+
aria-label={`Confirm Dialog ${title}`}
4343
onClick={onConfirm}
4444
onKeyDown={(e) => e.key === 'Enter' && onConfirm()}
4545
{...props}
@@ -79,14 +79,14 @@ describe('AssessmentActions', () => {
7979
render(<AssessmentActions />);
8080

8181
expect(
82-
screen.getByTestId('action-button-outline-primary'),
82+
screen.getByLabelText('Action Button outline-primary'),
8383
).toBeInTheDocument();
84-
expect(screen.getByTestId('action-button-primary')).toBeInTheDocument();
84+
expect(screen.getByLabelText('Action Button primary')).toBeInTheDocument();
8585
expect(
86-
screen.getByTestId('confirm-dialog-Exit without saving'),
86+
screen.getByLabelText('Confirm Dialog Exit without saving'),
8787
).toBeInTheDocument();
8888
expect(
89-
screen.getByTestId('confirm-dialog-Submit assessment'),
89+
screen.getByLabelText('Confirm Dialog Submit assessment'),
9090
).toBeInTheDocument();
9191
});
9292

@@ -98,37 +98,41 @@ describe('AssessmentActions', () => {
9898
render(<AssessmentActions />);
9999

100100
expect(
101-
screen.getByTestId('action-button-outline-primary'),
101+
screen.getByLabelText('Action Button outline-primary'),
102102
).toBeInTheDocument();
103-
expect(screen.getByTestId('action-button-primary')).toBeInTheDocument();
103+
expect(screen.getByLabelText('Action Button primary')).toBeInTheDocument();
104104
expect(
105-
screen.getByTestId('confirm-dialog-Exit without saving'),
105+
screen.getByLabelText('Confirm Dialog Exit without saving'),
106106
).toBeInTheDocument();
107107
expect(
108-
screen.queryByTestId('confirm-dialog-Submit assessment'),
108+
screen.queryByLabelText('Confirm Dialog Submit assessment'),
109109
).not.toBeInTheDocument();
110110
});
111111

112112
it('calls the correct handlers when buttons and dialogs are clicked', () => {
113113
render(<AssessmentActions />);
114114

115-
const exitButton = screen.getByTestId('action-button-outline-primary');
115+
const exitButton = screen.getByLabelText('Action Button outline-primary');
116116
expect(exitButton).toHaveTextContent('Exit without saving');
117117
fireEvent.click(exitButton);
118118
expect(mockExitWithoutSavingAction.action.onClick).toHaveBeenCalled();
119119

120-
const submitButton = screen.getByTestId('action-button-primary');
120+
const submitButton = screen.getByLabelText('Action Button primary');
121121
expect(submitButton).toHaveTextContent('Submit assessment');
122122
fireEvent.click(submitButton);
123123
expect(mockSubmitAssessmentAction.action.onClick).toHaveBeenCalled();
124124

125-
const exitDialog = screen.getByTestId('confirm-dialog-Exit without saving');
125+
const exitDialog = screen.getByLabelText(
126+
'Confirm Dialog Exit without saving',
127+
);
126128
fireEvent.click(exitDialog);
127129
expect(
128130
mockExitWithoutSavingAction.confirmProps.onConfirm,
129131
).toHaveBeenCalled();
130132

131-
const submitDialog = screen.getByTestId('confirm-dialog-Submit assessment');
133+
const submitDialog = screen.getByLabelText(
134+
'Confirm Dialog Submit assessment',
135+
);
132136
fireEvent.click(submitDialog);
133137
expect(
134138
mockSubmitAssessmentAction.confirmProps.onConfirm,

src/components/FileUpload/index.test.jsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@ jest.mock('./hooks', () => ({
2626
useFileUploadHooks: jest.fn(),
2727
}));
2828

29-
jest.mock('./UploadConfirmModal', () => () => (
30-
<div data-testid="upload-confirm-modal" />
31-
));
32-
jest.mock('./ActionCell', () => () => <div data-testid="action-cell" />);
33-
jest.mock('./FileDownload', () => () => <div data-testid="file-download" />);
34-
jest.mock('components/FilePreview', () => () => (
35-
<div data-testid="file-preview" />
36-
));
29+
jest.mock('./UploadConfirmModal', () => () => <div>Upload Confirm Modal</div>);
30+
jest.mock('./ActionCell', () => () => <div>Action Cell</div>);
31+
jest.mock('./FileDownload', () => () => <div>File Download</div>);
32+
jest.mock('components/FilePreview', () => () => <div>File Preview</div>);
3733

3834
const renderComponent = (props = {}) => render(
3935
<MemoryRouter>

src/views/AssessmentView/index.test.jsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@ jest.mock('hooks/routing', () => ({
1919

2020
jest.mock('./useAssessmentData', () => jest.fn());
2121

22-
jest.mock('components/Prompt', () => () => <div data-testid="prompt" />);
23-
jest.mock('components/TextResponse', () => () => (
24-
<div data-testid="text-response" />
25-
));
26-
jest.mock('components/FileUpload', () => () => (
27-
<div data-testid="file-upload" />
28-
));
22+
jest.mock('components/Prompt', () => () => <div>Prompt</div>);
23+
jest.mock('components/TextResponse', () => () => <div>Text Response</div>);
24+
jest.mock('components/FileUpload', () => () => <div>File Upload</div>);
2925
jest.mock('./BaseAssessmentView', () => ({ children }) => (
30-
<div data-testid="base-view">{children}</div>
26+
<div>Base View {children}</div>
3127
));
3228

3329
const renderComponent = (component) => render(
@@ -60,9 +56,9 @@ describe('AssessmentView', () => {
6056

6157
renderComponent(<AssessmentView />);
6258

63-
const prompts = screen.getAllByTestId('prompt');
59+
const prompts = screen.getAllByText('Prompt');
6460
expect(prompts).toHaveLength(2);
65-
expect(screen.queryByTestId('text-response')).not.toBeInTheDocument();
61+
expect(screen.queryByText('Text Response')).not.toBeInTheDocument();
6662
});
6763

6864
it('renders file upload when there are uploaded files', () => {
@@ -77,7 +73,7 @@ describe('AssessmentView', () => {
7773

7874
renderComponent(<AssessmentView />);
7975

80-
expect(screen.getByTestId('file-upload')).toBeInTheDocument();
76+
expect(screen.getByText('File Upload')).toBeInTheDocument();
8177
});
8278

8379
it('does not render file upload when there are no files', () => {
@@ -92,6 +88,6 @@ describe('AssessmentView', () => {
9288

9389
renderComponent(<AssessmentView />);
9490

95-
expect(screen.queryByTestId('file-upload')).not.toBeInTheDocument();
91+
expect(screen.queryByText('File Upload')).not.toBeInTheDocument();
9692
});
9793
});

src/views/SubmissionView/index.test.jsx

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,12 @@ jest.unmock('@openedx/paragon');
99
jest.unmock('react');
1010
jest.unmock('@edx/frontend-platform/i18n');
1111

12-
jest.mock('components/Rubric', () => () => <div data-testid="rubric" />);
13-
jest.mock('components/ModalActions', () => () => (
14-
<div data-testid="modal-actions" />
15-
));
16-
jest.mock('components/FileUpload', () => () => (
17-
<div data-testid="file-upload" />
18-
));
19-
jest.mock('components/Instructions', () => () => (
20-
<div data-testid="instructions" />
21-
));
22-
jest.mock('components/StatusAlert', () => () => (
23-
<div data-testid="status-alert" />
24-
));
25-
jest.mock('./SubmissionPrompts', () => () => (
26-
<div data-testid="submission-prompts" />
27-
));
12+
jest.mock('components/Rubric', () => () => <div>Rubric</div>);
13+
jest.mock('components/ModalActions', () => () => <div>Modal Actions</div>);
14+
jest.mock('components/FileUpload', () => () => <div>File Upload</div>);
15+
jest.mock('components/Instructions', () => () => <div>Instructions</div>);
16+
jest.mock('components/StatusAlert', () => () => <div>Status Alert</div>);
17+
jest.mock('./SubmissionPrompts', () => () => <div>Submission Prompts</div>);
2818
jest.mock('./hooks', () => jest.fn());
2919

3020
const renderWithIntl = (component) => render(<IntlProvider locale="en">{component}</IntlProvider>);
@@ -50,9 +40,9 @@ describe('<SubmissionView />', () => {
5040
it('does not render rubric when showRubric is false', () => {
5141
renderWithIntl(<SubmissionView />);
5242

53-
expect(screen.queryByTestId('rubric')).not.toBeInTheDocument();
54-
expect(screen.getByTestId('modal-actions')).toBeInTheDocument();
55-
expect(screen.getByTestId('submission-prompts')).toBeInTheDocument();
43+
expect(screen.queryByText('Rubric')).not.toBeInTheDocument();
44+
expect(screen.getByText('Modal Actions')).toBeInTheDocument();
45+
expect(screen.getByText('Submission Prompts')).toBeInTheDocument();
5646
});
5747

5848
it('renders rubric when showRubric is true', () => {
@@ -62,8 +52,8 @@ describe('<SubmissionView />', () => {
6252
});
6353
renderWithIntl(<SubmissionView />);
6454

65-
expect(screen.getByTestId('rubric')).toBeInTheDocument();
66-
expect(screen.getByTestId('modal-actions')).toBeInTheDocument();
67-
expect(screen.getByTestId('submission-prompts')).toBeInTheDocument();
55+
expect(screen.getByText('Rubric')).toBeInTheDocument();
56+
expect(screen.getByText('Modal Actions')).toBeInTheDocument();
57+
expect(screen.getByText('Submission Prompts')).toBeInTheDocument();
6858
});
6959
});

0 commit comments

Comments
 (0)