This repository was archived by the owner on Jun 11, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +80
-4
lines changed
src/common/components/repositories-home
test/unit/src/common/components/repositories-home Expand file tree Collapse file tree 2 files changed +80
-4
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,10 @@ class RepositoriesHome extends Component {
55
55
}
56
56
57
57
componentWillReceiveProps ( nextProps ) {
58
- if ( this . props . snaps . success !== nextProps . snaps . success ) {
58
+ const snapsLength = nextProps . snaps . snaps && nextProps . snaps . snaps . length ;
59
+
60
+ if ( ( this . props . snaps . success !== nextProps . snaps . success )
61
+ || ( snapsLength === 0 ) ) {
59
62
this . fetchData ( nextProps ) ;
60
63
}
61
64
}
@@ -89,9 +92,14 @@ class RepositoriesHome extends Component {
89
92
90
93
render ( ) {
91
94
const { snaps } = this . props ;
92
- const hasSnaps = ( snaps . snaps && Object . keys ( snaps . snaps ) . length > 0 ) ;
93
- // show spinner until we know if user has any enabled repos
94
- return ( snaps . isFetching && ! hasSnaps )
95
+ const hasSnaps = ( snaps . snaps && snaps . snaps . length > 0 ) ;
96
+
97
+ // show spinner if snaps data was not yet fetched (snaps list is empty)
98
+ // (to avoid spinner during polling we are not checking `success` or `isFetching`
99
+ //
100
+ // when snaps are loaded and user doesn't have any, they will be redirected
101
+ // to select repositories (so spinner won't be showing endlessly)
102
+ return ! hasSnaps
95
103
? this . renderSpinner ( )
96
104
: this . renderRepositoriesList ( ) ;
97
105
}
Original file line number Diff line number Diff line change @@ -18,6 +18,74 @@ describe('The RepositoriesHome component', () => {
18
18
clock . restore ( ) ;
19
19
} ) ;
20
20
21
+ context ( 'when snaps are not loaded' , ( ) => {
22
+ let wrapper ;
23
+
24
+ beforeEach ( ( ) => {
25
+ props = {
26
+ auth : {
27
+ authenticated : true
28
+ } ,
29
+ user : { } ,
30
+ snaps : { } ,
31
+ snapBuilds : { } ,
32
+ fetchBuilds : ( ) => { } ,
33
+ updateSnaps : ( ) => { } ,
34
+ router : { }
35
+ } ;
36
+
37
+ wrapper = shallow ( < RepositoriesHome { ...props } /> ) ;
38
+ } ) ;
39
+
40
+ it ( 'should render spinner' , ( ) => {
41
+ expect ( wrapper . find ( 'Spinner' ) . length ) . toBe ( 1 ) ;
42
+ } ) ;
43
+ } ) ;
44
+
45
+ context ( 'when user has no snaps' , ( ) => {
46
+ let wrapper ;
47
+
48
+ beforeEach ( ( ) => {
49
+ props = {
50
+ auth : {
51
+ authenticated : true
52
+ } ,
53
+ user : { } ,
54
+ snaps : {
55
+ success : true ,
56
+ snaps : [ ]
57
+ } ,
58
+ snapBuilds : { } ,
59
+ fetchBuilds : ( ) => { } ,
60
+ updateSnaps : ( ) => { } ,
61
+ router : {
62
+ replace : expect . createSpy ( )
63
+ }
64
+ } ;
65
+
66
+ wrapper = shallow ( < RepositoriesHome { ...props } /> ) ;
67
+ } ) ;
68
+
69
+ it ( 'should render spinner' , ( ) => {
70
+ expect ( wrapper . find ( 'Spinner' ) . length ) . toBe ( 1 ) ;
71
+ } ) ;
72
+
73
+ context ( 'and component recieves props' , ( ) => {
74
+ beforeEach ( ( ) => {
75
+ wrapper . instance ( ) . componentDidMount ( ) ;
76
+ wrapper . instance ( ) . componentWillReceiveProps ( props ) ;
77
+ } ) ;
78
+
79
+ afterEach ( ( ) => {
80
+ wrapper . instance ( ) . componentWillUnmount ( ) ;
81
+ } ) ;
82
+
83
+ it ( 'should redirect to select repositories' , ( ) => {
84
+ expect ( props . router . replace ) . toHaveBeenCalledWith ( '/select-repositories' ) ;
85
+ } ) ;
86
+ } ) ;
87
+ } ) ;
88
+
21
89
context ( 'when user is logged in' , ( ) => {
22
90
let wrapper ;
23
91
You can’t perform that action at this time.
0 commit comments