@@ -4,14 +4,14 @@ import { Action } from '@ngrx/store';
44import { Item } from '@workspace/common-data' ;
55import { selectCurrentItem , selectCurrentItemId } from '../index' ;
66
7- fdescribe ( 'itemsReducer' , ( ) => {
7+ describe ( 'itemsReducer' , ( ) => {
88 it ( 'should return state with unknown action' , ( ) => {
99 const action = { type : 'DoesNotExist' , payload : 'Sample' } as Action ;
1010 const actual = itemsReducer ( initialState , action as any ) ;
1111 expect ( actual ) . toEqual ( initialState ) ;
1212 } ) ;
1313
14- it ( `${ ItemsActionTypes . ItemsLoaded } action` , ( ) => {
14+ it ( `${ ItemsActionTypes . ItemsLoaded } action should replace state with payload ` , ( ) => {
1515 const exampleItems : Item [ ] = [ { id : 'cb1234-sa' , name : 'test' , description : 'testing' , price : 10 } ] ;
1616 const entities = {
1717 'cb1234-sa' : exampleItems [ 0 ]
@@ -22,7 +22,7 @@ fdescribe('itemsReducer', () => {
2222 expect ( state . entities ) . toEqual ( entities ) ;
2323 } ) ;
2424
25- it ( `${ ItemsActionTypes . ItemAdded } action` , ( ) => {
25+ it ( `${ ItemsActionTypes . ItemAdded } action should add item to state ` , ( ) => {
2626 const addedItem : Item = { id : 'added-item' , name : 'added' , description : 'added testing' , price : 1001 } ;
2727 const entities = {
2828 'added-item' : addedItem
@@ -33,7 +33,7 @@ fdescribe('itemsReducer', () => {
3333 expect ( state . entities ) . toEqual ( entities ) ;
3434 } ) ;
3535
36- it ( `${ ItemsActionTypes . ItemUpdated } action` , ( ) => {
36+ it ( `${ ItemsActionTypes . ItemUpdated } action should update item in state ` , ( ) => {
3737 const existingEntities = { 'existing-item' : { id : 'existing-item' , name : 'existing' , description : 'existing testing' , price : 1001 } } ;
3838 const existingState = { ...initialState , entities : existingEntities } ;
3939
@@ -44,7 +44,7 @@ fdescribe('itemsReducer', () => {
4444 expect ( state . entities [ 'existing-item' ] ) . toEqual ( updatedItem ) ;
4545 } ) ;
4646
47- it ( `${ ItemsActionTypes . ItemDeleted } action` , ( ) => {
47+ it ( `${ ItemsActionTypes . ItemDeleted } action should remove item from state ` , ( ) => {
4848 const existingEntities = {
4949 'existing-item' : { id : 'existing-item' , name : 'existing' , description : 'existing testing' , price : 1001 } ,
5050 'another-item' : { id : 'another-item' , name : 'another' , description : 'another testing' , price : 5824 } ,
@@ -58,43 +58,42 @@ fdescribe('itemsReducer', () => {
5858 expect ( state . entities [ 'another-item' ] ) . not . toBeTruthy ( ) ;
5959 } ) ;
6060
61- it ( `${ ItemsActionTypes . ItemSelected } action` , ( ) => {
61+ it ( `${ ItemsActionTypes . ItemSelected } action should set 'selectedItemId' in state ` , ( ) => {
6262 const selectedItem = 'item-id' ;
6363
6464 const action : ItemSelected = new ItemSelected ( selectedItem ) ;
6565 const state = itemsReducer ( initialState , action ) ;
6666 expect ( state . selectedItemId ) . toBe ( selectedItem ) ;
6767 } ) ;
6868
69- // -------------------------------------------------------------------
70- // SELECTORS
71- // -------------------------------------------------------------------
72- it ( '`selectCurrentItemId` should get currently selected item ID' , ( ) => {
73- const state = { items : { ...initialState , selectedItemId : '123' } } ;
74- expect ( selectCurrentItemId ( state ) ) . toBe ( '123' ) ;
75- } ) ;
76-
77- describe ( '`selectCurrentItem`' , ( ) => {
78- it ( 'should get currently selected item' , ( ) => {
79- const state = {
80- items : {
81- ...initialState ,
82- selectedItemId : '123' ,
83- entities : { '123' : { id : '123' , name : 'Test' , description : 'Testing' , price : 134 } }
84- }
85- } ;
86- expect ( selectCurrentItem ( state ) ) . toBe ( state . items . entities [ '123' ] ) ;
69+ describe ( 'selectors' , ( ) => {
70+ it ( '`selectCurrentItemId` should get currently selected item ID' , ( ) => {
71+ const state = { items : { ...initialState , selectedItemId : '123' } } ;
72+ expect ( selectCurrentItemId ( state ) ) . toBe ( '123' ) ;
8773 } ) ;
8874
89- it ( 'should return an empty item if no selected item' , ( ) => {
90- const state = {
91- items : {
92- ...initialState ,
93- selectedItemId : null ,
94- entities : { '123' : { id : '123' , name : 'Test' , description : 'Testing' , price : 134 } }
95- }
96- } ;
97- expect ( selectCurrentItem ( state ) ) . toEqual ( { id : null , name : '' , price : 0 , description : '' } ) ;
98- } ) ;
75+ describe ( '`selectCurrentItem`' , ( ) => {
76+ it ( 'should get currently selected item' , ( ) => {
77+ const state = {
78+ items : {
79+ ...initialState ,
80+ selectedItemId : '123' ,
81+ entities : { '123' : { id : '123' , name : 'Test' , description : 'Testing' , price : 134 } }
82+ }
83+ } ;
84+ expect ( selectCurrentItem ( state ) ) . toBe ( state . items . entities [ '123' ] ) ;
85+ } ) ;
86+
87+ it ( 'should return an empty item if no selected item' , ( ) => {
88+ const state = {
89+ items : {
90+ ...initialState ,
91+ selectedItemId : null ,
92+ entities : { '123' : { id : '123' , name : 'Test' , description : 'Testing' , price : 134 } }
93+ }
94+ } ;
95+ expect ( selectCurrentItem ( state ) ) . toEqual ( { id : null , name : '' , price : 0 , description : '' } ) ;
96+ } ) ;
97+ } )
9998 } ) ;
10099} ) ;
0 commit comments