You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
consttext1='The quick brown fox jumps over the lazy dog'
9
-
constsearchTerm1='fox'
10
-
constexpectedResult1='The quick brown <mark class="orama-highlight">fox</mark> jumps over the lazy dog'
11
-
12
-
consttext2='Yesterday all my troubles seemed so far away, now it looks as though they\'re here to stay oh, I believe in yesterday'
13
-
constsearchTerm2='yesterday I was in trouble'
14
-
constexpectedResult2='<mark class="orama-highlight">Yesterday</mark> all my <mark class="orama-highlight">trouble</mark>s seemed so far away, now <mark class="orama-highlight">i</mark>t looks as though they\'re here to stay oh, <mark class="orama-highlight">I</mark> bel<mark class="orama-highlight">i</mark>eve <mark class="orama-highlight">i</mark>n <mark class="orama-highlight">yesterday</mark>'
it('should correctly highlight a text (case sensitive)',()=>{
45
-
consttext1='The quick brown fox jumps over the lazy dog'
46
-
constsearchTerm1='Fox'
47
-
constexpectedResult1='The quick brown fox jumps over the lazy dog'
48
-
49
-
consttext2='Yesterday all my troubles seemed so far away, now it looks as though they\'re here to stay oh, I believe in yesterday'
50
-
constsearchTerm2='yesterday I was in trouble'
51
-
constexpectedResult2='Yesterday all my <mark class="orama-highlight">trouble</mark>s seemed so far away, now it looks as though they\'re here to stay oh, <mark class="orama-highlight">I</mark> believe <mark class="orama-highlight">in</mark> <mark class="orama-highlight">yesterday</mark>'
consttext1="The quick brown fox jumps over the lazy dog";
9
+
constsearchTerm1="fox";
10
+
constexpectedResult1=
11
+
'The quick brown <mark class="orama-highlight">fox</mark> jumps over the lazy dog';
12
+
13
+
consttext2=
14
+
"Yesterday all my troubles seemed so far away, now it looks as though they're here to stay oh, I believe in yesterday";
15
+
constsearchTerm2="yesterday I was in trouble";
16
+
constexpectedResult2=
17
+
'<mark class="orama-highlight">Yesterday</mark> all my <mark class="orama-highlight">trouble</mark>s seemed so far away, now <mark class="orama-highlight">i</mark>t looks as though they\'re here to stay oh, <mark class="orama-highlight">I</mark> bel<mark class="orama-highlight">i</mark>eve <mark class="orama-highlight">i</mark>n <mark class="orama-highlight">yesterday</mark>';
18
+
19
+
consthighlighter=newHighlight();
20
+
21
+
assert.strictEqual(
22
+
highlighter.highlight(text1,searchTerm1).HTML,
23
+
expectedResult1
24
+
);
25
+
assert.strictEqual(
26
+
highlighter.highlight(text2,searchTerm2).HTML,
27
+
expectedResult2
28
+
);
29
+
});
30
+
31
+
it("should return the correct positions",()=>{
32
+
consttext="The quick brown fox jumps over the lazy dog";
33
+
constsearchTerm="fox";
34
+
constexpectedPositions=[{start: 16,end: 18}];
35
+
36
+
consthighlighter=newHighlight();
37
+
38
+
assert.deepStrictEqual(
39
+
highlighter.highlight(text,searchTerm).positions,
40
+
expectedPositions
41
+
);
42
+
});
43
+
44
+
it("should return multiple positions",()=>{
45
+
consttext="The quick brown fox jumps over the lazy dog";
46
+
constsearchTerm="the";
47
+
constexpectedPositions=[
48
+
{start: 0,end: 2},
49
+
{start: 31,end: 33},
50
+
];
51
+
52
+
consthighlighter=newHighlight();
53
+
54
+
assert.deepStrictEqual(
55
+
highlighter.highlight(text,searchTerm).positions,
56
+
expectedPositions
57
+
);
58
+
});
59
+
});
60
+
61
+
describe("custom configuration",()=>{
62
+
it("should correctly highlight a text (case sensitive)",()=>{
63
+
consttext1="The quick brown fox jumps over the lazy dog";
64
+
constsearchTerm1="Fox";
65
+
constexpectedResult1="The quick brown fox jumps over the lazy dog";
66
+
67
+
consttext2=
68
+
"Yesterday all my troubles seemed so far away, now it looks as though they're here to stay oh, I believe in yesterday";
69
+
constsearchTerm2="yesterday I was in trouble";
70
+
constexpectedResult2=
71
+
'Yesterday all my <mark class="orama-highlight">trouble</mark>s seemed so far away, now it looks as though they\'re here to stay oh, <mark class="orama-highlight">I</mark> believe <mark class="orama-highlight">in</mark> <mark class="orama-highlight">yesterday</mark>';
0 commit comments