* Refactored to use a common <OrganizationPicker /> component. * Small refactor to organization <option />s. * Renamed files from OrgSettings* to OrganizationPicker* * Brought orgsettings inline to article form. * Brought orgsettings inline to listings form. * Rename onBlur to onToggle for org picker instances. Ooops. * Updated <OrganizationPicker /> test.
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
import { h } from 'preact';
|
|
import render from 'preact-render-to-json';
|
|
import { OrganizationPicker } from '../OrganizationPicker';
|
|
|
|
const commonProps = {
|
|
id: 'someFormElementId',
|
|
name: 'someFormElementName',
|
|
onToggle: jest.fn(),
|
|
};
|
|
|
|
const organizations = [
|
|
{ id: 1, name: 'Acme Org 1' },
|
|
{ id: 2, name: 'Acme Org 2' },
|
|
];
|
|
|
|
describe('<OrganizationPicker />', () => {
|
|
it('renders with the given organization selected from the list of available organizations', () => {
|
|
const tree = render(
|
|
<OrganizationPicker
|
|
{...commonProps}
|
|
organizationId={1}
|
|
organizations={organizations}
|
|
/>,
|
|
);
|
|
expect(tree).toMatchSnapshot();
|
|
});
|
|
|
|
it('renders with no organization selected when the organization ID is not set', () => {
|
|
const tree = render(
|
|
<OrganizationPicker
|
|
{...commonProps}
|
|
organizationId={undefined}
|
|
organizations={organizations}
|
|
/>,
|
|
);
|
|
expect(tree).toMatchSnapshot();
|
|
});
|
|
|
|
it('renders an organization list with only "None" as an option when no organizations are passed in.', () => {
|
|
const tree = render(
|
|
<OrganizationPicker
|
|
{...commonProps}
|
|
organizationId={undefined}
|
|
organizations={[]}
|
|
/>,
|
|
);
|
|
expect(tree).toMatchSnapshot();
|
|
});
|
|
});
|