first-commit
Some checks failed
CI Pipeline / build (push) Failing after 3m23s

This commit is contained in:
2025-08-27 14:05:33 +08:00
commit 9e1b8bdc9d
5159 changed files with 1081326 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
'use strict';
describe('mark with acrossElements and accuracy exactly', function() {
var $ctx1, $ctx2, $ctx3;
beforeEach(function(done) {
loadFixtures('across-elements/basic/accuracy-exactly.html');
$ctx1 = $('.across-elements-accuracy-exactly > div:nth-child(1)');
$ctx2 = $('.across-elements-accuracy-exactly > div:nth-child(2)');
$ctx3 = $('.across-elements-accuracy-exactly > div:nth-child(3)');
new Mark($ctx1[0]).mark('ipsu', {
'accuracy': 'exactly',
'separateWordSearch': false,
'acrossElements': true,
'done': function() {
new Mark($ctx2[0]).mark('ipsu dolo', {
'accuracy': 'exactly',
'separateWordSearch': true,
'acrossElements': true,
'done': function() {
new Mark($ctx3[0]).mark('ipsu', {
'accuracy': 'exactly',
'separateWordSearch': false,
'acrossElements': true,
'done': done
});
}
});
}
});
});
it('should wrap the right matches', function() {
expect($ctx1.find('mark')).toHaveLength(1);
expect($ctx1.find('mark').text()).toBe('ipsu');
expect($ctx1.find('.not mark')).toHaveLength(0);
});
it('should work with separateWordSearch', function() {
expect($ctx2.find('mark')).toHaveLength(2);
var textOpts = ['ipsu', 'dolo'];
$ctx2.find('mark').each(function() {
expect($.inArray($(this).text(), textOpts)).toBeGreaterThan(-1);
});
expect($ctx2.find('.not mark')).toHaveLength(0);
});
it('should work with diacritics', function() {
expect($ctx3.find('mark')).toHaveLength(4);
var textOpts = ['ipsu', 'ipsü', 'īpsu', 'īpsü'];
$ctx3.find('mark').each(function() {
expect($.inArray($(this).text(), textOpts)).toBeGreaterThan(-1);
});
expect($ctx3.find('.not mark')).toHaveLength(0);
});
});

View File

@@ -0,0 +1,30 @@
'use strict';
describe('mark with acrossElements and done callback', function() {
var $ctx, doneCalled, totalMatches;
beforeEach(function(done) {
loadFixtures('across-elements/basic/main.html');
totalMatches = doneCalled = 0;
$ctx = $('.across-elements');
new Mark($ctx[0]).mark('lorem ipsum', {
'diacritics': false,
'separateWordSearch': false,
'acrossElements': true,
'done': function(counter) {
doneCalled++;
totalMatches = counter;
done();
}
});
});
it('should call the done callback once only', function(done) {
setTimeout(function() {
expect(doneCalled).toBe(1);
done();
}, 3000);
});
it('should call the done callback with total matches', function() {
expect(totalMatches).toBe(6);
});
});

View File

@@ -0,0 +1,23 @@
'use strict';
describe('mark with acrossElements and each callback', function() {
var $ctx, eachCalled;
beforeEach(function(done) {
loadFixtures('across-elements/basic/main.html');
eachCalled = 0;
$ctx = $('.across-elements');
new Mark($ctx[0]).mark('lorem ipsum', {
'diacritics': false,
'separateWordSearch': false,
'acrossElements': true,
'each': function() {
eachCalled++;
},
'done': done
});
});
it('should call the each callback for each marked element', function() {
expect(eachCalled).toBe(6);
});
});

View File

@@ -0,0 +1,32 @@
'use strict';
describe('mark with acrossElements in an empty context', function() {
var $ctx1, $ctx2, done1 = false,
done2 = false;
beforeEach(function(done) {
loadFixtures('across-elements/basic/empty.html');
$ctx1 = $('.notExistingSelector');
$ctx2 = $('.across-elements-empty');
new Mark($ctx1[0]).mark('lorem', {
'diacritics': false,
'separateWordSearch': false,
'acrossElements': true,
'done': function() {
done1 = true;
new Mark($ctx2[0]).mark('lorem', {
'diacritics': false,
'separateWordSearch': false,
'done': function() {
done2 = true;
done();
}
});
}
});
});
it('should call the done function', function() {
expect(done1).toBe(true);
expect(done2).toBe(true);
});
});

View File

@@ -0,0 +1,48 @@
'use strict';
describe('mark with acrossElements and filter callback', function() {
var $ctx;
beforeEach(function() {
loadFixtures('across-elements/basic/filter.html');
$ctx = $('.across-elements-filter');
});
it('should call the callback with the right parameters', function(done) {
var counter = {
'lorem': 0,
'ipsum': 0,
'dolor': 0
},
totalCounter = 0,
calls = 0;
try {
new Mark($ctx[0]).mark(Object.keys(counter), {
'diacritics': false,
'separateWordSearch': false,
'acrossElements': true,
'filter': function(node, term, totalMatches, matches) {
expect(node.nodeType).toBe(3);
expect($.inArray(
term,
Object.keys(counter)
)).toBeGreaterThan(-1);
expect(totalCounter).toBe(totalMatches);
expect(counter[term]).toBe(matches);
if (++calls !== 3) {
counter[term]++;
totalCounter++;
return true;
} else {
return false;
}
},
'done': function() {
expect($ctx.find('mark')).toHaveLength(15);
done();
}
});
} catch (e){
done.fail(e.message);
}
});
});

View File

@@ -0,0 +1,20 @@
'use strict';
describe('mark with acrossElements and ignoreJoiners', function() {
var $ctx;
beforeEach(function(done) {
loadFixtures('across-elements/basic/ignore-joiners.html');
$ctx = $('.across-elements-ignore-joiners');
new Mark($ctx[0]).mark('lorem ipsum', {
'diacritics': false,
'separateWordSearch': false,
'acrossElements': true,
'ignoreJoiners': true,
'done': done
});
});
it('should wrap matches and ignoreJoiners', function() {
expect($ctx.find('mark')).toHaveLength(6);
});
});

View File

@@ -0,0 +1,19 @@
'use strict';
describe('mark with acrossElements', function() {
var $ctx;
beforeEach(function(done) {
loadFixtures('across-elements/basic/main.html');
$ctx = $('.across-elements');
new Mark($ctx[0]).mark('lorem ipsum', {
'diacritics': false,
'separateWordSearch': false,
'acrossElements': true,
'done': done
});
});
it('should wrap matches', function() {
expect($ctx.find('mark')).toHaveLength(6);
});
});

View File

@@ -0,0 +1,28 @@
'use strict';
describe('mark with acrossElements and multiple blanks', function() {
var $ctx1, $ctx2;
beforeEach(function(done) {
loadFixtures('across-elements/basic/merge-blanks.html');
$ctx1 = $('.across-elements-merge-blanks > div:nth-child(1)');
$ctx2 = $('.across-elements-merge-blanks > div:nth-child(2)');
new Mark($ctx1.get()).mark('lorem ipsum', {
'diacritics': false,
'separateWordSearch': false,
'acrossElements': true,
'done': function() {
new Mark($ctx2.get()).mark('lorem ipsum', {
'diacritics': false,
'separateWordSearch': false,
'acrossElements': true,
'done': done
});
}
});
});
it('should wrap matches regardless of the number of blanks', function() {
expect($ctx1.find('mark')).toHaveLength(5);
expect($ctx2.find('mark')).toHaveLength(5);
});
});