-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:folio-org/ui-organizations into f…
…eat/number_generator
- Loading branch information
Showing
56 changed files
with
570 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/OrganizationIntegration/OrganizationIntegrationForm/SchedulingForm/constants.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
33 changes: 33 additions & 0 deletions
33
src/OrganizationIntegration/OrganizationIntegrationForm/SchedulingForm/utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) | ||
); | ||
}; |
49 changes: 49 additions & 0 deletions
49
src/OrganizationIntegration/OrganizationIntegrationForm/SchedulingForm/utils.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.