Skip to content

Commit

Permalink
Merge pull request #1 from jaknas/metadata-taxonomy-options-api-test
Browse files Browse the repository at this point in the history
feat: add test
  • Loading branch information
TylerGauntlett authored Oct 11, 2024
2 parents 8f943f5 + d58ffea commit bceaf14
Showing 1 changed file with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { type MetadataTemplateInstance } from '@box/metadata-editor';
import { MetadataTemplateField, type MetadataTemplateInstance } from '@box/metadata-editor';
import userEvent from '@testing-library/user-event';
import { screen, render } from '../../../test-utils/testing-library';
import MetadataInstanceEditor, { MetadataInstanceEditorProps } from '../MetadataInstanceEditor';
Expand Down Expand Up @@ -136,4 +136,44 @@ describe('MetadataInstanceEditor', () => {

expect(mockOnDiscardUnsavedChanges).toHaveBeenCalled();
});

test('should call taxonomyOptionsFetcher on metadata taxonomy field search', async () => {
const taxonomyField: MetadataTemplateField = {
type: 'taxonomy',
key: 'States',
displayName: 'States',
description: 'State locations',
hidden: false,
id: '2',
taxonomyKey: 'geography',
taxonomyId: '1',
optionsRules: {
multiSelect: true,
selectableLevels: [1],
},
};

const template: MetadataTemplateInstance = {
...mockCustomMetadataTemplateWithField,
fields: [...mockCustomMetadataTemplateWithField.fields, taxonomyField],
};

const props: MetadataInstanceEditorProps = {
...defaultProps,
template,
};

const { getByRole } = render(<MetadataInstanceEditor {...props} />);
const combobox = getByRole('combobox', { name: 'States' });

await userEvent.type(combobox, 'A');

expect(props.taxonomyOptionsFetcher).toHaveBeenCalledWith(
template.scope,
template.templateKey,
taxonomyField.key,
taxonomyField.optionsRules.selectableLevels[0],
{ marker: null, searchInput: 'A', signal: expect.anything() },
);
});
});

0 comments on commit bceaf14

Please sign in to comment.