|
| 1 | +/*global jest, describe, it, expect, spyOn, beforeEach */ |
| 2 | + |
| 3 | +'use strict'; |
| 4 | + |
| 5 | +jest.dontMock('reflux'); |
| 6 | +jest.dontMock('../../stores/notifications.js'); |
| 7 | +jest.dontMock('../../utils/api-requests.js'); |
| 8 | +jest.dontMock('../../actions/actions.js'); |
| 9 | + |
| 10 | +describe('Tests for NotificationsStore', function () { |
| 11 | + |
| 12 | + var NotificationsStore, Actions, apiRequests; |
| 13 | + |
| 14 | + beforeEach(function () { |
| 15 | + |
| 16 | + // Mock Electron's window.require |
| 17 | + window.require = function () { |
| 18 | + return { |
| 19 | + sendChannel: function () { |
| 20 | + return; |
| 21 | + } |
| 22 | + }; |
| 23 | + }; |
| 24 | + |
| 25 | + // Mock localStorage |
| 26 | + window.localStorage = { |
| 27 | + item: false, |
| 28 | + getItem: function () { |
| 29 | + return this.item; |
| 30 | + } |
| 31 | + }; |
| 32 | + |
| 33 | + Actions = require('../../actions/actions.js'); |
| 34 | + apiRequests = require('../../utils/api-requests.js'); |
| 35 | + NotificationsStore = require('../../stores/notifications.js'); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should get the notifications from the GitHub API', function () { |
| 39 | + |
| 40 | + spyOn(NotificationsStore, 'trigger'); |
| 41 | + |
| 42 | + var response = [{ |
| 43 | + 'id': '1', |
| 44 | + 'repository': { |
| 45 | + 'id': 1296269, |
| 46 | + 'owner': { |
| 47 | + 'login': 'octocat', |
| 48 | + 'id': 1, |
| 49 | + 'avatar_url': 'https://github.com/images/error/octocat_happy.gif', |
| 50 | + 'gravatar_id': '', |
| 51 | + 'url': 'https://api.github.com/users/octocat', |
| 52 | + 'html_url': 'https://github.com/octocat', |
| 53 | + 'followers_url': 'https://api.github.com/users/octocat/followers', |
| 54 | + 'following_url': 'https://api.github.com/users/octocat/following{/other_user}', |
| 55 | + 'gists_url': 'https://api.github.com/users/octocat/gists{/gist_id}', |
| 56 | + 'starred_url': 'https://api.github.com/users/octocat/starred{/owner}{/repo}', |
| 57 | + 'subscriptions_url': 'https://api.github.com/users/octocat/subscriptions', |
| 58 | + 'organizations_url': 'https://api.github.com/users/octocat/orgs', |
| 59 | + 'repos_url': 'https://api.github.com/users/octocat/repos', |
| 60 | + 'events_url': 'https://api.github.com/users/octocat/events{/privacy}', |
| 61 | + 'received_events_url': 'https://api.github.com/users/octocat/received_events', |
| 62 | + 'type': 'User', |
| 63 | + 'site_admin': false |
| 64 | + }, |
| 65 | + 'name': 'Hello-World', |
| 66 | + 'full_name': 'octocat/Hello-World', |
| 67 | + 'description': 'This your first repo!', |
| 68 | + 'private': false, |
| 69 | + 'fork': false, |
| 70 | + 'url': 'https://api.github.com/repos/octocat/Hello-World', |
| 71 | + 'html_url': 'https://github.com/octocat/Hello-World' |
| 72 | + }, |
| 73 | + 'subject': { |
| 74 | + 'title': 'Greetings', |
| 75 | + 'url': 'https://api.github.com/repos/octokit/octokit.rb/issues/123', |
| 76 | + 'latest_comment_url': 'https://api.github.com/repos/octokit/octokit.rb/issues/comments/123', |
| 77 | + 'type': 'Issue' |
| 78 | + }, |
| 79 | + 'reason': 'subscribed', |
| 80 | + 'unread': true, |
| 81 | + 'updated_at': '2014-11-07T22:01:45Z', |
| 82 | + 'last_read_at': '2014-11-07T22:01:45Z', |
| 83 | + 'url': 'https://api.github.com/notifications/threads/1' |
| 84 | + }]; |
| 85 | + |
| 86 | + var superagent = require('superagent'); |
| 87 | + superagent.__setResponse(200, 'ok', response, false); |
| 88 | + |
| 89 | + Actions.getNotifications(); |
| 90 | + |
| 91 | + jest.runAllTimers(); |
| 92 | + |
| 93 | + var repository = NotificationsStore._notifications[0][0].repository; |
| 94 | + expect(repository.full_name).toBe('octocat/Hello-World'); |
| 95 | + expect(NotificationsStore.trigger).toHaveBeenCalled(); |
| 96 | + |
| 97 | + }); |
| 98 | + |
| 99 | +}); |
0 commit comments