2018-07-25 14:58:18 +00:00
|
|
|
import { expect, tap } from '@pushrocks/tapbundle';
|
2016-11-20 00:11:22 +00:00
|
|
|
|
2018-07-25 14:58:18 +00:00
|
|
|
import * as smartinteract from '../ts/index';
|
2016-11-20 00:11:22 +00:00
|
|
|
|
2018-07-25 14:58:18 +00:00
|
|
|
let testInteract: smartinteract.SmartInteract;
|
2017-07-28 12:27:09 +00:00
|
|
|
|
|
|
|
tap.test('should create a valid new instance', async () => {
|
2018-07-25 14:58:18 +00:00
|
|
|
testInteract = new smartinteract.SmartInteract();
|
|
|
|
expect(testInteract).to.be.instanceOf(smartinteract.SmartInteract);
|
|
|
|
});
|
2017-07-28 12:27:09 +00:00
|
|
|
|
2020-08-31 19:23:51 +00:00
|
|
|
tap.test('should get a simple confirmation', async () => {
|
2020-08-31 19:25:25 +00:00
|
|
|
const response = await smartinteract.SmartInteract.getCliConfirmation(
|
|
|
|
'You feel awesome, right?',
|
|
|
|
true
|
|
|
|
);
|
2020-08-31 19:23:51 +00:00
|
|
|
expect(response).to.be.true;
|
|
|
|
});
|
|
|
|
|
2017-07-28 12:27:09 +00:00
|
|
|
tap.test('should add question to SmartInteract instance', async () => {
|
2018-07-25 14:58:18 +00:00
|
|
|
testInteract.addQuestions([
|
|
|
|
{
|
|
|
|
name: 'testQuestion1',
|
|
|
|
type: 'input',
|
|
|
|
message: 'what is your favourite color? Answer is blue',
|
2020-08-31 19:23:51 +00:00
|
|
|
default: 'blue',
|
|
|
|
},
|
2018-07-25 14:58:18 +00:00
|
|
|
]);
|
|
|
|
testInteract.addQuestions([
|
|
|
|
{
|
|
|
|
name: 'testQuestion2',
|
|
|
|
type: 'input',
|
|
|
|
message: 'what is your second favourite color? Answer is red',
|
2020-08-31 19:23:51 +00:00
|
|
|
default: 'red',
|
|
|
|
},
|
2018-07-25 14:58:18 +00:00
|
|
|
]);
|
|
|
|
testInteract.addQuestions([
|
|
|
|
{
|
|
|
|
name: 'some.dotted.name',
|
|
|
|
type: 'input',
|
2020-02-02 13:45:59 +00:00
|
|
|
message: 'what is your second favourite color? Answer is aValidAnswer',
|
2020-08-31 19:23:51 +00:00
|
|
|
default: 'aValidAnswer',
|
|
|
|
},
|
2018-07-25 14:58:18 +00:00
|
|
|
]);
|
|
|
|
});
|
2017-07-28 12:27:09 +00:00
|
|
|
|
|
|
|
tap.test('should use default value when not in CI', async () => {
|
2020-02-02 13:45:59 +00:00
|
|
|
const answerBucket = await testInteract.runQueue();
|
2018-07-25 14:58:18 +00:00
|
|
|
expect(answerBucket.getAnswerFor('testQuestion1')).to.equal('blue');
|
|
|
|
expect(answerBucket.getAnswerFor('testQuestion2')).to.equal('red');
|
|
|
|
expect(answerBucket.getAnswerFor('some.dotted.name')).to.equal('aValidAnswer');
|
|
|
|
});
|
2017-07-28 12:27:09 +00:00
|
|
|
|
2018-07-25 14:58:18 +00:00
|
|
|
tap.start();
|