{"size": 5099, "ext": "js", "max_stars_repo_path": "tests/unit/components/NumberInput.spec.js", "max_stars_repo_name": "bcgov/common-lib-vue", "max_stars_repo_stars_event_min_datetime": "2021-03-01T18:47:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-01T18:47:38.000Z", "max_issues_repo_path": "tests/unit/components/NumberInput.spec.js", "max_issues_repo_name": "bcgov/common-lib-vue", "max_issues_repo_issues_event_min_datetime": "2021-02-26T21:05:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-23T22:30:27.000Z", "max_forks_repo_path": "tests/unit/components/NumberInput.spec.js", "max_forks_repo_name": "bcgov/common-lib-vue", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 7, "max_forks_count": null, "avg_line_length": 38.6287878788, "max_line_length": 64, "alphanum_fraction": 0.6987644636}
import {
  mount,
  createLocalVue
} from '@vue/test-utils';
import Component, {
  intValidator,
  floatValidator,
  positiveNumberValidator,
  negativeNumberValidator,
  nonZeroNumberValidator,
  dollarNumberValidator,
} from '../../../src/components/NumberInput.vue';

const localVue = createLocalVue();

describe('NumberInput.vue', () => {
  it('renders', () => {
    const wrapper = mount(Component, {
      localVue,
    });
    expect(wrapper.element).toBeDefined();
  });
});

describe('Number validators', () => {
  it('intValidator', () => {
    expect(intValidator(123)).toBe(true);
    expect(intValidator('123')).toBe(true);
    expect(intValidator(-123)).toBe(true);
    expect(intValidator('-123')).toBe(true);
    expect(intValidator(123.123)).toBe(false);
    expect(intValidator('123.123')).toBe(false);
    expect(intValidator(-123.123)).toBe(false);
    expect(intValidator('-123.123')).toBe(false);
    expect(intValidator(undefined)).toBe(false);
    expect(intValidator(null)).toBe(false);
    expect(intValidator(NaN)).toBe(false);
  });

  it('floatValidator', () => {
    expect(floatValidator(123)).toBe(false);
    expect(floatValidator('123')).toBe(false);
    expect(floatValidator(-123)).toBe(false);
    expect(floatValidator('-123')).toBe(false);
    expect(floatValidator(123.123)).toBe(true);
    expect(floatValidator('123.123')).toBe(true);
    expect(floatValidator(-123.123)).toBe(true);
    expect(floatValidator('-123.123')).toBe(true);
    expect(floatValidator(undefined)).toBe(false);
    expect(floatValidator(null)).toBe(false);
    expect(floatValidator(NaN)).toBe(false);
  });

  it('positiveNumberValidator', () => {
    expect(positiveNumberValidator(123)).toBe(true);
    expect(positiveNumberValidator('123')).toBe(true);
    expect(positiveNumberValidator(-123)).toBe(false);
    expect(positiveNumberValidator('-123')).toBe(false);
    expect(positiveNumberValidator(123.123)).toBe(true);
    expect(positiveNumberValidator('123.123')).toBe(true);
    expect(positiveNumberValidator(-123.123)).toBe(false);
    expect(positiveNumberValidator('-123.123')).toBe(false);
    expect(positiveNumberValidator(undefined)).toBe(false);
    expect(positiveNumberValidator(null)).toBe(false);
    expect(positiveNumberValidator(NaN)).toBe(false);
  });

  it('negativeNumberValidator', () => {
    expect(negativeNumberValidator(123)).toBe(false);
    expect(negativeNumberValidator('123')).toBe(false);
    expect(negativeNumberValidator(-123)).toBe(true);
    expect(negativeNumberValidator('-123')).toBe(true);
    expect(negativeNumberValidator(123.123)).toBe(false);
    expect(negativeNumberValidator('123.123')).toBe(false);
    expect(negativeNumberValidator(-123.123)).toBe(true);
    expect(negativeNumberValidator('-123.123')).toBe(true);
    expect(negativeNumberValidator(undefined)).toBe(false);
    expect(negativeNumberValidator(null)).toBe(false);
    expect(negativeNumberValidator(NaN)).toBe(false);
  });

  it('nonZeroNumberValidator', () => {
    expect(nonZeroNumberValidator(123)).toBe(true);
    expect(nonZeroNumberValidator('123')).toBe(true);
    expect(nonZeroNumberValidator(-123)).toBe(true);
    expect(nonZeroNumberValidator('-123')).toBe(true);
    expect(nonZeroNumberValidator(123.123)).toBe(true);
    expect(nonZeroNumberValidator('123.123')).toBe(true);
    expect(nonZeroNumberValidator(-123.123)).toBe(true);
    expect(nonZeroNumberValidator('-123.123')).toBe(true);
    expect(nonZeroNumberValidator(0)).toBe(false);
    expect(nonZeroNumberValidator('0')).toBe(false);
    expect(nonZeroNumberValidator(undefined)).toBe(false);
    expect(nonZeroNumberValidator(null)).toBe(false);
    expect(nonZeroNumberValidator(NaN)).toBe(false);
  });

  it('dollarNumberValidator', () => {
    expect(dollarNumberValidator(123)).toBe(false);
    expect(dollarNumberValidator('123')).toBe(false);
    expect(dollarNumberValidator(-123)).toBe(false);
    expect(dollarNumberValidator('-123')).toBe(false);
    expect(dollarNumberValidator(123.123)).toBe(false);
    expect(dollarNumberValidator('123.123')).toBe(false);
    expect(dollarNumberValidator(-123.123)).toBe(false);
    expect(dollarNumberValidator('-123.123')).toBe(false);
    expect(dollarNumberValidator(0)).toBe(false);
    expect(dollarNumberValidator('0')).toBe(false);
    expect(dollarNumberValidator(123.12)).toBe(true);
    expect(dollarNumberValidator('123.12')).toBe(true);
    expect(dollarNumberValidator(-123.12)).toBe(true);
    expect(dollarNumberValidator('-123.12')).toBe(true);
    expect(dollarNumberValidator(0.00)).toBe(false);
    expect(dollarNumberValidator('0.00')).toBe(true);
    expect(dollarNumberValidator(undefined)).toBe(false);
    expect(dollarNumberValidator(null)).toBe(false);
    expect(dollarNumberValidator(NaN)).toBe(false);
  });
});

describe('NumberInput getCypressValue()', () => {
  it('contains cypress Value', () => {
    const wrapper = mount(Component, {
      localVue,
      propsData: {
        cypressId: 'potato'
      }
    });
    expect(wrapper.find("[data-cy=potato]").exists()).toBe(true)
  });
});
