Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Commit 77f0473

Browse files
committed
test(time-table): add tests for time estimates table
1 parent 44f37ab commit 77f0473

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

β€Žsrc/services/converters.test.jsβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
convertDistance,
88
} from './converters';
99

10+
jest.mock('convert-units');
11+
1012
describe('converters', () => {
1113
describe('#convertDuration', () => {
1214
it('converts from seconds to minutes', () => {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import TimeUnit from '../../../data/TimeUnit';
2+
3+
import build from './build';
4+
5+
jest.unmock('convert-units');
6+
7+
describe('#build', () => {
8+
const location = { name: 'foobar' };
9+
10+
// both tests use emojis and assumes process.platform = darwin
11+
// apologies in advance if this causes problems
12+
13+
it('builds table for products that do not share same formatted duration', () => {
14+
const estimates = [
15+
{
16+
estimatedDuration: { length: 120, unit: TimeUnit.SECOND },
17+
productName: 'first product',
18+
},
19+
{
20+
estimatedDuration: { length: 60, unit: TimeUnit.SECOND },
21+
productName: 'second product',
22+
},
23+
{
24+
estimatedDuration: { length: 0, unit: TimeUnit.SECOND },
25+
productName: 'third product',
26+
},
27+
];
28+
const expected = '\u001b[90mβ”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”\u001b[39m\n\u001b[90mβ”‚\u001b[39m πŸ“ foobar \u001b[90mβ”‚\u001b[39m\n\u001b[90mβ”œβ”€β”€β”€β”€β”€β”€β”€β”€\u001b[39m\u001b[90m┬─────────────────\u001b[39m\n\u001b[90mβ”‚\u001b[39m ⏳ \u001b[90mβ”‚\u001b[39m 🚘 \u001b[90mβ”‚\u001b[39m\n\u001b[90mβ”œβ”€β”€β”€β”€β”€β”€β”€β”€\u001b[39m\u001b[90m┼─────────────────\u001b[39m\n\u001b[90mβ”‚\u001b[39m 0 sec. \u001b[90mβ”‚\u001b[39m third product \u001b[90mβ”‚\u001b[39m\n\u001b[90mβ”œβ”€β”€β”€β”€β”€β”€β”€β”€\u001b[39m\u001b[90m┼─────────────────\u001b[39m\n\u001b[90mβ”‚\u001b[39m 1 min. \u001b[90mβ”‚\u001b[39m second product \u001b[90mβ”‚\u001b[39m\n\u001b[90mβ”œβ”€β”€β”€β”€β”€β”€β”€β”€\u001b[39m\u001b[90m┼─────────────────\u001b[39m\n\u001b[90mβ”‚\u001b[39m 2 min. \u001b[90mβ”‚\u001b[39m first product \u001b[90mβ”‚\u001b[39m\n\u001b[90m└────────\u001b[39m\u001b[90mβ”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜\u001b[39m';
29+
expect(build({ estimates, location })).toEqual(expected);
30+
});
31+
32+
it('builds table for products that do share same formatted duration', () => {
33+
const estimates = [
34+
{
35+
estimatedDuration: { length: 120, unit: TimeUnit.SECOND },
36+
productName: 'first product',
37+
},
38+
{
39+
estimatedDuration: { length: 120, unit: TimeUnit.SECOND },
40+
productName: 'second product',
41+
},
42+
{
43+
estimatedDuration: { length: 120, unit: TimeUnit.SECOND },
44+
productName: 'third product',
45+
},
46+
];
47+
const expected = '\u001b[90mβ”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”\u001b[39m\n\u001b[90mβ”‚\u001b[39m πŸ“ foobar \u001b[90mβ”‚\u001b[39m\n\u001b[90mβ”œβ”€β”€β”€β”€β”€β”€β”€β”€\u001b[39m\u001b[90m┬───────────────────────────────────────────────\u001b[39m\n\u001b[90mβ”‚\u001b[39m ⏳ \u001b[90mβ”‚\u001b[39m 🚘 \u001b[90mβ”‚\u001b[39m\n\u001b[90mβ”œβ”€β”€β”€β”€β”€β”€β”€β”€\u001b[39m\u001b[90m┼───────────────────────────────────────────────\u001b[39m\n\u001b[90mβ”‚\u001b[39m 2 min. \u001b[90mβ”‚\u001b[39m first product, second product, third product \u001b[90mβ”‚\u001b[39m\n\u001b[90m└────────\u001b[39m\u001b[90mβ”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜\u001b[39m';
48+
expect(build({ estimates, location })).toEqual(expected);
49+
});
50+
});

0 commit comments

Comments
Β (0)