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

Sprint 182 - UIORGS-417, UIORGS-418 #604

Merged
merged 3 commits into from
Jan 23, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* Enable "Hourly" and "Monthly" EDI export scheduling frequency options. Refs UIORGS-415.
* Create Privileged donor information accordion in organization record. Refs UIORGS-397.
* Factor away from unsupported `color()` function. Refs UIORGS-416.
* Suppress banking information management for unauthorized user. Refs UIORGS-418.
* Add validation for `Day` field in `Monthly` scheduler for export method. Refs UIORGS-417.

## [5.0.0](https://github.com/folio-org/ui-organizations/tree/v5.0.0) (2023-10-12)
[Full Changelog](https://github.com/folio-org/ui-organizations/compare/v4.0.0...v5.0.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,16 @@ import {
SCHEDULE_PERIODS,
WEEKDAYS,
} from '../../constants';

const ALLOWED_SCHEDULE_PERIODS = [
SCHEDULE_PERIODS.none,
SCHEDULE_PERIODS.hours,
SCHEDULE_PERIODS.days,
SCHEDULE_PERIODS.weeks,
SCHEDULE_PERIODS.months,
];

const normalizeNumber = value => {
if (!value && value !== 0) return value;

return Number(value);
};

const validatePeriod = (value) => {
return value !== SCHEDULE_PERIODS.none
? undefined
: <FormattedMessage id="stripes-acq-components.validation.required" />;
};
import {
ALLOWED_SCHEDULE_PERIODS,
MAX_DAYS_OF_MONTHLY_SCHEDULE,
MIN_REQUIRED_NUMBER,
} from './constants';
import {
validateRequiredMinAndMaxNumber,
normalizeNumber,
validatePeriod,
} from './utils';

export const SchedulingForm = () => {
const { formatMessage } = useIntl();
Expand Down Expand Up @@ -135,7 +125,7 @@ export const SchedulingForm = () => {
label={<FormattedMessage id="ui-organizations.integration.scheduling.scheduleFrequency" />}
name="exportTypeSpecificParameters.vendorEdiOrdersExportConfig.ediSchedule.scheduleParameters.scheduleFrequency"
type="number"
min={1}
min={MIN_REQUIRED_NUMBER}
hasClearIcon={false}
required
validate={validateRequiredPositiveNumber}
Expand Down Expand Up @@ -167,7 +157,7 @@ export const SchedulingForm = () => {
label={<FormattedMessage id="ui-organizations.integration.scheduling.scheduleFrequency" />}
name="exportTypeSpecificParameters.vendorEdiOrdersExportConfig.ediSchedule.scheduleParameters.scheduleFrequency"
type="number"
min={1}
min={MIN_REQUIRED_NUMBER}
hasClearIcon={false}
required
validate={validateRequiredPositiveNumber}
Expand Down Expand Up @@ -207,7 +197,7 @@ export const SchedulingForm = () => {
label={<FormattedMessage id="ui-organizations.integration.scheduling.scheduleFrequency" />}
name="exportTypeSpecificParameters.vendorEdiOrdersExportConfig.ediSchedule.scheduleParameters.scheduleFrequency"
type="number"
min={1}
min={MIN_REQUIRED_NUMBER}
hasClearIcon={false}
required
validate={validateRequiredPositiveNumber}
Expand Down Expand Up @@ -259,11 +249,11 @@ export const SchedulingForm = () => {
label={<FormattedMessage id="ui-organizations.integration.scheduling.scheduleDay" />}
name="exportTypeSpecificParameters.vendorEdiOrdersExportConfig.ediSchedule.scheduleParameters.scheduleDay"
type="number"
min={1}
max={31}
min={MIN_REQUIRED_NUMBER}
max={MAX_DAYS_OF_MONTHLY_SCHEDULE}
hasClearIcon={false}
required
validate={validateRequiredPositiveNumber}
validate={validateRequiredMinAndMaxNumber}
parse={normalizeNumber}
/>
</Col>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { SCHEDULE_PERIODS } from '../../constants';

export const ALLOWED_SCHEDULE_PERIODS = [
SCHEDULE_PERIODS.none,
SCHEDULE_PERIODS.hours,
SCHEDULE_PERIODS.days,
SCHEDULE_PERIODS.weeks,
SCHEDULE_PERIODS.months,
];

export const MIN_REQUIRED_NUMBER = 1;
export const MAX_DAYS_OF_MONTHLY_SCHEDULE = 31;
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { FormattedMessage } from 'react-intl';

import {
validateRequiredMinNumber,
validateRequiredMaxNumber,
validateRequiredNumber,
} from '@folio/stripes-acq-components';

import { SCHEDULE_PERIODS } from '../../constants';
import {
MAX_DAYS_OF_MONTHLY_SCHEDULE,
MIN_REQUIRED_NUMBER,
} from './constants';

export const normalizeNumber = value => {
if (!value && value !== 0) return value;

return Number(value);
};

export const validatePeriod = (value) => {
return value !== SCHEDULE_PERIODS.none
? undefined
: <FormattedMessage id="stripes-acq-components.validation.required" />;
};

export const validateRequiredMinAndMaxNumber = (value) => {
return (
validateRequiredNumber(value)
|| validateRequiredMinNumber({ minNumber: MIN_REQUIRED_NUMBER, value })
|| validateRequiredMaxNumber({ maxNumber: MAX_DAYS_OF_MONTHLY_SCHEDULE, value })
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { SCHEDULE_PERIODS } from '../../constants';
import {
validateRequiredMinAndMaxNumber,
normalizeNumber,
validatePeriod,
} from './utils';

jest.mock('@folio/stripes-acq-components', () => ({
...jest.requireActual('@folio/stripes-acq-components'),
validateRequiredMinNumber: jest.fn(({ minNumber, value }) => (minNumber <= value ? undefined : 'min error')),
validateRequiredMaxNumber: jest.fn(({ maxNumber, value }) => (maxNumber >= value ? undefined : 'max error')),
}));

describe('OrganizationIntegrationForm utils', () => {
describe('normalizeNumber', () => {
it('should return number', () => {
expect(normalizeNumber(0)).toBe(0);
});

it('should return number', () => {
expect(normalizeNumber('0')).toBe(0);
});

it('should return undefined', () => {
expect(normalizeNumber('')).toBe('');
});
});

describe('validatePeriod', () => {
it('should return undefined', () => {
expect(validatePeriod(SCHEDULE_PERIODS.monthly)).toBe(undefined);
});

it('should return error message', () => {
expect(validatePeriod(SCHEDULE_PERIODS.none)).toBeDefined();
});
});

describe('validateRequiredMinAndMaxNumber', () => {
it('should return undefined', () => {
expect(validateRequiredMinAndMaxNumber(0)).toBeTruthy();
expect(validateRequiredMinAndMaxNumber('')).toBeTruthy();
expect(validateRequiredMinAndMaxNumber(-1)).toBeTruthy();
expect(validateRequiredMinAndMaxNumber(1)).toBe(undefined);
expect(validateRequiredMinAndMaxNumber(2)).toBe(undefined);
expect(validateRequiredMinAndMaxNumber(34)).toBeTruthy();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ exports[`OrganizationIntegrationForm should render correct form structure 1`] =
</div>
<div
class="content-wrap expanded"
style="z-index: 1;"
style="z-index: 4;"
>
<div
aria-labelledby="accordion-toggle-button-integrationInfo"
Expand Down Expand Up @@ -205,24 +205,27 @@ exports[`OrganizationIntegrationForm should render correct form structure 1`] =
class="col-xs-3"
>
<div
class="textArea inputGroup fullWidth"
class="textArea fullWidth"
>
<label
class="label"
for="textarea-input-8"
>
ui-organizations.integration.info.configDescription
</label>
<textarea
aria-invalid="false"
class="formControl"
id="textarea-input-8"
name="exportTypeSpecificParameters.vendorEdiOrdersExportConfig.configDescription"
type="text"
/>
<div
role="alert"
/>
class="inputGroup"
>
<textarea
aria-invalid="false"
class="formControl"
id="textarea-input-8"
name="exportTypeSpecificParameters.vendorEdiOrdersExportConfig.configDescription"
/>
<div
role="alert"
/>
</div>
</div>
</div>
<div
Expand Down Expand Up @@ -327,7 +330,7 @@ exports[`OrganizationIntegrationForm should render correct form structure 1`] =
</div>
<div
class="content-wrap expanded"
style="z-index: 1;"
style="z-index: 3;"
>
<div
aria-labelledby="accordion-toggle-button-edi"
Expand Down Expand Up @@ -829,24 +832,27 @@ exports[`OrganizationIntegrationForm should render correct form structure 1`] =
data-test-notes="true"
>
<div
class="textArea inputGroup fullWidth"
class="textArea fullWidth"
>
<label
class="label"
for="textarea-input-17"
>
ui-organizations.integration.edi.notes
</label>
<textarea
aria-invalid="false"
class="formControl"
id="textarea-input-17"
name="exportTypeSpecificParameters.vendorEdiOrdersExportConfig.ediConfig.notes"
type="text"
/>
<div
role="alert"
/>
class="inputGroup"
>
<textarea
aria-invalid="false"
class="formControl"
id="textarea-input-17"
name="exportTypeSpecificParameters.vendorEdiOrdersExportConfig.ediConfig.notes"
/>
<div
role="alert"
/>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -898,7 +904,7 @@ exports[`OrganizationIntegrationForm should render correct form structure 1`] =
</div>
<div
class="content-wrap expanded"
style="z-index: 1;"
style="z-index: 2;"
>
<div
aria-labelledby="accordion-toggle-button-ftp"
Expand Down Expand Up @@ -1301,24 +1307,27 @@ exports[`OrganizationIntegrationForm should render correct form structure 1`] =
data-test-notes="true"
>
<div
class="textArea inputGroup fullWidth"
class="textArea fullWidth"
>
<label
class="label"
for="textarea-input-27"
>
ui-organizations.integration.ftp.notes
</label>
<textarea
aria-invalid="false"
class="formControl"
id="textarea-input-27"
name="exportTypeSpecificParameters.vendorEdiOrdersExportConfig.ediFtp.notes"
type="text"
/>
<div
role="alert"
/>
class="inputGroup"
>
<textarea
aria-invalid="false"
class="formControl"
id="textarea-input-27"
name="exportTypeSpecificParameters.vendorEdiOrdersExportConfig.ediFtp.notes"
/>
<div
role="alert"
/>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ exports[`OrganizationIntegrationView should render correct view structure 1`] =
</div>
<div
class="content-wrap expanded"
style="z-index: 1;"
style="z-index: 4;"
>
<div
aria-labelledby="accordion-toggle-button-integrationInfo"
Expand Down Expand Up @@ -369,7 +369,7 @@ exports[`OrganizationIntegrationView should render correct view structure 1`] =
</div>
<div
class="content-wrap expanded"
style="z-index: 1;"
style="z-index: 3;"
>
<div
aria-labelledby="accordion-toggle-button-edi"
Expand Down Expand Up @@ -764,7 +764,7 @@ exports[`OrganizationIntegrationView should render correct view structure 1`] =
</div>
<div
class="content-wrap expanded"
style="z-index: 1;"
style="z-index: 2;"
>
<div
aria-labelledby="accordion-toggle-button-ftp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,24 +414,27 @@ exports[`OrganizationAccountsForm should render correct structure with defined a
class="col-xs-6 col-md-3"
>
<div
class="textArea inputGroup fullWidth"
class="textArea fullWidth"
>
<label
class="label"
for="accounts[0].notes"
>
ui-organizations.accounts.notes
</label>
<textarea
aria-invalid="false"
class="formControl"
id="accounts[0].notes"
name="accounts[0].notes"
type="text"
/>
<div
role="alert"
/>
class="inputGroup"
>
<textarea
aria-invalid="false"
class="formControl"
id="accounts[0].notes"
name="accounts[0].notes"
/>
<div
role="alert"
/>
</div>
</div>
</div>
<div
Expand Down
Loading
Loading