Skip to content

Commit ab14ff1

Browse files
Added tests for numbers filter
1 parent 7050631 commit ab14ff1

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

src/app/core/config/config-fix.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ export const defaultJsonConfig = {
503503
"name",
504504
"age",
505505
"gender",
506+
"shoeSize",
506507
"schoolClass",
507508
"schoolId",
508509
"center",
@@ -566,9 +567,9 @@ export const defaultJsonConfig = {
566567
"label": $localize`:Label of schools filter:School`
567568
},
568569
{
569-
"id": "schoolClass",
570+
"id": "shoeSize",
570571
"type": "numbers",
571-
"label": "Classes"
572+
"label": "Shoe Size"
572573
}
573574
],
574575
"exportConfig": [
@@ -599,7 +600,7 @@ export const defaultJsonConfig = {
599600
"header": $localize`:Header for form section:Personal Information`
600601
},
601602
{
602-
"fields": ["dateOfBirth", "birth_certificate", "gender", "motherTongue"],
603+
"fields": ["dateOfBirth", "birth_certificate", "gender", "motherTongue","shoeSize"],
603604
"header": $localize`:Header for form section:Additional`
604605
},
605606
{
@@ -1035,6 +1036,10 @@ export const defaultJsonConfig = {
10351036
"dataType": "location",
10361037
"label": $localize`:Label for the address of a child:Address`
10371038
},
1039+
"shoeSize": {
1040+
"dataType": "number",
1041+
"label": $localize`:Label for a child attribute:Shoe Size`
1042+
},
10381043
"health_bloodGroup": {
10391044
"dataType": "string",
10401045
"label": $localize`:Label for a child attribute:Blood Group`

src/app/core/filter/filters/filters.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Filter, SelectableFilter } from "./filters";
22
import { FilterService } from "../filter.service";
33
import { BooleanFilter } from "./booleanFilter";
4+
import { NumberFilter } from "./numberFilter";
45
import { Entity } from "../../entity/model/entity";
56

67
describe("Filters", () => {
@@ -73,6 +74,36 @@ describe("Filters", () => {
7374
testFilter(filter, [recordFalse, recordTrue], [recordFalse, recordTrue]);
7475
});
7576

77+
fit("should support a numbers filter", async () => {
78+
const filter = new NumberFilter("value", "My Filter");
79+
80+
const record_5 = { value: -5 };
81+
const record0 = { value: 0 };
82+
const record1 = { value: 1 };
83+
const record2 = { value: 2 };
84+
const record3 = { value: 3 };
85+
const record10 = { value: 10 };
86+
const records = [record_5, record0, record1, record2, record3, record10];
87+
88+
filter.selectedOptionValues = ["2", "3"];
89+
testFilter(filter, records, [record2, record3]);
90+
91+
filter.selectedOptionValues = ["-8", "1"];
92+
testFilter(filter, records, [record_5, record0, record1]);
93+
94+
filter.selectedOptionValues = ["10", "10"];
95+
testFilter(filter, records, [record10]);
96+
97+
filter.selectedOptionValues = ["10", ""];
98+
testFilter(filter, records, [record10]);
99+
100+
filter.selectedOptionValues = ["", "-1"];
101+
testFilter(filter, records, [record_5]);
102+
103+
filter.selectedOptionValues = ["", ""];
104+
testFilter(filter, records, records);
105+
});
106+
76107
it("should support numbers as options", () => {
77108
const filter = new SelectableFilter("counts", [], "Counts");
78109

src/app/core/filter/filters/numberFilter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class NumberFilter<T extends Entity> extends Filter<T> {
2121

2222
const filterObject: { $gte?; $lte?: number } = {};
2323
if (this.selectedOptionValues[0]) {
24-
filterObject.$gte = [{}, Number(this.selectedOptionValues[0])];
24+
filterObject.$gte = Number(this.selectedOptionValues[0]);
2525
}
2626
if (this.selectedOptionValues[1]) {
2727
filterObject.$lte = Number(this.selectedOptionValues[1]);

src/environments/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const environment = {
3333
remoteLoggingDsn: undefined, // only set for production mode in environment.prod.ts
3434

3535
demo_mode: true,
36-
session_type: SessionType.local,
36+
session_type: SessionType.mock,
3737
account_url: "https://accounts.aam-digital.net",
3838
email: undefined,
3939

0 commit comments

Comments
 (0)