Fixes tests and issues causing test failures.

This commit is contained in:
Shannon
2020-07-29 18:46:01 +10:00
parent 8b19e11b58
commit 58331bbdef
7 changed files with 434 additions and 393 deletions
File diff suppressed because it is too large Load Diff
+3 -4
View File
@@ -27,7 +27,7 @@
"angular-ui-sortable": "0.19.0",
"animejs": "2.2.0",
"bootstrap-social": "5.1.1",
"chart.js": "^2.8.0",
"chart.js": "^2.9.3",
"clipboard": "2.0.4",
"diff": "3.5.0",
"flatpickr": "4.5.2",
@@ -39,7 +39,7 @@
"moment": "2.22.2",
"ng-file-upload": "12.2.13",
"nouislider": "14.4.0",
"npm": "^6.14.0",
"npm": "^6.14.7",
"signalr": "2.4.0",
"spectrum-colorpicker": "1.8.0",
"tinymce": "4.9.10",
@@ -57,7 +57,7 @@
"gulp-angular-embed-templates": "^2.3.0",
"gulp-babel": "8.0.0",
"gulp-clean-css": "4.2.0",
"gulp-cli": "^2.2.0",
"gulp-cli": "^2.3.0",
"gulp-concat": "2.6.1",
"gulp-eslint": "6.0.0",
"gulp-imagemin": "6.1.1",
@@ -71,7 +71,6 @@
"gulp-wrap": "0.15.0",
"gulp-wrap-js": "0.4.1",
"jasmine-core": "3.5.0",
"jasmine-promise-matchers": "^2.6.0",
"karma": "4.4.1",
"karma-chrome-launcher": "^3.1.0",
"karma-jasmine": "2.0.1",
@@ -305,6 +305,7 @@ angular.module('umbraco.mocks').
allowedActions: ["U", "H", "A"],
contentTypeAlias: "testAlias",
contentTypeKey: "7C5B74D1-E2F9-45A3-AE4B-FC7A829BF8AB",
apps: [],
variants: [
{
name: "",
@@ -14,7 +14,7 @@
'use strict';
function blockEditorModelObjectFactory($interpolate, udiService, contentResource, localizationService) {
function blockEditorModelObjectFactory($interpolate, $q, udiService, contentResource, localizationService) {
/**
* Simple mapping from property model content entry to editing model,
@@ -219,7 +219,7 @@
* @param {any} contentData
* @param {any} udi
*/
function ensureUdiAndKey(contentData, udi) {
function ensureUdiAndKey(contentData, udi) {
contentData.udi = udi;
// Change the content.key to the GUID part of the udi, else it's just random which we don't want, it must be consistent
contentData.key = udiService.getKey(udi);
@@ -236,7 +236,7 @@
/**
* Formats the content apps and ensures unsupported property's have the notsupported view
* Formats the content apps and ensures unsupported property's have the notsupported view (returns a promise)
* @param {any} scaffold
*/
function formatScaffoldData(scaffold) {
@@ -252,10 +252,17 @@
});
});
// could be empty in tests
if (!scaffold.apps) {
console.warn("No content apps found in scaffold");
return $q.resolve(scaffold);
}
// replace view of content app
var contentApp = scaffold.apps.find(entry => entry.alias === "umbContent");
if (contentApp) {
contentApp.view = "views/common/infiniteeditors/blockeditor/blockeditor.content.html";
contentApp.view = "views/common/infiniteeditors/blockeditor/blockeditor.content.html";
}
// remove info app
@@ -267,6 +274,7 @@
// add the settings app
return localizationService.localize("blockEditor_tabBlockSettings").then(
function (settingsName) {
var settingsTab = {
"name": settingsName,
"alias": "settings",
@@ -379,19 +387,24 @@
// removing duplicates.
scaffoldKeys = scaffoldKeys.filter((value, index, self) => self.indexOf(value) === index);
scaffoldKeys.forEach((contentTypeKey => {
var self = this;
scaffoldKeys.forEach(contentTypeKey => {
tasks.push(contentResource.getScaffoldByKey(-20, contentTypeKey).then(scaffold => {
// this.scaffolds might not exists anymore, this happens if this instance has been destroyed before the load is complete.
if (this.scaffolds) {
return formatScaffoldData(scaffold).then(s => this.scaffolds.push(s));
// self.scaffolds might not exists anymore, this happens if this instance has been destroyed before the load is complete.
if (self.scaffolds) {
return formatScaffoldData(scaffold).then(s => {
self.scaffolds.push(s);
return s;
});
}
else {
return Promise.resolve();
return $q.resolve(scaffold);
}
}));
}));
});
return Promise.all(tasks);
return $q.all(tasks);
},
/**
@@ -67,6 +67,9 @@ angular.module('umbraco.services')
// loads the language resource file from the server
initLocalizedResources: function () {
// TODO: This promise handling is super ugly, we should just be returnning the promise from $http and returning inner values.
var deferred = $q.defer();
if (resourceFileLoadStatus === "loaded") {
@@ -179,7 +182,7 @@ angular.module('umbraco.services')
*/
localize: function (value, tokens, fallbackValue) {
return service.initLocalizedResources().then(function (dic) {
return _lookup(value, tokens, dic, fallbackValue);
return _lookup(value, tokens, dic, fallbackValue);
});
},
@@ -11,7 +11,6 @@ module.exports = function (config) {
files: [
// Jasmine plugins
'node_modules/jasmine-promise-matchers/dist/jasmine-promise-matchers.js',
//libraries
'node_modules/jquery/dist/jquery.min.js',
@@ -5,24 +5,34 @@
var settingsKey = "2AF42343-C8A2-400D-BA43-4818C2B3CDC5";
var settingsUdi = "umb://element/2AF42343C8A2400DBA434818C2B3CDC5";
var blockEditorService, contentResource, $rootScope, $scope;
var blockEditorService, contentResource, $rootScope, $scope, $q, localizationService, $timeout;
beforeEach(module('umbraco.services'));
beforeEach(module('umbraco.resources'));
beforeEach(module('umbraco.mocks'));
beforeEach(module('umbraco'));
beforeEach(inject(function ($injector, mocksUtils, _$rootScope_) {
beforeEach(inject(function ($injector, mocksUtils, _$rootScope_, _$q_, _$timeout_) {
mocksUtils.disableAuth();
$rootScope = _$rootScope_;
$scope = $rootScope.$new();
$q = _$q_;
$timeout = _$timeout_;
contentResource = $injector.get("contentResource");
spyOn(contentResource, "getScaffoldByKey").and.callFake(
function () {
return Promise.resolve(mocksUtils.getMockVariantContent(1234, contentKey, contentUdi))
var scaffold = mocksUtils.getMockVariantContent(1234, contentKey, contentUdi);
return $q.resolve(scaffold);
}
);
// this seems to be required because of the poor promise implementation in localizationService (see TODO in that service)
localizationService = $injector.get("localizationService");
spyOn(localizationService, "localize").and.callFake(
function () {
return $q.resolve("Localized test text");
}
);
@@ -101,13 +111,19 @@
it('load provides data for itemPicker', function (done) {
var modelObject = blockEditorService.createModelObject({}, "Umbraco.TestBlockEditor", [blockConfigurationMock], $scope, $scope);
modelObject.load().then(() => {
var itemPickerOptions = modelObject.getAvailableBlocksForBlockPicker();
expect(itemPickerOptions.length).toBe(1);
expect(itemPickerOptions[0].blockConfigModel.contentTypeKey).toBe(blockConfigurationMock.contentTypeKey);
done();
modelObject.load().then(() => {
try {
var itemPickerOptions = modelObject.getAvailableBlocksForBlockPicker();
expect(itemPickerOptions.length).toBe(1);
expect(itemPickerOptions[0].blockConfigModel.contentTypeKey).toBe(blockConfigurationMock.contentTypeKey);
done();
} catch (e) {
done.fail(e);
}
});
$rootScope.$digest();
$timeout.flush();
});
it('getLayoutEntry has values', function (done) {
@@ -117,16 +133,22 @@
modelObject.load().then(() => {
var layout = modelObject.getLayout();
try {
var layout = modelObject.getLayout();
expect(layout).not.toBeUndefined();
expect(layout.length).toBe(1);
expect(layout[0]).toBe(propertyModelMock.layout["Umbraco.TestBlockEditor"][0]);
expect(layout[0].udi).toBe(propertyModelMock.layout["Umbraco.TestBlockEditor"][0].udi);
expect(layout).not.toBeUndefined();
expect(layout.length).toBe(1);
expect(layout[0]).toBe(propertyModelMock.layout["Umbraco.TestBlockEditor"][0]);
expect(layout[0].udi).toBe(propertyModelMock.layout["Umbraco.TestBlockEditor"][0].udi);
done();
done();
} catch (e) {
done.fail(e);
}
});
$rootScope.$digest();
$timeout.flush();
});
it('getBlockObject has values', function (done) {
@@ -151,6 +173,8 @@
}
});
$rootScope.$digest();
$timeout.flush();
});
@@ -169,18 +193,23 @@
blockObject.content.variants[0].tabs[0].properties[0].value = "anotherTestValue";
$rootScope.$digest();// invoke angularJS Store.
// invoke angularJS Store.
$timeout(function () {
expect(blockObject.data).toEqual(propertyModel.contentData[0]);
expect(blockObject.data.testproperty).toBe("anotherTestValue");
expect(propertyModel.contentData[0].testproperty).toBe("anotherTestValue");
expect(blockObject.data).toEqual(propertyModel.contentData[0]);
expect(blockObject.data.testproperty).toBe("anotherTestValue");
expect(propertyModel.contentData[0].testproperty).toBe("anotherTestValue");
done();
});
done();
} catch (e) {
done.fail(e);
}
});
$rootScope.$digest();
$timeout.flush();
});
@@ -204,17 +233,22 @@
blockObject.content.variants[0].tabs[0].properties[0].value.list[0] = "AA";
blockObject.content.variants[0].tabs[0].properties[0].value.list.push("D");
$rootScope.$digest();// invoke angularJS Store.
// invoke angularJS Store.
$timeout(function () {
expect(propertyModel.contentData[0].testproperty.list[0]).toBe("AA");
expect(propertyModel.contentData[0].testproperty.list.length).toBe(4);
expect(propertyModel.contentData[0].testproperty.list[0]).toBe("AA");
expect(propertyModel.contentData[0].testproperty.list.length).toBe(4);
done();
});
done();
} catch (e) {
done.fail(e);
}
}
});
$rootScope.$digest();
$timeout.flush();
});
it('layout is referencing layout of propertyModel', function (done) {
@@ -236,6 +270,8 @@
done();
});
$rootScope.$digest();
$timeout.flush();
});
it('removeDataAndDestroyModel removes data', function (done) {
@@ -270,6 +306,9 @@
done.fail(e);
}
});
$rootScope.$digest();
$timeout.flush();
});
it('getBlockObject of block with settings has values', function (done) {
@@ -291,6 +330,8 @@
done();
});
$rootScope.$digest();
$timeout.flush();
});
@@ -309,21 +350,23 @@
blockObject.content.variants[0].tabs[0].properties[0].value = "anotherTestValue";
blockObject.settings.variants[0].tabs[0].properties[0].value = "anotherTestValueForSettings";
$rootScope.$digest();// invoke angularJS Store.
// invoke angularJS Store.
$timeout(function () {
expect(blockObject.data).toEqual(propertyModel.contentData[0]);
expect(blockObject.data.testproperty).toBe("anotherTestValue");
expect(propertyModel.contentData[0].testproperty).toBe("anotherTestValue");
expect(blockObject.data).toEqual(propertyModel.contentData[0]);
expect(blockObject.data.testproperty).toBe("anotherTestValue");
expect(propertyModel.contentData[0].testproperty).toBe("anotherTestValue");
expect(blockObject.settingsData).toEqual(propertyModel.settingsData[0]);
expect(blockObject.settingsData.testproperty).toBe("anotherTestValueForSettings");
expect(propertyModel.settingsData[0].testproperty).toBe("anotherTestValueForSettings");
expect(blockObject.settingsData).toEqual(propertyModel.settingsData[0]);
expect(blockObject.settingsData.testproperty).toBe("anotherTestValueForSettings");
expect(propertyModel.settingsData[0].testproperty).toBe("anotherTestValueForSettings");
//
done();
done();
});
});
$rootScope.$digest();
$timeout.flush();
});
@@ -352,20 +395,25 @@
blockObject.settings.variants[0].tabs[0].properties[0].value.list[0] = "settingsValue";
blockObject.settings.variants[0].tabs[0].properties[0].value.list.push("settingsNewValue");
$rootScope.$digest();// invoke angularJS Store.
// invoke angularJS Store.
$timeout(function () {
expect(propertyModel.contentData[0].testproperty.list[0]).toBe("AA");
expect(propertyModel.contentData[0].testproperty.list.length).toBe(4);
expect(propertyModel.contentData[0].testproperty.list[0]).toBe("AA");
expect(propertyModel.contentData[0].testproperty.list.length).toBe(4);
expect(propertyModel.settingsData[0].testproperty.list[0]).toBe("settingsValue");
expect(propertyModel.settingsData[0].testproperty.list.length).toBe(4);
expect(propertyModel.settingsData[0].testproperty.list[0]).toBe("settingsValue");
expect(propertyModel.settingsData[0].testproperty.list.length).toBe(4);
done();
});
done();
} catch (e) {
done.fail(e);
}
});
$rootScope.$digest();
$timeout.flush();
});