@@ -4,18 +4,17 @@ import reducer, {
44 INITIAL_STATE ,
55 CLEAR_SAMPLE_DOCUMENTS ,
66 clearSampleDocuments ,
7- fetchingValidDocument ,
8- FETCHING_VALID_DOCUMENT ,
97 fetchedValidDocument ,
108 FETCHED_VALID_DOCUMENT ,
11- fetchingInvalidDocument ,
12- FETCHING_INVALID_DOCUMENT ,
139 fetchedInvalidDocument ,
1410 FETCHED_INVALID_DOCUMENT ,
1511 fetchingValidDocumentFailed ,
1612 FETCHING_INVALID_DOCUMENT_FAILED ,
1713 fetchingInvalidDocumentFailed ,
1814 FETCHING_VALID_DOCUMENT_FAILED ,
15+ fetchingSampleDocuments ,
16+ FETCHING_SAMPLE_DOCUMENTS ,
17+ type SampleDocumentState ,
1918} from './sample-documents' ;
2019
2120const SAMPLE_DOCUMENT = {
@@ -31,14 +30,8 @@ describe('sample-documents module', function () {
3130 } ) ;
3231
3332 it ( 'returns the FETCHING_VALID_DOCUMENT action' , function ( ) {
34- expect ( fetchingValidDocument ( ) ) . to . deep . equal ( {
35- type : FETCHING_VALID_DOCUMENT ,
36- } ) ;
37- } ) ;
38-
39- it ( 'returns the FETCHING_INVALID_DOCUMENT action' , function ( ) {
40- expect ( fetchingInvalidDocument ( ) ) . to . deep . equal ( {
41- type : FETCHING_INVALID_DOCUMENT ,
33+ expect ( fetchingSampleDocuments ( ) ) . to . deep . equal ( {
34+ type : FETCHING_SAMPLE_DOCUMENTS ,
4235 } ) ;
4336 } ) ;
4437
@@ -93,66 +86,72 @@ describe('sample-documents module', function () {
9386 } ) ;
9487 } ) ;
9588
96- context ( 'when the action is FETCHING_VALID_DOCUMENT ' , function ( ) {
89+ context ( 'when the action is FETCHING_SAMPLE_DOCUMENTS ' , function ( ) {
9790 it ( 'returns a loading state' , function ( ) {
98- const sampleDocuments = reducer ( undefined , fetchingValidDocument ( ) ) ;
91+ const sampleDocuments = reducer ( undefined , fetchingSampleDocuments ( ) ) ;
9992 expect ( sampleDocuments . validDocumentState ) . to . equal ( 'loading' ) ;
93+ expect ( sampleDocuments . invalidDocumentState ) . to . equal ( 'loading' ) ;
10094 } ) ;
10195 } ) ;
10296
103- context ( 'when the action is FETCHING_INVALID_DOCUMENT ' , function ( ) {
104- it ( 'returns a loading state' , function ( ) {
105- const sampleDocuments = reducer ( undefined , fetchingInvalidDocument ( ) ) ;
106- expect ( sampleDocuments . invalidDocumentState ) . to . equal ( 'loading' ) ;
97+ context ( 'fetch results ' , function ( ) {
98+ let loadingState : SampleDocumentState ;
99+ beforeEach ( function ( ) {
100+ loadingState = reducer ( undefined , fetchingSampleDocuments ( ) ) ;
107101 } ) ;
108- } ) ;
109102
110- context ( 'when the action is FETCHED_VALID_DOCUMENT' , function ( ) {
111- it ( 'updates the state with the document' , function ( ) {
112- for ( const document of [ null , undefined , SAMPLE_DOCUMENT ] as any [ ] ) {
113- const sampleDocuments = reducer (
114- undefined ,
115- fetchedValidDocument ( document )
116- ) ;
117- expect ( sampleDocuments . validDocumentState ) . to . equal ( 'success' ) ;
118- expect ( sampleDocuments . validDocument ) . to . deep . equal ( document ) ;
119- }
103+ context ( 'when the action is FETCHED_VALID_DOCUMENT' , function ( ) {
104+ it ( 'updates the state with the document' , function ( ) {
105+ for ( const document of [ null , undefined , SAMPLE_DOCUMENT ] as any [ ] ) {
106+ const sampleDocuments = reducer (
107+ loadingState ,
108+ fetchedValidDocument ( document )
109+ ) ;
110+ expect ( sampleDocuments . validDocumentState ) . to . equal ( 'success' ) ;
111+ expect ( sampleDocuments . validDocument ) . to . deep . equal ( document ) ;
112+ expect ( sampleDocuments . invalidDocumentState ) . to . equal ( 'loading' ) ;
113+ }
114+ } ) ;
120115 } ) ;
121- } ) ;
122116
123- context ( 'when the action is FETCHED_INVALID_DOCUMENT' , function ( ) {
124- it ( 'updates the state with the document' , function ( ) {
117+ context ( 'when the action is FETCHED_INVALID_DOCUMENT' , function ( ) {
125118 for ( const document of [ null , undefined , SAMPLE_DOCUMENT ] as any [ ] ) {
126119 const sampleDocuments = reducer (
127- undefined ,
120+ loadingState ,
128121 fetchedInvalidDocument ( document )
129122 ) ;
130123 expect ( sampleDocuments . invalidDocumentState ) . to . equal ( 'success' ) ;
131124 expect ( sampleDocuments . invalidDocument ) . to . deep . equal ( document ) ;
125+ expect ( sampleDocuments . validDocumentState ) . to . equal ( 'loading' ) ;
132126 }
133127 } ) ;
134- } ) ;
135128
136- context ( 'when the action is FETCHING_VALID_DOCUMENT_FAILED' , function ( ) {
137- it ( 'updates an error state' , function ( ) {
138- const sampleDocuments = reducer (
139- undefined ,
140- fetchingValidDocumentFailed ( )
141- ) ;
142- expect ( sampleDocuments . validDocumentState ) . to . equal ( 'error' ) ;
143- expect ( sampleDocuments . validDocument ) . to . equal ( undefined ) ;
129+ context ( 'when the action is FETCHING_VALID_DOCUMENT_FAILED' , function ( ) {
130+ it ( 'updates an error state' , function ( ) {
131+ const sampleDocuments = reducer (
132+ loadingState ,
133+ fetchingValidDocumentFailed ( )
134+ ) ;
135+ expect ( sampleDocuments . validDocumentState ) . to . equal ( 'error' ) ;
136+ expect ( sampleDocuments . validDocument ) . to . equal ( undefined ) ;
137+ expect ( sampleDocuments . invalidDocumentState ) . to . equal ( 'loading' ) ;
138+ } ) ;
144139 } ) ;
145- } ) ;
146140
147- context ( 'when the action is FETCHING_INVALID_DOCUMENT_FAILED' , function ( ) {
148- it ( 'updates an error state' , function ( ) {
149- const sampleDocuments = reducer (
150- undefined ,
151- fetchingInvalidDocumentFailed ( )
152- ) ;
153- expect ( sampleDocuments . invalidDocumentState ) . to . equal ( 'error' ) ;
154- expect ( sampleDocuments . invalidDocument ) . to . deep . equal ( undefined ) ;
155- } ) ;
141+ context (
142+ 'when the action is FETCHING_INVALID_DOCUMENT_FAILED' ,
143+ function ( ) {
144+ it ( 'updates an error state' , function ( ) {
145+ const sampleDocuments = reducer (
146+ loadingState ,
147+ fetchingInvalidDocumentFailed ( )
148+ ) ;
149+ expect ( sampleDocuments . invalidDocumentState ) . to . equal ( 'error' ) ;
150+ expect ( sampleDocuments . invalidDocument ) . to . deep . equal ( undefined ) ;
151+ expect ( sampleDocuments . validDocumentState ) . to . equal ( 'loading' ) ;
152+ } ) ;
153+ }
154+ ) ;
156155 } ) ;
157156 } ) ;
158157} ) ;
0 commit comments