|
| 1 | +import { PlaceholdersValidatorDirective } from './placeholders-validator.directive'; |
| 2 | + |
| 3 | +describe('PlaceholdersValidatorDirective', () => { |
| 4 | + let directive: PlaceholdersValidatorDirective; |
| 5 | + |
| 6 | + beforeEach(() => { |
| 7 | + directive = new PlaceholdersValidatorDirective(); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should create', () => { |
| 11 | + expect(directive).toBeTruthy(); |
| 12 | + }); |
| 13 | + |
| 14 | + it('should be valid without original and value placeholders', () => { |
| 15 | + directive.originalPlaceholders = []; |
| 16 | + const err = directive.validate({value: 'No placeholder text'} as any); |
| 17 | + expect(err).toEqual({placeholders: null}); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should be valid without original placeholder', () => { |
| 21 | + directive.originalPlaceholders = []; |
| 22 | + const err = directive.validate({value: '{$PLACEHOLDER}'} as any); |
| 23 | + expect(err).toEqual({placeholders: null}); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should be valid when placeholders are equal', () => { |
| 27 | + directive.originalPlaceholders = ['{$PLACEHOLDER}']; |
| 28 | + const err = directive.validate({value: '{$PLACEHOLDER}'} as any); |
| 29 | + expect(err).toEqual({placeholders: null}); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should be invalid when placeholder are different', () => { |
| 33 | + directive.originalPlaceholders = ['{$PLACEHOLDER_ORIG}']; |
| 34 | + const err = directive.validate({value: '{$PLACEHOLDER_VAL}'} as any); |
| 35 | + expect(err).toEqual({placeholders: ['{$PLACEHOLDER_ORIG}']}); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should be invalid when multiple placeholder are different', () => { |
| 39 | + directive.originalPlaceholders = ['{$PLACEHOLDER_1}', '{$PLACEHOLDER_2}', '{$PLACEHOLDER_3}', '{$PLACEHOLDER_4}']; |
| 40 | + const err = directive.validate({value: '{$PLACEHOLDER_1}, {$PLACEHOLDER_3}'} as any); |
| 41 | + expect(err).toEqual({placeholders: ['{$PLACEHOLDER_2}', '{$PLACEHOLDER_4}']}); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should be invalid when similar placeholder in original have another count in content', () => { |
| 45 | + directive.originalPlaceholders = ['{$PLACEHOLDER_ORIG}', '{$PLACEHOLDER_ORIG}', '{$PLACEHOLDER_ORIG}']; |
| 46 | + const err = directive.validate({value: '{$PLACEHOLDER_ORIG}{$PLACEHOLDER_ORIG}'} as any); |
| 47 | + expect(err).toEqual({placeholders: ['{$PLACEHOLDER_ORIG}']}); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should be invalid when multiple similar placeholder in original have another count in content', () => { |
| 51 | + directive.originalPlaceholders = ['{$PLACEHOLDER_ORIG}', '{$PLACEHOLDER_ORIG_2}', '{$PLACEHOLDER_ORIG}', '{$PLACEHOLDER_ORIG_2}', '{$PLACEHOLDER_ORIG_3}', '{$PLACEHOLDER_ORIG}']; |
| 52 | + const err = directive.validate({value: '{$PLACEHOLDER_ORIG}{$PLACEHOLDER_ORIG}{$PLACEHOLDER_ORIG_2}{$PLACEHOLDER_ORIG_3}'} as any); |
| 53 | + expect(err).toEqual({placeholders: ['{$PLACEHOLDER_ORIG_2}', '{$PLACEHOLDER_ORIG}']}); |
| 54 | + }); |
| 55 | +}); |
0 commit comments