Skip to content

[QInputNumber] upgrade with additions and formatting #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 160 additions & 2 deletions src/qComponents/QInputNumber/QInputNumber.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,165 @@ describe('QInputNumber', () => {
expect(element).toMatchSnapshot();
});

it('data should match snapshot', () => {
expect(Component.data()).toMatchSnapshot();
describe('computed', () => {
it('increaseClass', async () => {
const instance = shallowMount(Component, {
propsData: {
value: 9007199254740992
}
});

expect(instance.vm.increaseClass).toEqual(
'q-input-number__button_is-disabled'
);
});

it('decreaseClass', async () => {
const instance = shallowMount(Component, {
propsData: {
value: -9007199254740992
}
});

expect(instance.vm.decreaseClass).toEqual(
'q-input-number__button_is-disabled'
);
});
});

describe('methods', () => {
it('handleIncreaseClick', () => {
const instance = shallowMount(Component, {
propsData: {
value: 0
}
});
instance.vm.handleIncreaseClick();

expect(instance.emitted().change[0]).toEqual([1]);
});

it('handleDecreaseClick', () => {
const instance = shallowMount(Component, {
propsData: {
value: 0
}
});
instance.vm.handleDecreaseClick();

expect(instance.emitted().change[0]).toEqual([-1]);
});

describe('getLocaleSeparator', () => {
it('should return decimal', () => {
const { vm } = shallowMount(Component);

expect(vm.getLocaleSeparator('decimal')).toEqual('.');
});

it('should return thousands', () => {
const { vm } = shallowMount(Component);

expect(vm.getLocaleSeparator()).toEqual(',');
});
});

it('parseLocaleNumber', () => {
const { vm } = shallowMount(Component);

expect(vm.parseLocaleNumber('123,123.0')).toEqual(123123);
});

describe('getLocaleSeparator', () => {
it('should return 2 parts', () => {
const { vm } = shallowMount(Component);

expect(vm.getFormattedPartsLength('1,120,120', 5)).toEqual(2);
});

it('should return 1 part', () => {
const { vm } = shallowMount(Component);

expect(vm.getFormattedPartsLength('1,234', 1)).toEqual(1);
});
});

describe('checkStringAdditions', () => {
it('should return prefix', () => {
const { vm } = shallowMount(Component, {
propsData: {
prefix: '>'
}
});

expect(vm.checkStringAdditions('>1120<', 'prefix')).toBeTruthy();
});

it('should return suffix', () => {
const { vm } = shallowMount(Component, {
propsData: {
suffix: '<'
}
});

expect(vm.checkStringAdditions('>1120<', 'suffix')).toBeTruthy();
});
});

describe('getSplittedValue', () => {
it('should return value from args', () => {
const defaultValue = '1120';
const { vm } = shallowMount(Component);

expect(vm.getSplittedValue(defaultValue, 'prefix')).toEqual(
defaultValue
);
});

it('should return string without prefix', () => {
const { vm } = shallowMount(Component, {
propsData: {
prefix: '>'
}
});

expect(vm.getSplittedValue('>1120<', 'prefix')).toEqual('1120<');
});

it('should return string without suffix', () => {
const { vm } = shallowMount(Component, {
propsData: {
suffix: '<'
}
});

expect(vm.getSplittedValue('>1120<', 'suffix')).toEqual('>1120');
});
});

it('getValueWithoutAdditions', () => {
const { vm } = shallowMount(Component, {
propsData: {
prefix: '>',
suffix: '<'
}
});

expect(vm.getValueWithoutAdditions('>1120<')).toEqual('1120');
});

describe('isCharReadonly', () => {
it('should return false if char is number', () => {
const { vm } = shallowMount(Component);

expect(vm.isCharReadonly('1')).toBeFalsy();
});

it('should return true if char is -', () => {
const { vm } = shallowMount(Component);

expect(vm.isCharReadonly('.')).toBeTruthy();
});
});
});
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`QInputNumber data should match snapshot 1`] = `
Object {
"number": null,
"prevNumber": null,
"userNumber": null,
}
`;

exports[`QInputNumber should match snapshot 1`] = `
<div
class="q-input-number q-input-number_with-controls"
Expand All @@ -22,7 +14,7 @@ exports[`QInputNumber should match snapshot 1`] = `
label=""
suffixicon=""
tabindex=""
type="number"
type="text"
value=""
/>

Expand All @@ -44,7 +36,7 @@ exports[`QInputNumber should match snapshot without controls 1`] = `
label=""
suffixicon=""
tabindex=""
type="number"
type="text"
value=""
/>

Expand Down
Loading