Skip to content

Commit

Permalink
UIQM-649 Added validation rule to prevent deletion of 010 when it is …
Browse files Browse the repository at this point in the history
…a linking point. (#675)
  • Loading branch information
BogdanDenis authored and Dmytro-Melnyshyn committed Apr 18, 2024
1 parent c023a1e commit 4fbcb05
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 53 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [UIQM-641](https://issues.folio.org/browse/UIQM-641) Call `cleanBytesFields` function with correct arguments to fix 008 field.
* [UIQM-640](https://issues.folio.org/browse/UIQM-640) Create authority | Make list of authority files in lookup alphabetical.
* [UIQM-650](https://issues.folio.org/browse/UIQM-650) Use `setTimeout` to defer the execution of `showCallout` to ensure the toasts are shown after the potentially heavy render.
* [UIQM-649](https://issues.folio.org/browse/UIQM-649) Added validation rule to prevent deletion of 010 when it is a linking point.

## [8.0.0](https://github.com/folio-org/ui-quick-marc/tree/v8.0.0) (2024-03-21)

Expand Down
6 changes: 6 additions & 0 deletions src/hooks/useValidation/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ const BASE_AUTHORITY_VALIDATORS = [
validator: RULES.SUBFIELD_VALUE_EXISTS,
message: () => <FormattedMessage id="ui-quick-marc.record.error.010.$aRemoved" />,
},
{
tag: '010',
ignore: ({ initialValues, naturalId }) => !is010LinkedToBibRecord(initialValues.records, naturalId),
validator: RULES.EXISTS,
message: () => <FormattedMessage id="ui-quick-marc.record.error.010.removed" />,
},
{
tag: '010',
validator: RULES.NON_REPEATABLE,
Expand Down
168 changes: 115 additions & 53 deletions src/hooks/useValidation/useValidation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ describe('useValidation', () => {
});
});

describe('when record is MARC Authority record', () => {
describe('when validating Authority record', () => {
const localSourceFile = {
id: '1',
source: 'local',
Expand Down Expand Up @@ -1328,59 +1328,121 @@ describe('useValidation', () => {
});
});

describe('when 010 was removed', () => {
it('should not return an error message', () => {
const _initialValues = {
leader: initialValues.leader,
records: [
{
id: 1,
content: initialValues.leader,
tag: 'LDR',
},
{
id: 2,
content: {},
tag: '008',
},
{
id: 3,
tag: '110',
content: '$a Record title',
},
{
id: 4,
tag: '010',
content: '$a n123456',
},
],
};
const { result } = renderHook(() => useValidation({
...marcContext,
initialValues: _initialValues,
}));

const record = {
...initialValues,
records: [
{
id: 'LDR',
content: initialValues.leader,
tag: 'LDR',
},
{
id: 1,
content: {},
tag: '008',
},
{
id: 3,
tag: '110',
},
],
};
describe('when 010 was a linking point', () => {
describe('and 010 was removed', () => {
it('should return an error message', () => {
const _initialValues = {
leader: initialValues.leader,
records: [
{
id: 1,
content: initialValues.leader,
tag: 'LDR',
},
{
id: 2,
content: {},
tag: '008',
},
{
id: 3,
tag: '110',
content: '$a Record title',
},
{
id: 4,
tag: '010',
content: '$a n123456',
},
],
};
const { result } = renderHook(() => useValidation({
...marcContext,
initialValues: _initialValues,
naturalId: 'n123456',
}));

const record = {
...initialValues,
records: [
{
id: 'LDR',
content: initialValues.leader,
tag: 'LDR',
},
{
id: 1,
content: {},
tag: '008',
},
{
id: 3,
tag: '110',
},
],
};

expect(result.current.validate(record.records).props.id).toBe('ui-quick-marc.record.error.010.removed');
});
});
});

expect(result.current.validate(record.records)).toBeUndefined();
describe('when 010 was not a linking point', () => {
describe('and 010 was removed', () => {
it('should not return an error message', () => {
const _initialValues = {
leader: initialValues.leader,
records: [
{
id: 1,
content: initialValues.leader,
tag: 'LDR',
},
{
id: 2,
content: {},
tag: '008',
},
{
id: 3,
tag: '110',
content: '$a Record title',
},
{
id: 4,
tag: '010',
content: '$a n123456',
},
],
};
const { result } = renderHook(() => useValidation({
...marcContext,
initialValues: _initialValues,
naturalId: 'n09876',
}));

const record = {
...initialValues,
records: [
{
id: 'LDR',
content: initialValues.leader,
tag: 'LDR',
},
{
id: 1,
content: {},
tag: '008',
},
{
id: 3,
tag: '110',
},
],
};

expect(result.current.validate(record.records)).toBeUndefined();
});
});
});
});
Expand Down

0 comments on commit 4fbcb05

Please sign in to comment.