|
9 | 9 | import {PLATFORM_ID} from '@angular/core';
|
10 | 10 | import {TestBed} from '@angular/core/testing';
|
11 | 11 | import {NgswCommChannel} from '@angular/service-worker/src/low_level';
|
12 |
| -import {SwRegistrationOptions, ngswCommChannelFactory} from '@angular/service-worker/src/module'; |
| 12 | +import {ServiceWorkerModule, SwRegistrationOptions, ngswCommChannelFactory} from '@angular/service-worker/src/module'; |
13 | 13 | import {SwPush} from '@angular/service-worker/src/push';
|
14 | 14 | import {SwUpdate} from '@angular/service-worker/src/update';
|
15 | 15 | import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockServiceWorkerRegistration, patchDecodeBase64} from '@angular/service-worker/testing/mock';
|
@@ -47,6 +47,45 @@ import {async_fit, async_it} from './async';
|
47 | 47 | });
|
48 | 48 | });
|
49 | 49 |
|
| 50 | + describe('ServiceWorkerModule config', () => { |
| 51 | + it('SwUpdate isEnabled is false when configuring via static method', () => { |
| 52 | + TestBed.configureTestingModule( |
| 53 | + {imports: [ServiceWorkerModule.register('', {enabled: false})]}); |
| 54 | + |
| 55 | + expect(TestBed.get(SwUpdate).isEnabled).toEqual(false); |
| 56 | + }); |
| 57 | + |
| 58 | + it('SwUpdate isEnabled is true when configuring via static method', () => { |
| 59 | + TestBed.configureTestingModule({ |
| 60 | + imports: [ServiceWorkerModule.register('', {enabled: true})], |
| 61 | + providers: [{provide: NgswCommChannel, useValue: comm}] |
| 62 | + }); |
| 63 | + |
| 64 | + expect(TestBed.get(SwUpdate).isEnabled).toEqual(true); |
| 65 | + }); |
| 66 | + |
| 67 | + it('SwUpdate isEnabled is false when configuring directly via token', () => { |
| 68 | + TestBed.configureTestingModule({ |
| 69 | + imports: [ServiceWorkerModule.register('')], |
| 70 | + providers: [{provide: SwRegistrationOptions, useFactory: () => ({enabled: false})}] |
| 71 | + }); |
| 72 | + |
| 73 | + expect(TestBed.get(SwUpdate).isEnabled).toEqual(false); |
| 74 | + }); |
| 75 | + |
| 76 | + it('SwUpdate isEnabled is true when configuring directly via token', () => { |
| 77 | + TestBed.configureTestingModule({ |
| 78 | + imports: [ServiceWorkerModule.register('')], |
| 79 | + providers: [ |
| 80 | + {provide: NgswCommChannel, useValue: comm}, |
| 81 | + {provide: SwRegistrationOptions, useFactory: () => ({enabled: true})} |
| 82 | + ] |
| 83 | + }); |
| 84 | + |
| 85 | + expect(TestBed.get(SwUpdate).isEnabled).toEqual(true); |
| 86 | + }); |
| 87 | + }); |
| 88 | + |
50 | 89 | describe('ngswCommChannelFactory', () => {
|
51 | 90 | it('gives disabled NgswCommChannel for platform-server', () => {
|
52 | 91 | TestBed.configureTestingModule({
|
|
0 commit comments