botbuilder-dialogs-adaptive
Version:
Rule system for the Microsoft BotBuilder dialog system.
127 lines • 5.61 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
require("mocha");
const adaptive_expressions_1 = require("adaptive-expressions");
const assert = __importStar(require("assert"));
const __1 = require("../");
function assertValues(value) {
assert.equal('test1', value[0].value);
assert.equal('test2', value[1].value);
assert.equal('test3', value[2].value);
}
describe('ChoiceSetTests', function () {
this.timeout(10000);
it('TestExpression', function () {
return __awaiter(this, void 0, void 0, function* () {
const state = {
choices: [{ value: 'test1' }, { value: 'test2' }, { value: 'test3' }],
};
const ep = new adaptive_expressions_1.ObjectExpression('choices');
const { value } = ep.tryGetValue(state);
assertValues(value);
});
});
it('TestValue', function () {
return __awaiter(this, void 0, void 0, function* () {
const state = {};
const ep = new adaptive_expressions_1.ObjectExpression(new __1.ChoiceSet([{ value: 'test1' }, { value: 'test2' }, { value: 'test3' }]));
const { value } = ep.tryGetValue(state);
assertValues(value);
});
});
it('TestStringArrayAccess', function () {
return __awaiter(this, void 0, void 0, function* () {
const state = {};
const stringArr = ['test1', 'test2', 'test3'];
const ep = new adaptive_expressions_1.ObjectExpression(new __1.ChoiceSet(stringArr));
const { value } = ep.tryGetValue(state);
assertValues(value);
});
});
it('TestConverterExpressionAccess', function () {
return __awaiter(this, void 0, void 0, function* () {
const state = {
test: [{ value: 'test1' }, { value: 'test2' }, { value: 'test3' }],
};
const sample = {
choices: 'test',
};
const ep = new adaptive_expressions_1.ObjectExpression(sample.choices);
const { value } = ep.tryGetValue(state);
assertValues(value);
});
});
it('TestConvertObjectAccess', function () {
return __awaiter(this, void 0, void 0, function* () {
const state = {};
const sample = {
choices: [{ value: 'test1' }, { value: 'test2' }, { value: 'test3' }],
};
const json = JSON.stringify(sample);
const bar = JSON.parse(json);
// TS doesn't run 'new' automatically unlike C#
const choicesBar = new adaptive_expressions_1.ObjectExpression(bar.choices);
const { value } = choicesBar.tryGetValue(state);
assertValues(value);
});
});
it('TestConvertStringAccess', function () {
return __awaiter(this, void 0, void 0, function* () {
const state = {};
const sample = {
choices: ['test1', 'test2', 'test3'],
};
const json = JSON.stringify(sample);
const bar = JSON.parse(json);
bar.choices = new __1.ChoiceSet(bar.choices);
// TS doesn't run 'new' automatically unlike C#
const choicesBar = new adaptive_expressions_1.ObjectExpression(bar.choices);
const { value } = choicesBar.tryGetValue(state);
assertValues(value);
});
});
it('TestConvertStringArray', function () {
return __awaiter(this, void 0, void 0, function* () {
const sample = [];
sample.push('test1');
sample.push('test2');
sample.push('test3');
const json = JSON.stringify(sample);
const value = new __1.ChoiceSet(JSON.parse(json));
assertValues(value);
});
});
});
//# sourceMappingURL=choiceSet.test.js.map