diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-11-06 18:08:04 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:15:27 +0100 |
| commit | c9c1c90b30e243563bb4f731da15b3fe657556d2 (patch) | |
| tree | 8263c176b4096e2893b9d9319bfa7edb01fce188 /src/utils/helpers/reading-time.test.ts | |
| parent | 2771de88f40a5f4ed7480bd8614532dda72deeda (diff) | |
refactor(components): replace Summary component with PostPreview
* rename component to PostPreview because Summary is an HTML element
and it could lead to confusion
* replace `title` and `titleLevel` with `heading` and `headingLvl`
because `title` is a native attribute
* rename `intro` prop to `excerpt`
* extract `cover` from `meta` prop
* rewrite meta type
* extract meta logic into a new component
Diffstat (limited to 'src/utils/helpers/reading-time.test.ts')
| -rw-r--r-- | src/utils/helpers/reading-time.test.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/utils/helpers/reading-time.test.ts b/src/utils/helpers/reading-time.test.ts new file mode 100644 index 0000000..24181a6 --- /dev/null +++ b/src/utils/helpers/reading-time.test.ts @@ -0,0 +1,31 @@ +import { describe, it } from '@jest/globals'; +import { getReadingTimeFrom } from './reading-time'; + +describe('reading-time', () => { + it('can transform a words count into a reading time in minutes', () => { + const wordsCount = 250; + + // With the default settings, 250 words should be rounded to one minute. + expect(getReadingTimeFrom(wordsCount).inMinutes()).toBe(1); + }); + + it('can transform a words count into a reading time in minutes and seconds', () => { + const wordsCount = 1200; + const readingTime = getReadingTimeFrom(wordsCount).inMinutesAndSeconds(); + + expect(readingTime.minutes).toBeGreaterThan(1); + expect(readingTime.seconds).toBeGreaterThan(0); + }); + + it('can use a custom words per minute setting', () => { + const wordsCount = 100; + const wordsPerMinute = 100; + const readingTime = getReadingTimeFrom( + wordsCount, + wordsPerMinute + ).inMinutesAndSeconds(); + + expect(readingTime.minutes).toBe(1); + expect(readingTime.seconds).toBe(0); + }); +}); |
