UNPKG

maestro-cli-roku

Version:

command line tools for maestro-roku projects

408 lines (407 loc) 21.4 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); var chai_1 = require("chai"); var chai = require("chai"); var path = require("path"); var BindingType_1 = require("../bindingSupport/BindingType"); var Feedback_1 = require("../utils/Feedback"); var File_1 = require("./File"); var XMLTag_1 = require("./XMLTag"); var chaiSubset = require('chai-subset'); chai.use(chaiSubset); var config = require('../../test/testProcessorConfig.json'); var processor; var fileMap; var importFilesPath = path.join('components', 'screens', 'imports'); var projectPath = path.join(path.resolve(config.outputPath), importFilesPath); var bindingProcessor; var file = createFile('file.brs', '.brs'); describe('XMLElement', function () { var _this = this; beforeEach(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { Feedback_1.resetFeedback(); return [2 /*return*/]; }); }); }); describe('constructor', function () { it('throws error for null element', function () { chai_1.expect(function () { return new XMLTag_1.XMLTag(null, null, file); }).to.throw(Error); chai_1.expect(Feedback_1.getFeedbackErrors()).to.not.be.empty; }); it('throws error for empty text', function () { chai_1.expect(function () { return new XMLTag_1.XMLTag(null, null, file); }).to.throw(Error); chai_1.expect(Feedback_1.getFeedbackErrors()).to.not.be.empty; }); }); describe('Valid bindings', function () { it('identifies simple one way binding', function () { var element = { name: 'Label', attr: { id: 'titleLabel', text: '{{vm.titleText}}' }, val: '', children: [], firstChild: null, lastChild: null, line: 24, column: 37, position: 697, startTagPosition: 626, endTagPosition: 697 }; var tagText = "Label\n id=\"titleLabel\"\n text=\"{{vm.titleText}}\" />"; var tag = new XMLTag_1.XMLTag(element, tagText, file); chai_1.expect(tag.bindings).to.have.lengthOf(1); var binding = tag.bindings[0]; chai_1.expect(binding.nodeField).to.equal('text'); chai_1.expect(binding.nodeId).to.equal('titleLabel'); chai_1.expect(binding.observerField).to.equal('titleText'); chai_1.expect(binding.observerId).to.equal('vm'); chai_1.expect(binding.isFunctionBinding).to.be.false; chai_1.expect(binding.properties.type).to.equal(BindingType_1.BindingType.oneWaySource); chai_1.expect(binding.properties.transformFunction).to.be.null; chai_1.expect(binding.properties.isSettingInitialValue).to.be.true; chai_1.expect(Feedback_1.getAllFeedback()).to.be.empty; binding.validate(); chai_1.expect(binding.isValid).to.be.true; }); it('identifies simple one way binding on top field', function () { var element = { name: 'Field', attr: { id: 'titleLabel', type: 'string', value: '{{vm.titleText}}' }, val: '', children: [], firstChild: null, lastChild: null, line: 24, column: 37, position: 697, startTagPosition: 626, endTagPosition: 697 }; var tagText = "Field\n id=\"titleLabel\"\n type=\"string\"\n value=\"{{vm.titleText}}\" />"; var tag = new XMLTag_1.XMLTag(element, tagText, file); chai_1.expect(tag.bindings).to.have.lengthOf(1); var binding = tag.bindings[0]; chai_1.expect(binding.nodeField).to.equal('titleLabel'); chai_1.expect(binding.nodeId).to.equal('top'); chai_1.expect(binding.observerField).to.equal('titleText'); chai_1.expect(binding.observerId).to.equal('vm'); chai_1.expect(binding.isFunctionBinding).to.be.false; chai_1.expect(binding.isTopBinding).to.be.true; chai_1.expect(binding.properties.type).to.equal(BindingType_1.BindingType.oneWaySource); chai_1.expect(binding.properties.transformFunction).to.be.null; chai_1.expect(binding.properties.isSettingInitialValue).to.be.true; chai_1.expect(Feedback_1.getAllFeedback()).to.be.empty; binding.validate(); chai_1.expect(binding.isValid).to.be.true; }); it('identifies one way target binding - alternate syntax', function () { var element = { name: 'Label', attr: { id: 'titleLabel', text: '{(vm.titleText)}' }, val: '', children: [], firstChild: null, lastChild: null, line: 24, column: 37, position: 697, startTagPosition: 626, endTagPosition: 697 }; var tagText = "Label\n id=\"titleLabel\"\n text=\"{(vm.titleText)}\" />"; var tag = new XMLTag_1.XMLTag(element, tagText, file); var a = Feedback_1.getAllFeedback(); chai_1.expect(tag.bindings).to.have.lengthOf(1); var binding = tag.bindings[0]; chai_1.expect(binding.nodeField).to.equal('text'); chai_1.expect(binding.nodeId).to.equal('titleLabel'); chai_1.expect(binding.observerField).to.equal('titleText'); chai_1.expect(binding.observerId).to.equal('vm'); chai_1.expect(binding.isFunctionBinding).to.be.false; chai_1.expect(binding.properties.type).to.equal(BindingType_1.BindingType.oneWayTarget); chai_1.expect(binding.properties.transformFunction).to.be.null; chai_1.expect(binding.properties.isSettingInitialValue).to.be.true; chai_1.expect(Feedback_1.getAllFeedback()).to.be.empty; binding.validate(); chai_1.expect(binding.isValid).to.be.true; }); it('identifies two way binding - alternate syntax', function () { var element = { name: 'Label', attr: { id: 'titleLabel', text: '{[vm.titleText]}' }, val: '', children: [], firstChild: null, lastChild: null, line: 24, column: 37, position: 697, startTagPosition: 626, endTagPosition: 697 }; var tagText = "Label\n id=\"titleLabel\"\n text=\"{[vm.titleText]}}\" />"; var tag = new XMLTag_1.XMLTag(element, tagText, file); var a = Feedback_1.getAllFeedback(); chai_1.expect(tag.bindings).to.have.lengthOf(1); var binding = tag.bindings[0]; chai_1.expect(binding.nodeField).to.equal('text'); chai_1.expect(binding.nodeId).to.equal('titleLabel'); chai_1.expect(binding.observerField).to.equal('titleText'); chai_1.expect(binding.observerId).to.equal('vm'); chai_1.expect(binding.isFunctionBinding).to.be.false; chai_1.expect(binding.properties.type).to.equal(BindingType_1.BindingType.twoWay); chai_1.expect(binding.properties.transformFunction).to.be.null; chai_1.expect(binding.properties.isSettingInitialValue).to.be.true; chai_1.expect(Feedback_1.getAllFeedback()).to.be.empty; binding.validate(); chai_1.expect(binding.isValid).to.be.true; }); it('identifies simple one way binding to function', function () { var element = { name: 'Label', attr: { id: 'titleLabel', text: '{(vm.titleText())}' }, val: '', children: [], firstChild: null, lastChild: null, line: 24, column: 37, position: 697, startTagPosition: 626, endTagPosition: 697 }; var tagText = "Label\n id=\"titleLabel\"\n text=\"{(vm.titleText())}\" />"; var tag = new XMLTag_1.XMLTag(element, tagText, file); chai_1.expect(tag.bindings).to.have.lengthOf(1); var binding = tag.bindings[0]; chai_1.expect(binding.nodeField).to.equal('text'); chai_1.expect(binding.nodeId).to.equal('titleLabel'); chai_1.expect(binding.isFunctionBinding).to.be.true; chai_1.expect(binding.observerField).to.equal('titleText'); chai_1.expect(binding.observerId).to.equal('vm'); chai_1.expect(binding.properties.type).to.equal(BindingType_1.BindingType.oneWayTarget); chai_1.expect(binding.properties.transformFunction).to.be.null; chai_1.expect(binding.properties.isSettingInitialValue).to.be.true; chai_1.expect(Feedback_1.getAllFeedback()).to.be.empty; binding.validate(); chai_1.expect(binding.isValid).to.be.true; }); it('identifies two way binding', function () { var element = { name: 'InputBox', attr: { id: 'nameInput', text: '{{vm.name, mode=TwoWay}}' }, val: '', children: [], firstChild: null, lastChild: null, line: 35, column: 45, position: 970, startTagPosition: 889, endTagPosition: 970 }; var tagText = "InputBox\n id=\"nameInput\"\n text=\"{{vm.name, mode=TwoWay}}\" />"; var tag = new XMLTag_1.XMLTag(element, tagText, file); chai_1.expect(tag.bindings).to.have.lengthOf(1); var binding = tag.bindings[0]; chai_1.expect(binding.nodeField).to.equal('text'); chai_1.expect(binding.nodeId).to.equal('nameInput'); chai_1.expect(binding.isFunctionBinding).to.be.false; chai_1.expect(binding.observerField).to.equal('name'); chai_1.expect(binding.observerId).to.equal('vm'); chai_1.expect(binding.properties.type).to.equal(BindingType_1.BindingType.twoWay); chai_1.expect(binding.properties.transformFunction).to.be.null; chai_1.expect(binding.properties.isSettingInitialValue).to.be.true; chai_1.expect(Feedback_1.getAllFeedback()).to.be.empty; binding.validate(); chai_1.expect(binding.isValid).to.be.true; }); it('identifies multiple bindings', function () { var element = { name: 'RowList', attr: { id: 'rowList', visible: '{{vm.isGroupVisible, transform=OM_transform_invertBoolean}}', clicked: '{(vm.onItemClicked())}', jumpToIndex: '{{vm.jumpToIndex, mode=oneWayTarget}}', focusedIndex: '{{vm.focusedIndex, mode=oneWaySource}}', selectedIndex: '{{vm.selectedIndex, mode=twoWay, isSettingInitialValue=false}}' }, val: '', children: [], firstChild: null, lastChild: null, line: 57, column: 67, position: 1831, startTagPosition: 1466, endTagPosition: 1831 }; var tagText = "RowList\n id=\"rowList\"\n visible=\"{{vm.isGroupVisible, transform=OM_transform_invertBoolean}}\"\n clicked=\"{(vm.onItemClicked())}\"\n jumpToIndex=\"{{vm.jumpToIndex, mode=oneWay}}\"\n focusedIndex=\"{{vm.focusedIndex, mode=oneWaySource}}\"\n selectedIndex=\"{{vm.selectedIndex, mode=twoWay, isSettingInitialValue=false}}\" />"; var tag = new XMLTag_1.XMLTag(element, tagText, file); chai_1.expect(tag.bindings).to.have.lengthOf(5); //visible var binding = tag.bindings[0]; chai_1.expect(binding.nodeField).to.equal('visible'); chai_1.expect(binding.nodeId).to.equal('rowList'); chai_1.expect(binding.isFunctionBinding).to.be.false; chai_1.expect(binding.observerField).to.equal('isGroupVisible'); chai_1.expect(binding.observerId).to.equal('vm'); chai_1.expect(binding.properties.type).to.equal(BindingType_1.BindingType.oneWaySource); chai_1.expect(binding.properties.transformFunction).to.equal('OM_transform_invertBoolean'); chai_1.expect(binding.properties.isSettingInitialValue).to.be.true; chai_1.expect(Feedback_1.getAllFeedback()).to.be.empty; binding.validate(); chai_1.expect(binding.isValid).to.be.true; //clicked binding = tag.bindings[1]; chai_1.expect(binding.nodeField).to.equal('clicked'); chai_1.expect(binding.nodeId).to.equal('rowList'); chai_1.expect(binding.isFunctionBinding).to.be.true; chai_1.expect(binding.observerField).to.equal('onItemClicked'); chai_1.expect(binding.observerId).to.equal('vm'); chai_1.expect(binding.properties.type).to.equal(BindingType_1.BindingType.oneWayTarget); chai_1.expect(binding.properties.transformFunction).to.be.null; chai_1.expect(binding.properties.isSettingInitialValue).to.be.true; chai_1.expect(Feedback_1.getAllFeedback()).to.be.empty; binding.validate(); chai_1.expect(binding.isValid).to.be.true; //jumpToIndex binding = tag.bindings[2]; chai_1.expect(binding.nodeField).to.equal('jumpToIndex'); chai_1.expect(binding.nodeId).to.equal('rowList'); chai_1.expect(binding.isFunctionBinding).to.be.false; chai_1.expect(binding.observerField).to.equal('jumpToIndex'); chai_1.expect(binding.observerId).to.equal('vm'); chai_1.expect(binding.properties.type).to.equal(BindingType_1.BindingType.oneWayTarget); chai_1.expect(binding.properties.transformFunction).to.be.null; chai_1.expect(binding.properties.isSettingInitialValue).to.be.true; chai_1.expect(Feedback_1.getAllFeedback()).to.be.empty; binding.validate(); chai_1.expect(binding.isValid).to.be.true; //focusedIndex binding = tag.bindings[3]; chai_1.expect(binding.nodeField).to.equal('focusedIndex'); chai_1.expect(binding.nodeId).to.equal('rowList'); chai_1.expect(binding.isFunctionBinding).to.be.false; chai_1.expect(binding.observerField).to.equal('focusedIndex'); chai_1.expect(binding.observerId).to.equal('vm'); chai_1.expect(binding.properties.type).to.equal(BindingType_1.BindingType.oneWaySource); chai_1.expect(binding.properties.transformFunction).to.be.null; chai_1.expect(binding.properties.isSettingInitialValue).to.be.true; chai_1.expect(Feedback_1.getAllFeedback()).to.be.empty; binding.validate(); chai_1.expect(binding.isValid).to.be.true; //selectedIndex binding = tag.bindings[4]; chai_1.expect(binding.nodeField).to.equal('selectedIndex'); chai_1.expect(binding.nodeId).to.equal('rowList'); chai_1.expect(binding.isFunctionBinding).to.be.false; chai_1.expect(binding.observerField).to.equal('selectedIndex'); chai_1.expect(binding.observerId).to.equal('vm'); chai_1.expect(binding.properties.type).to.equal(BindingType_1.BindingType.twoWay); chai_1.expect(binding.properties.transformFunction).to.be.null; chai_1.expect(binding.properties.isSettingInitialValue).to.be.false; chai_1.expect(Feedback_1.getAllFeedback()).to.be.empty; binding.validate(); chai_1.expect(binding.isValid).to.be.true; }); it('identifies transform function', function () { var element = { name: 'Group', attr: { id: 'innerGroup', visible: '{{vm.isGroupVisible, transform=OM_transform_invertBoolean}}' }, val: '\n\n \n \n\n \n \n ', children: [], firstChild: { text: '\n\n ' }, lastChild: { text: '\n ' }, line: 43, column: 81, position: 1223, startTagPosition: 1120, endTagPosition: 1223 }; var tagText = "Group id=\"innerGroup\"\n visible=\"{{vm.isGroupVisible, transform=OM_transform_invertBoolean}}\">"; var tag = new XMLTag_1.XMLTag(element, tagText, file); chai_1.expect(tag.bindings).to.have.lengthOf(1); var binding = tag.bindings[0]; chai_1.expect(binding.nodeField).to.equal('visible'); chai_1.expect(binding.nodeId).to.equal('innerGroup'); chai_1.expect(binding.isFunctionBinding).to.be.false; chai_1.expect(binding.observerField).to.equal('isGroupVisible'); chai_1.expect(binding.observerId).to.equal('vm'); chai_1.expect(binding.properties.type).to.equal(BindingType_1.BindingType.oneWaySource); chai_1.expect(binding.properties.transformFunction).to.equal('OM_transform_invertBoolean'); chai_1.expect(binding.properties.isSettingInitialValue).to.be.true; chai_1.expect(Feedback_1.getAllFeedback()).to.be.empty; binding.validate(); chai_1.expect(binding.isValid).to.be.true; }); }); }); function createFile(path, extension) { return new File_1.File(config.outputPath, path, "test" + extension, '.extension'); }