Skip to content

Commit 48534fa

Browse files
committed
Update tests
1 parent b82fa21 commit 48534fa

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-10
lines changed

tests/hooks/useTextAnalyzer.test.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ describe('useTextAnalyzer', () => {
2828
sentenceCount: 14,
2929
paragraphCount: 7,
3030
searchFrequency: 2,
31-
readingTime: 24,
31+
readingTime: {
32+
minutes: 0,
33+
seconds: 19,
34+
total: 19,
35+
text: 'less than a minute read',
36+
},
3237
mostFrequentWord: 'paragraph',
3338
leastFrequentWord: 'first',
3439
mostFrequentCharacter: 'a',
@@ -51,7 +56,12 @@ describe('useTextAnalyzer', () => {
5156
sentenceCount: 14,
5257
paragraphCount: 7,
5358
searchFrequency: 1,
54-
readingTime: 24,
59+
readingTime: {
60+
minutes: 0,
61+
seconds: 19,
62+
total: 19,
63+
text: 'less than a minute read',
64+
},
5565
mostFrequentWord: 'This',
5666
leastFrequentWord: 'first',
5767
mostFrequentCharacter: 'a',
@@ -68,7 +78,12 @@ describe('useTextAnalyzer', () => {
6878
sentenceCount: 14,
6979
paragraphCount: 7,
7080
searchFrequency: 0,
71-
readingTime: 24,
81+
readingTime: {
82+
minutes: 0,
83+
seconds: 19,
84+
total: 19,
85+
text: 'less than a minute read',
86+
},
7287
mostFrequentWord: 'paragraph',
7388
leastFrequentWord: 'first',
7489
mostFrequentCharacter: 'a',
@@ -91,7 +106,12 @@ describe('useTextAnalyzer', () => {
91106
sentenceCount: 14,
92107
paragraphCount: 7,
93108
searchFrequency: 1,
94-
readingTime: 24,
109+
readingTime: {
110+
minutes: 0,
111+
seconds: 19,
112+
total: 19,
113+
text: 'less than a minute read',
114+
},
95115
mostFrequentWord: 'paragraph',
96116
leastFrequentWord: 'first',
97117
mostFrequentCharacter: 'a',
Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,42 @@
11
import { estimateReadingTime } from '../../src/utils/estimateReadingTime';
22

33
describe('estimateReadingTime', () => {
4-
it('should return the correct reading time based on the word count', () => {
5-
expect(estimateReadingTime(0)).toBe(0);
6-
expect(estimateReadingTime(100)).toBe(30);
7-
expect(estimateReadingTime(200)).toBe(60);
8-
expect(estimateReadingTime(250)).toBe(75);
9-
expect(estimateReadingTime(500)).toBe(150);
4+
const wordsPerMinute = 250;
5+
6+
it('should return the correct reading time for various word counts', () => {
7+
expect(estimateReadingTime(0, wordsPerMinute)).toEqual({
8+
minutes: 0,
9+
seconds: 0,
10+
total: 0,
11+
text: 'less than a minute read',
12+
});
13+
14+
expect(estimateReadingTime(100, wordsPerMinute)).toEqual({
15+
minutes: 0,
16+
seconds: 24,
17+
total: 24,
18+
text: 'less than a minute read',
19+
});
20+
21+
expect(estimateReadingTime(250, wordsPerMinute)).toEqual({
22+
minutes: 1,
23+
seconds: 0,
24+
total: 60,
25+
text: '1 min read',
26+
});
27+
28+
expect(estimateReadingTime(275, wordsPerMinute)).toEqual({
29+
minutes: 1,
30+
seconds: 6,
31+
total: 66,
32+
text: '1 min read',
33+
});
34+
35+
expect(estimateReadingTime(500, wordsPerMinute)).toEqual({
36+
minutes: 2,
37+
seconds: 0,
38+
total: 120,
39+
text: '2 min read',
40+
});
1041
});
1142
});

0 commit comments

Comments
 (0)