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);
});
});

View File

@@ -0,0 +1,30 @@
'use strict';
describe('mark with acrossElements and matches across iframes', function() {
var $ctx, $elements, errCall;
beforeEach(function(done) {
loadFixtures('across-elements/iframes/across.html');
$elements = $();
$ctx = $('.across-elements-iframes-across');
errCall = 0;
try {
new Mark($ctx[0]).mark(['dolor sit', 'amet. Lorem'], {
'diacritics': false,
'separateWordSearch': false,
'iframes': true,
'acrossElements': true,
'each': function($m) {
$elements = $elements.add($($m));
},
'done': done
});
} catch (e) {
errCall++;
}
}, 30000); // 30 sec timeout
it('should wrap matches across iframes recursively', function() {
expect(errCall).toBe(0);
expect($elements).toHaveLength(30); // including whitespace matches
});
});

View File

@@ -0,0 +1,38 @@
'use strict';
describe('mark with acrossElements and iframes', function() {
var $ctx, $elements, errCall;
beforeEach(function(done) {
loadFixtures('across-elements/iframes/main.html');
$elements = $();
$ctx = $('.across-elements-iframes');
errCall = 0;
try {
new Mark($ctx[0]).mark('lorem', {
'diacritics': false,
'separateWordSearch': false,
'iframes': true,
'acrossElements': true,
'each': function($m) {
$elements = $elements.add($($m));
},
'done': done
});
} catch (e) {
errCall++;
}
}, 30000); // 30 sec timeout
it('should wrap matches inside iframes', function() {
expect(errCall).toBe(0);
expect($elements).toHaveLength(8);
var unequal = false;
$elements.each(function() {
// make sure that some elements are inside an iframe
if ($(this).prop('ownerDocument') !== $ctx.prop('ownerDocument')) {
unequal = true;
}
});
expect(unequal).toBe(true);
});
});

View File

@@ -0,0 +1,30 @@
'use strict';
describe('mark with acrossElements and nested iframes', function() {
var $ctx, $elements, errCall;
beforeEach(function(done) {
loadFixtures('across-elements/iframes/nested.html');
$elements = $();
$ctx = $('.across-elements-iframes-nested');
errCall = 0;
try {
new Mark($ctx[0]).mark('lorem', {
'diacritics': false,
'separateWordSearch': false,
'iframes': true,
'acrossElements': true,
'each': function($m) {
$elements = $elements.add($($m));
},
'done': done
});
} catch (e) {
errCall++;
}
}, 30000); // 30 sec timeout
it('should wrap matches inside iframes recursively', function() {
expect(errCall).toBe(0);
expect($elements).toHaveLength(12);
});
});

View File

@@ -0,0 +1,19 @@
'use strict';
describe('mark with acrossElements and nested matches', function() {
var $ctx;
beforeEach(function(done) {
loadFixtures('across-elements/nested/main.html');
$ctx = $('.across-elements-nested');
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(7);
});
});

View File

@@ -0,0 +1,38 @@
'use strict';
describe(
'mark with acrossElements, regular expression and filter callback',
function() {
var $ctx;
beforeEach(function() {
loadFixtures('across-elements/regexp/filter.html');
$ctx = $('.across-elements-regexp-filter');
});
it(
'should call the callback with the right parameters',
function(done) {
var k = 0,
textOpts = ['Lorem', 'ipsum'];
new Mark($ctx[0]).markRegExp(/(Lore?m)|(ipsum)/gmi, {
'acrossElements': true,
'filter': function(node, term, totalMatches) {
expect(node.nodeType).toBe(3);
expect($.inArray(term, textOpts)).toBeGreaterThan(-1);
expect(k).toBe(totalMatches);
if (term !== 'ipsum') {
k++;
return true;
} else {
return false;
}
},
'done': function() {
expect($ctx.find('mark')).toHaveLength(4);
done();
}
});
}
);
}
);

View File

@@ -0,0 +1,38 @@
'use strict';
describe(
'mark with acrossElements, regular expression and ignoreGroups',
function() {
var $ctx1, $ctx2, prefix = 'across-elements-regexp';
beforeEach(function(done) {
loadFixtures('across-elements/regexp/ignore-groups.html');
$ctx1 = $('.' + prefix + '-ignore-groups > div:first-child');
$ctx2 = $('.' + prefix + '-ignore-groups > div:last-child');
new Mark($ctx1[0]).markRegExp(/(Lor)([^]?m[\s]*)(ipsum)/gmi, {
'acrossElements': true,
'done': function() {
new Mark($ctx2[0]).markRegExp(
/(Lor)([^]?m[\s]*)(ipsum)/gmi, {
'acrossElements': true,
'ignoreGroups': 2,
'done': done
}
);
}
});
});
it('should silently ignore groups when disabled', function() {
expect($ctx1.find('mark')).toHaveLength(4);
$ctx1.find('mark').each(function() {
expect($(this).text()).toBe('Lorem ipsum');
});
});
it('should ignore specified groups when enabled', function() {
expect($ctx2.find('mark')).toHaveLength(4);
$ctx2.find('mark').each(function() {
expect($(this).text()).toBe('ipsum');
});
});
}
);

View File

@@ -0,0 +1,23 @@
'use strict';
describe(
'mark with acrossElements and regular expression with infinite matches',
function() {
var $ctx;
beforeEach(function(done) {
loadFixtures('across-elements/regexp/infinite.html');
$ctx = $('.across-elements-regexp-infinite');
new Mark($ctx[0]).markRegExp(/(|)/gmi, {
'acrossElements': true,
'done': done
});
});
it(
'should not mark regular expressions with infinite matches',
function() {
expect($ctx.find('mark')).toHaveLength(0);
}
);
}
);

View File

@@ -0,0 +1,17 @@
'use strict';
describe('mark with acrossElements and regular expression', function() {
var $ctx;
beforeEach(function(done) {
loadFixtures('across-elements/regexp/main.html');
$ctx = $('.across-elements-regexp');
new Mark($ctx[0]).markRegExp(/lorem[\s]+ipsum/gmi, {
'acrossElements': true,
'done': done
});
});
it('should wrap matches', function() {
expect($ctx.find('mark')).toHaveLength(6);
});
});