// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ngrx NgModule Syntax generated unit tests should generate specs for the ngrx effects 1`] = `
"import { TestBed } from '@angular/core/testing';
import { provideMockActions } from '@ngrx/effects/testing';
import { Action } from '@ngrx/store';
import { provideMockStore } from '@ngrx/store/testing';
import { hot } from 'jasmine-marbles';
import { Observable } from 'rxjs';

import * as SuperUsersActions from './super-users.actions';
import { SuperUsersEffects } from './super-users.effects';

describe('SuperUsersEffects', () => {
  let actions: Observable<Action>;
  let effects: SuperUsersEffects;

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [],
      providers: [
        SuperUsersEffects,
        provideMockActions(() => actions),
        provideMockStore()
      ],
    });

    effects = TestBed.inject(SuperUsersEffects);
  });

  describe('init$', () => {
    it('should work', () => {
      actions = hot('-a-|', { a: SuperUsersActions.initSuperUsers() });

      const expected = hot('-a-|', { a: SuperUsersActions.loadSuperUsersSuccess({ superUsers: [] }) });

      expect(effects.init$).toBeObservable(expected);
    });
  });
});
"
`;

exports[`ngrx NgModule Syntax generated unit tests should generate specs for the ngrx facade 1`] = `
"import { NgModule } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { EffectsModule } from '@ngrx/effects';
import { StoreModule, Store } from '@ngrx/store';
import { readFirst } from '@nrwl/angular/testing';

import * as SuperUsersActions from './super-users.actions';
import { SuperUsersEffects } from './super-users.effects';
import { SuperUsersFacade } from './super-users.facade';
import { SuperUsersEntity } from './super-users.models';
import {
  SUPER_USERS_FEATURE_KEY,
  SuperUsersState,
  initialSuperUsersState,
  superUsersReducer
} from './super-users.reducer';
import * as SuperUsersSelectors from './super-users.selectors';

interface TestSchema {
  superUsers: SuperUsersState;
}

describe('SuperUsersFacade', () => {
  let facade: SuperUsersFacade;
  let store: Store<TestSchema>;
  const createSuperUsersEntity = (id: string, name = ''): SuperUsersEntity => ({
    id,
    name: name || \`name-\${id}\`
  });

  describe('used in NgModule', () => {
    beforeEach(() => {
      @NgModule({
        imports: [
          StoreModule.forFeature(SUPER_USERS_FEATURE_KEY, superUsersReducer),
          EffectsModule.forFeature([SuperUsersEffects])
        ],
        providers: [SuperUsersFacade]
      })
      class CustomFeatureModule {}

      @NgModule({
        imports: [
          StoreModule.forRoot({}),
          EffectsModule.forRoot([]),
          CustomFeatureModule,
        ]
      })
      class RootModule {}
      TestBed.configureTestingModule({ imports: [RootModule] });

      store = TestBed.inject(Store);
      facade = TestBed.inject(SuperUsersFacade);
    });

    /**
     * The initially generated facade::loadAll() returns empty array
     */
    it('loadAll() should return empty list with loaded == true', async () => {
      let list = await readFirst(facade.allSuperUsers$);
      let isLoaded = await readFirst(facade.loaded$);

      expect(list.length).toBe(0);
      expect(isLoaded).toBe(false);

      facade.init();

      list = await readFirst(facade.allSuperUsers$);
      isLoaded = await readFirst(facade.loaded$);

      expect(list.length).toBe(0);
      expect(isLoaded).toBe(true);
    });

    /**
     * Use \`loadSuperUsersSuccess\` to manually update list
     */
    it('allSuperUsers$ should return the loaded list; and loaded flag == true', async () => {
      let list = await readFirst(facade.allSuperUsers$);
      let isLoaded = await readFirst(facade.loaded$);

      expect(list.length).toBe(0);
      expect(isLoaded).toBe(false);

      store.dispatch(SuperUsersActions.loadSuperUsersSuccess({
        superUsers: [
          createSuperUsersEntity('AAA'),
          createSuperUsersEntity('BBB')
        ]})
      );

      list = await readFirst(facade.allSuperUsers$);
      isLoaded = await readFirst(facade.loaded$);

      expect(list.length).toBe(2);
      expect(isLoaded).toBe(true);
    });
  });
});
"
`;

exports[`ngrx NgModule Syntax generated unit tests should generate specs for the ngrx reducer 1`] = `
"import { Action } from '@ngrx/store';

import * as SuperUsersActions from './super-users.actions';
import { SuperUsersEntity } from './super-users.models';
import { SuperUsersState, initialSuperUsersState, superUsersReducer } from './super-users.reducer';

describe('SuperUsers Reducer', () => {
  const createSuperUsersEntity = (id: string, name = ''): SuperUsersEntity => ({
    id,
    name: name || \`name-\${id}\`
  });

  describe('valid SuperUsers actions', () => {
    it('loadSuperUsersSuccess should return the list of known SuperUsers', () => {
      const superUsers = [
        createSuperUsersEntity('PRODUCT-AAA'),
        createSuperUsersEntity('PRODUCT-zzz')
      ];
      const action = SuperUsersActions.loadSuperUsersSuccess({ superUsers });

      const result: SuperUsersState = superUsersReducer(initialSuperUsersState, action);

      expect(result.loaded).toBe(true);
      expect(result.ids.length).toBe(2);
    });
  });

  describe('unknown action', () => {
    it('should return the previous state', () => {
      const action = {} as Action;

      const result = superUsersReducer(initialSuperUsersState, action);

      expect(result).toBe(initialSuperUsersState);
    });
  });
});
"
`;

exports[`ngrx NgModule Syntax generated unit tests should generate specs for the ngrx selectors 1`] = `
"import { SuperUsersEntity } from './super-users.models';
import { superUsersAdapter, SuperUsersPartialState, initialSuperUsersState } from './super-users.reducer';
import * as SuperUsersSelectors from './super-users.selectors';

describe('SuperUsers Selectors', () => {
  const ERROR_MSG = 'No Error Available';
  const getSuperUsersId = (it: SuperUsersEntity) => it.id;
  const createSuperUsersEntity = (id: string, name = '') => ({
    id,
    name: name || \`name-\${id}\`
  }) as SuperUsersEntity;

  let state: SuperUsersPartialState;

  beforeEach(() => {
    state = {
      superUsers: superUsersAdapter.setAll([
        createSuperUsersEntity('PRODUCT-AAA'),
        createSuperUsersEntity('PRODUCT-BBB'),
        createSuperUsersEntity('PRODUCT-CCC')
      ], {
        ...initialSuperUsersState,
        selectedId : 'PRODUCT-BBB',
        error: ERROR_MSG,
        loaded: true
      })
    };
  });

  describe('SuperUsers Selectors', () => {
    it('selectAllSuperUsers() should return the list of SuperUsers', () => {
      const results = SuperUsersSelectors.selectAllSuperUsers(state);
      const selId = getSuperUsersId(results[1]);

      expect(results.length).toBe(3);
      expect(selId).toBe('PRODUCT-BBB');
    });

    it('selectEntity() should return the selected Entity', () => {
      const result = SuperUsersSelectors.selectEntity(state) as SuperUsersEntity;
      const selId = getSuperUsersId(result);

      expect(selId).toBe('PRODUCT-BBB');
    });

    it('selectSuperUsersLoaded() should return the current \\"loaded\\" status', () => {
      const result = SuperUsersSelectors.selectSuperUsersLoaded(state);

      expect(result).toBe(true);
    });

    it('selectSuperUsersError() should return the current \\"error\\" state', () => {
      const result = SuperUsersSelectors.selectSuperUsersError(state);

      expect(result).toBe(ERROR_MSG);
    });
  });
});
"
`;

exports[`ngrx NgModule Syntax should add a root module with feature module when minimal is set to false 1`] = `
"
     import { NgModule } from '@angular/core';
     import { BrowserModule } from '@angular/platform-browser';
     import { RouterModule } from '@angular/router';
     import { AppComponent } from './app.component';
import { StoreModule } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects';
import * as fromUsers from './+state/users.reducer';
import { UsersEffects } from './+state/users.effects';
import { StoreRouterConnectingModule } from '@ngrx/router-store';
     @NgModule({
       imports: [BrowserModule, RouterModule.forRoot([]), StoreModule.forRoot({}, {
      metaReducers: [],
      runtimeChecks: {
        strictActionImmutability: true,
        strictStateImmutability: true
      }
    }), EffectsModule.forRoot([UsersEffects]), StoreRouterConnectingModule.forRoot(), StoreModule.forFeature(fromUsers.USERS_FEATURE_KEY, fromUsers.usersReducer)],
       declarations: [AppComponent],
       bootstrap: [AppComponent]
     })
     export class AppModule {}
  "
`;

exports[`ngrx NgModule Syntax should add a root module with feature module when minimal is set to false using --module 1`] = `
"
     import { NgModule } from '@angular/core';
     import { BrowserModule } from '@angular/platform-browser';
     import { RouterModule } from '@angular/router';
     import { AppComponent } from './app.component';
import { StoreModule } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects';
import * as fromUsers from './+state/users.reducer';
import { UsersEffects } from './+state/users.effects';
import { StoreRouterConnectingModule } from '@ngrx/router-store';
     @NgModule({
       imports: [BrowserModule, RouterModule.forRoot([]), StoreModule.forRoot({}, {
      metaReducers: [],
      runtimeChecks: {
        strictActionImmutability: true,
        strictStateImmutability: true
      }
    }), EffectsModule.forRoot([UsersEffects]), StoreRouterConnectingModule.forRoot(), StoreModule.forFeature(fromUsers.USERS_FEATURE_KEY, fromUsers.usersReducer)],
       declarations: [AppComponent],
       bootstrap: [AppComponent]
     })
     export class AppModule {}
  "
`;

exports[`ngrx NgModule Syntax should add an empty root module when minimal and root are set to true 1`] = `
"
     import { NgModule } from '@angular/core';
     import { BrowserModule } from '@angular/platform-browser';
     import { RouterModule } from '@angular/router';
     import { AppComponent } from './app.component';
import { StoreModule } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects';
import { StoreRouterConnectingModule } from '@ngrx/router-store';
     @NgModule({
       imports: [BrowserModule, RouterModule.forRoot([]), StoreModule.forRoot({}, {
      metaReducers: [],
      runtimeChecks: {
        strictActionImmutability: true,
        strictStateImmutability: true
      }
    }), EffectsModule.forRoot([]), StoreRouterConnectingModule.forRoot()],
       declarations: [AppComponent],
       bootstrap: [AppComponent]
     })
     export class AppModule {}
  "
`;

exports[`ngrx NgModule Syntax should generate a models file for the feature 1`] = `
"/**
 * Interface for the 'Users' data
 */
export interface UsersEntity {
  id: string | number; // Primary ID
  name: string;
};"
`;

exports[`ngrx NgModule Syntax should generate the ngrx actions 1`] = `
"import { createAction, props } from '@ngrx/store';
import { UsersEntity } from './users.models';

export const initUsers = createAction(
  '[Users Page] Init'
);

export const loadUsersSuccess = createAction(
  '[Users/API] Load Users Success',
  props<{ users: UsersEntity[] }>()
);

export const loadUsersFailure = createAction(
  '[Users/API] Load Users Failure',
  props<{ error: any }>()
);
"
`;

exports[`ngrx NgModule Syntax should generate the ngrx effects 1`] = `
"import { Injectable, inject } from '@angular/core';
import { createEffect, Actions, ofType } from '@ngrx/effects';

import * as UsersActions from './users.actions';
import * as UsersFeature from './users.reducer';

import {switchMap, catchError, of} from 'rxjs';

@Injectable()
export class UsersEffects {
  private actions$ = inject(Actions);

  init$ = createEffect(() => this.actions$.pipe(
    ofType(UsersActions.initUsers),
    switchMap(() => of(UsersActions.loadUsersSuccess({ users: [] }))),
    catchError((error) => {
        console.error('Error', error);
        return of(UsersActions.loadUsersFailure({ error }));
      }
    )
  ));
}
"
`;

exports[`ngrx NgModule Syntax should generate the ngrx facade 1`] = `
"import { Injectable, inject } from '@angular/core';
import { select, Store, Action } from '@ngrx/store';

import * as UsersActions from './users.actions';
import * as UsersFeature from './users.reducer';
import * as UsersSelectors from './users.selectors';

@Injectable()
export class UsersFacade {
  private readonly store = inject(Store);

  /**
   * Combine pieces of state using createSelector,
   * and expose them as observables through the facade.
   */
  loaded$ = this.store.pipe(select(UsersSelectors.selectUsersLoaded));
  allUsers$ = this.store.pipe(select(UsersSelectors.selectAllUsers));
  selectedUsers$ = this.store.pipe(select(UsersSelectors.selectEntity));

  /**
   * Use the initialization action to perform one
   * or more tasks in your Effects.
   */
  init() {
    this.store.dispatch(UsersActions.initUsers());
  }
}
"
`;

exports[`ngrx NgModule Syntax should generate the ngrx reducer 1`] = `
"import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity';
import { createReducer, on, Action } from '@ngrx/store';

import * as UsersActions from './users.actions';
import { UsersEntity } from './users.models';

export const USERS_FEATURE_KEY = 'users';

export interface UsersState extends EntityState<UsersEntity> {
  selectedId?: string | number; // which Users record has been selected
  loaded: boolean; // has the Users list been loaded
  error?: string | null; // last known error (if any)
}

export interface UsersPartialState {
  readonly [USERS_FEATURE_KEY]: UsersState;
}

export const usersAdapter: EntityAdapter<UsersEntity> = createEntityAdapter<UsersEntity>();

export const initialUsersState: UsersState = usersAdapter.getInitialState({
  // set initial required properties
  loaded: false
});

const reducer = createReducer(
  initialUsersState,
  on(UsersActions.initUsers,
    state => ({ ...state, loaded: false, error: null })
  ),
  on(UsersActions.loadUsersSuccess,
    (state, { users }) => usersAdapter.setAll(users, { ...state, loaded: true })
  ),
  on(UsersActions.loadUsersFailure,
    (state, { error }) => ({ ...state, error })
  ),
);

export function usersReducer(state: UsersState | undefined, action: Action) {
  return reducer(state, action);
}
"
`;

exports[`ngrx NgModule Syntax should generate the ngrx selectors 1`] = `
"import { createFeatureSelector, createSelector } from '@ngrx/store';
import { USERS_FEATURE_KEY, UsersState, usersAdapter } from './users.reducer';

// Lookup the 'Users' feature state managed by NgRx
export const selectUsersState = createFeatureSelector<UsersState>(USERS_FEATURE_KEY);

const { selectAll, selectEntities } = usersAdapter.getSelectors();

export const selectUsersLoaded = createSelector(
  selectUsersState,
  (state: UsersState) => state.loaded
);

export const selectUsersError = createSelector(
  selectUsersState,
  (state: UsersState) => state.error
);

export const selectAllUsers = createSelector(
  selectUsersState,
  (state: UsersState) => selectAll(state)
);

export const selectUsersEntities = createSelector(
  selectUsersState,
  (state: UsersState) => selectEntities(state)
);

export const selectSelectedId = createSelector(
  selectUsersState,
  (state: UsersState) => state.selectedId
);

export const selectEntity = createSelector(
  selectUsersEntities,
  selectSelectedId,
  (entities, selectedId) => (selectedId ? entities[selectedId] : undefined)
);
"
`;

exports[`ngrx NgModule Syntax should not generate imports when skipImport is true 1`] = `
"
     import { NgModule } from '@angular/core';
     import { BrowserModule } from '@angular/platform-browser';
     import { RouterModule } from '@angular/router';
     import { AppComponent } from './app.component';
     @NgModule({
       imports: [BrowserModule, RouterModule.forRoot([])],
       declarations: [AppComponent],
       bootstrap: [AppComponent]
     })
     export class AppModule {}
  "
`;

exports[`ngrx NgModule Syntax should update the entry point file correctly when barrels is true 1`] = `
"import * as SuperUsersActions from './lib/+state/super-users.actions';

import * as SuperUsersFeature from './lib/+state/super-users.reducer';

import * as SuperUsersSelectors from './lib/+state/super-users.selectors';

export * from './lib/+state/super-users.facade';

export * from './lib/+state/super-users.models';

export { SuperUsersActions, SuperUsersFeature, SuperUsersSelectors };

    export * from './lib/flights.module';
  "
`;

exports[`ngrx NgModule Syntax should update the entry point file with no facade 1`] = `
"export * from './lib/+state/super-users.models';
export * from './lib/+state/super-users.selectors';
export * from './lib/+state/super-users.reducer';
export * from './lib/+state/super-users.actions';

    export * from './lib/flights.module';
  "
`;

exports[`ngrx NgModule Syntax should update the entry point file with the right exports 1`] = `
"export * from './lib/+state/super-users.facade';
export * from './lib/+state/super-users.models';
export * from './lib/+state/super-users.selectors';
export * from './lib/+state/super-users.reducer';
export * from './lib/+state/super-users.actions';

    export * from './lib/flights.module';
  "
`;

exports[`ngrx Standalone APIs should add a root module with feature module when minimal is set to false 1`] = `
"import { bootstrapApplication } from '@angular/platform-browser';
import { provideRouter, withEnabledBlockingInitialNavigation } from '@angular/router';
import { AppComponent } from './app/app.component';
import { appRoutes } from './app/app.routes';
import { provideStore, provideState } from '@ngrx/store';
import { provideEffects } from '@ngrx/effects';
import * as fromUsers from './+state/users.reducer';
import { UsersEffects } from './+state/users.effects';

bootstrapApplication(AppComponent, {
  providers: [provideEffects(UsersEffects),provideState(fromUsers.USERS_FEATURE_KEY, fromUsers.usersReducer),provideEffects(),provideStore(),provideRouter(appRoutes, withEnabledBlockingInitialNavigation())],
}).catch((err) => console.error(err));"
`;

exports[`ngrx Standalone APIs should add an empty provideStore when minimal and root are set to true 1`] = `
"import { bootstrapApplication } from '@angular/platform-browser';
import { provideRouter, withEnabledBlockingInitialNavigation } from '@angular/router';
import { AppComponent } from './app/app.component';
import { appRoutes } from './app/app.routes';
import { provideStore, provideState } from '@ngrx/store';
import { provideEffects } from '@ngrx/effects';

bootstrapApplication(AppComponent, {
  providers: [provideEffects(),provideStore(),provideRouter(appRoutes, withEnabledBlockingInitialNavigation())],
}).catch((err) => console.error(err));"
`;

exports[`ngrx Standalone APIs should add facade provider when facade is true 1`] = `
"import { bootstrapApplication } from '@angular/platform-browser';
import { provideRouter, withEnabledBlockingInitialNavigation } from '@angular/router';
import { AppComponent } from './app/app.component';
import { appRoutes } from './app/app.routes';
import { provideStore, provideState } from '@ngrx/store';
import { provideEffects } from '@ngrx/effects';
import * as fromUsers from './+state/users.reducer';
import { UsersEffects } from './+state/users.effects';
import { UsersFacade } from './+state/users.facade';

bootstrapApplication(AppComponent, {
  providers: [provideEffects(UsersEffects),provideState(fromUsers.USERS_FEATURE_KEY, fromUsers.usersReducer),provideEffects(),provideStore(),UsersFacade,provideRouter(appRoutes, withEnabledBlockingInitialNavigation())],
}).catch((err) => console.error(err));"
`;

exports[`ngrx Standalone APIs should add facade provider when facade is true and --root is false 1`] = `
"import { Routes } from '@angular/router';
        import { NxWelcomeComponent } from './nx-welcome.component';
import { provideStore, provideState } from '@ngrx/store';
import { provideEffects } from '@ngrx/effects';
import * as fromUsers from './+state/users.reducer';
import { UsersEffects } from './+state/users.effects';
import { UsersFacade } from './+state/users.facade'; 
      export const appRoutes: Routes = [{ path: '', component: NxWelcomeComponent , providers: [UsersFacade, provideState(fromUsers.USERS_FEATURE_KEY, fromUsers.usersReducer), provideEffects(UsersEffects)]}];"
`;

exports[`ngrx angular v14 support should generate the ngrx effects using "inject" for versions >= 14.1.0 1`] = `
"import { Injectable, inject } from '@angular/core';
import { createEffect, Actions, ofType } from '@ngrx/effects';

import * as UsersActions from './users.actions';
import * as UsersFeature from './users.reducer';

import {switchMap, catchError, of} from 'rxjs';

@Injectable()
export class UsersEffects {
  private actions$ = inject(Actions);

  init$ = createEffect(() => this.actions$.pipe(
    ofType(UsersActions.initUsers),
    switchMap(() => of(UsersActions.loadUsersSuccess({ users: [] }))),
    catchError((error) => {
        console.error('Error', error);
        return of(UsersActions.loadUsersFailure({ error }));
      }
    )
  ));
}
"
`;

exports[`ngrx angular v14 support should generate the ngrx effects with no usage of "inject" 1`] = `
"import { Injectable } from '@angular/core';
import { createEffect, Actions, ofType } from '@ngrx/effects';

import * as UsersActions from './users.actions';
import * as UsersFeature from './users.reducer';

import {switchMap, catchError, of} from 'rxjs';

@Injectable()
export class UsersEffects {
  init$ = createEffect(() => this.actions$.pipe(
    ofType(UsersActions.initUsers),
    switchMap(() => of(UsersActions.loadUsersSuccess({ users: [] }))),
    catchError((error) => {
        console.error('Error', error);
        return of(UsersActions.loadUsersFailure({ error }));
      }
    )
  ));

  constructor(private readonly actions$: Actions) {}
}
"
`;

exports[`ngrx angular v14 support should generate the ngrx facade using "inject" for versions >= 14.1.0 1`] = `
"import { Injectable, inject } from '@angular/core';
import { select, Store, Action } from '@ngrx/store';

import * as UsersActions from './users.actions';
import * as UsersFeature from './users.reducer';
import * as UsersSelectors from './users.selectors';

@Injectable()
export class UsersFacade {
  private readonly store = inject(Store);

  /**
   * Combine pieces of state using createSelector,
   * and expose them as observables through the facade.
   */
  loaded$ = this.store.pipe(select(UsersSelectors.selectUsersLoaded));
  allUsers$ = this.store.pipe(select(UsersSelectors.selectAllUsers));
  selectedUsers$ = this.store.pipe(select(UsersSelectors.selectEntity));

  /**
   * Use the initialization action to perform one
   * or more tasks in your Effects.
   */
  init() {
    this.store.dispatch(UsersActions.initUsers());
  }
}
"
`;

exports[`ngrx angular v14 support should generate the ngrx facade with no usage of "inject" 1`] = `
"import { Injectable } from '@angular/core';
import { select, Store, Action } from '@ngrx/store';

import * as UsersActions from './users.actions';
import * as UsersFeature from './users.reducer';
import * as UsersSelectors from './users.selectors';

@Injectable()
export class UsersFacade {
  /**
   * Combine pieces of state using createSelector,
   * and expose them as observables through the facade.
   */
  loaded$ = this.store.pipe(select(UsersSelectors.selectUsersLoaded));
  allUsers$ = this.store.pipe(select(UsersSelectors.selectAllUsers));
  selectedUsers$ = this.store.pipe(select(UsersSelectors.selectEntity));

  constructor(private readonly store: Store) {}

  /**
   * Use the initialization action to perform one
   * or more tasks in your Effects.
   */
  init() {
    this.store.dispatch(UsersActions.initUsers());
  }
}
"
`;
