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

UIREQ-1044: Increase code coverage for src/ChooseRequestTypeDialog.js by Jest/RTL tests #1243

Merged
merged 1 commit into from
Dec 6, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [11.1.0] IN PROGRESS

* Migrate from `mod-circulation` to `mod-circulation-bff` for `Print pick slips` and `Print search slips`. Refs UIREQ-1154.
* Increase code coverage for src/ChooseRequestTypeDialog.js by Jest/RTL tests. Refs UIREQ-1044.

## [11.0.1] (https://github.com/folio-org/ui-requests/tree/v11.0.1) (2024-12-02)
[Full Changelog](https://github.com/folio-org/ui-requests/compare/v11.0.0...v11.0.1)
Expand Down
1 change: 1 addition & 0 deletions src/ChooseRequestTypeDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class ChooseRequestTypeDialog extends React.Component {
{isLoading ?
<Loading data-testid="loading" /> :
<Select
data-testid="requestType"
label={<FormattedMessage id="ui-requests.moveRequest.chooseRequestMessage" />}
name="requestType"
onChange={this.selectRequestType}
Expand Down
36 changes: 36 additions & 0 deletions src/ChooseRequestTypeDialog.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
render,
screen,
fireEvent,
} from '@folio/jest-config-stripes/testing-library/react';

import { Button } from '@folio/stripes/components';
Expand All @@ -23,9 +24,12 @@ jest.mock('./utils', () => ({

const labelIds = {
chooseRequestType: 'ui-requests.moveRequest.chooseRequestType',
confirmButtonLabel: 'ui-requests.moveRequest.confirm',
requestTypeError: 'ui-requests.moveRequest.error.itemLevelRequest',
};
const testIds = {
loading: 'loading',
requestType: 'requestType',
};

describe('ChooseRequestTypeDialog', () => {
Expand Down Expand Up @@ -85,6 +89,38 @@ describe('ChooseRequestTypeDialog', () => {
it('should not render Loading component', () => {
expect(screen.queryByTestId(testIds.loading)).not.toBeInTheDocument();
});

it('should handle confirmation after changing request type', () => {
const requestType = screen.getByTestId(testIds.requestType);
const confirmButton = screen.getByText(labelIds.confirmButtonLabel);
const event = {
target: {
value: '',
},
};

fireEvent.change(requestType, event);
fireEvent.click(confirmButton);

expect(mockOnConfirm).toHaveBeenCalledWith(event.target.value);
});
});

describe('When request type is not provided', () => {
const props = {
...defaultTestProps,
requestTypes: [],
};

beforeEach(() => {
render(<ChooseRequestTypeDialog {...props} />);
});

it('should render request type error', () => {
const requestTypeError = screen.getByText(labelIds.requestTypeError);

expect(requestTypeError).toBeInTheDocument();
});
});

describe('when isLoading is true', () => {
Expand Down
1 change: 1 addition & 0 deletions test/jest/__mock__/stripesComponents.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ jest.mock('@folio/stripes/components', () => ({
<select {...props}>
{props.children}
</select>
<span>{props.error}</span>
</div>)),
TextArea: jest.fn(({
'data-testid': testId,
Expand Down
Loading