@shko.online/componentframework-mock
Version:
Mocking library to help with testing PowerApps Component Framework Components
87 lines (85 loc) • 3.38 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ContextMock = void 0;
var _sinon = require("sinon");
var _ComponentFrameworkMockGenerator = require("../ComponentFramework-Mock-Generator");
var _Client = require("./Client.mock");
var _Copilot = require("./Copilot.mock");
var _Device = require("./Device.mock");
var _Factory = require("./Factory.mocks");
var _FluentDesignState = require("./FluentDesignState.mock");
var _Formatting = require("./Formatting.mock");
var _Mode = require("./Mode.mock");
var _Navigation = require("./Navigation.mock");
var _Resources = require("./Resources.mock");
var _UserSettings = require("./UserSettings.mock");
var _Utility = require("./Utility.mock");
var _WebApi = require("./WebApi.mock");
var _EventsBag = require("./EventsBag.mock");
/*
Copyright (c) 2022 Betim Beja and Shko Online LLC
Licensed under the MIT license.
*/
class ContextMock {
constructor(inputs, db) {
this.client = void 0;
this.copilot = void 0;
this.device = void 0;
this.factory = void 0;
this.formatting = void 0;
this.mode = void 0;
this.navigation = void 0;
this.parameters = void 0;
this._parameters = void 0;
this._SetCanvasItems = void 0;
this.resources = void 0;
this.userSettings = void 0;
this.utils = void 0;
this.webAPI = void 0;
this.updatedProperties = void 0;
this.fluentDesignLanguage = void 0;
this.events = void 0;
this.updatedProperties = [];
this.events = new _EventsBag.EventsBagMock();
this.client = new _Client.ClientMock();
this.copilot = new _Copilot.CopilotMock();
this.device = new _Device.DeviceMock();
this.factory = new _Factory.FactoryMock();
this.formatting = new _Formatting.FormattingMock();
this.fluentDesignLanguage = new _FluentDesignState.FluentDesignStateMock();
this.mode = new _Mode.ModeMock();
this.navigation = new _Navigation.NavigationMock();
this.parameters = {};
this._parameters = {};
this._SetCanvasItems = (0, _sinon.stub)();
this._SetCanvasItems.callsFake(parameters => {
const mappedParameters = {};
Object.getOwnPropertyNames(this._parameters).forEach(propertyName => {
const parameter = this._parameters[propertyName];
if (propertyName in parameters) {
mappedParameters[parameter._boundColumn] = parameters[propertyName];
}
});
db.initCanvasItems([mappedParameters]);
});
const CanvasEntity = db.getTableMetadata(_ComponentFrameworkMockGenerator.MetadataDB.CanvasLogicalName) ?? {
LogicalName: _ComponentFrameworkMockGenerator.MetadataDB.CanvasLogicalName,
EntitySetName: _ComponentFrameworkMockGenerator.MetadataDB.CanvasLogicalName,
Attributes: []
};
Object.getOwnPropertyNames(inputs).forEach(propertyName => {
const parameterClass = inputs[propertyName];
const parameter = new parameterClass(propertyName, db, CanvasEntity);
this._parameters[propertyName] = parameter;
this.parameters[propertyName] = parameter;
});
db.initMetadata([CanvasEntity]);
this.resources = new _Resources.ResourcesMock();
this.userSettings = new _UserSettings.UserSettingsMock();
this.utils = new _Utility.UtilityMock();
this.webAPI = new _WebApi.WebApiMock(db, this.formatting);
}
}
exports.ContextMock = ContextMock;