|
1 | 1 | import {inject, TestBed} from '@angular/core/testing' |
2 | 2 | import {FormatterParser} from './formatter-parser' |
3 | 3 | import {IFormatterParserResult} from './struct/formatter-parser-result' |
4 | | -import {IConformToMaskConfig} from './struct/transform-functions/conform-to-mask-config' |
5 | 4 |
|
6 | 5 | describe('FormatterParser', () => { |
7 | 6 |
|
@@ -65,222 +64,4 @@ describe('FormatterParser', () => { |
65 | 64 | expect(conformToMask('abc')).toEqual(expectedResult); |
66 | 65 | })); |
67 | 66 |
|
68 | | - |
69 | | - describe('conformToMask', () => { |
70 | | - |
71 | | - it('Accepted character in mask', inject([], () => { |
72 | | - const mask = [/[a]/, '*', /[b]/]; |
73 | | - const config = { |
74 | | - guide: true, |
75 | | - }; |
76 | | - const rawValue = 'abc'; |
77 | | - const expectedResult: IFormatterParserResult = { |
78 | | - name: 'conformToMask', |
79 | | - previous: rawValue, |
80 | | - result: 'a*b', |
81 | | - meta: { |
82 | | - someCharsRejected: false |
83 | | - } |
84 | | - }; |
85 | | - |
86 | | - const conformToMask = FormatterParser.conformToMask(mask, config); |
87 | | - expect(conformToMask(rawValue)).toEqual(expectedResult); |
88 | | - })); |
89 | | - |
90 | | - it('Dont asccept palceholder characters that exist in mask', inject([], () => { |
91 | | - const mask = [/[a]/, '*', /[b]/]; |
92 | | - const config: IConformToMaskConfig = { |
93 | | - guide: true, |
94 | | - placeholderChar: '*' |
95 | | - }; |
96 | | - const rawValue = 'abc'; |
97 | | - const expectedResult: IFormatterParserResult = { |
98 | | - name: 'conformToMask', |
99 | | - previous: rawValue, |
100 | | - result: 'a*b', |
101 | | - meta: { |
102 | | - someCharsRejected: false |
103 | | - } |
104 | | - }; |
105 | | - |
106 | | - const conformToMask = FormatterParser.conformToMask(mask, config); |
107 | | - expect(() => {conformToMask(rawValue)}) |
108 | | - .toThrowError( |
109 | | - 'Placeholder character must not be used as part of the mask. Please specify a character ' + |
110 | | - 'that is not present in your mask as your placeholder character.\n\n' + |
111 | | - `The placeholder character that was received is: ${JSON.stringify(config.placeholderChar)}\n\n` + |
112 | | - `The mask that was received is: ${JSON.stringify(mask)}` |
113 | | - ); |
114 | | - })); |
115 | | - |
116 | | - it('Fill placeholder chars', inject([], () => { |
117 | | - const mask = [/[a]/, '*', /[b]/]; |
118 | | - const config = { |
119 | | - guide: false, |
120 | | - keepCharPositions: true |
121 | | - }; |
122 | | - const rawValue = 'ab'; |
123 | | - const newRawValue = 'a*'; |
124 | | - const expectedResult: IFormatterParserResult = { |
125 | | - name: 'conformToMask', |
126 | | - previous: newRawValue, |
127 | | - result: 'a', |
128 | | - meta: { |
129 | | - someCharsRejected: false |
130 | | - } |
131 | | - }; |
132 | | - |
133 | | - const conformToMask = FormatterParser.conformToMask(mask, config); |
134 | | - conformToMask(rawValue); |
135 | | - expect(conformToMask(newRawValue)).toEqual(expectedResult); |
136 | | - })); |
137 | | - |
138 | | - it('placeholderLoop should work', inject([], () => { |
139 | | - const mask = [/[a]/, '*', /[b]/]; |
140 | | - const config = { |
141 | | - guide: false, |
142 | | - keepCharPositions: true |
143 | | - }; |
144 | | - const rawValue = '_'; |
145 | | - const expectedResult: IFormatterParserResult = { |
146 | | - name: 'conformToMask', |
147 | | - previous: rawValue, |
148 | | - result: '', |
149 | | - meta: { |
150 | | - someCharsRejected: true |
151 | | - } |
152 | | - }; |
153 | | - |
154 | | - const conformToMask = FormatterParser.conformToMask(mask, config); |
155 | | - conformToMask('a') |
156 | | - expect(conformToMask(rawValue)).toEqual(expectedResult); |
157 | | - })); |
158 | | - |
159 | | - |
160 | | - it('Guide mode tests', inject([], () => { |
161 | | - const mask = [/[a]/, '*', /[b]/]; |
162 | | - const config = {}; |
163 | | - const rawValue = 'abc'; |
164 | | - const expectedResult: IFormatterParserResult = { |
165 | | - name: 'conformToMask', |
166 | | - previous: rawValue, |
167 | | - result: 'a*b', |
168 | | - meta: { |
169 | | - someCharsRejected: false |
170 | | - } |
171 | | - }; |
172 | | - |
173 | | - const conformToMask = FormatterParser.conformToMask(mask, config); |
174 | | - expect(conformToMask(rawValue)).toEqual(expectedResult); |
175 | | - })); |
176 | | - |
177 | | - it('No guide mode', inject([], () => { |
178 | | - const mask = [/[a]/, '*', /[b]/]; |
179 | | - const config = { |
180 | | - guide: false, |
181 | | - previousConformedValue: '', |
182 | | - currentCaretPosition: 0 |
183 | | - }; |
184 | | - const rawValue = 'abc'; |
185 | | - const expectedResult: IFormatterParserResult = { |
186 | | - name: 'conformToMask', |
187 | | - previous: rawValue, |
188 | | - result: 'a*b', |
189 | | - meta: { |
190 | | - someCharsRejected: false |
191 | | - } |
192 | | - }; |
193 | | - |
194 | | - const conformToMask = FormatterParser.conformToMask(mask, config); |
195 | | - expect(conformToMask(rawValue)).toEqual(expectedResult); |
196 | | - })); |
197 | | - |
198 | | - it('Allow escaped masking character in mask', inject([], () => { |
199 | | - const mask = [/[a]/, '*', /[b]/]; |
200 | | - const config = { |
201 | | - guide: true, |
202 | | - previousConformedValue: '' |
203 | | - }; |
204 | | - const rawValue = 'abc'; |
205 | | - const expectedResult: IFormatterParserResult = { |
206 | | - name: 'conformToMask', |
207 | | - previous: rawValue, |
208 | | - result: 'a*b', |
209 | | - meta: { |
210 | | - someCharsRejected: false |
211 | | - } |
212 | | - }; |
213 | | - |
214 | | - const conformToMask = FormatterParser.conformToMask(mask, config); |
215 | | - expect(conformToMask(rawValue)).toEqual(expectedResult); |
216 | | - })); |
217 | | - |
218 | | - it('keepCharPositionsTests', inject([], () => { |
219 | | - const mask = [/[a]/, '*', /[b]/]; |
220 | | - const config = { |
221 | | - guide: true, |
222 | | - previousConformedValue: '', |
223 | | - currentCaretPosition: 0 |
224 | | - }; |
225 | | - const rawValue = 'abc'; |
226 | | - const expectedResult: IFormatterParserResult = { |
227 | | - name: 'conformToMask', |
228 | | - previous: rawValue, |
229 | | - result: 'a*b', |
230 | | - meta: { |
231 | | - someCharsRejected: false |
232 | | - } |
233 | | - }; |
234 | | - |
235 | | - const conformToMask = FormatterParser.conformToMask(mask, config); |
236 | | - expect(conformToMask(rawValue)).toEqual(expectedResult); |
237 | | - })); |
238 | | - |
239 | | - |
240 | | - it('keepCharPositions tests', inject([], () => { |
241 | | - const mask = [/[a]/, '*', /[b]/]; |
242 | | - const config = { |
243 | | - guide: true, |
244 | | - keepCharPositions: true |
245 | | - }; |
246 | | - const rawValue = 'abc'; |
247 | | - const expectedResult: IFormatterParserResult = { |
248 | | - name: 'conformToMask', |
249 | | - previous: rawValue, |
250 | | - result: 'a*b', |
251 | | - meta: { |
252 | | - someCharsRejected: false |
253 | | - } |
254 | | - }; |
255 | | - |
256 | | - const conformToMask = FormatterParser.conformToMask(mask, config); |
257 | | - expect(conformToMask(rawValue)).toEqual(expectedResult); |
258 | | - })); |
259 | | - |
260 | | - it('Mask function', inject([], () => { |
261 | | - const maskFunc = (value) => { |
262 | | - if (value) { |
263 | | - return [/[a]/, '*', /[b]/]; |
264 | | - } |
265 | | - return [/[a]/, '#', /[b]/]; |
266 | | - }; |
267 | | - const config = { |
268 | | - guide: true |
269 | | - }; |
270 | | - const rawValue = 'abc'; |
271 | | - const expectedResult: IFormatterParserResult = { |
272 | | - name: 'conformToMask', |
273 | | - previous: rawValue, |
274 | | - result: 'a*b', |
275 | | - meta: { |
276 | | - someCharsRejected: false |
277 | | - } |
278 | | - }; |
279 | | - |
280 | | - const conformToMask = FormatterParser.conformToMask(maskFunc, config); |
281 | | - expect(conformToMask(rawValue)).toEqual(expectedResult); |
282 | | - })); |
283 | | - |
284 | | - }); |
285 | | - |
286 | 67 | }); |
0 commit comments