Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ngrx/platform into refact…
Browse files Browse the repository at this point in the history
…or(schematics)-Entity-schematics-should-update-the-state-with-a-plural-instead-of-a-singular
  • Loading branch information
santoshyadavdev committed Mar 8, 2019
2 parents ed6655d + 3d24787 commit 1510211
Show file tree
Hide file tree
Showing 21 changed files with 145 additions and 34 deletions.
43 changes: 36 additions & 7 deletions docs/effects/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ Usage:
```ts
import { TestBed } from '@angular/core/testing';
import { provideMockActions } from '@ngrx/effects/testing';
import { ReplaySubject } from 'rxjs/ReplaySubject';
import { hot, cold } from 'jasmine-marbles';
import { cold, hot } from 'jasmine-marbles';
import { Observable } from 'rxjs';

import { MyEffects } from './my-effects';
import * as MyActions from '../actions/my-actions';

describe('My Effects', () => {
let effects: MyEffects;
let actions: Subject<any>;
let actions: Observable<any>>;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -55,14 +54,44 @@ describe('My Effects', () => {

expect(effects.someSource$).toBeObservable(expected);
});
});
```

it('should work also', () => {
actions = new ReplaySubject(1);
It is also possible to use `ReplaySubject` as an alternative for marble tests:

```ts
import { TestBed } from '@angular/core/testing';
import { provideMockActions } from '@ngrx/effects/testing';
import { ReplaySubject } from 'rxjs';

import { MyEffects } from './my-effects';
import * as MyActions from '../actions/my-actions';

describe('My Effects', () => {
let effects: MyEffects;
let actions: ReplaySubject&lt;any&gt;;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
// any modules needed
],
providers: [
MyEffects,
provideMockActions(() => actions),
// other providers
],
});

actions.next(SomeAction);
effects = TestBed.get(MyEffects);
});

it('should work', () => {
actions = new ReplaySubject(1);
actions.next(new MyActions.ExampleAction());

effects.someSource$.subscribe(result => {
expect(result).toEqual(AnotherAction);
expect(result).toEqual(new MyActions.ExampleActionSuccess());
});
});
});
Expand Down
5 changes: 4 additions & 1 deletion modules/effects/schematics-core/utility/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export function getProject(
const workspace = getWorkspace(host);

if (!options.project) {
options.project = Object.keys(workspace.projects)[0];
options.project =
workspace.defaultProject !== undefined
? workspace.defaultProject
: Object.keys(workspace.projects)[0];
}

return workspace.projects[options.project];
Expand Down
5 changes: 4 additions & 1 deletion modules/entity/schematics-core/utility/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export function getProject(
const workspace = getWorkspace(host);

if (!options.project) {
options.project = Object.keys(workspace.projects)[0];
options.project =
workspace.defaultProject !== undefined
? workspace.defaultProject
: Object.keys(workspace.projects)[0];
}

return workspace.projects[options.project];
Expand Down
5 changes: 4 additions & 1 deletion modules/router-store/schematics-core/utility/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export function getProject(
const workspace = getWorkspace(host);

if (!options.project) {
options.project = Object.keys(workspace.projects)[0];
options.project =
workspace.defaultProject !== undefined
? workspace.defaultProject
: Object.keys(workspace.projects)[0];
}

return workspace.projects[options.project];
Expand Down
1 change: 1 addition & 0 deletions modules/schematics-core/testing/create-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const defaultWorkspaceOptions = {
name: 'workspace',
newProjectRoot: 'projects',
version: '6.0.0',
defaultProject: 'bar',
};

export const defaultAppOptions = {
Expand Down
5 changes: 4 additions & 1 deletion modules/schematics-core/utility/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export function getProject(
const workspace = getWorkspace(host);

if (!options.project) {
options.project = Object.keys(workspace.projects)[0];
options.project =
workspace.defaultProject !== undefined
? workspace.defaultProject
: Object.keys(workspace.projects)[0];
}

return workspace.projects[options.project];
Expand Down
5 changes: 4 additions & 1 deletion modules/schematics/schematics-core/utility/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export function getProject(
const workspace = getWorkspace(host);

if (!options.project) {
options.project = Object.keys(workspace.projects)[0];
options.project =
workspace.defaultProject !== undefined
? workspace.defaultProject
: Object.keys(workspace.projects)[0];
}

return workspace.projects[options.project];
Expand Down
23 changes: 23 additions & 0 deletions modules/schematics/src/store/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ describe('Store Schematic', () => {
const options = { ...defaultOptions };

const tree = schematicRunner.runSchematic('store', options, appTree);

const files = tree.files;

expect(
files.indexOf(`${projectPath}/src/app/reducers/index.ts`)
).toBeGreaterThanOrEqual(0);
Expand All @@ -56,11 +58,32 @@ describe('Store Schematic', () => {

const tree = schematicRunner.runSchematic('store', options, appTree);
const files = tree.files;

expect(
files.indexOf(`${specifiedProjectPath}/src/lib/reducers/index.ts`)
).toBeGreaterThanOrEqual(0);
});

it('should create the initial store to defaultProject if project is not provided', () => {
const options = {
...defaultOptions,
project: undefined,
};

const specifiedProjectPath = getTestProjectPath(defaultWorkspaceOptions, {
...defaultAppOptions,
name: defaultWorkspaceOptions.defaultProject,
});

const tree = schematicRunner.runSchematic('store', options, appTree);

const files = tree.files;

expect(
files.indexOf(`${specifiedProjectPath}/src/app/reducers/index.ts`)
).toBeGreaterThanOrEqual(0);
});

it('should not be provided by default', () => {
const options = { ...defaultOptions };

Expand Down
5 changes: 4 additions & 1 deletion modules/store-devtools/schematics-core/utility/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export function getProject(
const workspace = getWorkspace(host);

if (!options.project) {
options.project = Object.keys(workspace.projects)[0];
options.project =
workspace.defaultProject !== undefined
? workspace.defaultProject
: Object.keys(workspace.projects)[0];
}

return workspace.projects[options.project];
Expand Down
5 changes: 4 additions & 1 deletion modules/store/schematics-core/utility/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export function getProject(
const workspace = getWorkspace(host);

if (!options.project) {
options.project = Object.keys(workspace.projects)[0];
options.project =
workspace.defaultProject !== undefined
? workspace.defaultProject
: Object.keys(workspace.projects)[0];
}

return workspace.projects[options.project];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports[`Selected Book Page should compile 1`] = `
>
<bc-book-detail
_nghost-c0=""
ng-reflect-in-collection="false"
>
</bc-book-detail>
Expand Down
2 changes: 1 addition & 1 deletion projects/example-app/src/app/books/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,6 @@ export const isSelectedBookInCollection = createSelector(
getCollectionBookIds,
getSelectedBookId,
(ids, selected) => {
return selected && ids.indexOf(selected) > -1;
return !!selected && ids.indexOf(selected) > -1;
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class AppComponent {
showSidenav$: Observable<boolean>;
loggedIn$: Observable<boolean>;

constructor(private store: Store<fromRoot.State>) {
constructor(private store: Store<fromRoot.State & fromAuth.State>) {
/**
* Selectors can be applied with the `select` operator which passes the state
* tree to the provided selector
Expand Down
14 changes: 6 additions & 8 deletions projects/example-app/src/app/core/reducers/layout.reducer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
LayoutActions
} from '@example-app/core/actions';
import { Action } from '@ngrx/store';
import { LayoutActions } from '@example-app/core/actions';

export interface State {
showSidenav: boolean;
Expand All @@ -10,11 +9,10 @@ const initialState: State = {
showSidenav: false,
};

export function reducer(
state: State = initialState,
action: LayoutActions.LayoutActionsUnion
): State {
switch (action.type) {
export function reducer(state: State = initialState, action: Action): State {
const specificAction = action as LayoutActions.LayoutActionsUnion;

switch (specificAction.type) {
case LayoutActions.LayoutActionTypes.CloseSidenav:
return {
showSidenav: false,
Expand Down
2 changes: 1 addition & 1 deletion projects/example-app/src/app/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const reducers: ActionReducerMap<State> = {

// console.log all actions
export function logger(reducer: ActionReducer<State>): ActionReducer<State> {
return (state: State, action: any): any => {
return (state, action) => {
const result = reducer(state, action);
console.groupCollapsed(action.type);
console.log('prev state', state);
Expand Down
2 changes: 2 additions & 0 deletions projects/example-app/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"compilerOptions": {
"strict": true,
"strictPropertyInitialization": false,
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
Expand Down
41 changes: 35 additions & 6 deletions projects/ngrx.io/content/guide/effects/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ Usage:
<code-example header="my.effects.spec.ts">
import { TestBed } from '@angular/core/testing';
import { provideMockActions } from '@ngrx/effects/testing';
import { ReplaySubject } from 'rxjs/ReplaySubject';
import { hot, cold } from 'jasmine-marbles';
import { cold, hot } from 'jasmine-marbles';
import { Observable } from 'rxjs';

import { MyEffects } from './my-effects';
Expand Down Expand Up @@ -48,14 +47,44 @@ describe('My Effects', () => {

expect(effects.someSource$).toBeObservable(expected);
});
});
</code-example>

it('should work also', () => {
actions = new ReplaySubject(1);
It is also possible to use `ReplaySubject` as an alternative for marble tests:

<code-example header="my.effects.spec.ts">
import { TestBed } from '@angular/core/testing';
import { provideMockActions } from '@ngrx/effects/testing';
import { ReplaySubject } from 'rxjs';

import { MyEffects } from './my-effects';
import * as MyActions from '../actions/my-actions';

describe('My Effects', () => {
let effects: MyEffects;
let actions: ReplaySubject&lt;any&gt;;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
// any modules needed
],
providers: [
MyEffects,
provideMockActions(() => actions),
// other providers
],
});

actions.next(SomeAction);
effects = TestBed.get(MyEffects);
});

it('should work', () => {
actions = new ReplaySubject(1);
actions.next(new MyActions.ExampleAction());

effects.someSource$.subscribe(result => {
expect(result).toEqual(AnotherAction);
expect(result).toEqual(new MyActions.ExampleActionSuccess());
});
});
});
Expand Down
6 changes: 6 additions & 0 deletions projects/ngrx.io/content/marketing/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
"url": "https://github.com/avatsaev/angular-contacts-app-example",
"rev": true
},
"angular-checklist": {
"title": "Angular Checklist",
"desc": "Curated list of common mistakes made when developing Angular applications",
"url": "https://angular-checklist.io",
"rev": true
},
"online-training": {
"title":
"Online Training website using ASP.Net Core 2.0 & Angular 4",
Expand Down
2 changes: 1 addition & 1 deletion projects/ngrx.io/src/404-body.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h1 class="no-toc" id="page-not-found">Resource Not Found</h1>
<footer class="no-print">
<aio-footer>
<p>
Powered by The Community ©2015-2018.
Powered by The Community ©2015-2019.
Code licensed under an <a href="license" title="License text">MIT-style License</a>.
Documentation licensed under <a href="http://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>.
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h3>{{node.title}}</h3>
</div>

<p>
Powered by the Community ©2015-2018.
Powered by the Community ©2015-2019.
Code licensed under an <a href="license" title="License text" >MIT-style License</a>.
Documentation licensed under
<a href="http://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>.
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"@ngrx/schematics/schematics-core": [
"./modules/schematics/schematics-core"
],
"@example-app/*": ["./projects/example-app/src/app/*"]
"@example-app/*": ["./projects/example-app/src/app/*"],
"ngrx-store-freeze": ["./projects/ngrx-store-freeze"]
}
},
"exclude": [
Expand Down

0 comments on commit 1510211

Please sign in to comment.