"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importDefault(require("react"));
const test_utilities_1 = require("../../test-utilities");
const Checkbox_1 = require("../Checkbox");
const RadioControl_1 = require("../RadioControl");
const ChoiceList_1 = require("./ChoiceList");
const defaultProps = {
    name: 'choice_list',
};
const id = '123';
const singleValue = id;
const multiValue = [id];
const labelContent = 'Label content';
const accessibilityLabel = 'Accessibility label content';
describe('<ChoiceList />', () => {
    it('renders a `RadioControl` component as the `Choice` when `value` is a single string', () => {
        const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={singleValue} onChange={noop}>
        <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
      </ChoiceList_1.ChoiceList>);
        expect(choiceList).toContainReactComponent(RadioControl_1.RadioControl);
    });
    it('does not render a `RadioControl` component as the `Choice` when `value` is a single string', () => {
        const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={singleValue} onChange={noop}>
        <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
      </ChoiceList_1.ChoiceList>);
        expect(choiceList).not.toContainReactComponent(Checkbox_1.CheckboxControl);
    });
    it('renders a `CheckboxControl` component as the `Choice` when `value` is a string array', () => {
        const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={multiValue} onChange={noop}>
        <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
      </ChoiceList_1.ChoiceList>);
        expect(choiceList).toContainReactComponent(Checkbox_1.CheckboxControl);
    });
    it('does not render a `RadioControl` component as the `Choice` when `value` is a string array', () => {
        const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={multiValue} onChange={noop}>
        <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
      </ChoiceList_1.ChoiceList>);
        expect(choiceList).not.toContainReactComponent(RadioControl_1.RadioControl);
    });
    it('passes its name down to its `RadioControl` component', () => {
        const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={singleValue} onChange={noop}>
        <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
      </ChoiceList_1.ChoiceList>);
        expect(choiceList.find(RadioControl_1.RadioControl)).toHaveReactProps({
            name: defaultProps.name,
        });
    });
    it('passes its onChange down to its `RadioControl` component', () => {
        const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={singleValue} onChange={noop}>
        <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
      </ChoiceList_1.ChoiceList>);
        expect(choiceList.find(RadioControl_1.RadioControl)).toHaveReactProps({
            onChange: expect.any(Function),
        });
    });
    it('sets a checked prop on its `RadioControl` component whose id equals the Choice value', () => {
        const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={singleValue} onChange={noop}>
        <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
      </ChoiceList_1.ChoiceList>);
        expect(choiceList.find(RadioControl_1.RadioControl)).toHaveReactProps({ checked: true });
    });
    it('does not set a checked prop on its `RadioControl` component whose id does not equal the Choice value', () => {
        const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value="" onChange={noop}>
        <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
      </ChoiceList_1.ChoiceList>);
        expect(choiceList.find(RadioControl_1.RadioControl)).toHaveReactProps({ checked: false });
    });
    it('passes its name down to its `CheckboxControl` component', () => {
        const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={multiValue} onChange={noop}>
        <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
      </ChoiceList_1.ChoiceList>);
        expect(choiceList.find(Checkbox_1.CheckboxControl)).toHaveReactProps({
            name: defaultProps.name,
        });
    });
    it('passes its onChange down to its `CheckboxControl` component', () => {
        const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={multiValue} onChange={noop}>
        <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
      </ChoiceList_1.ChoiceList>);
        expect(choiceList.find(Checkbox_1.CheckboxControl)).toHaveReactProps({
            onChange: expect.any(Function),
        });
    });
    it('sets a checked prop on its `CheckboxControl` component whose id is contained in the Choice value', () => {
        const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={multiValue} onChange={noop}>
        <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
      </ChoiceList_1.ChoiceList>);
        expect(choiceList.find(Checkbox_1.CheckboxControl)).toHaveReactProps({
            checked: true,
        });
    });
    it('does not set a checked prop on its `CheckboxControl` component whose id is not contained in the Choice value', () => {
        const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={['']} onChange={noop}>
        <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
      </ChoiceList_1.ChoiceList>);
        expect(choiceList.find(Checkbox_1.CheckboxControl)).toHaveReactProps({
            checked: false,
        });
    });
    describe('<Choice />', () => {
        it('renders children as its label content', () => {
            const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={multiValue} onChange={noop}>
          <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
        </ChoiceList_1.ChoiceList>);
            expect(choiceList.find('label')).toHaveReactProps({
                children: labelContent,
            });
        });
        it('sets an aria-label on the Choice label when accessibilityLabel is provided', () => {
            const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={multiValue} onChange={noop}>
          <ChoiceList_1.Choice id={id} accessibilityLabel={accessibilityLabel}>
            {labelContent}
          </ChoiceList_1.Choice>
        </ChoiceList_1.ChoiceList>);
            expect(choiceList.find('label')).toHaveReactProps({
                'aria-label': accessibilityLabel,
            });
        });
        it('does not set an aria-label on the Choice label when accessibilityLabel is not provided', () => {
            const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={multiValue} onChange={noop}>
          <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
        </ChoiceList_1.ChoiceList>);
            expect(choiceList.find('label')).not.toHaveReactProps({
                'aria-label': accessibilityLabel,
            });
        });
        it('calls its `onChange` handler with a string value when checked on a choicelist with a string value', () => {
            const onChangeSpy = jest.fn();
            const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value="" onChange={onChangeSpy}>
          <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
        </ChoiceList_1.ChoiceList>);
            choiceList.find(RadioControl_1.RadioControl).trigger('onChange', true);
            expect(onChangeSpy).toHaveBeenCalledWith(id);
        });
        it('calls its `onChange` handler with a string value when unchecked on a choicelist with a string value', () => {
            const onChangeSpy = jest.fn();
            const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={singleValue} onChange={onChangeSpy}>
          <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
        </ChoiceList_1.ChoiceList>);
            choiceList.find(RadioControl_1.RadioControl).trigger('onChange', false);
            expect(onChangeSpy).toHaveBeenCalledWith('');
        });
        it('calls its `onChange` handler with a string array value when checked on a choicelist with a string array value', () => {
            const onChangeSpy = jest.fn();
            const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={[]} onChange={onChangeSpy}>
          <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
        </ChoiceList_1.ChoiceList>);
            choiceList.find(Checkbox_1.CheckboxControl).trigger('onChange', true);
            expect(onChangeSpy).toHaveBeenCalledWith([id]);
        });
        it('calls its `onChange` handler with a string array value when unchecked on a choicelist with a string array value', () => {
            const onChangeSpy = jest.fn();
            const choiceList = test_utilities_1.mountWithContext(<ChoiceList_1.ChoiceList {...defaultProps} value={multiValue} onChange={onChangeSpy}>
          <ChoiceList_1.Choice id={id}>{labelContent}</ChoiceList_1.Choice>
        </ChoiceList_1.ChoiceList>);
            choiceList.find(Checkbox_1.CheckboxControl).trigger('onChange', false);
            expect(onChangeSpy).toHaveBeenCalledWith([]);
        });
    });
});
function noop() { }
