@@ -7,51 +7,98 @@ import {
77 TheGreatGatsby ,
88} from './fixtures/book' ;
99
10- describe ( 'Entity State' , ( ) => {
11- interface State {
12- books : EntityState < BookModel > ;
13- }
10+ describe ( 'Entity State Selectors' , ( ) => {
11+ describe ( 'Composed Selectors' , ( ) => {
12+ interface State {
13+ books : EntityState < BookModel > ;
14+ }
1415
15- let adapter : EntityAdapter < BookModel > ;
16- let selectors : EntitySelectors < BookModel , State > ;
17- let state : State ;
16+ let adapter : EntityAdapter < BookModel > ;
17+ let selectors : EntitySelectors < BookModel , State > ;
18+ let state : State ;
1819
19- beforeEach ( ( ) => {
20- adapter = createEntityAdapter ( {
21- selectId : ( book : BookModel ) => book . id ,
20+ beforeEach ( ( ) => {
21+ adapter = createEntityAdapter ( {
22+ selectId : ( book : BookModel ) => book . id ,
23+ } ) ;
24+
25+ state = {
26+ books : adapter . addAll (
27+ [ AClockworkOrange , AnimalFarm , TheGreatGatsby ] ,
28+ adapter . getInitialState ( )
29+ ) ,
30+ } ;
31+
32+ selectors = adapter . getSelectors ( ( state : State ) => state . books ) ;
33+ } ) ;
34+
35+ it ( 'should create a selector for selecting the ids' , ( ) => {
36+ const ids = selectors . selectIds ( state ) ;
37+
38+ expect ( ids ) . toEqual ( state . books . ids ) ;
39+ } ) ;
40+
41+ it ( 'should create a selector for selecting the entities' , ( ) => {
42+ const entities = selectors . selectEntities ( state ) ;
43+
44+ expect ( entities ) . toEqual ( state . books . entities ) ;
45+ } ) ;
46+
47+ it ( 'should create a selector for selecting the list of models' , ( ) => {
48+ const models = selectors . selectAll ( state ) ;
49+
50+ expect ( models ) . toEqual ( [ AClockworkOrange , AnimalFarm , TheGreatGatsby ] ) ;
2251 } ) ;
2352
24- state = {
25- books : adapter . addAll (
53+ it ( 'should create a selector for selecting the count of models' , ( ) => {
54+ const total = selectors . selectTotal ( state ) ;
55+
56+ expect ( total ) . toEqual ( 3 ) ;
57+ } ) ;
58+ } ) ;
59+
60+ describe ( 'Uncomposed Selectors' , ( ) => {
61+ type State = EntityState < BookModel > ;
62+
63+ let adapter : EntityAdapter < BookModel > ;
64+ let selectors : EntitySelectors < BookModel , EntityState < BookModel > > ;
65+ let state : State ;
66+
67+ beforeEach ( ( ) => {
68+ adapter = createEntityAdapter ( {
69+ selectId : ( book : BookModel ) => book . id ,
70+ } ) ;
71+
72+ state = adapter . addAll (
2673 [ AClockworkOrange , AnimalFarm , TheGreatGatsby ] ,
2774 adapter . getInitialState ( )
28- ) ,
29- } ;
75+ ) ;
3076
31- selectors = adapter . getSelectors ( ( state : State ) => state . books ) ;
32- } ) ;
77+ selectors = adapter . getSelectors ( ) ;
78+ } ) ;
3379
34- it ( 'should create a selector for selecting the ids' , ( ) => {
35- const ids = selectors . selectIds ( state ) ;
80+ it ( 'should create a selector for selecting the ids' , ( ) => {
81+ const ids = selectors . selectIds ( state ) ;
3682
37- expect ( ids ) . toEqual ( state . books . ids ) ;
38- } ) ;
83+ expect ( ids ) . toEqual ( state . ids ) ;
84+ } ) ;
3985
40- it ( 'should create a selector for selecting the entities' , ( ) => {
41- const entities = selectors . selectEntities ( state ) ;
86+ it ( 'should create a selector for selecting the entities' , ( ) => {
87+ const entities = selectors . selectEntities ( state ) ;
4288
43- expect ( entities ) . toEqual ( state . books . entities ) ;
44- } ) ;
89+ expect ( entities ) . toEqual ( state . entities ) ;
90+ } ) ;
4591
46- it ( 'should create a selector for selecting the list of models' , ( ) => {
47- const models = selectors . selectAll ( state ) ;
92+ it ( 'should create a selector for selecting the list of models' , ( ) => {
93+ const models = selectors . selectAll ( state ) ;
4894
49- expect ( models ) . toEqual ( [ AClockworkOrange , AnimalFarm , TheGreatGatsby ] ) ;
50- } ) ;
95+ expect ( models ) . toEqual ( [ AClockworkOrange , AnimalFarm , TheGreatGatsby ] ) ;
96+ } ) ;
5197
52- it ( 'should create a selector for selecting the count of models' , ( ) => {
53- const total = selectors . selectTotal ( state ) ;
98+ it ( 'should create a selector for selecting the count of models' , ( ) => {
99+ const total = selectors . selectTotal ( state ) ;
54100
55- expect ( total ) . toEqual ( 3 ) ;
101+ expect ( total ) . toEqual ( 3 ) ;
102+ } ) ;
56103 } ) ;
57104} ) ;
0 commit comments