Skip to content

Commit 3bf82eb

Browse files
aerfustimonback
authored andcommitted
Test coverage for schema range component (springwolf#578)
* refactor(schema): correct margin and padding values Warnings are present Refs springwolf#378 * test(ui): cover schema-range component 0 coverage Refs springwolf#378 * refactor(ui): simplify schema range rendering Is difficult to maintain Refs springwolf#378
1 parent e49b07e commit 3bf82eb

File tree

3 files changed

+135
-44
lines changed

3 files changed

+135
-44
lines changed

springwolf-ui/src/app/components/schemas/range/schema-range.component.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.range {
33
background-color: rgb(128, 90, 213);
44
color: rgb(255, 255, 255);
5-
margin: 0 8 0 8;
6-
padding: 2 4 2 4;
5+
margin: 0 8px 0 8px;
6+
padding: 2px 4px 2px 4px;
77
border-radius: 4px;
88
}

springwolf-ui/src/app/components/schemas/range/schema-range.component.html

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,18 @@
44
class="range"
55
*ngIf="schema.minimum !== undefined && schema.maximum === undefined"
66
>
7-
<span
8-
*ngIf="
9-
schema.exclusiveMinimum;
10-
then exclusiveMinimumSign;
11-
else inclusiveMinimumSign
12-
"
13-
></span>
14-
{{ schema.minimum }}
7+
{{ schema.exclusiveMinimum ? ">" : ">=" }} {{ schema.minimum }}
158
</span>
169
<span
1710
class="range"
1811
*ngIf="schema.minimum === undefined && schema.maximum !== undefined"
1912
>
20-
<span
21-
*ngIf="
22-
schema.exclusiveMaximum;
23-
then exclusiveMaximumSign;
24-
else inclusiveMaximumSign
25-
"
26-
></span>
27-
{{ schema.maximum }}
13+
{{ schema.exclusiveMaximum ? "<" : "<=" }} {{ schema.maximum }}
2814
</span>
2915
<span
3016
class="range"
3117
*ngIf="schema.minimum !== undefined && schema.maximum !== undefined"
18+
>{{ schema.exclusiveMinimum ? "(" : "[" }} {{ schema.minimum }} ..
19+
{{ schema.maximum }} {{ schema.exclusiveMaximum ? ")" : "]" }}</span
3220
>
33-
<span
34-
*ngIf="
35-
schema.exclusiveMinimum;
36-
then exclusiveMinimumBrackets;
37-
else inclusiveMinimumBrackets
38-
"
39-
></span>
40-
{{ schema.minimum }} .. {{ schema.maximum }}
41-
<span
42-
*ngIf="
43-
schema.exclusiveMaximum;
44-
then exclusiveMaximumBrackets;
45-
else inclusiveMaximumBrackets
46-
"
47-
></span>
48-
</span>
4921
</div>
50-
51-
<ng-template #exclusiveMinimumBrackets>(</ng-template>
52-
<ng-template #exclusiveMaximumBrackets>)</ng-template>
53-
<ng-template #inclusiveMinimumBrackets>[</ng-template>
54-
<ng-template #inclusiveMaximumBrackets>]</ng-template>
55-
56-
<ng-template #exclusiveMinimumSign>&gt;</ng-template>
57-
<ng-template #exclusiveMaximumSign>&lt;</ng-template>
58-
<ng-template #inclusiveMinimumSign>&gt;=</ng-template>
59-
<ng-template #inclusiveMaximumSign>&lt;=</ng-template>
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/* SPDX-License-Identifier: Apache-2.0 */
2+
import { ComponentFixture, TestBed } from "@angular/core/testing";
3+
import { SchemaRangeComponent } from "./schema-range.component";
4+
5+
describe("SchemaRangeComponent", function () {
6+
let component: SchemaRangeComponent;
7+
let fixture: ComponentFixture<SchemaRangeComponent>;
8+
9+
beforeEach(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [SchemaRangeComponent],
12+
}).compileComponents();
13+
14+
fixture = TestBed.createComponent(SchemaRangeComponent as any);
15+
component = fixture.debugElement.componentInstance;
16+
});
17+
18+
it("should create the component", () => {
19+
expect(component).toBeTruthy();
20+
});
21+
22+
it("should have `( 0.1 .. 10 )` as value", async () => {
23+
component.schema = {
24+
title: "test",
25+
minimum: 0.1,
26+
maximum: 10,
27+
exclusiveMinimum: true,
28+
exclusiveMaximum: true,
29+
};
30+
31+
fixture.detectChanges();
32+
const compiled = fixture.debugElement.nativeElement;
33+
expect(compiled.querySelector("span").textContent).toContain(
34+
"( 0.1 .. 10 )"
35+
);
36+
});
37+
38+
it("should have `[ 0.1 .. 10 )` as value", async () => {
39+
component.schema = {
40+
title: "test",
41+
minimum: 0.1,
42+
maximum: 10,
43+
exclusiveMinimum: false,
44+
exclusiveMaximum: true,
45+
};
46+
47+
fixture.detectChanges();
48+
const compiled = fixture.debugElement.nativeElement;
49+
expect(compiled.querySelector("span").textContent).toContain(
50+
"[ 0.1 .. 10 )"
51+
);
52+
});
53+
54+
it("should have `( 0.1 .. 10 ]` as value", async () => {
55+
component.schema = {
56+
title: "test",
57+
minimum: 0.1,
58+
maximum: 10,
59+
exclusiveMinimum: true,
60+
exclusiveMaximum: false,
61+
};
62+
63+
fixture.detectChanges();
64+
const compiled = fixture.debugElement.nativeElement;
65+
expect(compiled.querySelector("span").textContent).toContain(
66+
"( 0.1 .. 10 ]"
67+
);
68+
});
69+
70+
it("should have `[ 0.1 .. 10 ]` as value", async () => {
71+
component.schema = {
72+
title: "test",
73+
minimum: 0.1,
74+
maximum: 10,
75+
};
76+
77+
fixture.detectChanges();
78+
const compiled = fixture.debugElement.nativeElement;
79+
expect(compiled.querySelector("span").textContent).toContain(
80+
"[ 0.1 .. 10 ]"
81+
);
82+
});
83+
84+
it("should have `> 0.1` as value", async () => {
85+
component.schema = {
86+
title: "test",
87+
minimum: 0.1,
88+
exclusiveMinimum: true,
89+
};
90+
91+
fixture.detectChanges();
92+
const compiled = fixture.debugElement.nativeElement;
93+
expect(compiled.querySelector("span").textContent).toContain("> 0.1");
94+
});
95+
96+
it("should have `< 10` as value", async () => {
97+
component.schema = {
98+
title: "test",
99+
maximum: 10,
100+
exclusiveMaximum: true,
101+
};
102+
103+
fixture.detectChanges();
104+
const compiled = fixture.debugElement.nativeElement;
105+
expect(compiled.querySelector("span").textContent).toContain("< 10");
106+
});
107+
108+
it("should have `>= 0.1` as value", async () => {
109+
component.schema = {
110+
title: "test",
111+
minimum: 0.1,
112+
};
113+
114+
fixture.detectChanges();
115+
const compiled = fixture.debugElement.nativeElement;
116+
expect(compiled.querySelector("span").textContent).toContain(">= 0.1");
117+
});
118+
119+
it("should have `<= 10` as value", async () => {
120+
component.schema = {
121+
title: "test",
122+
maximum: 10,
123+
};
124+
125+
fixture.detectChanges();
126+
const compiled = fixture.debugElement.nativeElement;
127+
expect(compiled.querySelector("span").textContent).toContain("<= 10");
128+
});
129+
});

0 commit comments

Comments
 (0)