Skip to content

Commit

Permalink
fix(quantity): fix test and calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
skhamvon authored and dpellier committed Nov 9, 2023
1 parent 155f675 commit e03cf0b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('spec:ods-quantity-controller', () => {
input.focus();
input.blur();

expect(input.value).toEqual(input.min);
expect(input.value).toBe(input.min);
});

it('should change value of input if superior to max on Blur', () => {
Expand All @@ -120,7 +120,7 @@ describe('spec:ods-quantity-controller', () => {
input.focus();
input.blur();

expect(input.value).toEqual(input.max);
expect(input.value).toBe(input.max);
});

it('should change value of input if not in a valid step', () => {
Expand All @@ -138,7 +138,7 @@ describe('spec:ods-quantity-controller', () => {
input.focus();
input.blur();

expect(input.value).toEqual(validInput);
expect(input.value).toBe(validInput);
});

it('should change value of osds-input if inferior to min on Blur', () => {
Expand All @@ -160,7 +160,7 @@ describe('spec:ods-quantity-controller', () => {
input.blur();
input.dispatchEvent(new CustomEvent('odsInputBlur'));

expect(input.value).toEqual(input.min);
expect(input.value).toBe(input.min);
});

it('should change value of osds-input if superior to max on Blur', () => {
Expand All @@ -182,7 +182,7 @@ describe('spec:ods-quantity-controller', () => {
input.blur();
input.dispatchEvent(new CustomEvent('odsInputBlur'));

expect(input.value).toEqual(input.max);
expect(input.value).toBe(input.max);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class OdsQuantityController {
let valueToCheck = valueAsNb;

if (stepNb && !Number.isInteger((valueAsNb - minNb) / stepNb)) {
valueToCheck = Math.floor( valueAsNb / stepNb ) * stepNb
valueToCheck = Math.floor( (valueAsNb - minNb) / stepNb) * stepNb + minNb
}

if (this.component.input.min !== '' && valueToCheck < minNb) {
this.component.input.value = minNb;
} else if (this.component.input.max !== '' && valueToCheck > maxNb) {
this.component.input.value = maxNb;
} else if (valueToCheck != valueAsNb) {
} else if (valueToCheck !== valueAsNb) {
this.component.input.value = valueToCheck;
}
}
Expand Down

0 comments on commit e03cf0b

Please sign in to comment.