@@ -12,7 +12,7 @@ var TestUtils = React.addons.TestUtils;
1212
1313describe ( 'Test for Repository Component' , function ( ) {
1414
15- var Actions , Repository ;
15+ var apiRequests , Actions , Repository ;
1616
1717 beforeEach ( function ( ) {
1818 // Mock Electron's window.require
@@ -37,6 +37,7 @@ describe('Test for Repository Component', function () {
3737 }
3838 } ;
3939
40+ apiRequests = require ( '../../utils/api-requests.js' ) ;
4041 Actions = require ( '../../actions/actions.js' ) ;
4142 Repository = require ( '../../components/repository.js' ) ;
4243 } ) ;
@@ -63,8 +64,10 @@ describe('Test for Repository Component', function () {
6364 ) ;
6465
6566 expect ( instance . props . repo [ 0 ] . repository . full_name ) . toBe ( 'ekonstantinidis/gitify' ) ;
67+ expect ( instance . isRead ) . toBeFalsy ( ) ;
6668 expect ( instance . getAvatar ) . toBeDefined ( ) ;
6769 expect ( instance . openBrowser ) . toBeDefined ( ) ;
70+ expect ( instance . markRepoAsRead ) . toBeDefined ( ) ;
6871
6972 // Get Avatar
7073 var avatar = instance . getAvatar ( ) ;
@@ -75,4 +78,80 @@ describe('Test for Repository Component', function () {
7578
7679 } ) ;
7780
81+ it ( 'Should mark a repo as read - successfully' , function ( ) {
82+
83+ var repoDetails = [ {
84+ 'repository' : {
85+ 'name' : 'gitify' ,
86+ 'full_name' : 'ekonstantinidis/gitify' ,
87+ 'owner' : {
88+ 'login' : 'ekonstantinidis' ,
89+ 'avatar_url' : 'http://avatar.url'
90+ }
91+ } ,
92+ 'subject' : {
93+ 'type' : 'Issue'
94+ }
95+ } ] ;
96+
97+ var instance = TestUtils . renderIntoDocument (
98+ < Repository
99+ repo = { repoDetails }
100+ repoName = 'ekonstantinidis/gitify'
101+ key = 'ekonstantinidis/gitify' />
102+ ) ;
103+
104+ expect ( instance . state . isRead ) . toBeFalsy ( ) ;
105+ expect ( instance . markRepoAsRead ) . toBeDefined ( ) ;
106+
107+ var superagent = require ( 'superagent' ) ;
108+ superagent . __setResponse ( 200 , 'ok' , { } , false ) ;
109+
110+ // Mark Repo as Read
111+ instance . markRepoAsRead ( ) ;
112+ jest . runAllTimers ( ) ;
113+
114+ expect ( instance . state . isRead ) . toBeTruthy ( ) ;
115+
116+ } ) ;
117+
118+ it ( 'Should mark a repo as read - fail' , function ( ) {
119+
120+ var repoDetails = [ {
121+ 'repository' : {
122+ 'name' : 'gitify' ,
123+ 'full_name' : 'ekonstantinidis/gitify' ,
124+ 'owner' : {
125+ 'login' : 'ekonstantinidis' ,
126+ 'avatar_url' : 'http://avatar.url'
127+ }
128+ } ,
129+ 'subject' : {
130+ 'type' : 'Issue'
131+ }
132+ } ] ;
133+
134+ var instance = TestUtils . renderIntoDocument (
135+ < Repository
136+ repo = { repoDetails }
137+ repoName = 'ekonstantinidis/gitify'
138+ key = 'ekonstantinidis/gitify' />
139+ ) ;
140+
141+ expect ( instance . state . isRead ) . toBeFalsy ( ) ;
142+ expect ( instance . state . errors ) . toBeFalsy ( ) ;
143+ expect ( instance . markRepoAsRead ) . toBeDefined ( ) ;
144+
145+ var superagent = require ( 'superagent' ) ;
146+ superagent . __setResponse ( 400 , false ) ;
147+
148+ // Mark Repo as Read
149+ instance . markRepoAsRead ( ) ;
150+ jest . runAllTimers ( ) ;
151+
152+ expect ( instance . state . isRead ) . toBeFalsy ( ) ;
153+ expect ( instance . state . errors ) . toBeTruthy ( ) ;
154+
155+ } ) ;
156+
78157} ) ;
0 commit comments