|
| 1 | +import { log, state, SYMBOL_LOG, SYMBOL_STATE } from '@escapace/fluent' |
| 2 | +import { assert, describe, it } from 'vitest' |
| 3 | +import { SYMBOL_INPUT_NUMBER } from '../../types' |
| 4 | +import { number } from './domain-language' |
| 5 | +import { reducer } from './reducer' |
| 6 | +import { InputNumberTypeAction } from './types' |
| 7 | + |
| 8 | +describe('input/number', () => { |
| 9 | + it('domain-language', () => { |
| 10 | + const reference = 'test' |
| 11 | + |
| 12 | + assert.isFunction(number) |
| 13 | + |
| 14 | + const test0 = number() |
| 15 | + |
| 16 | + assert.hasAllKeys(test0, [SYMBOL_LOG, SYMBOL_STATE, 'reference']) |
| 17 | + |
| 18 | + assert.deepEqual(log(test0), []) |
| 19 | + |
| 20 | + assert.deepEqual(state(test0), { |
| 21 | + default: undefined, |
| 22 | + description: undefined, |
| 23 | + isEmpty: true, |
| 24 | + options: [], |
| 25 | + reducer, |
| 26 | + reference: undefined, |
| 27 | + repeat: false, |
| 28 | + type: SYMBOL_INPUT_NUMBER, |
| 29 | + variables: [], |
| 30 | + }) |
| 31 | + |
| 32 | + const test1 = test0.reference(reference) |
| 33 | + |
| 34 | + assert.hasAllKeys(test1, [SYMBOL_LOG, SYMBOL_STATE, 'description']) |
| 35 | + |
| 36 | + assert.deepEqual(log(test1), [{ payload: reference, type: InputNumberTypeAction.Reference }]) |
| 37 | + |
| 38 | + assert.deepEqual(state(test1), { |
| 39 | + default: undefined, |
| 40 | + description: undefined, |
| 41 | + isEmpty: true, |
| 42 | + options: [], |
| 43 | + reducer, |
| 44 | + reference, |
| 45 | + repeat: false, |
| 46 | + type: SYMBOL_INPUT_NUMBER, |
| 47 | + variables: [], |
| 48 | + }) |
| 49 | + |
| 50 | + const test2 = test1.description('ABC') |
| 51 | + |
| 52 | + assert.hasAllKeys(test2, [SYMBOL_LOG, SYMBOL_STATE, 'repeat', 'option', 'variable']) |
| 53 | + |
| 54 | + assert.deepEqual(log(test2), [ |
| 55 | + { payload: 'ABC', type: InputNumberTypeAction.Description }, |
| 56 | + { payload: reference, type: InputNumberTypeAction.Reference }, |
| 57 | + ]) |
| 58 | + |
| 59 | + assert.deepEqual(state(test2), { |
| 60 | + default: undefined, |
| 61 | + description: 'ABC', |
| 62 | + isEmpty: true, |
| 63 | + options: [], |
| 64 | + reducer, |
| 65 | + reference, |
| 66 | + repeat: false, |
| 67 | + type: SYMBOL_INPUT_NUMBER, |
| 68 | + variables: [], |
| 69 | + }) |
| 70 | + |
| 71 | + const test3 = test2.repeat() |
| 72 | + |
| 73 | + assert.hasAllKeys(test3, [SYMBOL_LOG, SYMBOL_STATE, 'option', 'variable']) |
| 74 | + |
| 75 | + assert.deepEqual(log(test3), [ |
| 76 | + { payload: undefined, type: InputNumberTypeAction.Repeat }, |
| 77 | + { payload: 'ABC', type: InputNumberTypeAction.Description }, |
| 78 | + { payload: reference, type: InputNumberTypeAction.Reference }, |
| 79 | + ]) |
| 80 | + |
| 81 | + assert.deepEqual(state(test3), { |
| 82 | + default: undefined, |
| 83 | + description: 'ABC', |
| 84 | + isEmpty: true, |
| 85 | + options: [], |
| 86 | + reducer, |
| 87 | + reference, |
| 88 | + repeat: true, |
| 89 | + type: SYMBOL_INPUT_NUMBER, |
| 90 | + variables: [], |
| 91 | + }) |
| 92 | + |
| 93 | + const test4 = test3.option('--option') |
| 94 | + |
| 95 | + assert.hasAllKeys(test4, [SYMBOL_LOG, SYMBOL_STATE, 'default', 'option', 'variable']) |
| 96 | + |
| 97 | + assert.deepEqual(log(test4), [ |
| 98 | + { |
| 99 | + payload: { |
| 100 | + name: '--option', |
| 101 | + }, |
| 102 | + type: InputNumberTypeAction.Option, |
| 103 | + }, |
| 104 | + { payload: undefined, type: InputNumberTypeAction.Repeat }, |
| 105 | + { payload: 'ABC', type: InputNumberTypeAction.Description }, |
| 106 | + { payload: reference, type: InputNumberTypeAction.Reference }, |
| 107 | + ]) |
| 108 | + |
| 109 | + assert.deepEqual(state(test4), { |
| 110 | + default: undefined, |
| 111 | + description: 'ABC', |
| 112 | + isEmpty: false, |
| 113 | + options: ['--option'], |
| 114 | + reducer, |
| 115 | + reference, |
| 116 | + repeat: true, |
| 117 | + type: SYMBOL_INPUT_NUMBER, |
| 118 | + variables: [], |
| 119 | + }) |
| 120 | + |
| 121 | + const test5 = test4.variable('VARIABLE') |
| 122 | + |
| 123 | + assert.hasAllKeys(test5, [SYMBOL_LOG, SYMBOL_STATE, 'default', 'option', 'variable']) |
| 124 | + |
| 125 | + assert.deepEqual(log(test5), [ |
| 126 | + { |
| 127 | + payload: 'VARIABLE', |
| 128 | + type: InputNumberTypeAction.Variable, |
| 129 | + }, |
| 130 | + { |
| 131 | + payload: { |
| 132 | + name: '--option', |
| 133 | + }, |
| 134 | + type: InputNumberTypeAction.Option, |
| 135 | + }, |
| 136 | + { payload: undefined, type: InputNumberTypeAction.Repeat }, |
| 137 | + { payload: 'ABC', type: InputNumberTypeAction.Description }, |
| 138 | + { payload: reference, type: InputNumberTypeAction.Reference }, |
| 139 | + ]) |
| 140 | + |
| 141 | + assert.deepEqual(state(test5), { |
| 142 | + default: undefined, |
| 143 | + description: 'ABC', |
| 144 | + isEmpty: false, |
| 145 | + options: ['--option'], |
| 146 | + reducer, |
| 147 | + reference, |
| 148 | + repeat: true, |
| 149 | + type: SYMBOL_INPUT_NUMBER, |
| 150 | + variables: ['VARIABLE'], |
| 151 | + }) |
| 152 | + |
| 153 | + const test6 = test5.default([1, 2, 3]) |
| 154 | + |
| 155 | + assert.hasAllKeys(test6, [SYMBOL_LOG, SYMBOL_STATE]) |
| 156 | + |
| 157 | + assert.deepEqual(log(test6), [ |
| 158 | + { payload: [1, 2, 3], type: InputNumberTypeAction.Default }, |
| 159 | + { |
| 160 | + payload: 'VARIABLE', |
| 161 | + type: InputNumberTypeAction.Variable, |
| 162 | + }, |
| 163 | + { |
| 164 | + payload: { |
| 165 | + name: '--option', |
| 166 | + }, |
| 167 | + type: InputNumberTypeAction.Option, |
| 168 | + }, |
| 169 | + { payload: undefined, type: InputNumberTypeAction.Repeat }, |
| 170 | + { payload: 'ABC', type: InputNumberTypeAction.Description }, |
| 171 | + { payload: reference, type: InputNumberTypeAction.Reference }, |
| 172 | + ]) |
| 173 | + |
| 174 | + assert.deepEqual(state(test6), { |
| 175 | + default: [1, 2, 3], |
| 176 | + description: 'ABC', |
| 177 | + isEmpty: false, |
| 178 | + options: ['--option'], |
| 179 | + reducer, |
| 180 | + reference, |
| 181 | + repeat: true, |
| 182 | + type: SYMBOL_INPUT_NUMBER, |
| 183 | + variables: ['VARIABLE'], |
| 184 | + }) |
| 185 | + }) |
| 186 | +}) |
0 commit comments