import React from 'react';
import assert from 'assert';
import { shallow } from 'enzyme';
import { UnconnectedReferenceFieldController as ReferenceFieldController } from './ReferenceFieldController';
describe('', () => {
it('should call crudGetManyAccumulate on componentDidMount if reference source is defined', () => {
const crudGetManyAccumulate = jest.fn();
shallow(
);
assert.equal(crudGetManyAccumulate.mock.calls.length, 1);
});
it('should not call crudGetManyAccumulate on componentDidMount if reference source is null or undefined', () => {
const crudGetManyAccumulate = jest.fn();
shallow(
);
assert.equal(crudGetManyAccumulate.mock.calls.length, 0);
});
it('should render a link to the Edit page of the related record by default', () => {
const children = jest.fn();
const crudGetManyAccumulate = jest.fn();
shallow(
{children}
);
assert.equal(children.mock.calls[0][0].resourceLinkPath, '/posts/123');
});
it('should render a link to the Edit page of the related record when the resource contains slashes', () => {
const children = jest.fn();
const crudGetManyAccumulate = jest.fn();
shallow(
{children}
);
assert.equal(
children.mock.calls[0][0].resourceLinkPath,
'/prefix/posts/123'
);
});
it('should render a link to the Edit page of the related record when the resource is named edit or show', () => {
const children = jest.fn();
const crudGetManyAccumulate = jest.fn();
shallow(
{children}
);
assert.equal(children.mock.calls[0][0].resourceLinkPath, '/edit/123');
shallow(
{children}
);
assert.equal(children.mock.calls[1][0].resourceLinkPath, '/show/123');
});
it('should render a link to the Show page of the related record when the linkType is show', () => {
const children = jest.fn();
const crudGetManyAccumulate = jest.fn();
shallow(
{children}
);
assert.equal(
children.mock.calls[0][0].resourceLinkPath,
'/posts/123/show'
);
});
it('should render a link to the Show page of the related record when the resource is named edit or show and linkType is show', () => {
const children = jest.fn();
const crudGetManyAccumulate = jest.fn();
shallow(
{children}
);
assert.equal(
children.mock.calls[0][0].resourceLinkPath,
'/edit/123/show'
);
shallow(
{children}
);
assert.equal(
children.mock.calls[1][0].resourceLinkPath,
'/show/123/show'
);
});
it('should render no link when the linkType is false', () => {
const children = jest.fn();
const crudGetManyAccumulate = jest.fn();
shallow(
{children}
);
assert.equal(children.mock.calls[0][0].resourceLinkPath, false);
});
});