File tree Expand file tree Collapse file tree 2 files changed +32
-11
lines changed
app/components/Client/List Expand file tree Collapse file tree 2 files changed +32
-11
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ class Client extends React.Component
1212 clients : null ,
1313 error : ''
1414 } ;
15+ this . showError = this . showError . bind ( this ) ;
16+ this . listClients = this . listClients . bind ( this ) ;
1517 this . getClients ( ) ;
1618 }
1719
@@ -26,14 +28,18 @@ class Client extends React.Component
2628 } ) ;
2729 }
2830
29- render ( ) {
31+ showError ( ) {
3032 if ( this . state . error ) {
3133 return ( < Error error = { this . state . error } /> ) ;
3234 }
33- if ( ! this . state . clients ) {
34- return < div > Loading...</ div > ;
35+ return '' ;
36+ }
37+
38+ listClients ( ) {
39+ if ( this . state . error ) {
40+ return '' ;
3541 }
36- const clientList = this . state . clients . map ( ( client , key ) => {
42+ return this . state . clients . map ( ( client , key ) => {
3743 let line = ( ( key % 2 ) ? 'is-success' : 'is-info' ) ;
3844 return (
3945 < tr key = { key } >
@@ -58,10 +64,17 @@ class Client extends React.Component
5864 </ tr >
5965 ) ;
6066 } ) ;
67+ }
68+
69+ render ( ) {
70+ if ( ! this . state . clients && ! this . state . error ) {
71+ return < div > Loading...</ div > ;
72+ }
6173
6274 return (
6375 < section className = "" >
6476 < div className = "container hello" >
77+ { this . showError ( ) }
6578 < div className = "level header" >
6679 < div className = "level-left" >
6780 < h2 className = "title is-2" > iClient</ h2 >
@@ -77,7 +90,7 @@ class Client extends React.Component
7790 </ div >
7891 < table className = "table" >
7992 < tbody >
80- { clientList }
93+ { this . listClients ( ) }
8194 </ tbody >
8295 </ table >
8396 </ div >
Original file line number Diff line number Diff line change @@ -33,9 +33,13 @@ describe('Test Client', () => {
3333 ) ;
3434
3535 setTimeout ( ( ) => {
36- component . update ( ) ;
37- expect ( component . render ( ) . text ( ) ) . toEqual ( 'Client Not Found' ) ;
38- done ( ) ;
36+ try {
37+ component . update ( ) ;
38+ expect ( component . render ( ) . find ( '.is-danger' ) . text ( ) ) . toEqual ( 'Client Not Found' ) ;
39+ done ( ) ;
40+ } catch ( e ) {
41+ console . log ( e ) ;
42+ }
3943 } , 0 ) ;
4044 } ) ;
4145
@@ -55,9 +59,13 @@ describe('Test Client', () => {
5559 ) ;
5660
5761 setTimeout ( ( ) => {
58- component . update ( ) ;
59- expect ( component . render ( ) . text ( ) ) . toEqual ( 'Error Found: Trying get client' ) ;
60- done ( ) ;
62+ try {
63+ component . update ( ) ;
64+ expect ( component . render ( ) . find ( '.is-danger' ) . text ( ) ) . toEqual ( 'Error Found: Trying get client' ) ;
65+ done ( ) ;
66+ } catch ( e ) {
67+ console . log ( e ) ;
68+ }
6169 } , 0 ) ;
6270 } ) ;
6371
You can’t perform that action at this time.
0 commit comments