-
Notifications
You must be signed in to change notification settings - Fork 953
Expand file tree
/
Copy pathmarkWordsInSentenceSpec.js
More file actions
144 lines (136 loc) · 7.11 KB
/
markWordsInSentenceSpec.js
File metadata and controls
144 lines (136 loc) · 7.11 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { markWordsInSentences } from "../../../../src/languageProcessing/helpers/word/markWordsInSentences";
import Mark from "../../../../src/values/Mark";
import matchWordCustomHelper from "../../../../src/languageProcessing/languages/ja/helpers/matchTextWithWord";
describe( "Adds Yoast marks to specific words in a sentence", function() {
it( "should add Yoast marks to all instances of specified words in a sentence, except when there is an anchor," +
" the marking should not be applied to the anchor tag attribute", function() {
expect( markWordsInSentences(
[ "picket", "tile" ],
[ "Introducing Palisades Ceramic Picket Tile — the latest trend in <a href=\"https://www.tileclub.com/collections/ceramic-tile\"" +
" target=\"_blank\" rel=\"noopener\">ceramic tile</a>!" ],
"en_EN"
) ).toEqual( [
new Mark( {
marked: "Introducing Palisades Ceramic <yoastmark class='yoast-text-mark'>Picket Tile</yoastmark> — the latest trend in " +
"<a href=\"https://www.tileclub.com/" +
"collections/ceramic-tile\" target=\"_blank\" rel=\"noopener\">ceramic " +
"<yoastmark class='yoast-text-mark'>tile</yoastmark></a>!",
original: "Introducing Palisades Ceramic Picket Tile — the latest trend in " +
"<a href=\"https://www.tileclub.com/collections/ceramic-tile\"" +
" target=\"_blank\" rel=\"noopener\">ceramic tile</a>!" } ),
]
);
} );
it( "should add Yoast marks to all instances of specified words in a sentence, except when there are multiple anchors," +
" the marking should not be applied to the anchor tag attribute", function() {
expect( markWordsInSentences(
[ "picket", "tile" ],
[ "Introducing Palisades Ceramic <a href=\"https://www.tileclub.com/ceramic-tile\">Picket Tile</a> — " +
"the latest trend in <a href=\"https://www.tileclub.com/collections/ceramic-tile\"" +
" target=\"_blank\" rel=\"noopener\">ceramic tile</a>!" ],
"en_EN"
) ).toEqual( [
new Mark( {
marked: "Introducing Palisades Ceramic <a href=\"https://www.tileclub.com/ceramic-tile\"><yoastmark class='yoast-text-mark'>" +
"Picket Tile</yoastmark></a> — the latest trend in " +
"<a href=\"https://www.tileclub.com/" +
"collections/ceramic-tile\" target=\"_blank\" rel=\"noopener\">ceramic " +
"<yoastmark class='yoast-text-mark'>tile</yoastmark></a>!",
original: "Introducing Palisades Ceramic <a href=\"https://www.tileclub.com/ceramic-tile\">Picket Tile</a> — " +
"the latest trend in <a href=\"https://www.tileclub.com/collections/ceramic-tile\"" +
" target=\"_blank\" rel=\"noopener\">ceramic tile</a>!" } ),
]
);
} );
it( "should add Yoast marks to all instances of specified words in a sentence", function() {
expect( markWordsInSentences(
[ "turtle", "hamster" ],
[ "A cat and a turtle and a hamster.", "A turtle and another turtle." ],
"en_EN"
) ).toEqual( [
new Mark( {
marked: "A cat and a <yoastmark class='yoast-text-mark'>turtle</yoastmark> " +
"and a <yoastmark class='yoast-text-mark'>hamster</yoastmark>.",
original: "A cat and a turtle and a hamster." } ),
new Mark( {
marked: "A <yoastmark class='yoast-text-mark'>turtle</yoastmark> and another <yoastmark class='yoast-text-mark'>turtle</yoastmark>.",
original: "A turtle and another turtle." } ) ]
);
} );
it( "should generate continuous Yoast marks multiple matches separated by a single space", function() {
expect( markWordsInSentences(
[ "turtle", "hamster" ],
[ "A cat and a turtle hamster.", "A hamster turtle and another turtle." ],
"en_EN"
) ).toEqual( [
new Mark( {
marked: "A cat and a <yoastmark class='yoast-text-mark'>turtle hamster</yoastmark>.",
original: "A cat and a turtle hamster." } ),
new Mark( {
marked: "A <yoastmark class='yoast-text-mark'>hamster turtle</yoastmark> and another " +
"<yoastmark class='yoast-text-mark'>turtle</yoastmark>.",
original: "A hamster turtle and another turtle." } ) ]
);
} );
it( "returns an empty array when the topic is not found in the sentence", function() {
expect( markWordsInSentences(
[ "turtle", "hamster" ],
[ "A cat as a pet.", "A cat is a special pet." ],
"en_EN"
) ).toEqual( [] );
} );
} );
describe( "Adds Yoast marks to specific words in a sentence for languages with custom helper to match words", function() {
// Japanese has the custom helper to match words.
it( "should add Yoast marks to all instances of specified words in a sentence", function() {
expect( markWordsInSentences(
[ "黒", "長袖", "マキシドレス" ],
[ "彼女はオンラインストアで黒の長袖マキシドレスを購入したかった。", "しかし、それは在庫切れでしたマキシドレス。" ],
"ja",
matchWordCustomHelper
) ).toEqual( [
new Mark( {
marked: "彼女はオンラインストアで<yoastmark class='yoast-text-mark'>黒</yoastmark>の<yoastmark class='yoast-text-mark'>長袖</yoastmark>" +
"<yoastmark class='yoast-text-mark'>マキシドレス</yoastmark>を購入したかった。",
original: "彼女はオンラインストアで黒の長袖マキシドレスを購入したかった。" } ),
new Mark( {
marked: "しかし、それは在庫切れでした<yoastmark class='yoast-text-mark'>マキシドレス</yoastmark>。",
original: "しかし、それは在庫切れでしたマキシドレス。" } ) ]
);
} );
it( "should still add Yoast marks to all instances of specified words in a sentence even when the word is enclosed in double quotes", function() {
expect( markWordsInSentences(
[ "『小さい花の刺繍』" ],
[ "彼女はオンラインストアで黒の長袖マキシドレスを購入したかった。", "小さい花の刺繍しかし、それは在庫切れでしたマキシドレス。" ],
"ja",
matchWordCustomHelper
) ).toEqual( [
new Mark( {
marked: "<yoastmark class='yoast-text-mark'>小さい花の刺繍</yoastmark>しかし、それは在庫切れでしたマキシドレス。",
original: "小さい花の刺繍しかし、それは在庫切れでしたマキシドレス。" } ),
]
);
} );
it( "should still add Yoast marks to all instances of specified words in a sentence even when " +
"the keyword is enclosed in double quotes and the instances in the text is followed by a fullstop", function() {
expect( markWordsInSentences(
[ "『小さい花の刺繍』" ],
[ "彼女はオンラインストアで黒の長袖マキシドレスを購入したかった。", "しかし、それは在庫切れでしたマキシドレス。", "小さい花の刺繍。" ],
"ja",
matchWordCustomHelper
) ).toEqual( [
new Mark( {
marked: "<yoastmark class='yoast-text-mark'>小さい花の刺繍</yoastmark>。",
original: "小さい花の刺繍。" } ),
]
);
} );
it( "returns an empty array when the topic is not found in the sentence", function() {
expect( markWordsInSentences(
[ "書き", "甘い香ら" ],
[ "私はペットとして2匹の猫を飼っています。", "どちらもとても可愛くて甘い猫で、猫の餌を食べるのが大好きです。" ],
"ja",
matchWordCustomHelper
) ).toEqual( [] );
} );
} );