|
1 | | -import { InputFieldDeclaration, InputFieldDeclarationParser, InputFieldType } from '../src/parsers/InputFieldDeclarationParser'; |
| 1 | +import { MetaBindParsingError } from '../src/utils/Utils'; |
| 2 | +import { InputFieldArgumentContainer } from '../src/inputFieldArguments/InputFieldArgumentContainer'; |
| 3 | +import { InputFieldArgumentType, InputFieldDeclaration, InputFieldDeclarationParser, InputFieldType } from '../src/parsers/InputFieldDeclarationParser'; |
2 | 4 |
|
3 | 5 | test('placeholder', () => { |
4 | 6 | expect(true).toEqual(true); |
5 | 7 | }); |
6 | 8 |
|
| 9 | +describe('apply template', () => { |
| 10 | + test('found', () => { |
| 11 | + InputFieldDeclarationParser.templates = [ |
| 12 | + { |
| 13 | + identifier: "Test", |
| 14 | + template: { |
| 15 | + isBound: true, |
| 16 | + bindTarget: "Test#Target", |
| 17 | + argumentContainer: new InputFieldArgumentContainer() |
| 18 | + } as InputFieldDeclaration |
| 19 | + } |
| 20 | + ]; |
| 21 | + |
| 22 | + const inputFieldDeclaration: InputFieldDeclaration = InputFieldDeclarationParser.parseString("INPUT[toggle(class(a))]"); |
| 23 | + InputFieldDeclarationParser.applyTemplate(inputFieldDeclaration, "Test"); |
| 24 | + |
| 25 | + expect(inputFieldDeclaration.isBound).toEqual(true); |
| 26 | + expect(inputFieldDeclaration.bindTarget).toEqual("Test#Target"); |
| 27 | + expect(inputFieldDeclaration.inputFieldType).toEqual(InputFieldType.TOGGLE); |
| 28 | + expect(inputFieldDeclaration.argumentContainer.arguments[0].identifier).toEqual(InputFieldArgumentType.CLASS); |
| 29 | + expect(inputFieldDeclaration.argumentContainer.arguments[0].value).toEqual(["a"]); |
| 30 | + }); |
| 31 | + test('not found', () => { |
| 32 | + InputFieldDeclarationParser.templates = []; |
| 33 | + |
| 34 | + const inputFieldDeclaration: InputFieldDeclaration = InputFieldDeclarationParser.parseString("INPUT[toggle(class(a))]"); |
| 35 | + expect(() => InputFieldDeclarationParser.applyTemplate(inputFieldDeclaration, "Test")).toThrowError(MetaBindParsingError); |
| 36 | + }); |
| 37 | +}); |
| 38 | + |
7 | 39 | describe('bind target', () => { |
8 | 40 | test('no bind target', () => { |
9 | 41 | const declaration: string = 'INPUT[toggle]'; |
|
0 commit comments