aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/resolvers/flag/flag.resolver.spec.ts
blob: 930562ce0368b1a5a16fd35dde45e2b710b34bf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import {TestBed, getTestBed} from '@angular/core/testing';
import {
  HttpClientTestingModule,
  HttpTestingController
} from '@angular/common/http/testing';
import {NgRedux} from "@angular-redux/store";
import {FeatureFlagsService} from "../../services/featureFlag/feature-flags.service";
import {ActivatedRouteSnapshot, convertToParamMap} from "@angular/router";
import {FlagsResolve} from "./flag.resolver";
import {ConfigurationService} from "../../services/configuration.service";

class MockAppStore<T> {
  getState() {
    return {
      service: {
        serviceInstance: {}
      }
    }
  }
}


describe('Flag resolver', () => {
  let injector;
  let resolver: FlagsResolve;
  let configurationService: ConfigurationService;
  let httpMock: HttpTestingController;

  let activatedRouteSnapshot: ActivatedRouteSnapshot;
  beforeAll(done => (async () => {
    TestBed.configureTestingModule({
      imports: [HttpClientTestingModule],
      providers: [
        FlagsResolve,
        ConfigurationService,
        FeatureFlagsService,
        {provide: NgRedux, useClass: MockAppStore},
        {
          provide: ActivatedRouteSnapshot, useValue: {
            queryParamMap:
              convertToParamMap({ })
          }
        },
      ]
    });
    await TestBed.compileComponents();

    injector = getTestBed();
    resolver = injector.get(FlagsResolve);
    httpMock = injector.get(HttpTestingController);
    activatedRouteSnapshot = injector.get(ActivatedRouteSnapshot);
    configurationService = injector.get(ConfigurationService);

  })().then(done).catch(done.fail));

  test('should update flags', () => {
    spyOn(configurationService, 'getFlags');
    resolver.resolve(activatedRouteSnapshot);
    expect(configurationService.getFlags).toHaveBeenCalled();
  });
});