@jsonforms/angular-material 3.0.0 → 3.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/lib/cjs/controls/autocomplete.renderer.d.ts +2 -2
  2. package/lib/cjs/controls/autocomplete.renderer.js +1 -1
  3. package/lib/cjs/controls/autocomplete.renderer.js.map +1 -1
  4. package/lib/cjs/controls/autocomplete.renderer.metadata.json +1 -1
  5. package/lib/cjs/controls/date.renderer.js +1 -1
  6. package/lib/cjs/controls/date.renderer.js.map +1 -1
  7. package/lib/cjs/controls/date.renderer.metadata.json +1 -1
  8. package/lib/cjs/controls/number.renderer.js +2 -2
  9. package/lib/cjs/controls/number.renderer.js.map +1 -1
  10. package/lib/cjs/controls/number.renderer.metadata.json +1 -1
  11. package/lib/cjs/controls/text.renderer.js +1 -1
  12. package/lib/cjs/controls/text.renderer.js.map +1 -1
  13. package/lib/cjs/controls/text.renderer.metadata.json +1 -1
  14. package/lib/cjs/controls/textarea.renderer.js +1 -1
  15. package/lib/cjs/controls/textarea.renderer.js.map +1 -1
  16. package/lib/cjs/controls/textarea.renderer.metadata.json +1 -1
  17. package/lib/cjs/layouts/array-layout.renderer.d.ts +8 -0
  18. package/lib/cjs/layouts/array-layout.renderer.js +12 -2
  19. package/lib/cjs/layouts/array-layout.renderer.js.map +1 -1
  20. package/lib/cjs/layouts/array-layout.renderer.metadata.json +1 -1
  21. package/lib/cjs/layouts/categorization-layout.renderer.d.ts +2 -1
  22. package/lib/cjs/layouts/categorization-layout.renderer.js +5 -2
  23. package/lib/cjs/layouts/categorization-layout.renderer.js.map +1 -1
  24. package/lib/cjs/layouts/categorization-layout.renderer.metadata.json +1 -1
  25. package/lib/cjs/layouts/group-layout.renderer.js +1 -1
  26. package/lib/cjs/layouts/group-layout.renderer.js.map +1 -1
  27. package/lib/cjs/layouts/group-layout.renderer.metadata.json +1 -1
  28. package/lib/cjs/layouts/horizontal-layout.renderer.js +1 -1
  29. package/lib/cjs/layouts/horizontal-layout.renderer.js.map +1 -1
  30. package/lib/cjs/layouts/horizontal-layout.renderer.metadata.json +1 -1
  31. package/lib/cjs/layouts/layout.renderer.d.ts +5 -3
  32. package/lib/cjs/layouts/layout.renderer.js +18 -14
  33. package/lib/cjs/layouts/layout.renderer.js.map +1 -1
  34. package/lib/cjs/layouts/layout.renderer.metadata.json +1 -1
  35. package/lib/cjs/layouts/vertical-layout.renderer.js +1 -1
  36. package/lib/cjs/layouts/vertical-layout.renderer.js.map +1 -1
  37. package/lib/cjs/layouts/vertical-layout.renderer.metadata.json +1 -1
  38. package/lib/cjs/module.js +3 -1
  39. package/lib/cjs/module.js.map +1 -1
  40. package/lib/cjs/module.metadata.json +1 -1
  41. package/lib/cjs/other/master-detail/master.js +3 -0
  42. package/lib/cjs/other/master-detail/master.js.map +1 -1
  43. package/lib/cjs/other/master-detail/master.metadata.json +1 -1
  44. package/lib/cjs/other/table.renderer.d.ts +9 -0
  45. package/lib/cjs/other/table.renderer.js +28 -2
  46. package/lib/cjs/other/table.renderer.js.map +1 -1
  47. package/lib/cjs/other/table.renderer.metadata.json +1 -1
  48. package/lib/esm/controls/autocomplete.renderer.d.ts +2 -2
  49. package/lib/esm/controls/autocomplete.renderer.js +1 -1
  50. package/lib/esm/controls/autocomplete.renderer.js.map +1 -1
  51. package/lib/esm/controls/autocomplete.renderer.metadata.json +1 -1
  52. package/lib/esm/controls/date.renderer.js +1 -1
  53. package/lib/esm/controls/date.renderer.js.map +1 -1
  54. package/lib/esm/controls/date.renderer.metadata.json +1 -1
  55. package/lib/esm/controls/number.renderer.js +3 -3
  56. package/lib/esm/controls/number.renderer.js.map +1 -1
  57. package/lib/esm/controls/number.renderer.metadata.json +1 -1
  58. package/lib/esm/controls/text.renderer.js +1 -1
  59. package/lib/esm/controls/text.renderer.js.map +1 -1
  60. package/lib/esm/controls/text.renderer.metadata.json +1 -1
  61. package/lib/esm/controls/textarea.renderer.js +1 -1
  62. package/lib/esm/controls/textarea.renderer.js.map +1 -1
  63. package/lib/esm/controls/textarea.renderer.metadata.json +1 -1
  64. package/lib/esm/layouts/array-layout.renderer.d.ts +8 -0
  65. package/lib/esm/layouts/array-layout.renderer.js +12 -2
  66. package/lib/esm/layouts/array-layout.renderer.js.map +1 -1
  67. package/lib/esm/layouts/array-layout.renderer.metadata.json +1 -1
  68. package/lib/esm/layouts/categorization-layout.renderer.d.ts +2 -1
  69. package/lib/esm/layouts/categorization-layout.renderer.js +6 -3
  70. package/lib/esm/layouts/categorization-layout.renderer.js.map +1 -1
  71. package/lib/esm/layouts/categorization-layout.renderer.metadata.json +1 -1
  72. package/lib/esm/layouts/group-layout.renderer.js +1 -1
  73. package/lib/esm/layouts/group-layout.renderer.js.map +1 -1
  74. package/lib/esm/layouts/group-layout.renderer.metadata.json +1 -1
  75. package/lib/esm/layouts/horizontal-layout.renderer.js +1 -1
  76. package/lib/esm/layouts/horizontal-layout.renderer.js.map +1 -1
  77. package/lib/esm/layouts/horizontal-layout.renderer.metadata.json +1 -1
  78. package/lib/esm/layouts/layout.renderer.d.ts +5 -3
  79. package/lib/esm/layouts/layout.renderer.js +18 -14
  80. package/lib/esm/layouts/layout.renderer.js.map +1 -1
  81. package/lib/esm/layouts/layout.renderer.metadata.json +1 -1
  82. package/lib/esm/layouts/vertical-layout.renderer.js +1 -1
  83. package/lib/esm/layouts/vertical-layout.renderer.js.map +1 -1
  84. package/lib/esm/layouts/vertical-layout.renderer.metadata.json +1 -1
  85. package/lib/esm/module.js +3 -1
  86. package/lib/esm/module.js.map +1 -1
  87. package/lib/esm/module.metadata.json +1 -1
  88. package/lib/esm/other/master-detail/master.js +4 -1
  89. package/lib/esm/other/master-detail/master.js.map +1 -1
  90. package/lib/esm/other/master-detail/master.metadata.json +1 -1
  91. package/lib/esm/other/table.renderer.d.ts +9 -0
  92. package/lib/esm/other/table.renderer.js +29 -3
  93. package/lib/esm/other/table.renderer.js.map +1 -1
  94. package/lib/esm/other/table.renderer.metadata.json +1 -1
  95. package/package.json +23 -8
  96. package/src/controls/autocomplete.renderer.ts +5 -3
  97. package/src/controls/date.renderer.ts +3 -1
  98. package/src/controls/number.renderer.ts +4 -3
  99. package/src/controls/text.renderer.ts +3 -1
  100. package/src/controls/textarea.renderer.ts +3 -1
  101. package/src/layouts/array-layout.renderer.ts +43 -2
  102. package/src/layouts/categorization-layout.renderer.ts +8 -2
  103. package/src/layouts/group-layout.renderer.ts +1 -1
  104. package/src/layouts/horizontal-layout.renderer.ts +1 -1
  105. package/src/layouts/layout.renderer.ts +17 -12
  106. package/src/layouts/vertical-layout.renderer.ts +1 -1
  107. package/src/module.ts +3 -1
  108. package/src/other/master-detail/master.ts +5 -0
  109. package/src/other/table.renderer.ts +80 -3
  110. package/docs/assets/css/main.css +0 -1
  111. package/docs/assets/images/icons.png +0 -0
  112. package/docs/assets/images/icons@2x.png +0 -0
  113. package/docs/assets/images/widgets.png +0 -0
  114. package/docs/assets/images/widgets@2x.png +0 -0
  115. package/docs/assets/js/main.js +0 -51
  116. package/docs/assets/js/search.json +0 -1
  117. package/docs/classes/arraylayoutrenderer.html +0 -1046
  118. package/docs/classes/autocompletecontrolrenderer.html +0 -887
  119. package/docs/classes/booleancontrolrenderer.html +0 -771
  120. package/docs/classes/categorizationtablayoutrenderer.html +0 -370
  121. package/docs/classes/datecontrolrenderer.html +0 -739
  122. package/docs/classes/grouplayoutrenderer.html +0 -426
  123. package/docs/classes/horizontallayoutrenderer.html +0 -426
  124. package/docs/classes/jsonformsangularmaterialmodule.html +0 -133
  125. package/docs/classes/jsonformsdetailcomponent.html +0 -227
  126. package/docs/classes/labelrenderer.html +0 -363
  127. package/docs/classes/layoutrenderer.html +0 -465
  128. package/docs/classes/masterlistcomponent.html +0 -1054
  129. package/docs/classes/numbercontrolrenderer.html +0 -893
  130. package/docs/classes/objectcontrolrenderer.html +0 -761
  131. package/docs/classes/rangecontrolrenderer.html +0 -792
  132. package/docs/classes/tablerenderer.html +0 -920
  133. package/docs/classes/textarearenderer.html +0 -739
  134. package/docs/classes/textcontrolrenderer.html +0 -760
  135. package/docs/classes/togglecontrolrenderer.html +0 -771
  136. package/docs/classes/verticallayoutrenderer.html +0 -426
  137. package/docs/globals.html +0 -606
  138. package/docs/index.html +0 -375
  139. package/docs/interfaces/columndescription.html +0 -192
  140. package/docs/interfaces/ownpropsofautocomplete.html +0 -327
  141. package/example/app/app.component.ts +0 -122
  142. package/example/app/app.module.ts +0 -42
  143. package/example/index.html +0 -25
  144. package/example/main.ts +0 -37
  145. package/test/autocomplete-control.spec.ts +0 -322
  146. package/test/boolean-control.spec.ts +0 -76
  147. package/test/categorization-tab-layout.spec.ts +0 -331
  148. package/test/date-control.spec.ts +0 -280
  149. package/test/group-layout.spec.ts +0 -104
  150. package/test/horizontal-layout.spec.ts +0 -94
  151. package/test/label-renderer.spec.ts +0 -78
  152. package/test/master-detail.spec.ts +0 -408
  153. package/test/number-control.spec.ts +0 -208
  154. package/test/object-control.spec.ts +0 -245
  155. package/test/range-control.spec.ts +0 -104
  156. package/test/table-control.spec.ts +0 -253
  157. package/test/text-area.spec.ts +0 -108
  158. package/test/text-control.spec.ts +0 -89
  159. package/test/toggle-control.spec.ts +0 -77
  160. package/test/tsconfig.test.json +0 -18
  161. package/test/util.ts +0 -28
  162. package/test/vertical-layout.spec.ts +0 -113
  163. package/test-config/karma-test-shim.js +0 -21
  164. package/test-config/karma.conf.js +0 -58
  165. package/test-config/protractor.conf.js +0 -28
  166. package/test-config/webpack.test.js +0 -65
  167. package/tsconfig.cjs.json +0 -9
  168. package/tsconfig.json +0 -16
  169. package/webpack/webpack.build.js +0 -13
  170. package/webpack/webpack.dev.js +0 -37
@@ -1,104 +0,0 @@
1
- /*
2
- The MIT License
3
-
4
- Copyright (c) 2017-2019 EclipseSource Munich
5
- https://github.com/eclipsesource/jsonforms
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated documentation files (the "Software"), to deal
9
- in the Software without restriction, including without limitation the rights
10
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom the Software is
12
- furnished to do so, subject to the following conditions:
13
-
14
- The above copyright notice and this permission notice shall be included in
15
- all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- THE SOFTWARE.
24
- */
25
- import { ComponentFixture } from '@angular/core/testing';
26
- import { GroupLayout, UISchemaElement } from '@jsonforms/core';
27
- import { MatCard, MatCardTitle } from '@angular/material/card';
28
- import { By } from '@angular/platform-browser';
29
- import { DebugElement } from '@angular/core';
30
- import {
31
- beforeEachLayoutTest,
32
- setupMockStore
33
- } from '@jsonforms/angular-test';
34
- import { FlexLayoutModule } from '@angular/flex-layout';
35
- import {
36
- GroupLayoutRenderer,
37
- groupLayoutTester
38
- } from '../src/layouts/group-layout.renderer';
39
-
40
- describe('Group layout tester', () => {
41
- it('should succeed', () => {
42
- expect(groupLayoutTester({ type: 'Group' }, undefined, undefined)).toBe(1);
43
- });
44
- });
45
- describe('Group layout', () => {
46
- let fixture: ComponentFixture<any>;
47
-
48
- beforeEach(() => {
49
- fixture = beforeEachLayoutTest(GroupLayoutRenderer, {
50
- declarations: [MatCard, MatCardTitle],
51
- imports: [FlexLayoutModule]
52
- });
53
- });
54
-
55
- it('render with undefined elements', () => {
56
- const uischema: UISchemaElement = {
57
- type: 'Group'
58
- };
59
- setupMockStore(fixture, { data: {}, schema: {}, uischema });
60
- fixture.componentInstance.ngOnInit();
61
- fixture.detectChanges();
62
- const card: DebugElement[] = fixture.debugElement.queryAll(
63
- By.directive(MatCard)
64
- );
65
- // title
66
- expect(card[0].nativeElement.children.length).toBe(1);
67
- });
68
-
69
- it('render with null elements', () => {
70
- const uischema: GroupLayout = {
71
- type: 'Group',
72
- elements: null
73
- };
74
- setupMockStore(fixture, { data: {}, schema: {}, uischema });
75
- fixture.componentInstance.ngOnInit();
76
- fixture.detectChanges();
77
- const card: DebugElement[] = fixture.debugElement.queryAll(
78
- By.directive(MatCard)
79
- );
80
- // title
81
- expect(card[0].nativeElement.children.length).toBe(1);
82
- });
83
-
84
- it('render with children', () => {
85
- const uischema: GroupLayout = {
86
- type: 'Group',
87
- label: 'foo',
88
- elements: [{ type: 'Control' }, { type: 'Control' }]
89
- };
90
- setupMockStore(fixture, { data: {}, schema: {}, uischema });
91
- fixture.componentInstance.ngOnInit();
92
- fixture.detectChanges();
93
- const card: DebugElement[] = fixture.debugElement.queryAll(
94
- By.directive(MatCard)
95
- );
96
- const title: DebugElement = fixture.debugElement.query(
97
- By.directive(MatCardTitle)
98
- );
99
-
100
- expect(title.nativeElement.textContent).toBe('foo');
101
- // title + 2 controls
102
- expect(card[0].nativeElement.children.length).toBe(3);
103
- });
104
- });
@@ -1,94 +0,0 @@
1
- /*
2
- The MIT License
3
-
4
- Copyright (c) 2017-2019 EclipseSource Munich
5
- https://github.com/eclipsesource/jsonforms
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated documentation files (the "Software"), to deal
9
- in the Software without restriction, including without limitation the rights
10
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom the Software is
12
- furnished to do so, subject to the following conditions:
13
-
14
- The above copyright notice and this permission notice shall be included in
15
- all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- THE SOFTWARE.
24
- */
25
- import { ComponentFixture } from '@angular/core/testing';
26
- import { HorizontalLayout, UISchemaElement } from '@jsonforms/core';
27
- import { beforeEachLayoutTest, setupMockStore } from '@jsonforms/angular-test';
28
- import { FlexLayoutModule } from '@angular/flex-layout';
29
- import {
30
- HorizontalLayoutRenderer,
31
- horizontalLayoutTester
32
- } from '../src/layouts/horizontal-layout.renderer';
33
-
34
- describe('Horizontal layout tester', () => {
35
- it('should succeed', () => {
36
- expect(
37
- horizontalLayoutTester({ type: 'HorizontalLayout' }, undefined, undefined)
38
- ).toBe(1);
39
- });
40
- });
41
- describe('Horizontal layout', () => {
42
- let fixture: ComponentFixture<any>;
43
-
44
- beforeEach(() => {
45
- fixture = beforeEachLayoutTest(HorizontalLayoutRenderer, {
46
- imports: [FlexLayoutModule]
47
- });
48
- });
49
-
50
- it('render with undefined elements', () => {
51
- const uischema: UISchemaElement = {
52
- type: 'HorizontalLayout'
53
- };
54
- setupMockStore(fixture, {
55
- data: {},
56
- schema: {},
57
- uischema
58
- });
59
- fixture.componentInstance.ngOnInit();
60
- fixture.detectChanges();
61
- expect(fixture.nativeElement.children[0].children.length).toBe(0);
62
- });
63
-
64
- it('render with null elements', () => {
65
- const uischema: HorizontalLayout = {
66
- type: 'HorizontalLayout',
67
- elements: null
68
- };
69
- setupMockStore(fixture, {
70
- data: {},
71
- schema: {},
72
- uischema
73
- });
74
- fixture.componentInstance.ngOnInit();
75
- fixture.detectChanges();
76
- expect(fixture.nativeElement.children[0].children.length).toBe(0);
77
- });
78
-
79
- it('render with children', () => {
80
- const uischema: HorizontalLayout = {
81
- type: 'HorizontalLayout',
82
- elements: [{ type: 'Control' }, { type: 'Control' }]
83
- };
84
- setupMockStore(fixture, {
85
- data: {},
86
- schema: {},
87
- uischema
88
- });
89
- fixture.componentInstance.ngOnInit();
90
- fixture.detectChanges();
91
- expect(fixture.nativeElement.children[0].children.length).toBe(2);
92
- expect(fixture.nativeElement.children[0].hidden).toBe(false);
93
- });
94
- });
@@ -1,78 +0,0 @@
1
- /*
2
- The MIT License
3
-
4
- Copyright (c) 2017-2019 EclipseSource Munich
5
- https://github.com/eclipsesource/jsonforms
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated documentation files (the "Software"), to deal
9
- in the Software without restriction, including without limitation the rights
10
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom the Software is
12
- furnished to do so, subject to the following conditions:
13
-
14
- The above copyright notice and this permission notice shall be included in
15
- all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- THE SOFTWARE.
24
- */
25
- import { ComponentFixture, TestBed } from '@angular/core/testing';
26
- import { By } from '@angular/platform-browser';
27
- import { JsonSchema, LabelElement } from '@jsonforms/core';
28
-
29
- import { LabelRenderer, LabelRendererTester } from '../src/other';
30
- import { setupMockStore } from '@jsonforms/angular-test';
31
- import { JsonFormsAngularService } from '@jsonforms/angular';
32
-
33
- const data = {};
34
- const schema: JsonSchema = {
35
- type: 'object',
36
- properties: {
37
- foo: {
38
- type: 'string'
39
- }
40
- }
41
- };
42
- const uischema: LabelElement = {
43
- type: 'Label',
44
- text: 'FooBar'
45
- };
46
-
47
- describe('Material label field tester', () => {
48
- it('should succeed', () => {
49
- expect(LabelRendererTester(uischema, schema, undefined)).toBe(4);
50
- });
51
- });
52
- const providers = [JsonFormsAngularService];
53
- const componentUT: any = LabelRenderer;
54
-
55
- describe('Label Renderer Base Tests', () => {
56
- let fixture: ComponentFixture<LabelRenderer>;
57
- let component: LabelRenderer;
58
- let labelElement: HTMLLabelElement;
59
- beforeEach(() => {
60
- TestBed.configureTestingModule({
61
- declarations: [componentUT],
62
- providers: providers
63
- }).compileComponents();
64
- });
65
- beforeEach(() => {
66
- fixture = TestBed.createComponent(componentUT);
67
- component = fixture.componentInstance;
68
-
69
- labelElement = fixture.debugElement.query(By.css('label')).nativeElement;
70
- });
71
-
72
- it('should render', () => {
73
- setupMockStore(fixture, { uischema, schema, data });
74
- fixture.detectChanges();
75
- component.ngOnInit();
76
- expect(labelElement.innerText.trim()).toBe('FooBar');
77
- });
78
- });
@@ -1,408 +0,0 @@
1
- /*
2
- The MIT License
3
-
4
- Copyright (c) 2017-2019 EclipseSource Munich
5
- https://github.com/eclipsesource/jsonforms
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated documentation files (the "Software"), to deal
9
- in the Software without restriction, including without limitation the rights
10
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom the Software is
12
- furnished to do so, subject to the following conditions:
13
-
14
- The above copyright notice and this permission notice shall be included in
15
- all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- THE SOFTWARE.
24
- */
25
- import { async, ComponentFixture, TestBed } from '@angular/core/testing';
26
- import { By } from '@angular/platform-browser';
27
- import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
28
- import { MatButtonModule } from '@angular/material/button';
29
- import { MatIconModule } from '@angular/material/icon';
30
- import { MatListItem, MatListModule } from '@angular/material/list';
31
- import { MatSidenavModule } from '@angular/material/sidenav';
32
- import { NoopAnimationsModule } from '@angular/platform-browser/animations';
33
- import {
34
- JsonFormsAngularService,
35
- JsonFormsOutlet,
36
- UnknownRenderer
37
- } from '@jsonforms/angular';
38
- import { FlexLayoutModule } from '@angular/flex-layout';
39
- import { DebugElement } from '@angular/core';
40
- import { MasterListComponent } from '../src/other/master-detail/master';
41
- import { JsonFormsDetailComponent } from '../src/other/master-detail/detail';
42
- import { getJsonFormsService, setupMockStore } from '@jsonforms/angular-test';
43
- import { Actions } from '@jsonforms/core';
44
-
45
- describe('Master detail', () => {
46
- let fixture: ComponentFixture<MasterListComponent>;
47
- let component: any;
48
-
49
- const data = {
50
- orders: [
51
- {
52
- customer: {
53
- name: 'ACME'
54
- },
55
- title: 'Carrots'
56
- }
57
- ]
58
- };
59
- const schema = {
60
- definitions: {
61
- order: {
62
- type: 'object',
63
- properties: {
64
- customer: {
65
- type: 'object',
66
- properties: {
67
- name: { type: 'string' }
68
- }
69
- },
70
- title: {
71
- type: 'string'
72
- }
73
- }
74
- }
75
- },
76
- type: 'object',
77
- properties: {
78
- orders: {
79
- type: 'array',
80
- items: {
81
- $ref: '#/definitions/order'
82
- }
83
- }
84
- }
85
- };
86
- const uischema = {
87
- type: 'ListWithDetail',
88
- scope: '#/properties/orders',
89
- options: {
90
- labelRef: '#/items/properties/customer/properties/name',
91
- detail: {
92
- type: 'VerticalLayout',
93
- elements: [
94
- {
95
- type: 'Control',
96
- scope: '#/properties/customer/properties/name'
97
- }
98
- ]
99
- }
100
- }
101
- };
102
-
103
- beforeEach(() => {
104
- TestBed.configureTestingModule({
105
- declarations: [
106
- JsonFormsOutlet,
107
- MasterListComponent,
108
- UnknownRenderer,
109
- JsonFormsDetailComponent
110
- ],
111
- imports: [
112
- MatListModule,
113
- MatSidenavModule,
114
- MatIconModule,
115
- MatButtonModule,
116
- FlexLayoutModule,
117
- NoopAnimationsModule
118
- ],
119
- providers: [JsonFormsAngularService]
120
- })
121
- .overrideModule(BrowserDynamicTestingModule, {
122
- set: {
123
- entryComponents: [UnknownRenderer]
124
- }
125
- })
126
- .compileComponents();
127
-
128
- fixture = TestBed.createComponent(MasterListComponent);
129
- component = fixture.componentInstance;
130
- });
131
-
132
- it('should render', async(() => {
133
- setupMockStore(fixture, { uischema, schema, data });
134
- getJsonFormsService(component).updateCore(Actions.init(data, schema));
135
- component.ngOnInit();
136
-
137
- fixture.detectChanges();
138
- fixture.whenStable().then(() => {
139
- fixture.detectChanges();
140
- expect(component.masterItems.length).toBe(1);
141
- expect(
142
- fixture.debugElement.queryAll(By.directive(MatListItem)).length
143
- ).toBe(1);
144
- // the component is wrapped in a div
145
- expect(fixture.nativeElement.children[0].style.display).not.toBe('none');
146
- });
147
- }));
148
-
149
- it('add a master item', async(() => {
150
- setupMockStore(fixture, { uischema, schema, data });
151
- getJsonFormsService(component).updateCore(Actions.init(data, schema));
152
- component.ngOnInit();
153
- fixture.detectChanges();
154
-
155
- const spy = spyOn(component, 'addItem').and.returnValue(() => {
156
- /* noop */
157
- });
158
- fixture.whenStable().then(() => {
159
- const buttons: DebugElement[] = fixture.debugElement.queryAll(
160
- By.css('button')
161
- );
162
- buttons[1].nativeElement.click();
163
- fixture.detectChanges();
164
- fixture.whenRenderingDone().then(() => {
165
- fixture.detectChanges();
166
- expect(spy).toHaveBeenCalled();
167
- });
168
- });
169
- }));
170
-
171
- it('remove an item', async(() => {
172
- setupMockStore(fixture, { uischema, schema, data });
173
- getJsonFormsService(component).updateCore(Actions.init(data, schema));
174
- component.ngOnInit();
175
- fixture.detectChanges();
176
-
177
- const spy = spyOn(component, 'removeItems').and.returnValue(() => {
178
- /* noop */
179
- });
180
- fixture.whenStable().then(() => {
181
- const buttons: DebugElement[] = fixture.debugElement.queryAll(
182
- By.css('button')
183
- );
184
- buttons[0].nativeElement.click();
185
- fixture.whenStable().then(() => {
186
- fixture.detectChanges();
187
- expect(spy).toHaveBeenCalled();
188
- });
189
- });
190
- }));
191
-
192
- it('remove an item with index < selected index', () => {
193
- const moreData = {
194
- orders: [
195
- {
196
- customer: { name: 'Carrot Chipmunk' },
197
- title: 'Carrots'
198
- },
199
- {
200
- customer: { name: 'Banana Joe' },
201
- title: 'Bananas'
202
- },
203
- {
204
- customer: { name: 'Fry' },
205
- title: 'Slurm'
206
- }
207
- ]
208
- };
209
-
210
- setupMockStore(fixture, {
211
- uischema,
212
- schema,
213
- data: moreData
214
- });
215
- getJsonFormsService(component).updateCore(Actions.init(moreData, schema));
216
- component.ngOnInit();
217
- fixture.detectChanges();
218
-
219
- // select last element
220
- const listItems: DebugElement[] = fixture.debugElement.queryAll(
221
- By.directive(MatListItem)
222
- );
223
- listItems[2].nativeElement.click();
224
- fixture.detectChanges();
225
- expect(component.selectedItemIdx).toBe(2);
226
-
227
- // delete 1st item
228
- spyOn(component, 'removeItems').and.callFake(() => () => {
229
- getJsonFormsService(component).updateCore(Actions.update('orders', () => moreData.orders.slice(1)));
230
- fixture.detectChanges();
231
- });
232
- const buttons: DebugElement[] = fixture.debugElement.queryAll(
233
- By.css('button')
234
- );
235
- buttons[0].nativeElement.click();
236
-
237
- expect(component.selectedItemIdx).toBe(1);
238
- expect(component.selectedItem.data.title).toBe('Slurm');
239
- });
240
-
241
- it('remove an item with index > selected index', () => {
242
- const moreData = {
243
- orders: [
244
- {
245
- customer: { name: 'Carrot Chipmunk' },
246
- title: 'Carrots'
247
- },
248
- {
249
- customer: { name: 'Banana Joe' },
250
- title: 'Bananas'
251
- },
252
- {
253
- customer: { name: 'Fry' },
254
- title: 'Slurm'
255
- }
256
- ]
257
- };
258
- setupMockStore(fixture, {
259
- uischema,
260
- schema,
261
- data: moreData
262
- });
263
- getJsonFormsService(component).updateCore(Actions.init(moreData, schema));
264
- component.ngOnInit();
265
- fixture.detectChanges();
266
-
267
- // delete 2nd item
268
- spyOn(component, 'removeItems').and.callFake(() => () => {
269
- const copy = moreData.orders.slice();
270
- copy.splice(1, 1);
271
- getJsonFormsService(component).updateCore(Actions.update('orders', () => copy));
272
- fixture.detectChanges();
273
- });
274
- const buttons: DebugElement[] = fixture.debugElement.queryAll(
275
- By.css('button')
276
- );
277
- buttons[1].nativeElement.click();
278
-
279
- expect(component.selectedItemIdx).toBe(0);
280
- expect(component.selectedItem.data.title).toBe('Carrots');
281
- });
282
-
283
- it('remove an item with index == selected index', () => {
284
- const moreData = {
285
- orders: [
286
- {
287
- customer: { name: 'Carrot Chipmunk' },
288
- title: 'Carrots'
289
- },
290
- {
291
- customer: { name: 'Banana Joe' },
292
- title: 'Bananas'
293
- },
294
- {
295
- customer: { name: 'Fry' },
296
- title: 'Slurm'
297
- }
298
- ]
299
- };
300
- setupMockStore(fixture, {
301
- uischema,
302
- schema,
303
- data: moreData
304
- });
305
- getJsonFormsService(component).updateCore(Actions.init(moreData, schema));
306
- component.ngOnInit();
307
- fixture.detectChanges();
308
-
309
- // delete 1st item
310
- spyOn(component, 'removeItems').and.callFake(() => () => {
311
- getJsonFormsService(component).updateCore(Actions.update('orders', () => moreData.orders.slice(1)));
312
- fixture.detectChanges();
313
- });
314
- const buttons: DebugElement[] = fixture.debugElement.queryAll(
315
- By.css('button')
316
- );
317
- buttons[0].nativeElement.click();
318
-
319
- expect(component.selectedItemIdx).toBe(0);
320
- expect(component.selectedItem.data.title).toBe('Bananas');
321
- });
322
-
323
- it('remove last item', () => {
324
- const moreData = {
325
- orders: [
326
- {
327
- customer: { name: 'Carrot Chipmunk' },
328
- title: 'Carrots'
329
- }
330
- ]
331
- };
332
- setupMockStore(fixture, {
333
- uischema,
334
- schema,
335
- data: moreData
336
- });
337
- getJsonFormsService(component).updateCore(Actions.init(moreData, schema));
338
- component.ngOnInit();
339
- fixture.detectChanges();
340
-
341
- // delete item
342
- spyOn(component, 'removeItems').and.callFake(() => () => {
343
- getJsonFormsService(component).updateCore(Actions.update('orders', () => []));
344
- fixture.detectChanges();
345
- });
346
- const buttons: DebugElement[] = fixture.debugElement.queryAll(
347
- By.css('button')
348
- );
349
- buttons[0].nativeElement.click();
350
-
351
- expect(component.selectedItemIdx).toBe(-1);
352
- expect(component.selectedItem).toBe(undefined);
353
- });
354
-
355
- it('setting detail on click', async(() => {
356
- setupMockStore(fixture, { uischema, schema, data });
357
- getJsonFormsService(component).updateCore(Actions.init(data, schema));
358
- component.ngOnInit();
359
-
360
- fixture.detectChanges();
361
- fixture.whenStable().then(() => {
362
- spyOn(component, 'onSelect');
363
- const select = fixture.debugElement.query(By.directive(MatListItem))
364
- .nativeElement;
365
- select.click();
366
- fixture.detectChanges();
367
- fixture.whenStable().then(() => {
368
- fixture.detectChanges();
369
- expect(
370
- fixture.debugElement.queryAll(By.directive(JsonFormsDetailComponent))
371
- .length
372
- ).toBe(1);
373
- expect(component.onSelect).toHaveBeenCalledWith(
374
- {
375
- label: 'ACME',
376
- data: {
377
- customer: { name: 'ACME' },
378
- title: 'Carrots'
379
- },
380
- path: 'orders.0',
381
- schema: schema.definitions.order,
382
- uischema: {
383
- type: 'VerticalLayout',
384
- elements: [
385
- {
386
- type: 'Control',
387
- scope: '#/properties/customer/properties/name'
388
- }
389
- ]
390
- }
391
- },
392
- 0
393
- );
394
- });
395
- });
396
- }));
397
-
398
- it('can be hidden', async(() => {
399
- setupMockStore(fixture, { uischema, schema, data });
400
- getJsonFormsService(component).updateCore(Actions.init(data, schema));
401
- component.visible = false;
402
- component.ngOnInit();
403
- fixture.detectChanges();
404
- fixture.whenRenderingDone().then(() => {
405
- expect(fixture.nativeElement.children[0].style.display).toBe('none');
406
- });
407
- }));
408
- });