Skip to content

Commit

Permalink
test fixing progress
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnC-80 committed Jan 9, 2024
1 parent 907f93c commit eac65db
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Col,
Row,
dayjs,
getLocaleDateFormat,
} from '@folio/stripes/components';
import {
BACKEND_DATE_STANDARD,
Expand Down Expand Up @@ -44,8 +45,9 @@ class PackageCoverageFields extends Component {

validateCoverageDate = (value) => {
const { intl } = this.props;
dayjs.locale(intl.locale);
const dateFormat = dayjs.localeData().longDateFormat('L');
// dayjs.locale(intl.locale);
// const dateFormat = dayjs.localeData().longDateFormat('L');
const dateFormat = getLocaleDateFormat({ intl });
let errors;

if (value && !dayjs.utc(value).isValid()) {
Expand Down
10 changes: 5 additions & 5 deletions src/components/resource/_fields/validate-date-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import {
FormattedMessage,
} from 'react-intl';

import { FormattedDate, dayjs, DayRange } from '@folio/stripes/components';
import { FormattedDate, dayjs, DayRange, getLocaleDateFormat } from '@folio/stripes/components';

/**
* Validator to ensure begin date is present and entered dates are valid
* @param {} dateRange - coverage date range to validate
* @returns {} - an error object if errors are found, or `undefined` otherwise
*/
const validateDateFormat = (dateRange, locale) => {
dayjs.locale(locale);
const dateFormat = dayjs.localeData().longDateFormat('L');
// dayjs.locale(locale);
const dateFormat = getLocaleDateFormat({ intl: { locale } });
const message = <FormattedMessage id="ui-eholdings.validate.errors.dateRange.format" values={{ dateFormat }} />;

if (!dateRange.beginCoverage || !dayjs.utc(dateRange.beginCoverage).isValid()) {
Expand Down Expand Up @@ -49,7 +49,7 @@ const validateNoRangeOverlaps = (dateRange, customCoverages, index) => {

const beginCoverageDate = dayjs.utc(dateRange.beginCoverage);
const endCoverageDate = dateRange.endCoverage ? dayjs.utc(dateRange.endCoverage) : present;
const coverageRange = dayjs.range(beginCoverageDate, endCoverageDate);
const coverageRange = new DayRange(beginCoverageDate, endCoverageDate);

for (let overlapIndex = 0, len = customCoverages.length; overlapIndex < len; overlapIndex++) {
const overlapRange = customCoverages[overlapIndex];
Expand All @@ -61,7 +61,7 @@ const validateNoRangeOverlaps = (dateRange, customCoverages, index) => {

const overlapCoverageBeginDate = dayjs.utc(overlapRange.beginCoverage);
const overlapCoverageEndDate = overlapRange.endCoverage ? dayjs.utc(overlapRange.endCoverage) : present;
const overlapCoverageRange = dayjs.range(overlapCoverageBeginDate, overlapCoverageEndDate);
const overlapCoverageRange = new DayRange(overlapCoverageBeginDate, overlapCoverageEndDate);

const startDate =
<FormattedDate
Expand Down
1 change: 1 addition & 0 deletions test/jest/__mock__/reactIntl.mock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
jest.mock('react-intl', () => {
const intl = {
formatMessage: ({ id }) => id,
locale: 'en'
};

return {
Expand Down
2 changes: 1 addition & 1 deletion test/jest/helpers/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const Harness = ({
<RouteHistoryContext.Provider value={routeHistoryCtx}>
<Provider store={store}>
<QueryClientProvider client={queryClient}>
<IntlProvider>
<IntlProvider locale="en">
{children}
</IntlProvider>
</QueryClientProvider>
Expand Down

0 comments on commit eac65db

Please sign in to comment.