ngx-promise-buttons 1.0.1 → 1.0.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 (53) hide show
  1. package/fesm2022/ngx-promise-buttons.mjs +243 -0
  2. package/fesm2022/ngx-promise-buttons.mjs.map +1 -0
  3. package/package.json +38 -87
  4. package/types/ngx-promise-buttons.d.ts +76 -0
  5. package/.editorconfig +0 -13
  6. package/.github/FUNDING.yml +0 -12
  7. package/.travis.yml +0 -21
  8. package/CHANGELOG.md +0 -0
  9. package/CONTRIBUTING.md +0 -36
  10. package/angular.json +0 -180
  11. package/e2e/protractor.conf.js +0 -32
  12. package/e2e/src/app.e2e-spec.ts +0 -23
  13. package/e2e/src/app.po.ts +0 -11
  14. package/e2e/tsconfig.json +0 -13
  15. package/logo.png +0 -0
  16. package/projects/ngx-promise-buttons/karma.conf.js +0 -32
  17. package/projects/ngx-promise-buttons/ng-package.json +0 -10
  18. package/projects/ngx-promise-buttons/package.json +0 -26
  19. package/projects/ngx-promise-buttons/src/default-promise-btn-config.ts +0 -10
  20. package/projects/ngx-promise-buttons/src/index.ts +0 -2
  21. package/projects/ngx-promise-buttons/src/promise-btn-config.ts +0 -7
  22. package/projects/ngx-promise-buttons/src/promise-btn.directive.spec.ts +0 -597
  23. package/projects/ngx-promise-buttons/src/promise-btn.directive.ts +0 -247
  24. package/projects/ngx-promise-buttons/src/provider.ts +0 -14
  25. package/projects/ngx-promise-buttons/src/test.ts +0 -16
  26. package/projects/ngx-promise-buttons/src/user-cfg.ts +0 -3
  27. package/projects/ngx-promise-buttons/tsconfig.lib.json +0 -27
  28. package/projects/ngx-promise-buttons/tsconfig.lib.prod.json +0 -10
  29. package/projects/ngx-promise-buttons/tsconfig.spec.json +0 -17
  30. package/projects/ngx-promise-buttons/tslint.json +0 -25
  31. package/projects/ngx-promise-buttons/yarn.lock +0 -9
  32. package/projects/ngx-promise-buttons-demo/e2e/protractor.conf.js +0 -30
  33. package/projects/ngx-promise-buttons-demo/e2e/tsconfig.json +0 -14
  34. package/projects/ngx-promise-buttons-demo/karma.conf.js +0 -56
  35. package/projects/ngx-promise-buttons-demo/src/app/app.component.css +0 -6
  36. package/projects/ngx-promise-buttons-demo/src/app/app.component.html +0 -109
  37. package/projects/ngx-promise-buttons-demo/src/app/app.component.spec.ts +0 -29
  38. package/projects/ngx-promise-buttons-demo/src/app/app.component.ts +0 -208
  39. package/projects/ngx-promise-buttons-demo/src/assets/.gitkeep +0 -0
  40. package/projects/ngx-promise-buttons-demo/src/environments/environment.prod.ts +0 -3
  41. package/projects/ngx-promise-buttons-demo/src/environments/environment.ts +0 -8
  42. package/projects/ngx-promise-buttons-demo/src/favicon.ico +0 -0
  43. package/projects/ngx-promise-buttons-demo/src/index.html +0 -72
  44. package/projects/ngx-promise-buttons-demo/src/main.ts +0 -11
  45. package/projects/ngx-promise-buttons-demo/src/polyfills.ts +0 -63
  46. package/projects/ngx-promise-buttons-demo/src/styles.scss +0 -135
  47. package/projects/ngx-promise-buttons-demo/tsconfig.app.json +0 -14
  48. package/projects/ngx-promise-buttons-demo/tsconfig.spec.json +0 -18
  49. package/projects/ngx-promise-buttons-demo/tslint.json +0 -156
  50. package/scripts/copy-readme-to-demo.js +0 -15
  51. package/tsconfig.build-lib.json +0 -32
  52. package/tsconfig.json +0 -41
  53. package/wallaby.js +0 -90
@@ -1,597 +0,0 @@
1
- // import 'core-js/fn/object/entries';
2
- import {Component, DebugElement, ElementRef} from '@angular/core';
3
- import {async, ComponentFixture, TestBed} from '@angular/core/testing';
4
- import {PromiseBtnDirective} from './promise-btn.directive';
5
- import {userCfg} from './user-cfg';
6
- import {By} from '@angular/platform-browser';
7
- import {Observable} from 'rxjs';
8
- import {delay} from 'rxjs/operators';
9
- import * as BlueBird from 'bluebird';
10
- import * as jQuery from 'jquery';
11
-
12
- class MockElementRef extends ElementRef {
13
- constructor() {
14
- super(null);
15
- this.nativeElement = {};
16
- }
17
- }
18
-
19
- @Component({
20
- selector: 'test-component',
21
- template: '',
22
- standalone: false
23
- })
24
- class TestComponent {
25
- testPromise: any;
26
- setPromise: any;
27
- isDisabled: any;
28
- }
29
-
30
-
31
- let testUserCfg: any;
32
-
33
- describe('PromiseBtnDirective', () => {
34
- beforeEach(async(() => {
35
- testUserCfg = {};
36
- TestBed.configureTestingModule({
37
- declarations: [
38
- TestComponent,
39
- PromiseBtnDirective
40
- ],
41
- providers: [
42
- // more providers
43
- {
44
- provide: ElementRef,
45
- useClass: MockElementRef
46
- },
47
- {
48
- provide: userCfg, useValue: testUserCfg
49
- },
50
- ]
51
- });
52
- }));
53
-
54
- describe('runtimeCfg', () => {
55
- let fixture: ComponentFixture<TestComponent>;
56
- let buttonDebugElement: DebugElement;
57
- let buttonElement: HTMLButtonElement;
58
- let promiseBtnDirective: PromiseBtnDirective;
59
-
60
- beforeEach(() => {
61
- fixture = TestBed.overrideComponent(TestComponent, {
62
- set: {
63
- template: '<button (click)="setPromise && setPromise();" [promiseBtn]="testPromise">BUTTON_TEXT</button>'
64
- }
65
- }).createComponent(TestComponent);
66
- fixture.detectChanges();
67
-
68
- buttonDebugElement = fixture.debugElement.query(By.css('button'));
69
- buttonElement = (buttonDebugElement.nativeElement as HTMLButtonElement);
70
- promiseBtnDirective = buttonDebugElement.injector.get<PromiseBtnDirective>(PromiseBtnDirective);
71
- });
72
-
73
- describe('default cfg', () => {
74
- describe('basic init', () => {
75
- it('should create an instance', () => {
76
- expect(promiseBtnDirective).toBeDefined();
77
- expect(promiseBtnDirective.cfg).toBeDefined();
78
- // const directive = new PromiseBtnDirective({}, {});
79
- // expect(directive).toBeTruthy();
80
- });
81
- it('should append the spinner el to the button', () => {
82
- const spinnerEl = buttonElement.querySelector('span');
83
- expect(spinnerEl && spinnerEl.outerHTML).toBe('<span class="btn-spinner"></span>');
84
- });
85
- describe('should accept all promise-alike values', () => {
86
- const possibleValues = {
87
- 'native Promise': () => new Promise((resolve) => {
88
- resolve();
89
- }),
90
- 'jQuery Deferred': () => jQuery.Deferred((defer: any) => {
91
- defer.resolve();
92
- }),
93
- 'jQuery Deferred Promise': () => jQuery.Deferred((defer: any) => {
94
- defer.resolve();
95
- }).promise(),
96
- 'bluebird Promise': () => new BlueBird((resolve) => {
97
- resolve();
98
- }),
99
- 'RxJs Observable': () => {
100
- const observable = new Observable((subscriber) => {
101
- subscriber.complete();
102
- });
103
-
104
- return observable.pipe(delay(0)).subscribe(
105
- () => {
106
- },
107
- () => {
108
- },
109
- () => {
110
- },
111
- );
112
- },
113
- };
114
-
115
- // Iterate over possible values
116
- for (const [description, getPromise] of (Object as any).entries(possibleValues)) {
117
- describe(`testing ${description}`, () => {
118
- beforeEach(() => {
119
- fixture.componentInstance.testPromise = getPromise();
120
- // test init before to be sure
121
- spyOn(promiseBtnDirective, 'initLoadingState').and.callThrough();
122
- fixture.detectChanges();
123
- });
124
-
125
- it('should init the loading state', () => {
126
- expect(promiseBtnDirective.initLoadingState).toHaveBeenCalled();
127
- });
128
- });
129
- }
130
- });
131
- it('should convert RxJs Observable Subscription to Promise', () => {
132
- const observable = new Observable((subscriber) => {
133
- subscriber.complete();
134
- });
135
- fixture.componentInstance.testPromise = observable.pipe(delay(0)).subscribe(
136
- () => {
137
- },
138
- () => {
139
- },
140
- () => {
141
- },
142
- );
143
- fixture.detectChanges();
144
- expect(promiseBtnDirective.promise instanceof Promise).toBe(true);
145
- });
146
- it('should throw an error if an observable is passed directly', () => {
147
- const observable = new Observable((subscriber) => {
148
- subscriber.complete();
149
- });
150
- fixture.componentInstance.testPromise = observable;
151
-
152
- expect(() => {
153
- fixture.detectChanges();
154
- }).toThrowError('promiseBtn must be an instance of Subscription, instance of Observable given');
155
- });
156
- it('should do nothing with a closed subscription', () => {
157
- spyOn(promiseBtnDirective, 'initLoadingState');
158
-
159
- const observable = new Observable((subscriber) => {
160
- subscriber.complete();
161
- });
162
- // subscription will immediately complete and close
163
- fixture.componentInstance.testPromise = observable.subscribe(
164
- () => {
165
- },
166
- () => {
167
- },
168
- () => {
169
- },
170
- );
171
- fixture.detectChanges();
172
-
173
- expect(promiseBtnDirective.promise).toBe(undefined);
174
- expect(promiseBtnDirective.initLoadingState).not.toHaveBeenCalled();
175
- });
176
- });
177
-
178
- describe('when promise is passed after click', () => {
179
- beforeEach(() => {
180
- fixture.componentInstance.setPromise = () => {
181
- fixture.componentInstance.testPromise = new Promise(() => {
182
- });
183
- };
184
- fixture.detectChanges();
185
-
186
- // remove initial promise
187
- fixture.componentInstance.testPromise = null;
188
- fixture.detectChanges();
189
-
190
- // test init before to be sure
191
- spyOn(promiseBtnDirective, 'initLoadingState').and.callThrough();
192
- fixture.detectChanges();
193
-
194
- buttonDebugElement.triggerEventHandler('click', null);
195
- fixture.detectChanges();
196
- });
197
-
198
- it('should init the loading state', () => {
199
- expect(promiseBtnDirective.initLoadingState).toHaveBeenCalled();
200
- });
201
- it('should add .is-loading class', async(() => {
202
- fixture.whenStable().then(() => {
203
- expect(buttonElement.className).toBe('is-loading');
204
- });
205
- }));
206
- it('should disable the button', async(() => {
207
- fixture.whenStable().then(() => {
208
- expect(buttonElement.getAttribute('disabled')).toBe('disabled');
209
- });
210
- }));
211
- });
212
-
213
- describe('once a promise is passed', () => {
214
- beforeEach(() => {
215
- fixture.componentInstance.testPromise = new Promise(() => {
216
- });
217
- spyOn(promiseBtnDirective, 'initLoadingState').and.callThrough();
218
- fixture.detectChanges();
219
- });
220
-
221
- it('should init the loading state', () => {
222
- expect(promiseBtnDirective.initLoadingState).toHaveBeenCalled();
223
- });
224
- it('should add .is-loading class', async(() => {
225
- fixture.whenStable().then(() => {
226
- expect(buttonElement.className).toBe('is-loading');
227
- });
228
- }));
229
- it('should disable the button', async(() => {
230
- fixture.whenStable().then(() => {
231
- expect(buttonElement.getAttribute('disabled')).toBe('disabled');
232
- });
233
- }));
234
- });
235
-
236
- describe('once a passed promise is resolved', () => {
237
- let promise;
238
- let resolve: any;
239
- beforeEach(async(() => {
240
- promise = new Promise((res) => {
241
- resolve = res;
242
- });
243
- fixture.componentInstance.testPromise = promise;
244
-
245
- // test init before to be sure
246
- spyOn(promiseBtnDirective, 'initLoadingState').and.callThrough();
247
- fixture.detectChanges();
248
- expect(promiseBtnDirective.initLoadingState).toHaveBeenCalled();
249
-
250
- fixture.whenStable().then(() => {
251
- spyOn(promiseBtnDirective, 'cancelLoadingStateIfPromiseAndMinDurationDone').and.callThrough();
252
- resolve();
253
- });
254
- fixture.detectChanges();
255
- }));
256
-
257
- it('should cancel the loading state', () => {
258
- expect(promiseBtnDirective.cancelLoadingStateIfPromiseAndMinDurationDone).toHaveBeenCalled();
259
- });
260
- it('should remove the .is-loading class', () => {
261
- expect(buttonElement.className).toBe('');
262
- });
263
- it('should enable the button', () => {
264
- expect(buttonElement.hasAttribute('disabled')).toBe(false);
265
- });
266
- });
267
-
268
- describe('once a passed promise is rejected', () => {
269
- let promise;
270
- let reject: any;
271
- beforeEach(async(() => {
272
- promise = new Promise((res, rej) => {
273
- reject = rej;
274
- });
275
- fixture.componentInstance.testPromise = promise;
276
-
277
- // test init before to be sure
278
- spyOn(promiseBtnDirective, 'initLoadingState').and.callThrough();
279
- fixture.detectChanges();
280
- expect(promiseBtnDirective.initLoadingState).toHaveBeenCalled();
281
-
282
- fixture.whenStable().then(() => {
283
- spyOn(promiseBtnDirective, 'cancelLoadingStateIfPromiseAndMinDurationDone').and.callThrough();
284
- reject();
285
- });
286
- fixture.detectChanges();
287
- }));
288
-
289
- it('should cancel the loading state', () => {
290
- expect(promiseBtnDirective.cancelLoadingStateIfPromiseAndMinDurationDone).toHaveBeenCalled();
291
- });
292
- it('should remove the .is-loading class', () => {
293
- expect(buttonElement.className).toBe('');
294
- });
295
- it('should enable the button', () => {
296
- expect(buttonElement.hasAttribute('disabled')).toBe(false);
297
- });
298
- });
299
-
300
- describe('should do nothing when anything else than a promise is passed', () => {
301
- const possibleValues = {
302
- undefined,
303
- null: null,
304
- boolean: false,
305
- number: 1,
306
- NaN,
307
- array: [],
308
- object: {},
309
- 'object, "then" is not a function': {then: true},
310
- 'object, "then" is invalid function': {
311
- then: () => {
312
- }
313
- },
314
- };
315
-
316
- // Iterate over possible values
317
- for (const [description, promise] of (Object as any).entries(possibleValues)) {
318
- describe(`testing ${description}`, () => {
319
- beforeEach(() => {
320
- fixture.componentInstance.testPromise = promise;
321
- // test init before to be sure
322
- spyOn(promiseBtnDirective, 'initLoadingState').and.callThrough();
323
- fixture.detectChanges();
324
- });
325
-
326
- it('should cancel the loading state', () => {
327
- expect(promiseBtnDirective.initLoadingState).not.toHaveBeenCalled();
328
- });
329
- it('should remove the .is-loading class', () => {
330
- expect(buttonElement.className).toBe('');
331
- });
332
- it('should enable the button', () => {
333
- expect(buttonElement.hasAttribute('disabled')).toBe(false);
334
- });
335
- });
336
- }
337
- });
338
- });
339
-
340
- describe('cfg:minDuration', () => {
341
- describe('once a passed promise is resolved but minDuration has not been exceeded', () => {
342
- let promise;
343
- let resolve: any;
344
- beforeEach((done) => {
345
- promiseBtnDirective.cfg.minDuration = 300;
346
- promise = new Promise((res) => {
347
- resolve = res;
348
- });
349
- fixture.componentInstance.testPromise = promise;
350
-
351
- // test init before to be sure
352
- spyOn(promiseBtnDirective, 'initLoadingState').and.callThrough();
353
- fixture.detectChanges();
354
- expect(promiseBtnDirective.initLoadingState).toHaveBeenCalled();
355
-
356
- spyOn(promiseBtnDirective, 'cancelLoadingStateIfPromiseAndMinDurationDone').and.callThrough();
357
- setTimeout(() => {
358
- resolve();
359
- setTimeout(() => {
360
- done();
361
- }, 10);
362
- }, 10);
363
- });
364
-
365
- it('should try to cancel the loading state', () => {
366
- expect(promiseBtnDirective.cancelLoadingStateIfPromiseAndMinDurationDone).toHaveBeenCalled();
367
- });
368
- it('should not yet remove the .is-loading class', () => {
369
- expect(buttonElement.className).toBe('is-loading');
370
- });
371
- it('should not yet enable the button', () => {
372
- expect(buttonElement.hasAttribute('disabled')).toBe(true);
373
- });
374
- });
375
-
376
- describe('once a passed promise is resolved and the minDuration has been exceeded', () => {
377
- let promise;
378
- let resolve: any;
379
- beforeEach((done) => {
380
- promiseBtnDirective.cfg.minDuration = 30;
381
- promise = new Promise((res) => {
382
- resolve = res;
383
- });
384
- fixture.componentInstance.testPromise = promise;
385
-
386
- // test init before to be sure
387
- spyOn(promiseBtnDirective, 'initLoadingState').and.callThrough();
388
- fixture.detectChanges();
389
- expect(promiseBtnDirective.initLoadingState).toHaveBeenCalled();
390
-
391
- spyOn(promiseBtnDirective, 'cancelLoadingStateIfPromiseAndMinDurationDone').and.callThrough();
392
- setTimeout(() => {
393
- resolve();
394
- setTimeout(() => {
395
- done();
396
- }, ((promiseBtnDirective.cfg.minDuration as number) + 5));
397
- }, 10);
398
- });
399
-
400
- it('should try to cancel the loading state', () => {
401
- expect(promiseBtnDirective.cancelLoadingStateIfPromiseAndMinDurationDone).toHaveBeenCalled();
402
- });
403
- it('should remove the .is-loading class', () => {
404
- expect(buttonElement.className).toBe('');
405
- });
406
- it('should enable the button', () => {
407
- expect(buttonElement.hasAttribute('disabled')).toBe(false);
408
- });
409
- });
410
- });
411
-
412
- describe('cfg:disableBtn:false once a promise is passed', () => {
413
- beforeEach(() => {
414
- promiseBtnDirective.cfg.disableBtn = false;
415
- fixture.componentInstance.testPromise = new Promise(() => {
416
- });
417
- spyOn(promiseBtnDirective, 'initLoadingState').and.callThrough();
418
- fixture.detectChanges();
419
- });
420
-
421
- it('should init the loading state', () => {
422
- expect(promiseBtnDirective.initLoadingState).toHaveBeenCalled();
423
- });
424
- it('should NOT disable the button', async(() => {
425
- expect(buttonElement.hasAttribute('disabled')).toBe(false);
426
- }));
427
- });
428
-
429
- describe('cfg:btnLoadingClass once a promise is passed', () => {
430
- it('should add a custom loading class', async(() => {
431
- spyOn(promiseBtnDirective, 'addLoadingClass').and.callThrough();
432
- promiseBtnDirective.cfg.btnLoadingClass = 'TEST';
433
-
434
- fixture.componentInstance.testPromise = new Promise(() => {
435
- });
436
- fixture.detectChanges();
437
-
438
- fixture.whenStable().then(() => {
439
- expect(promiseBtnDirective.addLoadingClass).toHaveBeenCalled();
440
- expect(buttonElement.className).toBe('TEST');
441
- });
442
- }));
443
- it('should not add a loading class if set to false', async(() => {
444
- spyOn(promiseBtnDirective, 'addLoadingClass').and.callThrough();
445
-
446
- promiseBtnDirective.cfg.btnLoadingClass = false;
447
- fixture.componentInstance.testPromise = new Promise(() => {
448
- });
449
- fixture.detectChanges();
450
-
451
- fixture.whenStable().then(() => {
452
- expect(buttonElement.className).toBe('');
453
- });
454
- }));
455
- });
456
- });
457
-
458
- describe('cfg:handleCurrentBtnOnly', () => {
459
- let fixture: ComponentFixture<TestComponent>;
460
- let buttonDebugElement: DebugElement;
461
- let divDebugElement: DebugElement;
462
- let buttonElement: HTMLButtonElement;
463
- let divElement: HTMLDivElement;
464
- let promiseBtnDirective1: PromiseBtnDirective;
465
- let promiseBtnDirective2: PromiseBtnDirective;
466
-
467
- beforeEach(() => {
468
- testUserCfg.handleCurrentBtnOnly = true;
469
-
470
- fixture = TestBed.overrideComponent(TestComponent, {
471
- set: {
472
- template: '<button [promiseBtn]="testPromise">1</button><div [promiseBtn]="testPromise">2</div>'
473
- }
474
- }).createComponent(TestComponent);
475
- fixture.detectChanges();
476
- buttonDebugElement = fixture.debugElement.query(By.css('button'));
477
- divDebugElement = fixture.debugElement.query(By.css('div'));
478
- buttonElement = (buttonDebugElement.nativeElement as HTMLButtonElement);
479
- divElement = (divDebugElement.nativeElement as HTMLDivElement);
480
- promiseBtnDirective1 = buttonDebugElement.injector.get<PromiseBtnDirective>(PromiseBtnDirective);
481
- promiseBtnDirective2 = divDebugElement.injector.get<PromiseBtnDirective>(PromiseBtnDirective);
482
- fixture.detectChanges();
483
-
484
- promiseBtnDirective1.cfg.handleCurrentBtnOnly = true;
485
- promiseBtnDirective2.cfg.handleCurrentBtnOnly = true;
486
-
487
- fixture.componentInstance.testPromise = new Promise(() => {
488
- });
489
-
490
- spyOn(promiseBtnDirective1, 'initLoadingState').and.callThrough();
491
- spyOn(promiseBtnDirective2, 'initLoadingState').and.callThrough();
492
- spyOn(promiseBtnDirective1, 'handleCurrentBtnOnly').and.callThrough();
493
- fixture.detectChanges();
494
- });
495
-
496
- it('should cancel the click handler when handleCurrentBtnOnly is false', async(() => {
497
- promiseBtnDirective1.cfg.handleCurrentBtnOnly = false;
498
- buttonElement.click();
499
- fixture.detectChanges();
500
-
501
- fixture.whenStable().then(() => {
502
- expect(promiseBtnDirective1.handleCurrentBtnOnly()).toBe(true);
503
- expect(promiseBtnDirective1.initLoadingState).not.toHaveBeenCalled();
504
- });
505
- }));
506
-
507
- it('should set loading state for first button when clicked, but not for second', async(() => {
508
- buttonElement.click();
509
- fixture.detectChanges();
510
- fixture.whenStable().then(() => {
511
- expect(promiseBtnDirective1.initLoadingState).toHaveBeenCalled();
512
- expect(promiseBtnDirective2.initLoadingState).not.toHaveBeenCalled();
513
- });
514
- }));
515
-
516
- it('should set loading state for second button when clicked, but not for first', async(() => {
517
- divElement.click();
518
- fixture.detectChanges();
519
- fixture.whenStable().then(() => {
520
- expect(promiseBtnDirective1.initLoadingState).not.toHaveBeenCalled();
521
- expect(promiseBtnDirective2.initLoadingState).toHaveBeenCalled();
522
- });
523
- }));
524
-
525
- it('should set loading state when promise is set after click', async(() => {
526
- const setPromise = () => {
527
- fixture.componentInstance.testPromise = new Promise(() => {
528
- });
529
- };
530
-
531
- // remove initial promise
532
- fixture.componentInstance.testPromise = null;
533
- fixture.detectChanges();
534
-
535
- // add promise on click
536
- buttonElement.addEventListener('click', setPromise);
537
- fixture.detectChanges();
538
-
539
- buttonElement.click();
540
- fixture.detectChanges();
541
-
542
- fixture.whenStable().then(() => {
543
- expect(promiseBtnDirective1.initLoadingState).toHaveBeenCalled();
544
-
545
- // cleanup
546
- buttonElement.removeEventListener('click', setPromise);
547
- });
548
- }));
549
- });
550
-
551
- describe('cfg before runtime', () => {
552
- let fixture: ComponentFixture<TestComponent>;
553
- let buttonDebugElement: DebugElement;
554
- let buttonElement: HTMLButtonElement;
555
- let promiseBtnDirective: PromiseBtnDirective;
556
-
557
- describe('cfg:spinnerTpl', () => {
558
- it('should add a custom template from config', () => {
559
- testUserCfg.spinnerTpl = '<div class="test">loading</div>';
560
-
561
- fixture = TestBed.overrideComponent(TestComponent, {
562
- set: {
563
- template: '<button [promiseBtn]="testPromise">BUTTON_TEXT</button>'
564
- }
565
- }).createComponent(TestComponent);
566
- fixture.detectChanges();
567
- buttonDebugElement = fixture.debugElement.query(By.css('button'));
568
- buttonElement = (buttonDebugElement.nativeElement as HTMLButtonElement);
569
- promiseBtnDirective = buttonDebugElement.injector.get<PromiseBtnDirective>(PromiseBtnDirective);
570
- fixture.detectChanges();
571
-
572
- const spinnerEl = buttonElement.querySelector('div');
573
- expect(spinnerEl && spinnerEl.outerHTML).toBe('<div class="test">loading</div>');
574
- });
575
- });
576
- });
577
-
578
-
579
- describe('simple boolean', () => {
580
- let fixture: ComponentFixture<TestComponent>;
581
-
582
- it('should not remove', () => {
583
- fixture = TestBed.overrideComponent(TestComponent, {
584
- set: {
585
- template: '<button [promiseBtn]="testPromise" [disabled]="isDisabled">BUTTON_TEXT</button>'
586
- }
587
- }).createComponent(TestComponent);
588
- const buttonDebugElement = fixture.debugElement.query(By.css('button'));
589
- const buttonElement = (buttonDebugElement.nativeElement as HTMLButtonElement);
590
- fixture.componentInstance.isDisabled = true;
591
-
592
- fixture.detectChanges();
593
- expect(buttonElement.hasAttribute('disabled')).toBe(true);
594
- });
595
- });
596
- });
597
-