Skip to content

Commit

Permalink
feat: remove added state properties, revert some of the tests back to…
Browse files Browse the repository at this point in the history
… normal. wip
  • Loading branch information
wesleygrimes committed Jan 25, 2019
1 parent 674056f commit 4615abf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 34 deletions.
10 changes: 4 additions & 6 deletions modules/schematics/src/action/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import {
UnitTestTree,
} from '@angular-devkit/schematics/testing';
import * as path from 'path';
import { Schema as ActionOptions } from './schema';
import {
getTestProjectPath,
createWorkspace,
defaultAppOptions,
defaultWorkspaceOptions,
getTestProjectPath,
defaultAppOptions,
} from '../../../schematics-core/testing';
import { Schema as ActionOptions } from './schema';

describe('Action Schematic', () => {
const schematicRunner = new SchematicTestRunner(
Expand Down Expand Up @@ -141,9 +141,7 @@ describe('Action Schematic', () => {
`${projectPath}/src/app/foo.actions.ts`
);

expect(fileContent).toMatch(
/export type FooActions = LoadFoos | LoadFoosSuccess | LoadFoosFailure;/
);
expect(fileContent).toMatch(/export type FooActions = LoadFoos/);
});

it('should group within an "actions" folder if group is set', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@ import { Action } from '@ngrx/store';
<% if(feature) { %>import { <%= classify(name) %>Actions, <%= classify(name) %>ActionTypes } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %>

export interface State {
data: any[];
loading: boolean;
error: any;

}

export const initialState: State = {
data: null,
loading: false,
error: null

};

export function reducer(state = initialState, action: <% if(feature) { %><%= classify(name) %>Actions<% } else { %>Action<% } %>): State {
switch (action.type) {
<% if(feature) { %>
case <%= classify(name) %>ActionTypes.Load<%= classify(name) %>s:
return { ...state, loading: true, error: null };
return state;

case <%= classify(name) %>ActionTypes.Load<%= classify(name) %>sSuccess:
return { ...state, data: action.payload.data, loading: false, error: null, };
return state;

case <%= classify(name) %>ActionTypes.Load<%= classify(name) %>sFailure:
return { ...state, loading: false, error: action.payload.error };
return state;

<% } %>
default:
Expand Down
22 changes: 3 additions & 19 deletions modules/schematics/src/reducer/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {
UnitTestTree,
} from '@angular-devkit/schematics/testing';
import * as path from 'path';
import { Schema as ReducerOptions } from './schema';
import {
getTestProjectPath,
createReducers,
createWorkspace,
defaultAppOptions,
defaultWorkspaceOptions,
getTestProjectPath,
defaultAppOptions,
} from '../../../schematics-core/testing';
import { Schema as ReducerOptions } from './schema';

describe('Reducer Schematic', () => {
const schematicRunner = new SchematicTestRunner(
Expand Down Expand Up @@ -89,22 +89,6 @@ describe('Reducer Schematic', () => {
expect(fileContent).toMatch(/export function reducer/);
});

it('should create a state with data, loading and error props', () => {
const tree = schematicRunner.runSchematic(
'reducer',
defaultOptions,
appTree
);
const fileContent = tree.readContent(
`${projectPath}/src/app/foo.reducer.ts`
);

expect(fileContent).toMatch(/export interface State {/);
expect(fileContent).toMatch(/data: any\[\];/);
expect(fileContent).toMatch(/loading: boolean;/);
expect(fileContent).toMatch(/error: any;/);
});

it('should import into a specified module', () => {
const options = { ...defaultOptions, module: 'app.module.ts' };

Expand Down

0 comments on commit 4615abf

Please sign in to comment.