smartinteract/test/test.ts

55 lines
1.5 KiB
TypeScript
Raw Normal View History

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
let testInteract: smartinteract.SmartInteract;
tap.test('should create a valid new instance', async () => {
testInteract = new smartinteract.SmartInteract();
2023-07-13 12:07:12 +00:00
expect(testInteract).toBeInstanceOf(smartinteract.SmartInteract);
});
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
});
tap.test('should add question to SmartInteract instance', async () => {
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',
},
]);
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',
},
]);
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',
},
]);
});
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');
});
tap.start();