Skip to content

Commit

Permalink
test: add tests for stringToMs improvements #3736
Browse files Browse the repository at this point in the history
  • Loading branch information
Edouard Cunibil authored and johannesjo committed Dec 8, 2024
1 parent 6325254 commit 1a842ee
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/app/ui/duration/string-to-ms.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,24 @@ describe('stringToMs', () => {
it('should not return NaN for just h', () => {
expect(stringToMs('h')).toBe(0);
});

// @covers #3737
it('should work improved', () => {
// Case: no spaces.
expect(stringToMs('1h10m')).toBe(4200000);

// Case: missing last unit.
expect(stringToMs('1h 10')).toBe(4200000);
expect(stringToMs('1h10')).toBe(4200000);

// Case: missing all units.
expect(stringToMs('10')).toBe(0);

// Case: using floats (with dot or comma separator).
expect(stringToMs('1.5h')).toBe(5400000);
expect(stringToMs('1,5h')).toBe(5400000);

// Case: combining floats with subunits (opinionated choice: adds up).
expect(stringToMs('1,5h 10m')).toBe(6000000);
});
});

0 comments on commit 1a842ee

Please sign in to comment.