|
23 | 23 | THE SOFTWARE. |
24 | 24 | */ |
25 | 25 | import { DebugElement } from '@angular/core'; |
| 26 | +import { ComponentFixture } from '@angular/core/testing'; |
| 27 | +import { FlexLayoutModule } from '@angular/flex-layout'; |
26 | 28 | import { ReactiveFormsModule } from '@angular/forms'; |
27 | 29 | import { MatError, MatFormFieldModule } from '@angular/material/form-field'; |
28 | 30 | import { MatInputModule } from '@angular/material/input'; |
29 | 31 | import { NoopAnimationsModule } from '@angular/platform-browser/animations'; |
| 32 | +import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular'; |
30 | 33 | import { |
| 34 | + baseSetup, |
31 | 35 | ErrorTestExpectation, |
| 36 | + getJsonFormsService, |
32 | 37 | numberAdditionalPropsTest, |
33 | 38 | numberBaseTest, |
34 | 39 | numberErrorTest, |
35 | | - numberInputEventTest |
| 40 | + numberInputEventTest, |
| 41 | + prepareComponent |
36 | 42 | } from '@jsonforms/angular-test'; |
37 | | -import { FlexLayoutModule } from '@angular/flex-layout'; |
| 43 | +import { Actions, ControlElement, JsonFormsCore } from '@jsonforms/core'; |
38 | 44 | import { NumberControlRenderer, NumberControlRendererTester } from '../src'; |
39 | | -import { JsonFormsAngularService } from '@jsonforms/angular'; |
40 | 45 |
|
41 | 46 | describe('Material number field tester', () => { |
42 | 47 | const uischema = { |
@@ -100,3 +105,110 @@ describe( |
100 | 105 | 'Number control Additional Props Tests', |
101 | 106 | numberAdditionalPropsTest(testConfig, 'input', toSelect) |
102 | 107 | ); |
| 108 | + |
| 109 | +describe( |
| 110 | + 'Number control custom', () => { |
| 111 | + let fixture: ComponentFixture<any>; |
| 112 | + let numberNativeElement: any; |
| 113 | + let component: JsonFormsControl; |
| 114 | + baseSetup(testConfig); |
| 115 | + |
| 116 | + const defaultSchema = { |
| 117 | + type: 'object', |
| 118 | + properties: { |
| 119 | + foo: { type: 'number' } |
| 120 | + } |
| 121 | + }; |
| 122 | + const defaultData = {foo:1000000}; |
| 123 | + const defaultUischema: ControlElement = { |
| 124 | + type: 'Control', |
| 125 | + scope: '#/properties/foo' |
| 126 | + }; |
| 127 | + |
| 128 | + beforeEach(() => { |
| 129 | + const preparedComponents = prepareComponent( |
| 130 | + testConfig, 'input', toSelect); |
| 131 | + fixture = preparedComponents.fixture; |
| 132 | + numberNativeElement = preparedComponents.numberNativeElement; |
| 133 | + component = preparedComponents.component; |
| 134 | + }); |
| 135 | + |
| 136 | + it('default grouping behavior', () => { |
| 137 | + const uischema = Object.assign({},defaultUischema); |
| 138 | + component.uischema = uischema; |
| 139 | + const state:JsonFormsCore = { |
| 140 | + data: defaultData, |
| 141 | + schema: defaultSchema, |
| 142 | + uischema: uischema |
| 143 | + }; |
| 144 | + getJsonFormsService(component).init({ |
| 145 | + core: state, i18n: { |
| 146 | + locale: 'en', |
| 147 | + localizedSchemas: undefined, |
| 148 | + localizedUISchemas: undefined |
| 149 | + } |
| 150 | + }); |
| 151 | + getJsonFormsService(component).updateCore( |
| 152 | + Actions.init(state.data, state.schema) |
| 153 | + ); |
| 154 | + component.ngOnInit(); |
| 155 | + fixture.detectChanges(); |
| 156 | + |
| 157 | + expect(numberNativeElement.value).toBe('1,000,000'); |
| 158 | + }); |
| 159 | + |
| 160 | + it('should use config for grouping', () => { |
| 161 | + const uischema = Object.assign({},defaultUischema); |
| 162 | + component.uischema = uischema; |
| 163 | + const state:JsonFormsCore = { |
| 164 | + data: defaultData, |
| 165 | + schema: defaultSchema, |
| 166 | + uischema: uischema |
| 167 | + }; |
| 168 | + getJsonFormsService(component).init({ |
| 169 | + core: state, i18n: { |
| 170 | + locale: 'en', |
| 171 | + localizedSchemas: undefined, |
| 172 | + localizedUISchemas: undefined |
| 173 | + },config: { |
| 174 | + useGrouping: false |
| 175 | + }, |
| 176 | + }); |
| 177 | + getJsonFormsService(component).updateCore( |
| 178 | + Actions.init(state.data, state.schema) |
| 179 | + ); |
| 180 | + component.ngOnInit(); |
| 181 | + fixture.detectChanges(); |
| 182 | + |
| 183 | + expect(numberNativeElement.value).toBe('1000000'); |
| 184 | + }); |
| 185 | + it('should use uischema for grouping', () => { |
| 186 | + const uischema = Object.assign({},defaultUischema); |
| 187 | + uischema.options = { |
| 188 | + useGrouping: false |
| 189 | + } |
| 190 | + component.uischema = uischema; |
| 191 | + const state:JsonFormsCore = { |
| 192 | + data: defaultData, |
| 193 | + schema: defaultSchema, |
| 194 | + uischema: uischema |
| 195 | + }; |
| 196 | + getJsonFormsService(component).init({ |
| 197 | + core: state, i18n: { |
| 198 | + locale: 'en', |
| 199 | + localizedSchemas: undefined, |
| 200 | + localizedUISchemas: undefined |
| 201 | + },config: { |
| 202 | + useGrouping: true |
| 203 | + }, |
| 204 | + }); |
| 205 | + getJsonFormsService(component).updateCore( |
| 206 | + Actions.init(state.data, state.schema) |
| 207 | + ); |
| 208 | + component.ngOnInit(); |
| 209 | + fixture.detectChanges(); |
| 210 | + |
| 211 | + expect(numberNativeElement.value).toBe('1000000'); |
| 212 | + }); |
| 213 | + } |
| 214 | +); |
0 commit comments