Skip to content

Commit

Permalink
Revert "Fix bug remplissage des revenus (#4075)" (#4097)
Browse files Browse the repository at this point in the history
This reverts commit 20f4f96.
  • Loading branch information
baptou12 authored Dec 6, 2023
1 parent 20f4f96 commit c953d5f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
11 changes: 2 additions & 9 deletions src/components/input-number.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,13 @@ export default {
computed: {
model: {
get() {
return this.value ?? this.modelValue ?? ""
return this.value || this.modelValue || ""
},
set(value) {
if (typeof value === "string") {
value = this.parseInputString(value)
}
if (value === "") {
this.error = false
this.$emit("update:modelValue", "")
this.$emit("input-error", this.error)
return
}
value = value == "" ? 0 : value
const valid = !isNaN(parseFloat(value))
const floor = this.min == null || this.min <= parseFloat(value)
const ceiling = this.max == null || this.max >= parseFloat(value)
Expand Down
8 changes: 2 additions & 6 deletions src/views/simulation/Ressources/montants.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default {
this.types.forEach((type) => {
Object.keys(type.amounts).forEach((period) => {
if (type.amounts[period] === null || type.amounts[period] === "") {
type.amounts[period] = ""
type.amounts[period] = 0
}
})
})
Expand Down Expand Up @@ -192,11 +192,7 @@ export default {
path: this.$route.path,
value: this.types.map((type) => {
Object.keys(type.amounts).forEach(function (period) {
if (
type.amounts[period] === null ||
isNaN(type.amounts[period]) ||
type.amounts[period] === ""
) {
if (type.amounts[period] === null || isNaN(type.amounts[period])) {
type.amounts[period] = 0
}
})
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/components/input-number.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function testInputNumber(
}

describe("input-number.vue", () => {
it("accept valid values", async () => {
it("accept valid numbers", async () => {
const testSet = [
{ input: "1", result: 1 },
{ input: "27,45", result: 27.45 },
Expand All @@ -33,7 +33,7 @@ describe("input-number.vue", () => {
{ input: "044", result: 44 },
{ input: "-1.45", result: -1.45 },
{ input: "200.0", result: 200 },
{ input: "", result: "" },
{ input: "", result: 0 },
]

for (const test of testSet) {
Expand All @@ -59,7 +59,7 @@ describe("input-number.vue", () => {
it("reject invalid numbers", async () => {
const testSet = [
{ input: "1+2", result: 12 },
{ input: "Infinity", result: "" },
{ input: "Infinity", result: 0 },
{ input: "1e25", result: 125 },
{ input: undefined, result: undefined, error: true },
]
Expand Down

0 comments on commit c953d5f

Please sign in to comment.