Skip to content

Commit

Permalink
UIQM-574 Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanDenis committed Nov 21, 2023
1 parent c36f459 commit 1d48986
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback } from 'react';
import { Field } from 'react-final-form';
import { useIntl } from 'react-intl';
import PropTypes from 'prop-types';
import { useField } from 'react-final-form';

import { SourceFileLookup } from '../../SourceFileLookup';
import { ContentField } from '../ContentField';
Expand All @@ -20,7 +21,7 @@ const ControlNumberField = ({
marcType,
action,
}) => {
const { input, ...inputRest } = useField(name);
const intl = useIntl();

const handleSourceFileSelection = useCallback(() => {
// TODO: handle generation of HRID + source file prefix here (UIQM-576)
Expand All @@ -30,11 +31,14 @@ const ControlNumberField = ({

return (
<>
<ContentField
id={id}
input={input}
<Field
component={ContentField}
aria-label={intl.formatMessage({ id: 'ui-quick-marc.record.subfield' })}
name={name}
disabled
{...inputRest}
data-testid={id}
id={id}
parse={v => v}
/>
{canSelectSourceFile && (
<SourceFileLookup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import arrayMutators from 'final-form-arrays';
import { ControlNumberField } from './ControlNumberField';
import { MARC_TYPES } from '../../../common/constants';
import { QUICK_MARC_ACTIONS } from '../../constants';

jest.mock('../../SourceFileLookup', () => ({
SourceFileLookup: ({ onSourceFileSelect }) => (
<button type="button" onClick={() => onSourceFileSelect({ target: { value: 'test-source-file-id' } })}>Select file</button>
),
}));
import Harness from '../../../../test/jest/helpers/harness';

const getControlNumberField = (props = {}, initialValues) => (
<Form
Expand All @@ -32,7 +27,7 @@ const getControlNumberField = (props = {}, initialValues) => (
/>
);

const renderControlNumberField = (props = {}) => render(getControlNumberField(props));
const renderControlNumberField = (props = {}) => render(getControlNumberField(props), { wrapper: Harness });

describe('Given ControlNumberField', () => {
it('should render content field', () => {
Expand All @@ -51,17 +46,25 @@ describe('Given ControlNumberField', () => {
marcType: MARC_TYPES.BIB,
});

expect(queryByText('ui-quick-marc.sourceFileLookup')).not.toBeDefined();
expect(queryByText('ui-quick-marc.sourceFileLookup')).toBeNull();
});
});

describe('when action is not CREATE', () => {
beforeAll(() => {
jest.mock('../../SourceFileLookup', () => ({
SourceFileLookup: ({ onSourceFileSelect }) => (
<button type="button" onClick={() => onSourceFileSelect({ target: { value: 'test-source-file-id' } })}>Select file</button>
),
}));
});

it('should not render source file lookup', () => {
const { queryByText } = renderControlNumberField({
action: QUICK_MARC_ACTIONS.EDIT,
});

expect(queryByText('ui-quick-marc.sourceFileLookup')).not.toBeDefined();
expect(queryByText('ui-quick-marc.sourceFileLookup')).toBeNull();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ describe('Given QuickMarcEditorRows', () => {
describe('when the subfield is focused', () => {
it('should have a cursor at the end of the field value', () => {
const { getByTestId } = renderQuickMarcEditorRows();
const subfield = getByTestId('content-field-0');
const subfield = getByTestId('content-field-4');
const valueLength = subfield.value.length;
const spySetSelectionRange = jest.spyOn(subfield, 'setSelectionRange');

Expand Down
1 change: 0 additions & 1 deletion src/QuickMarcEditor/SourceFileLookup/SourceFileLookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const SourceFileLookup = ({
return (
<>
<Button
key="searchButton"
buttonStyle="link"
marginBottom0
onClick={openModal}
Expand Down

0 comments on commit 1d48986

Please sign in to comment.