@@ -212,6 +212,12 @@ describe('suggestion unit tests', function () {
212
212
it ( 'Prefers https sipmle URLs' , function ( ) {
213
213
assert ( this . sort ( 'https://brave.com' , 'http://brave.com' ) < 0 )
214
214
} )
215
+ it ( 'sorts better matched domains based on more simple domains' , function ( ) {
216
+ assert ( this . sort ( 'https://facebook.github.io/' , 'https://facebook.com/' ) > 0 )
217
+ } )
218
+ it ( 'sorts better matched domains based on more simple domains ignoring www.' , function ( ) {
219
+ assert ( this . sort ( 'https://facebook.github.io/' , 'https://www.facebook.com/' ) > 0 )
220
+ } )
215
221
} )
216
222
describe ( 'getSortByDomain' , function ( ) {
217
223
before ( function ( ) {
@@ -241,9 +247,6 @@ describe('suggestion unit tests', function () {
241
247
it ( 'negative if first site has a match from the start of domain' , function ( ) {
242
248
assert ( this . sort ( 'https://google.com' , 'https://mygoogle.com' ) < 0 )
243
249
} )
244
- it ( 'positive if second site has a match but without www.' , function ( ) {
245
- assert ( this . sort ( 'https://www.google.com' , 'https://google.com' ) > 0 )
246
- } )
247
250
it ( 'negative if there is a pos 0 match not including www.' , function ( ) {
248
251
assert ( this . sort ( 'https://www.google.com' , 'https://mygoogle.com' ) < 0 )
249
252
} )
@@ -253,6 +256,34 @@ describe('suggestion unit tests', function () {
253
256
it ( 'does not throw error for file:// URL' , function ( ) {
254
257
assert ( this . sort ( 'https://google.com' , 'file://' ) < 0 )
255
258
} )
259
+ it ( 'sorts simple domains that match equally on subdomains as the same' , function ( ) {
260
+ const url1 = 'https://facebook.github.com'
261
+ const url2 = 'https://facebook.brave.com'
262
+ const sort = suggestion . getSortByDomain ( 'facebook' , 'facebook' )
263
+ assert ( sort ( {
264
+ location : url1 ,
265
+ parsedUrl : urlParse ( url1 )
266
+ } , {
267
+ location : url2 ,
268
+ parsedUrl : urlParse ( url2 )
269
+ } ) === 0 )
270
+ } )
271
+ it ( 'sorts simple domains that match equally but have different activity based on activity' , function ( ) {
272
+ const url1 = 'https://facebook.github.com'
273
+ const url2 = 'https://facebook.brave.com'
274
+ const sort = suggestion . getSortByDomain ( 'facebook' , 'facebook' )
275
+ assert ( sort ( {
276
+ location : url1 ,
277
+ parsedUrl : urlParse ( url1 ) ,
278
+ lastAccessedTime : 1495335766455 ,
279
+ count : 30
280
+ } , {
281
+ location : url2 ,
282
+ parsedUrl : urlParse ( url2 ) ,
283
+ lastAccessedTime : 1495334766432 ,
284
+ count : 10
285
+ } ) < 0 )
286
+ } )
256
287
} )
257
288
describe ( 'getSortForSuggestions' , function ( ) {
258
289
describe ( 'with url entered as path' , function ( ) {
@@ -299,6 +330,17 @@ describe('suggestion unit tests', function () {
299
330
assert ( this . sort ( 'https://brianbondy.com' , 'www.brianbondy.com' ) < 0 )
300
331
} )
301
332
} )
333
+ it ( 'sorts better matched domains based on more simple domains ignoring www.' , function ( ) {
334
+ const userInputLower = 'facebook'
335
+ const internalSort = suggestion . getSortForSuggestions ( userInputLower , userInputLower )
336
+ const sort = ( url1 , url2 ) => {
337
+ return internalSort (
338
+ { location : url1 , parsedUrl : urlParse ( url1 ) } ,
339
+ { location : url2 , parsedUrl : urlParse ( url2 ) }
340
+ )
341
+ }
342
+ assert ( sort ( 'https://facebook.github.io/' , 'https://www.facebook.com/' ) > 0 )
343
+ } )
302
344
} )
303
345
} )
304
346
} )
0 commit comments