2023-07-13 12:07:12 +00:00
|
|
|
import { expect, tap } from '@push.rocks/tapbundle';
|
2016-11-20 00:11:22 +00:00
|
|
|
|
2023-07-13 12:07:12 +00:00
|
|
|
import * as smartinteract from '../ts/index.js';
|
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();
|
2023-07-13 12:07:12 +00:00
|
|
|
expect(testInteract).toBeInstanceOf(smartinteract.SmartInteract);
|
2018-07-25 14:58:18 +00:00
|
|
|
});
|
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
|
|
|
|
);
|
2023-07-13 12:07:12 +00:00
|
|
|
expect(response).toBeTrue();
|
2020-08-31 19:23:51 +00:00
|
|
|
});
|
|
|
|
|
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();
|
2023-07-13 12:07:12 +00:00
|
|
|
expect(answerBucket.getAnswerFor('testQuestion1')).toEqual('blue');
|
|
|
|
expect(answerBucket.getAnswerFor('testQuestion2')).toEqual('red');
|
|
|
|
expect(answerBucket.getAnswerFor('some.dotted.name')).toEqual('aValidAnswer');
|
2018-07-25 14:58:18 +00:00
|
|
|
});
|
2017-07-28 12:27:09 +00:00
|
|
|
|
2018-07-25 14:58:18 +00:00
|
|
|
tap.start();
|