Skip to content

Commit

Permalink
refactor: correctly select transfer state in configuration effects
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi committed Oct 19, 2020
1 parent f45c6a0 commit e6e7041
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PLATFORM_ID } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { BrowserTransferStateModule } from '@angular/platform-browser';
import { ROOT_EFFECTS_INIT } from '@ngrx/effects';
import { provideMockActions } from '@ngrx/effects/testing';
import { Action } from '@ngrx/store';
Expand All @@ -23,7 +24,7 @@ describe('Configuration Effects', () => {
translateServiceMock = mock(TranslateService);

TestBed.configureTestingModule({
imports: [CoreStoreModule.forTesting(['configuration'], [ConfigurationEffects])],
imports: [BrowserTransferStateModule, CoreStoreModule.forTesting(['configuration'], [ConfigurationEffects])],
providers: [
ConfigurationEffects,
{ provide: TranslateService, useFactory: () => instance(translateServiceMock) },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isPlatformBrowser, isPlatformServer } from '@angular/common';
import { ApplicationRef, Inject, Injectable, Optional, PLATFORM_ID } from '@angular/core';
import { ApplicationRef, Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { TransferState } from '@angular/platform-browser';
import { Actions, ROOT_EFFECTS_INIT, createEffect, ofType } from '@ngrx/effects';
import { Store, select } from '@ngrx/store';
Expand All @@ -23,7 +23,7 @@ export class ConfigurationEffects {
private store: Store,
private translateService: TranslateService,
private stateProperties: StatePropertiesService,
@Optional() private transferState: TransferState,
private transferState: TransferState,
@Inject(PLATFORM_ID) private platformId: string,
private appRef: ApplicationRef,
@Inject(MEDIUM_BREAKPOINT_WIDTH) private mediumBreakpointWidth: number,
Expand All @@ -42,7 +42,7 @@ export class ConfigurationEffects {

setInitialRestEndpoint$ = createEffect(() =>
iif(
() => !this.transferState || !this.transferState.hasKey(NGRX_STATE_SK),
() => !this.transferState.hasKey(NGRX_STATE_SK),
this.actions$.pipe(
ofType(ROOT_EFFECTS_INIT),
take(1),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Location } from '@angular/common';
import { Component, PLATFORM_ID } from '@angular/core';
import { Component } from '@angular/core';
import { TestBed, fakeAsync, tick } from '@angular/core/testing';
import { BrowserTransferStateModule } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule } from '@ngx-translate/core';
Expand Down Expand Up @@ -34,6 +35,7 @@ describe('Configuration Integration', () => {
TestBed.configureTestingModule({
declarations: [DummyComponent],
imports: [
BrowserTransferStateModule,
CoreStoreModule.forTesting(['router', 'configuration'], [ConfigurationEffects], [configurationMeta]),
RouterTestingModule.withRoutes([
{ path: 'home', component: DummyComponent, canActivate: [ConfigurationGuard] },
Expand All @@ -42,7 +44,6 @@ describe('Configuration Integration', () => {
],
providers: [
provideStoreSnapshots(),
{ provide: PLATFORM_ID, useValue: 'server' },
{ provide: ConfigurationService, useFactory: () => instance(configurationService) },
{ provide: MEDIUM_BREAKPOINT_WIDTH, useValue: 768 },
{ provide: LARGE_BREAKPOINT_WIDTH, useValue: 992 },
Expand Down

0 comments on commit e6e7041

Please sign in to comment.