Skip to content

Commit

Permalink
test(app): fix all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abedzantout committed Jul 14, 2019
1 parent a3bc534 commit 0961ff3
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import {
selectEffectiveTheme,
selectSettingsStickyHeader
} from './settings/settings.selectors';
import { SettingsActionTypes } from './settings/settings.actions';

export {
TitleService,
Expand All @@ -61,7 +60,6 @@ export {
AuthGuardService,
selectRouterState,
NotificationService,
SettingsActionTypes,
selectEffectiveTheme,
selectSettingsLanguage,
selectSettingsStickyHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
actionSettingsChangeHour,
actionSettingsChangeLanguage,
actionSettingsChangeStickyHeader,
actionSettingsChangeTheme,
SettingsActionTypes
actionSettingsChangeTheme
} from './settings.actions';
import { NIGHT_MODE_THEME } from './settings.model';

Expand All @@ -17,7 +16,7 @@ describe('Settings Actions', () => {
theme: NIGHT_MODE_THEME
});

expect(action.type).toEqual(SettingsActionTypes.CHANGE_THEME);
expect(action.type).toEqual(actionSettingsChangeTheme.type);
expect(action.theme).toEqual(NIGHT_MODE_THEME);
});

Expand All @@ -26,7 +25,7 @@ describe('Settings Actions', () => {
elementsAnimations: true
});

expect(action.type).toEqual(SettingsActionTypes.CHANGE_ANIMATIONS_ELEMENTS);
expect(action.type).toEqual(actionSettingsChangeAnimationsElements.type);
expect(action.elementsAnimations).toEqual(true);
});

Expand All @@ -35,7 +34,7 @@ describe('Settings Actions', () => {
pageAnimations: true
});

expect(action.type).toEqual(SettingsActionTypes.CHANGE_ANIMATIONS_PAGE);
expect(action.type).toEqual(actionSettingsChangeAnimationsPage.type);
expect(action.pageAnimations).toEqual(true);
});

Expand All @@ -45,7 +44,7 @@ describe('Settings Actions', () => {
});

expect(action.type).toEqual(
SettingsActionTypes.CHANGE_ANIMATIONS_PAGE_DISABLED
actionSettingsChangeAnimationsPageDisabled.type
);
expect(action.pageAnimationsDisabled).toEqual(true);
});
Expand All @@ -55,9 +54,7 @@ describe('Settings Actions', () => {
autoNightMode: true
});

expect(action.type).toEqual(
SettingsActionTypes.CHANGE_AUTO_NIGHT_AUTO_MODE
);
expect(action.type).toEqual(actionSettingsChangeAutoNightMode.type);
expect(action.autoNightMode).toEqual(true);
});

Expand All @@ -66,7 +63,7 @@ describe('Settings Actions', () => {
language: 'en'
});

expect(action.type).toEqual(SettingsActionTypes.CHANGE_LANGUAGE);
expect(action.type).toEqual(actionSettingsChangeLanguage.type);
expect(action.language).toEqual('en');
});

Expand All @@ -75,7 +72,7 @@ describe('Settings Actions', () => {
stickyHeader: true
});

expect(action.type).toEqual(SettingsActionTypes.CHANGE_STICKY_HEADER);
expect(action.type).toEqual(actionSettingsChangeStickyHeader.type);
expect(action.stickyHeader).toEqual(true);
});

Expand All @@ -84,7 +81,7 @@ describe('Settings Actions', () => {
hour: 7
});

expect(action.type).toEqual(SettingsActionTypes.CHANGE_HOUR);
expect(action.type).toEqual(actionSettingsChangeHour.type);
expect(action.hour).toEqual(7);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,40 @@ import { createAction, props } from '@ngrx/store';

import { Language } from './settings.model';

export enum SettingsActionTypes {
CHANGE_LANGUAGE = '[Settings] Change Language',
CHANGE_THEME = '[Settings] Change Theme',
CHANGE_AUTO_NIGHT_AUTO_MODE = '[Settings] Change Auto Night Mode',
CHANGE_STICKY_HEADER = '[Settings] Change Sticky Header',
CHANGE_ANIMATIONS_PAGE = '[Settings] Change Animations Page',
CHANGE_ANIMATIONS_PAGE_DISABLED = '[Settings] Change Animations Page Disabled',
CHANGE_ANIMATIONS_ELEMENTS = '[Settings] Change Animations Elements',
CHANGE_HOUR = '[Settings] Change Hours'
}

export const actionSettingsChangeLanguage = createAction(
SettingsActionTypes.CHANGE_LANGUAGE,
'[Settings] Change Language',
props<{ language: Language }>()
);

export const actionSettingsChangeTheme = createAction(
SettingsActionTypes.CHANGE_THEME,
'[Settings] Change Theme',
props<{ theme: string }>()
);
export const actionSettingsChangeAutoNightMode = createAction(
SettingsActionTypes.CHANGE_AUTO_NIGHT_AUTO_MODE,
'[Settings] Change Auto Night Mode',
props<{ autoNightMode: boolean }>()
);

export const actionSettingsChangeStickyHeader = createAction(
SettingsActionTypes.CHANGE_STICKY_HEADER,
'[Settings] Change Sticky Header',
props<{ stickyHeader: boolean }>()
);

export const actionSettingsChangeAnimationsPage = createAction(
SettingsActionTypes.CHANGE_ANIMATIONS_PAGE,
'[Settings] Change Animations Page',
props<{ pageAnimations: boolean }>()
);

export const actionSettingsChangeAnimationsPageDisabled = createAction(
SettingsActionTypes.CHANGE_ANIMATIONS_PAGE_DISABLED,
'[Settings] Change Animations Page Disabled',
props<{ pageAnimationsDisabled: boolean }>()
);

export const actionSettingsChangeAnimationsElements = createAction(
SettingsActionTypes.CHANGE_ANIMATIONS_ELEMENTS,
'[Settings] Change Animations Elements',
props<{ elementsAnimations: boolean }>()
);
export const actionSettingsChangeHour = createAction(
SettingsActionTypes.CHANGE_HOUR,
'[Settings] Change Hours',
props<{ hour: number }>()
);
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
actionBooksDeleteOne,
actionBooksUpsertOne,
BookActionTypes
} from './books.actions';
import { actionBooksDeleteOne, actionBooksUpsertOne } from './books.actions';

describe('Books Actions', () => {
it('should create ActionBooksUpsertOne action', () => {
Expand All @@ -14,7 +10,7 @@ describe('Books Actions', () => {
description: ''
}
});
expect(action.type).toEqual(BookActionTypes.UPSERT_ONE);
expect(action.type).toEqual(actionBooksUpsertOne.type);
expect(action.book).toEqual(
jasmine.objectContaining({
id: '1',
Expand All @@ -27,7 +23,7 @@ describe('Books Actions', () => {

it('should create ActionBooksDeleteOne action', () => {
const action = actionBooksDeleteOne({ id: '1' });
expect(action.type).toEqual(BookActionTypes.DELETE_ONE);
expect(action.type).toEqual(actionBooksDeleteOne.type);
expect(action.id).toEqual('1');
});
});
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { createAction, props } from '@ngrx/store';
import { Book } from './books.model';

export enum BookActionTypes {
UPSERT_ONE = '[Books] Upsert One',
DELETE_ONE = '[Books] Delete One'
}

export const actionBooksUpsertOne = createAction(
BookActionTypes.UPSERT_ONE,
'[Books] Upsert One',
props<{ book: Book }>()
);

export const actionBooksDeleteOne = createAction(
BookActionTypes.DELETE_ONE,
'[Books] Delete One',
props<{ id: string }>()
);
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { Form } from './form.model';
import {
FormActionTypes,
actionFormUpdate,
actionFormReset
} from './form.actions';
import { actionFormUpdate, actionFormReset } from './form.actions';

describe('Form Actions', () => {
it('should create ActionFormUpdate action', () => {
Expand All @@ -20,12 +16,12 @@ describe('Form Actions', () => {
const action = actionFormUpdate({
form: testForm
});
expect(action.type).toEqual(FormActionTypes.UPDATE);
expect(action.type).toEqual(actionFormUpdate.type);
expect(action.form).toEqual(jasmine.objectContaining(testForm));
});

it('should create ActionFormReset action', () => {
const action = actionFormReset();
expect(action.type).toEqual(FormActionTypes.RESET);
expect(action.type).toEqual(actionFormReset.type);
});
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { createAction, props } from '@ngrx/store';
import { Form } from './form.model';

export enum FormActionTypes {
UPDATE = '[Form] Update',
RESET = '[Form] Reset'
}

export const actionFormUpdate = createAction(
FormActionTypes.UPDATE,
'[Form] Update',
props<{ form: Form }>()
);

export const actionFormReset = createAction(FormActionTypes.RESET);
export const actionFormReset = createAction('[Form] Reset');
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
actionStockMarketRetrieve,
actionStockMarketRetrieveError,
actionStockMarketRetrieveSuccess
} from './stock-market.actions';
import { Stock } from './stock-market.model';
import { HttpErrorResponse } from '@angular/common/http';

const symbol = 'TSLA';

describe('Stock Market Actions', () => {
it('should create StockMarketRetrieve action', () => {
const action = actionStockMarketRetrieve({ symbol });
expect(action.type).toEqual(actionStockMarketRetrieve.type);
expect(action.symbol).toEqual(symbol);
});

it('should create StockMarketRetrieveSuccess action', () => {
const stock: Stock = {
symbol,
exchange: 'exchange',
last: '42',
ccy: 'USD',
change: 'change',
changePositive: true,
changeNegative: false,
changePercent: '2.00'
};
const action = actionStockMarketRetrieveSuccess({ stock });
expect(action.type).toEqual(actionStockMarketRetrieveSuccess.type);
expect(action.stock).toEqual(
jasmine.objectContaining({
...stock
})
);
});

it('should create StockMarketRetrieveError action', () => {
const error = new HttpErrorResponse({});
const action = actionStockMarketRetrieveError({ error: error });

expect(action.type).toEqual(actionStockMarketRetrieveError.type);
expect(action.error).toEqual(error);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,17 @@ import { HttpErrorResponse } from '@angular/common/http';

import { Stock } from './stock-market.model';

export enum StockMarketActionTypes {
RETRIEVE = '[Stock] Retrieve',
RETRIEVE_SUCCESS = '[Stock] Retrieve Success',
RETRIEVE_ERROR = '[Stock] Retrieve Error'
}

export const actionStockMarketRetrieve = createAction(
StockMarketActionTypes.RETRIEVE,
'[Stock] Retrieve',
props<{ symbol: string }>()
);

export const actionStockMarketRetrieveSuccess = createAction(
StockMarketActionTypes.RETRIEVE_SUCCESS,
'[Stock] Retrieve Success',
props<{ stock: Stock }>()
);

export const actionStockMarketRetrieveError = createAction(
StockMarketActionTypes.RETRIEVE_ERROR,
'[Stock] Retrieve Error',
props<{ error: HttpErrorResponse }>()
);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { v4 as uuid } from 'uuid';
import { createAction, props } from '@ngrx/store';

import { TodosFilter, TodosState } from './todos.model';
import { TodosFilter } from './todos.model';

export const actionTodosAdd = createAction(
'[Todos] Add',
Expand Down

0 comments on commit 0961ff3

Please sign in to comment.