2018-10-12 18:49:06 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { Machine } from 'xstate';
|
|
|
|
import AuthMachineConfig from 'vault/machines/auth-machine';
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Unit | Machine | auth-machine', function () {
|
2018-10-12 18:49:06 +00:00
|
|
|
const authMachine = Machine(AuthMachineConfig);
|
|
|
|
|
|
|
|
const testCases = [
|
|
|
|
{
|
|
|
|
currentState: authMachine.initialState,
|
|
|
|
event: 'CONTINUE',
|
|
|
|
params: null,
|
|
|
|
expectedResults: {
|
|
|
|
value: 'enable',
|
|
|
|
actions: [
|
|
|
|
{ component: 'wizard/mounts-wizard', level: 'feature', type: 'render' },
|
|
|
|
{ component: 'wizard/auth-enable', level: 'step', type: 'render' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
currentState: 'enable',
|
|
|
|
event: 'CONTINUE',
|
|
|
|
params: null,
|
|
|
|
expectedResults: {
|
2019-02-14 18:52:34 +00:00
|
|
|
value: 'config',
|
2018-10-12 18:49:06 +00:00
|
|
|
actions: [
|
2019-02-14 18:52:34 +00:00
|
|
|
{ type: 'render', level: 'feature', component: 'wizard/mounts-wizard' },
|
|
|
|
{ type: 'render', level: 'step', component: 'wizard/auth-config' },
|
2018-10-12 18:49:06 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-02-14 18:52:34 +00:00
|
|
|
currentState: 'config',
|
|
|
|
event: 'CONTINUE',
|
2018-10-12 18:49:06 +00:00
|
|
|
expectedResults: {
|
|
|
|
value: 'details',
|
|
|
|
actions: [
|
|
|
|
{ component: 'wizard/auth-details', level: 'step', type: 'render' },
|
|
|
|
{ component: 'wizard/mounts-wizard', level: 'feature', type: 'render' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
currentState: 'details',
|
|
|
|
event: 'CONTINUE',
|
|
|
|
expectedResults: {
|
|
|
|
value: 'complete',
|
|
|
|
actions: ['completeFeature'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
currentState: 'details',
|
|
|
|
event: 'RESET',
|
|
|
|
params: null,
|
|
|
|
expectedResults: {
|
|
|
|
value: 'idle',
|
|
|
|
actions: [
|
|
|
|
{
|
|
|
|
params: ['vault.cluster.settings.auth.enable'],
|
|
|
|
type: 'routeTransition',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: 'wizard/mounts-wizard',
|
|
|
|
level: 'feature',
|
|
|
|
type: 'render',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: 'wizard/auth-idle',
|
|
|
|
level: 'step',
|
|
|
|
type: 'render',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
testCases.forEach((testCase) => {
|
|
|
|
test(`transition: ${testCase.event} for currentState ${testCase.currentState} and componentState ${testCase.params}`, function (assert) {
|
2018-10-12 18:49:06 +00:00
|
|
|
let result = authMachine.transition(testCase.currentState, testCase.event, testCase.params);
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(result.value, testCase.expectedResults.value);
|
2018-10-12 18:49:06 +00:00
|
|
|
assert.deepEqual(result.actions, testCase.expectedResults.actions);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|