Skip to content

Commit

Permalink
Replace Bibliographic, Authority, Holdings FixedField to one FixedField
Browse files Browse the repository at this point in the history
Replace Bibliographic, Authority, Holdings FixedField to one FixedField
Refactory getFixedField without marcType
Removed unnecessary tests, fixed current without using the marcType props
  • Loading branch information
przemyslawturek committed Oct 3, 2023
1 parent c43a349 commit 4dd34d1
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 135 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
BytesField,
} from '../BytesField';

const HoldingsFixedField = ({ name, config }) => {
const FixedField = ({ name, config }) => {
return (
<BytesField
name={name}
Expand All @@ -14,11 +14,9 @@ const HoldingsFixedField = ({ name, config }) => {
);
};

HoldingsFixedField.propTypes = {
FixedField.propTypes = {
name: PropTypes.string.isRequired,
config: PropTypes.object.isRequired,
};

HoldingsFixedField.displayName = 'HoldingsFixedField';

export default HoldingsFixedField;
export default FixedField;
Original file line number Diff line number Diff line change
@@ -1,35 +1,13 @@
import React from 'react';

import { MARC_TYPES } from '../../../common/constants';
import { LEADER_TAG } from '../../constants';
import {
SUBFIELD_TYPES,
} from '../BytesField';

import HoldingsFixedField from './HoldingsFixedField';
import AuthorityFixedField from './AuthorityFixedField';
import BibliographicFixedField from './BibliographicFixedField';
import FixedField from './FixedField';

export const FixedFieldFactory = {
getFixedFieldByType(marcType) {
let FixedField;

switch (marcType) {
case MARC_TYPES.HOLDINGS:
FixedField = HoldingsFixedField;
break;
case MARC_TYPES.AUTHORITY:
FixedField = AuthorityFixedField;
break;
case MARC_TYPES.BIB:
FixedField = BibliographicFixedField;
break;
default:
FixedField = null;
}

return FixedField;
},

getFixedFieldType(fixedFieldSpec, type, subtype) {
if (!fixedFieldSpec?.spec) {
Expand Down Expand Up @@ -97,10 +75,9 @@ export const FixedFieldFactory = {
return config;
},

getFixedField(name, marcType, fixedFieldSpec, type, subtype) {
const FixedField = this.getFixedFieldByType(marcType);
getFixedField(name, fixedFieldSpec, type, subtype) {
const configFixedField = this.getConfigFixedField(fixedFieldSpec, type, subtype);

return FixedField ? <FixedField name={name} config={configFixedField} /> : null;
return <FixedField name={name} config={configFixedField} />;
},
};
Original file line number Diff line number Diff line change
@@ -1,121 +1,88 @@
import '@folio/stripes-acq-components/test/jest/__mock__';

import { FixedFieldFactory } from './FixedFieldFactory';

import BibliographicFixedField from './BibliographicFixedField';
import HoldingsFixedField from './HoldingsFixedField';
import AuthorityFixedField from './AuthorityFixedField';
import { MARC_TYPES } from '../../../common/constants';
import fixedFieldSpecBib from '../../../../test/mocks/fixedFieldSpecBib';
import fixedFieldSpecAuth from '../../../../test/mocks/fixedFieldSpecAuth';
import fixedFieldSpecHold from '../../../../test/mocks/fixedFieldSpecHold';

describe('FixedFieldFactory', () => {
it('should create correct marc type fixed field', () => {
expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB).type.displayName,
).toBe(BibliographicFixedField.displayName);

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.AUTHORITY).type.displayName,
).toBe(AuthorityFixedField.displayName);

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.HOLDINGS).type.displayName,
).toBe(HoldingsFixedField.displayName);
});

it('should create correct fixed field type', () => {
expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 'a', 'm').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 'a', 'm').props.config.type,
).toBe('books');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 'a', 'a').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 'a', 'a').props.config.type,
).toBe('books');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 'a', 'd').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 'a', 'd').props.config.type,
).toBe('books');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 'a', 'x').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 'a', 'x').props.config.type,
).toBe(undefined);

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 't').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 't').props.config.type,
).toBe('books');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 'c').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 'c').props.config.type,
).toBe('scores');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 'i').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 'i').props.config.type,
).toBe('sound_recordings');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 'a', 'b').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 'a', 'b').props.config.type,
).toBe('continuing_resources');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 'a', 'i').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 'a', 'i').props.config.type,
).toBe('continuing_resources');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 'a', 's').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 'a', 's').props.config.type,
).toBe('continuing_resources');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 's').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 's').props.config.type,
).toBe('continuing_resources');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 'm').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 'm').props.config.type,
).toBe('computer_files');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 'g').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 'g').props.config.type,
).toBe('visual_materials');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 'e').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 'e').props.config.type,
).toBe('maps');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 'f').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 'f').props.config.type,
).toBe('maps');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 'p').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 'p').props.config.type,
).toBe('mixed_materials');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.AUTHORITY, fixedFieldSpecAuth, 'z').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecAuth, 'z').props.config.type,
).toBe('unknown');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.AUTHORITY, fixedFieldSpecAuth, 'z').type.displayName,
).toBe(AuthorityFixedField.displayName);

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.HOLDINGS, fixedFieldSpecHold, 'u').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecHold, 'u').props.config.type,
).toBe('unknown');

expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.HOLDINGS, fixedFieldSpecHold, 'u').type.displayName,
).toBe(HoldingsFixedField.displayName);
});

it('should return undefined type when there is no matched field', () => {
expect(
FixedFieldFactory.getFixedField('records', MARC_TYPES.BIB, fixedFieldSpecBib, 'l').props.config.type,
FixedFieldFactory.getFixedField('records', fixedFieldSpecBib, 'l').props.config.type,
).toBe(undefined);
});

it('should return null when marc types is wrong', () => {
expect(
FixedFieldFactory.getFixedField('records', 'instance', fixedFieldSpecBib, 'l'),
).toBe(null);
});
});
4 changes: 1 addition & 3 deletions src/QuickMarcEditor/QuickMarcEditorRows/FixedField/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export * from './FixedFieldFactory';

export { default as AutorityFixedField } from './AuthorityFixedField';
export { default as BibliographicFixedField } from './BibliographicFixedField';
export { default as HoldingsFixedField } from './HoldingsFixedField';
export { default as FixedField } from './FixedField';
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ const QuickMarcEditorRows = ({
{
isFixedField && (
FixedFieldFactory.getFixedField(
`${name}.content`, marcType, fixedFieldSpec, type, subtype,
`${name}.content`, fixedFieldSpec, type, subtype,
)
)
}
Expand Down

0 comments on commit 4dd34d1

Please sign in to comment.