import { focusTab, getTabVariant, getTabWidth } from '../utils';

describe('focusTab', () => {
  it('focuses on passed in element', () => {
    const tab = document.createElement('button');
    jest.spyOn(tab, 'focus');
    focusTab(tab);

    expect(tab.focus).toHaveBeenCalledTimes(1);
  });

  it('does nothing when element is null', () => {
    expect(focusTab(null)).toBe(undefined);
  });
});

describe('getTabVariant', () => {
  it.each`
    disabled | active   | variant
    ${true}  | ${true}  | ${'disabled'}
    ${true}  | ${false} | ${'disabled'}
    ${false} | ${true}  | ${'active'}
    ${false} | ${false} | ${'basic'}
  `(
    'returns $variant when disabled is $disabled and active is $active',
    ({ disabled, active, variant }) => {
      expect(getTabVariant({ disabled, active })).toEqual(variant);
    }
  );
});

describe('getTabWidth', () => {
  it('returns tab width', () => {
    const tab = document.createElement('button');
    tab.style.width = '20px';

    expect(getTabWidth(tab)).toEqual('20px');
  });

  it('returns empty string when element is null', () => {
    expect(getTabWidth(null)).toEqual('');
  });
});
