How to use the @leafygreen-ui/lib.typeIs.input function in @leafygreen-ui/lib

To help you get started, we’ve selected a few @leafygreen-ui/lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mongodb / leafygreen-ui / packages / radio-box-group / src / RadioBoxGroup.spec.tsx View on Github external
if (!typeIs.element(radioBoxGroup)) {
      throw new Error('Could not find radio box group element');
    }

    const firstRadioBoxLabel = radioBoxGroup.firstChild;

    if (!typeIs.element(firstRadioBoxLabel)) {
      throw new Error('Could not find label element');
    }

    const firstRadioBoxInput = firstRadioBoxLabel.firstChild;
    const secondRadioBoxInput = radioBoxGroup.children[1].firstChild;

    if (
      !typeIs.input(firstRadioBoxInput) ||
      !typeIs.input(secondRadioBoxInput)
    ) {
      throw new Error('Could not find input element');
    }

    fireEvent.click(secondRadioBoxInput);

    test('initial value set by radio box group when prop provided', () => {
      expect(firstRadioBoxInput.checked).toBe(true);
      expect(firstRadioBoxInput.getAttribute('aria-checked')).toBe('true');
    });

    test('onChange fires once when the label is clicked', () => {
      expect(controlledOnChange.mock.calls.length).toBe(1);
    });
github mongodb / leafygreen-ui / packages / radio-group / src / RadioGroup.spec.tsx View on Github external
Radio Button 1
      Radio Button 2
    ,
  );

  const controlledContainer = container.firstChild;

  if (!typeIs.element(controlledContainer)) {
    throw new Error('Could not find controlled container component');
  }

  const firstInput = controlledContainer.children[0].firstChild;
  const secondInput = controlledContainer.children[1].firstChild;

  if (!typeIs.input(firstInput)) {
    throw new Error('Could not find the first radio input element');
  }

  if (!typeIs.input(secondInput)) {
    throw new Error('Could not find the second radio input element');
  }

  fireEvent.click(secondInput);

  test(`initial value set by radio group when prop provided`, () => {
    expect(firstInput.checked).toBe(true);
    expect(firstInput.getAttribute('aria-checked')).toBe('true');
  });

  test('onChange fires once when the label is clicked', () => {
    expect(controlledOnChange.mock.calls.length).toBe(1);
github mongodb / leafygreen-ui / packages / radio-box-group / src / RadioBoxGroup.spec.tsx View on Github external
test('renders as disabled, when the disabled prop is set', () => {
    const { container } = render(
      
        Input 2
      ,
    );

    const radioBoxContainer = container.firstChild;

    if (!typeIs.element(radioBoxContainer)) {
      throw new Error('Could not find radio box container element');
    }

    const radioBox = radioBoxContainer.firstChild;

    if (!typeIs.input(radioBox)) {
      throw new Error('Could not find radio box input element');
    }

    expect(radioBox.getAttribute('aria-disabled')).toBe('true');
  });
});
github mongodb / leafygreen-ui / packages / radio-group / src / Radio.spec.tsx View on Github external
const className = 'radio-test-class';
  const { container } = render(
    
      Radio 1
    ,
  );

  const radio = container.firstChild;

  if (!typeIs.element(radio)) {
    throw new Error('Could not find controlled container component');
  }

  const input = radio.firstChild;

  if (!typeIs.input(input)) {
    throw new Error('Could not find input element');
  }

  test(`renders "${className}" in the labels's class list`, () => {
    expect(radio.classList.contains(className)).toBe(true);
  });

  test(`renders disabled radio when disabled prop is set`, () => {
    expect(input.disabled).toBe(true);
    expect(input.getAttribute('aria-disabled')).toBe('true');
  });

  test(`radio is checked when value is set`, () => {
    render(
      
        Radio 2
github mongodb / leafygreen-ui / packages / toggle / src / Toggle.spec.tsx View on Github external
describe('packages/Toggle', () => {
  const className = 'test-checkbox-class';
  const { container } = render(
    ,
  );
  const controlledContainer = container.firstChild;

  if (!typeIs.element(controlledContainer)) {
    throw new Error('Could not find controlled container element');
  }

  const controlledCheckbox = controlledContainer.children[0];

  if (!typeIs.input(controlledCheckbox)) {
    throw new Error('Could not find controlled checkbox input element');
  }

  test(`renders "${className}" in the container label's classList`, () => {
    expect(controlledContainer.classList.contains(className)).toBe(true);
  });

  test('checkbox is checked when checked prop is set', () => {
    expect(controlledCheckbox.checked).toBe(false);
    expect(controlledCheckbox.getAttribute('aria-checked')).toBe('false');

    render(, { container });

    expect(controlledCheckbox.checked).toBe(true);
    expect(controlledCheckbox.getAttribute('aria-checked')).toBe('true');
  });
github mongodb / leafygreen-ui / packages / radio-group / src / RadioGroup.spec.tsx View on Github external
,
  ).container.firstChild;

  if (!typeIs.element(uncontrolledContainer)) {
    throw new Error('Could not find uncontrolled container component');
  }

  const radioLabel = uncontrolledContainer.firstChild;

  if (!typeIs.element(radioLabel)) {
    throw new Error('Could not find the label element');
  }

  const radio = radioLabel.firstChild;

  if (!typeIs.input(radio)) {
    throw new Error('Could not find the radio input element');
  }

  fireEvent.click(radioLabel);

  test('onChange fires once when the label is clicked', () => {
    expect(uncontrolledOnChange.mock.calls.length).toBe(1);
  });

  test('radio button becomes checked when clicked', () => {
    expect(radio.checked).toBe(true);
  });

  describe('and the default prop is set', () => {
    const uncontrolledContainer = render(
github mongodb / leafygreen-ui / packages / checkbox / src / Checkbox.spec.tsx View on Github external
const uncontrolledOnClick = jest.fn();
    const uncontrolledOnChange = jest.fn();
    const uncontrolledContainer = render(
      ,
    ).container.firstChild;

    if (!typeIs.element(uncontrolledContainer)) {
      throw new Error('Could not find uncontrolled container component');
    }

    const uncontrolledCheckbox = uncontrolledContainer.children[0];

    if (!typeIs.input(uncontrolledCheckbox)) {
      throw new Error('Could not find checkbox input element');
    }

    fireEvent.click(uncontrolledContainer);

    test('onClick fires once when the label is clicked', () => {
      expect(uncontrolledOnClick.mock.calls.length).toBe(1);
    });

    test('onChange fires once when the label is clicked', () => {
      expect(uncontrolledOnChange.mock.calls.length).toBe(1);
    });

    test('checkbox becomes checked when clicked', () => {
      expect(uncontrolledCheckbox.checked).toBe(true);
    });
github mongodb / leafygreen-ui / packages / checkbox / src / Checkbox.spec.tsx View on Github external
describe('packages/Checkbox', () => {
  const className = 'test-checkbox-class';
  const { container } = render(
    ,
  );
  const controlledContainer = container.firstChild;

  if (!typeIs.element(controlledContainer)) {
    throw new Error('Could not find controlled container component');
  }

  const controlledCheckbox = controlledContainer.children[0];

  if (!typeIs.input(controlledCheckbox)) {
    throw new Error('Could not find checkbox input element');
  }

  test(`renders "${className}" in the Checkbox label's classList`, () => {
    expect(controlledContainer.classList.contains(className)).toBe(true);
  });

  test('Checkbox is checked when checked prop is set', () => {
    expect(controlledCheckbox.checked).toBe(false);
    expect(controlledCheckbox.getAttribute('aria-checked')).toBe('false');

    render(, { container });

    expect(controlledCheckbox.checked).toBe(true);
    expect(controlledCheckbox.getAttribute('aria-checked')).toBe('true');
  });
github mongodb / leafygreen-ui / packages / radio-box-group / src / RadioBoxGroup.spec.tsx View on Github external
if (!typeIs.element(radioBoxGroup)) {
      throw new Error('Could not find radio box group element');
    }

    const firstRadioBoxLabel = radioBoxGroup.firstChild;

    if (!typeIs.element(firstRadioBoxLabel)) {
      throw new Error('Could not find label element');
    }

    const firstRadioBoxInput = firstRadioBoxLabel.firstChild;
    const secondRadioBoxInput = radioBoxGroup.children[1].firstChild;

    if (
      !typeIs.input(firstRadioBoxInput) ||
      !typeIs.input(secondRadioBoxInput)
    ) {
      throw new Error('Could not find input element');
    }

    fireEvent.click(secondRadioBoxInput);

    test('initial value set by radio box group when prop provided', () => {
      expect(firstRadioBoxInput.checked).toBe(true);
      expect(firstRadioBoxInput.getAttribute('aria-checked')).toBe('true');
    });

    test('onChange fires once when the label is clicked', () => {
      expect(controlledOnChange.mock.calls.length).toBe(1);
    });

    test('radio input does not become checked when clicked', () => {
github mongodb / leafygreen-ui / packages / radio-box-group / src / RadioBoxGroup.spec.tsx View on Github external
const radioBoxGroup = container.firstChild;

    if (!typeIs.element(radioBoxGroup)) {
      throw new Error('Could not find radio box group element');
    }

    const radioBoxLabel = radioBoxGroup.firstChild;

    if (!typeIs.element(radioBoxLabel)) {
      throw new Error('Could not find label element');
    }

    const radioBoxInput = radioBoxLabel.firstChild;

    if (!typeIs.input(radioBoxInput)) {
      throw new Error('Could not find radio box input element');
    }

    fireEvent.click(radioBoxLabel);

    test('onChange fires once when the label is clicked', () => {
      expect(uncontrolledOnChange.mock.calls.length).toBe(1);
    });

    test('radio box becomes checked when clicked', () => {
      expect(radioBoxInput.getAttribute('aria-checked')).toBe('true');
      expect(radioBoxInput.checked).toBe(true);
    });

    describe('and the default prop is set', () => {
      const uncontrolledContainer = render(