Skip to content

Commit e7f8be9

Browse files
committed
test: refactor and expand unit tests
1 parent 6fc5794 commit e7f8be9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+5339
-6048
lines changed

jest.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ module.exports = {
2929
// Coverage thresholds
3030
coverageThreshold: {
3131
global: {
32-
statements: 62,
33-
branches: 53,
34-
functions: 75,
35-
lines: 63,
32+
statements: 70,
33+
branches: 60,
34+
functions: 80,
35+
lines: 70,
3636
},
3737
},
3838

src/core/event/handlers/handler_ww_key.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ export async function OnKeyUp_wysiwyg(fc, e) {
127127

128128
selectionNode.innerHTML = '';
129129

130-
const oFormatTag = dom.utils.createElement(this.format.isLine(this.status.currentNodes[0]) && !dom.check.isListCell(this.status.currentNodes[0]) ? this.status.currentNodes[0] : this.options.get('defaultLine'), null, '<br>');
130+
const oFormatTag = dom.utils.createElement(
131+
this.format.isLine(this.status.currentNodes[0]) && !dom.check.isListCell(this.status.currentNodes[0]) ? this.status.currentNodes[0].nodeName : this.options.get('defaultLine'),
132+
null,
133+
'<br>',
134+
);
131135
selectionNode.appendChild(oFormatTag);
132136
this.selection.setRange(oFormatTag, 0, oFormatTag, 0);
133137
this.applyTagEffect();

src/helper/converter.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export function kebabToCamelCase(param) {
230230
return param.replace(/-[a-zA-Z]/g, (letter) => letter.replace('-', '').toUpperCase());
231231
} else {
232232
return param.map(function (str) {
233-
return camelToKebabCase(str);
233+
return kebabToCamelCase(str);
234234
});
235235
}
236236
}
@@ -441,10 +441,6 @@ export function spanToStyleNode(styleToTag, node) {
441441
currentNode = nextNode;
442442
}
443443

444-
while (node.firstChild) {
445-
node.removeChild(node.firstChild);
446-
}
447-
448444
node.appendChild(temp);
449445
}
450446
}

src/helper/dom/domCheck.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,9 @@ export function isSameAttributes(a, b) {
263263

264264
const class_a = aEl.classList;
265265
const class_b = bEl.classList;
266-
const wRegExp = RegExp;
267266
let compClass = 0;
268-
269267
for (let i = 0, len = class_a.length; i < len; i++) {
270-
if (wRegExp('(s|^)' + class_a[i] + '(s|$)').test(class_b.value)) compClass++;
268+
if (class_b.contains(class_a[i])) compClass++;
271269
}
272270

273271
return compStyle === style_b.length && compStyle === style_a.length && compClass === class_b.length && compClass === class_a.length;

src/helper/dom/domQuery.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,25 @@ export function sortNodeByDepth(array, des) {
247247
export function compareElements(a, b) {
248248
let aNode = a,
249249
bNode = b;
250+
251+
// Equalize depth
252+
const aDepth = getNodeDepth(a);
253+
const bDepth = getNodeDepth(b);
254+
255+
if (aDepth > bDepth) {
256+
let diff = aDepth - bDepth;
257+
while (diff > 0 && aNode) {
258+
aNode = aNode.parentElement;
259+
diff--;
260+
}
261+
} else if (bDepth > aDepth) {
262+
let diff = bDepth - aDepth;
263+
while (diff > 0 && bNode) {
264+
bNode = bNode.parentElement;
265+
diff--;
266+
}
267+
}
268+
250269
while (aNode && bNode && aNode.parentElement !== bNode.parentElement) {
251270
aNode = aNode.parentElement;
252271
bNode = bNode.parentElement;

src/helper/env.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ export function getIncludePath(nameArray, extension) {
9191
}
9292
}
9393

94+
if (!path) {
95+
throw '[SUNEDITOR.helper.env.getIncludePath.fail] The SUNEDITOR installation path could not be automatically detected. (path: +' + path + ', extension: ' + extension + ')';
96+
}
97+
9498
if (path === '') path = pathList.length > 0 ? pathList[0][src] : '';
9599

96100
if (!path.includes(':/') && '//' !== path.slice(0, 2)) {
97101
path = false === path.includes('/') ? location.href.match(/^.*?:\/\/[^/]*/)[0] + path : location.href.match(/^[^?]*\/(?:)/)[0] + path;
98102
}
99103

100-
if (!path) {
101-
throw '[SUNEDITOR.helper.env.getIncludePath.fail] The SUNEDITOR installation path could not be automatically detected. (path: +' + path + ', extension: ' + extension + ')';
102-
}
103-
104104
return path;
105105
}
106106

test/unit/core/base/actives.simple.spec.js

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)