-
-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathMetaDescription_.test.res
More file actions
56 lines (44 loc) · 2.55 KB
/
MetaDescription_.test.res
File metadata and controls
56 lines (44 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
open Vitest
test("returns the first sentence for a one-sentence description", async () => {
let result = MetaDescription.shortenForSocialPreview("JavaScript Made Simple for Humans and AI.")
expect(result)->toBe("JavaScript Made Simple for Humans and AI.")
})
test("includes the second sentence when both sentences are within 140 characters", async () => {
let result = MetaDescription.shortenForSocialPreview(
"JavaScript Made Simple for Humans and AI. ReScript is a strongly typed language that compiles to clean, efficient JavaScript that humans and AI tools can read and understand.",
)
expect(result)->toBe(
"JavaScript Made Simple for Humans and AI. ReScript is a strongly typed language that compiles to clean, efficient JavaScript that humans and AI tools can read and understand.",
)
})
test("returns only the first sentence when the first sentence exceeds 140 characters", async () => {
let result = MetaDescription.shortenForSocialPreview(
"This first sentence is intentionally long enough to cross the one hundred and forty character threshold before it reaches its final word in the sentence. Short follow up.",
)
expect(result)->toBe(
"This first sentence is intentionally long enough to cross the one hundred and forty character threshold before it reaches its final word in the sentence.",
)
})
test(
"returns only the first sentence when the second sentence exceeds 140 characters",
async () => {
let result = MetaDescription.shortenForSocialPreview(
"Short opening sentence. This second sentence is intentionally long enough to cross the one hundred and forty character threshold before it reaches its final word in the sentence.",
)
expect(result)->toBe("Short opening sentence.")
},
)
test("collapses line breaks and repeated spaces before evaluating the sentences", async () => {
let result = MetaDescription.shortenForSocialPreview(
"JavaScript Made Simple for Humans and AI.\n\nReScript is a strongly typed language that compiles to clean, efficient JavaScript that humans and AI tools can read and understand.",
)
expect(result)->toBe(
"JavaScript Made Simple for Humans and AI. ReScript is a strongly typed language that compiles to clean, efficient JavaScript that humans and AI tools can read and understand.",
)
})
test("ignores empty sentence fragments created by repeated punctuation", async () => {
let result = MetaDescription.shortenForSocialPreview(
"First sentence... Second sentence stays short.",
)
expect(result)->toBe("First sentence. Second sentence stays short.")
})