Fix JS unit tests

This commit is contained in:
Sebastiaan Janssen
2019-04-22 12:10:53 +02:00
parent 687cc4630f
commit 344b7731ce
2 changed files with 13 additions and 5 deletions

View File

@@ -29,6 +29,15 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
return cacheKey;
}
// Adapted from: https://stackoverflow.com/a/2140723
// Please note, we can NOT test this functionality correctly in Phantom because it implements
// the localeCompare method incorrectly: https://github.com/ariya/phantomjs/issues/11063
function invariantEquals(a, b) {
return typeof a === "string" && typeof b === "string"
? a.localeCompare(b, undefined, { sensitivity: "base" }) === 0
: a === b;
}
return {
/** Internal method to return the tree cache */
@@ -166,8 +175,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
angular.isArray(Umbraco.Sys.ServerVariables.umbracoPlugins.trees)) {
var found = _.find(Umbraco.Sys.ServerVariables.umbracoPlugins.trees, function (item) {
// localeCompare returns 0 when strings are equal, so return false if there's no match
return item.alias.localeCompare(treeAlias, undefined, { ignorePunctuation: true }) !== 0;
return invariantEquals(item.alias, treeAlias);
});
return found ? found.packageFolder : undefined;

View File

@@ -303,7 +303,7 @@ describe('tree service tests', function () {
});
it('returns undefined for a not found tree', function () {
//we know this exists in the mock umbraco server vars
//we know this does not exist in the mock umbraco server vars
var found = treeService.getTreePackageFolder("asdfasdf");
expect(found).not.toBeDefined();
});
@@ -315,8 +315,8 @@ describe('tree service tests', function () {
it('hasChildren has to be updated on parent', function () {
var tree = getContentTree();
while (tree.children.length > 0){
treeService.removeNode(tree.children[0])
while (tree.children.length > 0) {
treeService.removeNode(tree.children[0]);
}
expect(tree.hasChildren).toBe(false);