Skip to content

Commit

Permalink
remove call to crudGetMany if ids list is empty, edit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fargito committed May 24, 2019
1 parent 37b501d commit 9415b04
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ describe('<ReferenceArrayInputController />', () => {
).toEqual([defaultProps.reference, [6]]);
});

it('should call crudGetMany with empty list when already fetched input value changes', () => {
it('should not call crudGetMany when already fetched input value changes', () => {
const crudGetMany = jest.fn();
const wrapper = shallow(
<ReferenceArrayInputController
Expand All @@ -447,15 +447,15 @@ describe('<ReferenceArrayInputController />', () => {
/>
);
expect(
crudGetMany.mock.calls[crudGetMany.mock.calls.length - 1]
crudGetMany.mock.calls[0]
).toEqual([defaultProps.reference, [5, 6]]);
wrapper.setProps({ input: { value: [6] } });
expect(
crudGetMany.mock.calls[crudGetMany.mock.calls.length - 1]
).toEqual([defaultProps.reference, []]);
crudGetMany.mock.calls.length
).toEqual(1);
});

it('should call crudGetOne and crudGetMatching when record changes', () => {
it('should only call crudGetOne and not crudGetMatching when only the record changes', () => {
const crudGetMany = jest.fn();
const crudGetMatching = jest.fn();
const wrapper = shallow(
Expand All @@ -471,6 +471,6 @@ describe('<ReferenceArrayInputController />', () => {
assert.equal(crudGetMany.mock.calls.length, 1);
wrapper.setProps({ record: { id: 1 } });
assert.equal(crudGetMatching.mock.calls.length, 2);
assert.equal(crudGetMany.mock.calls.length, 2);
assert.equal(crudGetMany.mock.calls.length, 1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ interface EnhancedProps {
* <SelectArrayInput optionText="name" />
* </ReferenceArrayInput>
*/
export class UnconnectedReferenceArrayInputController extends Component<
Props & EnhancedProps
> {
export class UnconnectedReferenceArrayInputController extends Component<Props & EnhancedProps> {
public static defaultProps = {
allowEmpty: false,
filter: {},
Expand Down Expand Up @@ -237,7 +235,7 @@ export class UnconnectedReferenceArrayInputController extends Component<
const idsToFetch = isInitialCall
? ids
: difference(ids, this.props.input.value);
crudGetMany(reference, idsToFetch);
if (idsToFetch.length) crudGetMany(reference, idsToFetch);
}
};

Expand Down

0 comments on commit 9415b04

Please sign in to comment.