Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fisenkodv committed Apr 24, 2018
1 parent 8d94d70 commit 565a8a8
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ Thumbs.db
package-lock.json

# application files
*version.ts
*version.ts
junit.xml
1 change: 0 additions & 1 deletion jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"/node_modules/",
"index.ts"
],
"mapCoverage": true,
"testURL": "http://localhost:4200",
"roots": [
"<rootDir>/src/"
Expand Down
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"ng": "ng",
"start": "ng serve",
"build": "npm run version && ng build --prod",
"test": "jest",
"test.watch": "jest --watch",
"test": "jest --config jest.config.json",
"test.watch": "jest --watchAll --config jest.config.json",
"test.coverage": "jest --ci --coverage --testResultsProcessor=jest-junit --config jest.config.json",
"lint": "ng lint",
"e2e": "ng e2e",
"version": "node ./scripts/version.js",
Expand Down Expand Up @@ -63,6 +64,7 @@
"jasmine-spec-reporter": "~4.2.1",
"jest": "^22.4.3",
"jest-preset-angular": "^5.2.1",
"jest-junit": "^3.6.0",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.4.2",
Expand All @@ -72,9 +74,5 @@
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.7.2"
},
"jest": {
"preset": "jest-preset-angular",
"setupTestFrameworkScriptFile": "<rootDir>/src/test.jest.ts"
}
}
28 changes: 28 additions & 0 deletions src/app/modules/core/state/layout.state.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { async, TestBed } from '@angular/core/testing';
import { NgxsModule, Store } from '@ngxs/store';

import { OpenSidenav, CloseSidenav } from './layout.actions';
import { LayoutState } from './layout.state';

describe('Layout', () => {
let store: Store;

beforeEach(async(() => {
TestBed.configureTestingModule({ imports: [NgxsModule.forRoot([LayoutState])] }).compileComponents();
store = TestBed.get(Store);
}));

it('it opens side navigation panel', () => {
store.dispatch(new OpenSidenav());
store.selectOnce(state => state.layout.showSidenav).subscribe(showSidenav => {
expect(showSidenav).toBe(true);
});
});

it('it closes side navigation panel', () => {
store.dispatch(new CloseSidenav());
store.selectOnce(state => state.layout.showSidenav).subscribe(showSidenav => {
expect(showSidenav).toBe(false);
});
});
});
43 changes: 43 additions & 0 deletions src/app/modules/places/state/filter.state.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { async, TestBed } from '@angular/core/testing';
import { NgxsModule, Store } from '@ngxs/store';

import { SetDistance, SetLocation, SetRating, SetReviews } from './filter.actions';
import { FilterState } from './filter.state';

describe('Filter', () => {
let store: Store;

beforeEach(async(() => {
TestBed.configureTestingModule({ imports: [NgxsModule.forRoot([FilterState])] }).compileComponents();
store = TestBed.get(Store);
}));

it('it should set location', () => {
store.dispatch(new SetLocation({ latitude: 10, longitude: 10 }));
store.selectOnce(state => state.filter.location).subscribe(location => {
expect(location.latitude).toBe(10);
expect(location.longitude).toBe(10);
});
});

it('it should set distance', () => {
store.dispatch(new SetDistance(100));
store.selectOnce(state => state.filter.distance).subscribe(distance => {
expect(distance).toBe(100);
});
});

it('it should set rating', () => {
store.dispatch(new SetRating(5));
store.selectOnce(state => state.filter.rating).subscribe(rating => {
expect(rating).toBe(5);
});
});

it('it should set reviews', () => {
store.dispatch(new SetReviews(50));
store.selectOnce(state => state.filter.reviews).subscribe(reviews => {
expect(reviews).toBe(50);
});
});
});
5 changes: 3 additions & 2 deletions src/app/modules/places/state/filter.state.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Location } from '@app/modules/places/models';
import { SetDistance, SetLocation, SetRating, SetReviews } from '@app/modules/places/state/filter.actions';
import { Action, Selector, State, StateContext } from '@ngxs/store';

import { Location } from '../models';
import { SetDistance, SetLocation, SetRating, SetReviews } from './filter.actions';

export interface FilterStateModel {
location: Location;
distance: number;
Expand Down

0 comments on commit 565a8a8

Please sign in to comment.