Skip to content

Commit

Permalink
UIEUS-321 Address test warnings (#456)
Browse files Browse the repository at this point in the history
* Add test for submit
Fix validate function for FieldArray

* Use custom propType for stripes
  • Loading branch information
alb3rtino authored Nov 3, 2023
1 parent 1720f93 commit 182ad79
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import counterReports from './data/counterReports';
import css from './SelectedReportsForm.css';

import SelectReportType from './SelectReportType';
import { notRequired, requiredArray } from '../../../util/validate';
import { requiredArray } from '../../../util/validate';

const getCounterReportsForVersion = (counterVersion) => {
return _.filter(counterReports.getOptions(), [
Expand Down Expand Up @@ -48,8 +48,8 @@ class SelectedReportsForm extends React.Component {
<FieldArray
name="harvestingConfig.requestedReports"
required={this.props.required}
validate={this.props.required ? requiredArray : notRequired}
data={this.props.required ? 1 : 0}
// dont know why, but this seems to work
validate={(value) => this.props.required && requiredArray(value)}
>
{({ fields }) => (
<SelectReportType
Expand Down
22 changes: 21 additions & 1 deletion src/components/views/UDPForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,27 @@ describe('UDPForm', () => {
expect(screen.getByRole('textbox', { name: 'Requestor mail' })).not.toBeRequired();
});

test('saving a named inactive provider', async () => {
const harvestingStatusCombobox = screen.getByRole('combobox', { name: 'Harvesting status' });
const providerNameTextbox = screen.getByRole('textbox', { name: 'Provider name' });
const saveAndCloseButton = screen.getByRole('button', { name: 'Save & close' });

// status = active && name set
await userEvent.selectOptions(harvestingStatusCombobox, ['active']);
await userEvent.type(providerNameTextbox, 'FooBar');
expect(harvestingStatusCombobox).toHaveValue('active');
expect(providerNameTextbox).toHaveValue('FooBar');
await userEvent.click(saveAndCloseButton);
expect(onSubmit).not.toHaveBeenCalled();

// status = inactive && name set
await userEvent.selectOptions(harvestingStatusCombobox, ['inactive']);
expect(harvestingStatusCombobox).toHaveValue('inactive');
expect(providerNameTextbox).toHaveValue('FooBar');
await userEvent.click(saveAndCloseButton);
expect(onSubmit).toHaveBeenCalled();
});

describe('test required value of customerId field', () => {
test('change harvest statistics via from sushi to aggregator', async () => {
await userEvent.selectOptions(
Expand Down Expand Up @@ -450,7 +471,6 @@ describe('UDPForm', () => {
const testSelectReportRelease = async (reportRelease) => {
renderUDPForm(stripes, reportReleaseProvider);
const reqIdBox = screen.getByRole('textbox', { name: 'Requestor ID' });
// const apiKeyBox = screen.getByRole('textbox', { name: 'API key' });
const releaseSelectBox = screen.getByLabelText('Report release', { exact: false });

expect(reqIdBox).toBeEnabled();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { stripesConnect, stripesShape, CalloutContext } from '@folio/stripes/core';
import { stripesConnect, CalloutContext } from '@folio/stripes/core';
import {
Button,
Dropdown,
Expand Down Expand Up @@ -52,7 +52,9 @@ const DownloadCredentialsButton = ({ aggregatorId, stripes }) => {

DownloadCredentialsButton.propTypes = {
aggregatorId: PropTypes.string.isRequired,
stripes: stripesShape.isRequired,
stripes: PropTypes.shape({
okapi: PropTypes.object.isRequired,
}).isRequired,
};

export default stripesConnect(DownloadCredentialsButton);

0 comments on commit 182ad79

Please sign in to comment.