@swimlane/ngx-datatable 11.1.7 → 11.3.2

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 (100) hide show
  1. package/assets/app.css +5 -6
  2. package/config/deploy.js +2 -2
  3. package/config/karma.conf.js +5 -0
  4. package/config/webpack.dev.js +1 -1
  5. package/package.json +8 -7
  6. package/release/assets/app.css +5 -6
  7. package/release/components/body/body-group-header.directive.d.ts +4 -5
  8. package/release/components/body/body-group-header.directive.js +4 -5
  9. package/release/components/body/body-group-header.directive.js.map +1 -1
  10. package/release/components/body/body-row.component.js +3 -2
  11. package/release/components/body/body-row.component.js.map +1 -1
  12. package/release/components/body/body-row.component.metadata.json +1 -1
  13. package/release/components/body/body.component.d.ts +4 -1
  14. package/release/components/body/body.component.js +22 -7
  15. package/release/components/body/body.component.js.map +1 -1
  16. package/release/components/body/body.component.metadata.json +1 -1
  17. package/release/components/body/index.d.ts +1 -0
  18. package/release/components/body/index.js +1 -0
  19. package/release/components/body/index.js.map +1 -1
  20. package/release/components/body/index.metadata.json +1 -1
  21. package/release/components/body/summary/index.d.ts +1 -0
  22. package/release/components/body/summary/index.js +7 -0
  23. package/release/components/body/summary/index.js.map +1 -0
  24. package/release/components/body/summary/index.metadata.json +1 -0
  25. package/release/components/body/summary/summary-row.component.d.ts +19 -0
  26. package/release/components/body/summary/summary-row.component.js +85 -0
  27. package/release/components/body/summary/summary-row.component.js.map +1 -0
  28. package/release/components/body/summary/summary-row.component.metadata.json +1 -0
  29. package/release/components/columns/column.directive.d.ts +2 -0
  30. package/release/components/columns/column.directive.js +8 -0
  31. package/release/components/columns/column.directive.js.map +1 -1
  32. package/release/components/columns/column.directive.metadata.json +1 -1
  33. package/release/components/datatable.component.css +7 -2
  34. package/release/components/datatable.component.d.ts +14 -1
  35. package/release/components/datatable.component.js +34 -7
  36. package/release/components/datatable.component.js.map +1 -1
  37. package/release/components/datatable.component.metadata.json +1 -1
  38. package/release/components/footer/pager.component.js +1 -1
  39. package/release/components/footer/pager.component.js.map +1 -1
  40. package/release/components/footer/pager.component.metadata.json +1 -1
  41. package/release/components/header/header-cell.component.js +2 -1
  42. package/release/components/header/header-cell.component.js.map +1 -1
  43. package/release/components/header/header-cell.component.metadata.json +1 -1
  44. package/release/components/header/header.component.js +1 -0
  45. package/release/components/header/header.component.js.map +1 -1
  46. package/release/datatable.module.js +2 -1
  47. package/release/datatable.module.js.map +1 -1
  48. package/release/datatable.module.metadata.json +1 -1
  49. package/release/directives/resizeable.directive.js +5 -2
  50. package/release/directives/resizeable.directive.js.map +1 -1
  51. package/release/events.js +3 -3
  52. package/release/events.js.map +1 -1
  53. package/release/events.metadata.json +1 -1
  54. package/release/index.css +8 -3
  55. package/release/index.js +201 -42
  56. package/release/index.min.js +1 -1
  57. package/release/index.min.js.map +1 -1
  58. package/release/themes/bootstrap.css +2 -0
  59. package/release/themes/dark.css +6 -0
  60. package/release/themes/material.css +6 -0
  61. package/release/types/table-column.type.d.ts +14 -0
  62. package/release/utils/column-helper.js +6 -0
  63. package/release/utils/column-helper.js.map +1 -1
  64. package/release/utils/column.d.ts +0 -4
  65. package/release/utils/column.js +0 -10
  66. package/release/utils/column.js.map +1 -1
  67. package/release/utils/column.metadata.json +1 -1
  68. package/release/utils/math.js +1 -1
  69. package/release/utils/math.js.map +1 -1
  70. package/src/components/body/body-group-header.directive.ts +5 -6
  71. package/src/components/body/body-row.component.ts +8 -7
  72. package/src/components/body/body.component.spec.ts +8 -7
  73. package/src/components/body/body.component.ts +27 -6
  74. package/src/components/body/index.ts +1 -0
  75. package/src/components/body/summary/index.ts +1 -0
  76. package/src/components/body/summary/summary-row.component.spec.ts +131 -0
  77. package/src/components/body/summary/summary-row.component.ts +74 -0
  78. package/src/components/columns/column.directive.ts +4 -2
  79. package/src/components/datatable.component.scss +14 -1
  80. package/src/components/datatable.component.spec.ts +55 -7
  81. package/src/components/datatable.component.ts +31 -9
  82. package/src/components/footer/footer.component.spec.ts +329 -47
  83. package/src/components/footer/pager.component.ts +10 -0
  84. package/src/components/header/header-cell.component.ts +2 -1
  85. package/src/components/header/header.component.ts +1 -0
  86. package/src/datatable.module.ts +8 -6
  87. package/src/directives/resizeable.directive.ts +4 -2
  88. package/src/events.ts +3 -3
  89. package/src/themes/bootstrap.scss +10 -1
  90. package/src/themes/dark.scss +14 -0
  91. package/src/themes/material.scss +20 -5
  92. package/src/types/table-column.type.ts +43 -28
  93. package/src/utils/column-helper.ts +9 -1
  94. package/src/utils/column-prop-getters.spec.ts +44 -0
  95. package/src/utils/column.ts +0 -12
  96. package/src/utils/math.ts +1 -1
  97. package/test/index.ts +1 -0
  98. package/test/jasmine-matchers.d.ts +12 -0
  99. package/test/jasmine-matchers.ts +70 -0
  100. package/tslint.json +1 -1
@@ -8,6 +8,8 @@ import {
8
8
  <ul class="pager">
9
9
  <li [class.disabled]="!canPrevious()">
10
10
  <a
11
+ role="button"
12
+ aria-label="go to first page"
11
13
  href="javascript:void(0)"
12
14
  (click)="selectPage(1)">
13
15
  <i class="{{pagerPreviousIcon}}"></i>
@@ -15,12 +17,16 @@ import {
15
17
  </li>
16
18
  <li [class.disabled]="!canPrevious()">
17
19
  <a
20
+ role="button"
21
+ aria-label="go to previous page"
18
22
  href="javascript:void(0)"
19
23
  (click)="prevPage()">
20
24
  <i class="{{pagerLeftArrowIcon}}"></i>
21
25
  </a>
22
26
  </li>
23
27
  <li
28
+ role="button"
29
+ [attr.aria-label]="'page ' + pg.number"
24
30
  class="pages"
25
31
  *ngFor="let pg of pages"
26
32
  [class.active]="pg.number === page">
@@ -32,6 +38,8 @@ import {
32
38
  </li>
33
39
  <li [class.disabled]="!canNext()">
34
40
  <a
41
+ role="button"
42
+ aria-label="go to next page"
35
43
  href="javascript:void(0)"
36
44
  (click)="nextPage()">
37
45
  <i class="{{pagerRightArrowIcon}}"></i>
@@ -39,6 +47,8 @@ import {
39
47
  </li>
40
48
  <li [class.disabled]="!canNext()">
41
49
  <a
50
+ role="button"
51
+ aria-label="go to last page"
42
52
  href="javascript:void(0)"
43
53
  (click)="selectPage(totalPages)">
44
54
  <i class="{{pagerNextIcon}}"></i>
@@ -9,7 +9,7 @@ import { MouseEvent } from '../../events';
9
9
  @Component({
10
10
  selector: 'datatable-header-cell',
11
11
  template: `
12
- <div>
12
+ <div class="datatable-header-cell-template-wrap">
13
13
  <label
14
14
  *ngIf="isCheckboxable"
15
15
  class="datatable-checkbox">
@@ -79,6 +79,7 @@ export class DataTableHeaderCellComponent {
79
79
  @Input() set sorts(val: any[]) {
80
80
  this._sorts = val;
81
81
  this.sortDir = this.calcSortDir(val);
82
+ this.cellContext.sortDir = this.sortDir;
82
83
  this.sortClass = this.calcSortClass(this.sortDir);
83
84
  this.cd.markForCheck();
84
85
  }
@@ -101,6 +101,7 @@ export class DataTableHeaderComponent {
101
101
  const colsByPin = columnsByPin(val);
102
102
  this._columnsByPin = columnsByPinArr(val);
103
103
  this._columnGroupWidths = columnGroupWidths(colsByPin, val);
104
+ this.setStylesByGroup();
104
105
  }
105
106
 
106
107
  get columns(): any[] {
@@ -9,7 +9,7 @@ import {
9
9
  DataTableFooterComponent,
10
10
  DataTableHeaderCellComponent,
11
11
  DataTablePagerComponent,
12
- DataTableBodyRowComponent,
12
+ DataTableBodyRowComponent,
13
13
  DataTableRowWrapperComponent,
14
14
  ProgressBarComponent,
15
15
  DataTableBodyCellComponent,
@@ -22,7 +22,8 @@ import {
22
22
  DatatableRowDetailTemplateDirective,
23
23
  DataTableFooterTemplateDirective,
24
24
  DatatableFooterDirective,
25
- DatatableGroupHeaderTemplateDirective
25
+ DatatableGroupHeaderTemplateDirective,
26
+ DataTableSummaryRowComponent
26
27
  } from './components';
27
28
 
28
29
  import {
@@ -33,9 +34,9 @@ import {
33
34
  DraggableDirective
34
35
  } from './directives';
35
36
 
36
- import {
37
+ import {
37
38
  ScrollbarHelper,
38
- DimensionsHelper
39
+ DimensionsHelper
39
40
  } from './services';
40
41
 
41
42
  @NgModule({
@@ -61,7 +62,7 @@ import {
61
62
  DataTableBodyComponent,
62
63
  DataTableFooterComponent,
63
64
  DataTablePagerComponent,
64
- ProgressBarComponent,
65
+ ProgressBarComponent,
65
66
  DataTableBodyRowComponent,
66
67
  DataTableRowWrapperComponent,
67
68
  DatatableRowDetailDirective,
@@ -72,7 +73,8 @@ import {
72
73
  DataTableColumnHeaderDirective,
73
74
  DataTableColumnCellDirective,
74
75
  DatatableFooterDirective,
75
- DatatableGroupHeaderTemplateDirective
76
+ DatatableGroupHeaderTemplateDirective,
77
+ DataTableSummaryRowComponent,
76
78
  ],
77
79
  exports: [
78
80
  DatatableComponent,
@@ -31,11 +31,13 @@ export class ResizeableDirective implements OnDestroy, AfterViewInit {
31
31
 
32
32
  ngAfterViewInit(): void {
33
33
  const renderer2 = this.renderer;
34
+ const node = renderer2.createElement('span');
34
35
  if (this.resizeEnabled) {
35
- const node = renderer2.createElement('span');
36
36
  renderer2.addClass(node, 'resize-handle');
37
- renderer2.appendChild(this.element, node);
37
+ } else {
38
+ renderer2.addClass(node, 'resize-handle--not-resizable');
38
39
  }
40
+ renderer2.appendChild(this.element, node);
39
41
  }
40
42
 
41
43
  ngOnDestroy(): void {
package/src/events.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  declare let global: any;
2
2
 
3
3
  /* tslint:disable:variable-name */
4
- export const MouseEvent = (global as any).MouseEvent as MouseEvent;
5
- export const KeyboardEvent = (global as any).KeyboardEvent as KeyboardEvent;
6
- export const Event = (global as any).Event as Event;
4
+ export const MouseEvent = ((window as any) || (global as any)).MouseEvent as MouseEvent;
5
+ export const KeyboardEvent = ((window as any) || (global as any)).KeyboardEvent as KeyboardEvent;
6
+ export const Event = ((window as any) || (global as any)).Event as Event;
@@ -83,4 +83,13 @@ bootstrap table theme
83
83
  }
84
84
  }
85
85
  }
86
- }
86
+
87
+ // Summary row styles
88
+ .datatable-summary-row {
89
+ .datatable-body-row {
90
+ .datatable-body-cell {
91
+ font-weight: bold;
92
+ }
93
+ }
94
+ }
95
+ }
@@ -103,4 +103,18 @@
103
103
  }
104
104
  }
105
105
  }
106
+
107
+ .datatable-summary-row {
108
+ .datatable-body-row {
109
+ background-color: #14171f;
110
+
111
+ &:hover {
112
+ background-color: #14171f;
113
+ }
114
+
115
+ .datatable-body-cell {
116
+ font-weight: bold;
117
+ }
118
+ }
119
+ }
106
120
  }
@@ -186,7 +186,7 @@
186
186
  background: #f5f5f5;
187
187
  padding: 10px;
188
188
  }
189
-
189
+
190
190
  .datatable-group-header {
191
191
  background: #f5f5f5;
192
192
  border-bottom: solid 1px #D9D8D9;
@@ -218,7 +218,7 @@
218
218
  transition: width 0.3s ease;
219
219
  font-size: 14px;
220
220
  font-weight: 400;
221
- }
221
+ }
222
222
  }
223
223
 
224
224
  .progress-linear {
@@ -321,6 +321,21 @@
321
321
  }
322
322
  }
323
323
  }
324
+
325
+ // Summary row styles
326
+ .datatable-summary-row {
327
+ .datatable-body-row {
328
+ background-color: #ddd;
329
+
330
+ &:hover {
331
+ background-color: #ddd;
332
+ }
333
+
334
+ .datatable-body-cell {
335
+ font-weight: bold;
336
+ }
337
+ }
338
+ }
324
339
  }
325
340
 
326
341
  /**
@@ -384,11 +399,11 @@
384
399
  @keyframes query {
385
400
  0% {
386
401
  opacity: 1;
387
- transform: translateX(35%) scale(.3, 1);
402
+ transform: translateX(35%) scale(.3, 1);
388
403
  }
389
404
 
390
405
  100% {
391
406
  opacity: 0;
392
- transform: translateX(-50%) scale(0, 1);
393
- }
407
+ transform: translateX(-50%) scale(0, 1);
408
+ }
394
409
  }
@@ -16,7 +16,7 @@ export interface TableColumn {
16
16
 
17
17
  /**
18
18
  * Internal unique id
19
- *
19
+ *
20
20
  * @type {string}
21
21
  * @memberOf TableColumn
22
22
  */
@@ -24,7 +24,7 @@ export interface TableColumn {
24
24
 
25
25
  /**
26
26
  * Internal for column width distributions
27
- *
27
+ *
28
28
  * @type {number}
29
29
  * @memberOf TableColumn
30
30
  */
@@ -32,7 +32,7 @@ export interface TableColumn {
32
32
 
33
33
  /**
34
34
  * Internal for setColumnDefaults
35
- *
35
+ *
36
36
  * @type {ValueGetter}
37
37
  * @memberOf TableColumn
38
38
  */
@@ -40,7 +40,7 @@ export interface TableColumn {
40
40
 
41
41
  /**
42
42
  * Determines if column is checkbox
43
- *
43
+ *
44
44
  * @type {boolean}
45
45
  * @memberOf TableColumn
46
46
  */
@@ -48,7 +48,7 @@ export interface TableColumn {
48
48
 
49
49
  /**
50
50
  * Determines if the column is frozen to the left
51
- *
51
+ *
52
52
  * @type {boolean}
53
53
  * @memberOf TableColumn
54
54
  */
@@ -56,7 +56,7 @@ export interface TableColumn {
56
56
 
57
57
  /**
58
58
  * Determines if the column is frozen to the right
59
- *
59
+ *
60
60
  * @type {boolean}
61
61
  * @memberOf TableColumn
62
62
  */
@@ -64,10 +64,10 @@ export interface TableColumn {
64
64
 
65
65
  /**
66
66
  * The grow factor relative to other columns. Same as the flex-grow
67
- * API from http =//www.w3.org/TR/css3-flexbox/. Basically;
67
+ * API from http =//www.w3.org/TR/css3-flexbox/. Basically;
68
68
  * take any available extra width and distribute it proportionally
69
69
  * according to all columns' flexGrow values.
70
- *
70
+ *
71
71
  * @type {number}
72
72
  * @memberOf TableColumn
73
73
  */
@@ -75,7 +75,7 @@ export interface TableColumn {
75
75
 
76
76
  /**
77
77
  * Min width of the column
78
- *
78
+ *
79
79
  * @type {number}
80
80
  * @memberOf TableColumn
81
81
  */
@@ -83,7 +83,7 @@ export interface TableColumn {
83
83
 
84
84
  /**
85
85
  * Max width of the column
86
- *
86
+ *
87
87
  * @type {number}
88
88
  * @memberOf TableColumn
89
89
  */
@@ -91,7 +91,7 @@ export interface TableColumn {
91
91
 
92
92
  /**
93
93
  * The default width of the column, in pixels
94
- *
94
+ *
95
95
  * @type {number}
96
96
  * @memberOf TableColumn
97
97
  */
@@ -99,7 +99,7 @@ export interface TableColumn {
99
99
 
100
100
  /**
101
101
  * Can the column be resized
102
- *
102
+ *
103
103
  * @type {boolean}
104
104
  * @memberOf TableColumn
105
105
  */
@@ -107,7 +107,7 @@ export interface TableColumn {
107
107
 
108
108
  /**
109
109
  * Custom sort comparator
110
- *
110
+ *
111
111
  * @type {*}
112
112
  * @memberOf TableColumn
113
113
  */
@@ -115,7 +115,7 @@ export interface TableColumn {
115
115
 
116
116
  /**
117
117
  * Custom pipe transforms
118
- *
118
+ *
119
119
  * @type {PipeTransform}
120
120
  * @memberOf TableColumn
121
121
  */
@@ -123,7 +123,7 @@ export interface TableColumn {
123
123
 
124
124
  /**
125
125
  * Can the column be sorted
126
- *
126
+ *
127
127
  * @type {boolean}
128
128
  * @memberOf TableColumn
129
129
  */
@@ -131,7 +131,7 @@ export interface TableColumn {
131
131
 
132
132
  /**
133
133
  * Can the column be re-arranged by dragging
134
- *
134
+ *
135
135
  * @type {boolean}
136
136
  * @memberOf TableColumn
137
137
  */
@@ -139,7 +139,7 @@ export interface TableColumn {
139
139
 
140
140
  /**
141
141
  * Whether the column can automatically resize to fill space in the table.
142
- *
142
+ *
143
143
  * @type {boolean}
144
144
  * @memberOf TableColumn
145
145
  */
@@ -147,7 +147,7 @@ export interface TableColumn {
147
147
 
148
148
  /**
149
149
  * Column name or label
150
- *
150
+ *
151
151
  * @type {string}
152
152
  * @memberOf TableColumn
153
153
  */
@@ -155,11 +155,11 @@ export interface TableColumn {
155
155
 
156
156
  /**
157
157
  * Property to bind to the row. Example:
158
- *
158
+ *
159
159
  * `someField` or `some.field.nested`, 0 (numeric)
160
- *
160
+ *
161
161
  * If left blank, will use the name as camel case conversion
162
- *
162
+ *
163
163
  * @type {TableColumnProp}
164
164
  * @memberOf TableColumn
165
165
  */
@@ -167,7 +167,7 @@ export interface TableColumn {
167
167
 
168
168
  /**
169
169
  * Cell template ref
170
- *
170
+ *
171
171
  * @type {*}
172
172
  * @memberOf TableColumn
173
173
  */
@@ -175,7 +175,7 @@ export interface TableColumn {
175
175
 
176
176
  /**
177
177
  * Header template ref
178
- *
178
+ *
179
179
  * @type {*}
180
180
  * @memberOf TableColumn
181
181
  */
@@ -183,26 +183,41 @@ export interface TableColumn {
183
183
 
184
184
  /**
185
185
  * CSS Classes for the cell
186
- *
187
- *
186
+ *
187
+ *
188
188
  * @memberOf TableColumn
189
189
  */
190
190
  cellClass?: string | ((data: any) => string|any);
191
191
 
192
192
  /**
193
193
  * CSS classes for the header
194
- *
195
- *
194
+ *
195
+ *
196
196
  * @memberOf TableColumn
197
197
  */
198
198
  headerClass?: string | ((data: any) => string|any);
199
199
 
200
200
  /**
201
201
  * Header checkbox enabled
202
- *
202
+ *
203
203
  * @type {boolean}
204
204
  * @memberOf TableColumn
205
205
  */
206
206
  headerCheckboxable?: boolean;
207
207
 
208
+ /**
209
+ * Summary function
210
+ *
211
+ * @type {(cells: any[]) => any}
212
+ * @memberOf TableColumn
213
+ */
214
+ summaryFunc?: (cells: any[]) => any;
215
+
216
+ /**
217
+ * Summary cell template ref
218
+ *
219
+ * @type {*}
220
+ * @memberOf TableColumn
221
+ */
222
+ summaryTemplate?: any;
208
223
  }
@@ -29,7 +29,7 @@ export function setColumnDefaults(columns: TableColumn[]) {
29
29
  if(!isNullOrUndefined(column.prop) && isNullOrUndefined(column.name)) {
30
30
  column.name = deCamelCase(String(column.prop));
31
31
  }
32
-
32
+
33
33
  if(isNullOrUndefined(column.prop) && isNullOrUndefined(column.name)) {
34
34
  column.name = ''; // Fixes IE and Edge displaying `null`
35
35
  }
@@ -82,6 +82,14 @@ export function translateTemplates(templates: DataTableColumnDirective[]): any[]
82
82
  col.cellTemplate = temp.cellTemplate;
83
83
  }
84
84
 
85
+ if(temp.summaryFunc) {
86
+ col.summaryFunc = temp.summaryFunc;
87
+ }
88
+
89
+ if(temp.summaryTemplate) {
90
+ col.summaryTemplate = temp.summaryTemplate;
91
+ }
92
+
85
93
  result.push(col);
86
94
  }
87
95
 
@@ -50,4 +50,48 @@ describe('deepValueGetter', () => {
50
50
  expect(deepValueGetter(data, 'a.b.value')).toEqual(5);
51
51
  });
52
52
 
53
+ it('should get array-element two-level deep', () => {
54
+ let data = {
55
+ a: {
56
+ b: [
57
+ 123
58
+ ]
59
+ }
60
+ };
61
+ expect(deepValueGetter(data, 'a.b.0')).toEqual(123);
62
+
63
+ });
64
+
65
+ it('should get value of object inside an array-element', () => {
66
+ let data = {
67
+ a: {
68
+ b: [
69
+ {c: 123}
70
+ ]
71
+ }
72
+ };
73
+ expect(deepValueGetter(data, 'a.b.0.c')).toEqual(123);
74
+ });
75
+ it('should get value of object inside a double array-element', () => {
76
+ let data = {
77
+ a: {
78
+ b: [
79
+ [
80
+ 123
81
+ ]
82
+ ]
83
+ }
84
+ };
85
+ expect(deepValueGetter(data, 'a.b.0.0')).toEqual(123);
86
+ });
87
+
88
+
89
+ it('should check for root-level fields with square brackets in name', () => {
90
+ let data = {
91
+ 'a.b.1.value': 5
92
+ };
93
+ expect(deepValueGetter(data, 'a.b.1.value')).toEqual(5);
94
+ });
95
+
96
+
53
97
  });
@@ -76,15 +76,3 @@ export function columnsByPinArr(val: any) {
76
76
 
77
77
  return colsByPinArr;
78
78
  }
79
-
80
- export function allColumnsByPinArr(val: any) {
81
- const colsByPinArr = [];
82
- const colsByPin = columnsByPin(val);
83
- const colsTest = [];
84
-
85
- colsByPinArr.push({ type: 'left', columns: colsByPin['left'] });
86
- colsByPinArr.push({ type: 'center', columns: colsByPin['center'] });
87
- colsByPinArr.push({ type: 'right', columns: colsByPin['right'] });
88
-
89
- return colsByPinArr;
90
- }
package/src/utils/math.ts CHANGED
@@ -36,7 +36,7 @@ function scaleColumns(colsByGroup: any, maxWidth: any, totalFlexGrow: any) {
36
36
  for(const column of colsByGroup[attr]) {
37
37
  if (!column.canAutoResize) {
38
38
  maxWidth -= column.width;
39
- totalFlexGrow -= column.flexGrow;
39
+ totalFlexGrow -= column.flexGrow ? column.flexGrow : 0;
40
40
  } else {
41
41
  column.width = 0;
42
42
  }
package/test/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './jasmine-matchers';
@@ -0,0 +1,12 @@
1
+ declare namespace jasmine {
2
+ interface Matchers<T> {
3
+ toHaveText(actual: any, expectationFailOutput?: any): jasmine.CustomMatcher;
4
+ toHaveCssClass(expected: any): boolean;
5
+ }
6
+ }
7
+
8
+ /*
9
+ Copyright 2017-2018 Google Inc. All Rights Reserved.
10
+ Use of this source code is governed by an MIT-style license that
11
+ can be found in the LICENSE file at http://angular.io/license
12
+ */
@@ -0,0 +1,70 @@
1
+ /// <reference path="./jasmine-matchers.d.ts" />
2
+
3
+ export const addMatchers = () => jasmine.addMatchers({
4
+ toHaveText, toHaveCssClass
5
+ });
6
+
7
+ /**
8
+ * `toHaveText()` adapted from https://angular.io/guide/testing
9
+ */
10
+ function toHaveText(): jasmine.CustomMatcher {
11
+ return {
12
+ compare(
13
+ actual: any,
14
+ expectedText: string,
15
+ expectationFailOutput?: any
16
+ ): jasmine.CustomMatcherResult {
17
+ const actualText = elementText(actual);
18
+ const pass = actualText.indexOf(expectedText) > -1;
19
+ const message = pass ? '' : composeMessage();
20
+ return { pass, message };
21
+
22
+ function composeMessage() {
23
+ const a =
24
+ actualText.length < 100
25
+ ? actualText
26
+ : actualText.substr(0, 100) + '...';
27
+ const efo = expectationFailOutput ? ` '${expectationFailOutput}'` : '';
28
+ return `Expected element to have text content '${expectedText}' instead of '${a}'${efo}`;
29
+ }
30
+ }
31
+ };
32
+ }
33
+
34
+ function elementText(n: any): string {
35
+ if (n instanceof Array) {
36
+ return n.map(elementText).join('');
37
+ }
38
+
39
+ if (n.nodeType === Node.COMMENT_NODE) {
40
+ return '';
41
+ }
42
+
43
+ if (n.nodeType === Node.ELEMENT_NODE && n.hasChildNodes()) {
44
+ return elementText(Array.prototype.slice.call(n.childNodes));
45
+ }
46
+
47
+ if (n.nativeElement) {
48
+ n = n.nativeElement;
49
+ }
50
+
51
+ return n.textContent;
52
+ }
53
+
54
+ /**
55
+ * adapted from https://github.com/ng-bootstrap/ng-bootstrap/blob/master/src/test/matchers.ts
56
+ */
57
+ function toHaveCssClass(util, customEqualityTests) {
58
+ return { compare: buildError(false), negativeCompare: buildError(true) };
59
+
60
+ function buildError(isNot: boolean) {
61
+ return function(actual: HTMLElement, className: string) {
62
+ return {
63
+ pass: actual.classList.contains(className) === !isNot,
64
+ message: `Expected ${actual.outerHTML} ${
65
+ isNot ? 'not ' : ''
66
+ }to contain the CSS class "${className}"`
67
+ };
68
+ };
69
+ }
70
+ }
package/tslint.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "tslint-config-swimlane/base",
2
+ "extends": "tslint-config-swimlane/base.json",
3
3
  "rulesDirectory": [],
4
4
  "rules": {
5
5
  "prefer-conditional-expression": false