Skip to content

Commit fb12e95

Browse files
author
Manuela Paula Ritter
committed
improve pipes and test them
1 parent 7d0bd85 commit fb12e95

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { XPositionPipe } from './x-position.pipe';
2+
3+
describe('XPositionPipe', () => {
4+
const pipe = new XPositionPipe();
5+
let today: Date;
6+
let maxTenDays: Date;
7+
8+
beforeEach(() => {
9+
const now = new Date();
10+
today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
11+
maxTenDays = new Date(today.valueOf());
12+
maxTenDays = new Date(maxTenDays.setDate(maxTenDays.getDate() + 10));
13+
});
14+
15+
it('should return a % string', () => {
16+
const result = pipe.transform(1, 1, 1, new Date());
17+
expect(result.charAt(result.length - 1)).toBe('%');
18+
});
19+
20+
it('should return 1 for maxDate', () => {
21+
const result = pipe.transform(
22+
maxTenDays.getDate(),
23+
maxTenDays.getMonth() + 1, // getMonth returns monthIndex which is one less than actual month
24+
maxTenDays.getFullYear() - 2000,
25+
maxTenDays,
26+
);
27+
expect(result).toBe('1%');
28+
});
29+
30+
it('should return 95 for today', () => {
31+
const result = pipe.transform(
32+
today.getDate(),
33+
today.getMonth() + 1,
34+
today.getFullYear() - 2000,
35+
maxTenDays,
36+
);
37+
expect(result).toBe('95%');
38+
});
39+
});

src/app/matrix/x-position.pipe.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ export class XPositionPipe implements PipeTransform {
2828
ratio = Math.max(ratio, 0);
2929
ratio = Math.min(ratio, 1);
3030

31-
return (1 - ratio) * 94 + '%';
31+
return (1 - ratio) * 94 + 1 + '%';
3232
}
3333
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { YPositionPipe } from './y-position.pipe';
2+
3+
describe('YPositionPipe', () => {
4+
const pipe = new YPositionPipe();
5+
6+
it('should return a % string', () => {
7+
const result = pipe.transform(10);
8+
expect(result.charAt(result.length - 1)).toBe('%');
9+
});
10+
11+
it('should return 95 for a value 0', () => {
12+
expect(pipe.transform(0)).toBe('95%');
13+
});
14+
15+
it('should return 1 for a value of 100', () => {
16+
expect(pipe.transform(100)).toBe('1%');
17+
});
18+
});

src/app/matrix/y-position.pipe.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import { Pipe, PipeTransform } from '@angular/core';
44
export class YPositionPipe implements PipeTransform {
55
// 100%, unten 5% Mindestabstand, 1% oben -> 94% übrig
66
transform(yValue: number): string {
7-
return ((100 - yValue) / 100) * 94 + '%';
7+
return ((100 - yValue) / 100) * 94 + 1 + '%';
88
}
99
}

0 commit comments

Comments
 (0)