|
| 1 | +/* global jest, describe, beforeEach, it, expect, spyOn */ |
| 2 | + |
| 3 | +jest.dontMock('reflux'); |
| 4 | +jest.dontMock('../../actions/actions.js'); |
| 5 | +jest.dontMock('../../utils/api-requests'); |
| 6 | +jest.dontMock('../../components/notification.js'); |
| 7 | +jest.dontMock('../../stores/auth.js'); |
| 8 | +jest.dontMock('../../stores/notifications.js'); |
| 9 | + |
| 10 | +var React = require('react/addons'); |
| 11 | +var TestUtils = React.addons.TestUtils; |
| 12 | + |
| 13 | +describe('Test for Notifications Component', function () { |
| 14 | + |
| 15 | + var Actions, AuthStore, Notification, NotificationsStore; |
| 16 | + |
| 17 | + beforeEach(function () { |
| 18 | + // Mock Electron's window.require |
| 19 | + // and remote.require('shell') |
| 20 | + window.require = function () { |
| 21 | + return { |
| 22 | + require: function () { |
| 23 | + return { |
| 24 | + openExternal: function () { |
| 25 | + return {}; |
| 26 | + } |
| 27 | + }; |
| 28 | + } |
| 29 | + }; |
| 30 | + }; |
| 31 | + |
| 32 | + // Mock localStorage |
| 33 | + window.localStorage = { |
| 34 | + item: false, |
| 35 | + getItem: function () { |
| 36 | + return this.item; |
| 37 | + } |
| 38 | + }; |
| 39 | + |
| 40 | + Actions = require('../../actions/actions.js'); |
| 41 | + AuthStore = require('../../stores/auth.js'); |
| 42 | + Notification = require('../../components/notifications.js'); |
| 43 | + NotificationsStore = require('../../stores/notifications.js'); |
| 44 | + }); |
| 45 | + |
| 46 | + it('Should render the notifications component', function () { |
| 47 | + |
| 48 | + AuthStore.authStatus = function () { |
| 49 | + return true; |
| 50 | + }; |
| 51 | + |
| 52 | + var instance = TestUtils.renderIntoDocument(<Notification />); |
| 53 | + expect(instance.state.loading).toBeTruthy(); |
| 54 | + |
| 55 | + var response = [[{ |
| 56 | + 'repository': { |
| 57 | + 'full_name': 'ekonstantinidis/gitify', |
| 58 | + 'owner': { |
| 59 | + 'avatar_url': 'http://avatar.url' |
| 60 | + } |
| 61 | + }, |
| 62 | + 'subject': { |
| 63 | + 'type': 'Issue' |
| 64 | + } |
| 65 | + }]]; |
| 66 | + |
| 67 | + NotificationsStore.trigger(response); |
| 68 | + expect(instance.state.notifications.length).toBe(1); |
| 69 | + |
| 70 | + expect(instance.state.loading).toBeTruthy(); |
| 71 | + instance.completedNotifications(); |
| 72 | + expect(instance.state.loading).toBeFalsy(); |
| 73 | + |
| 74 | + }); |
| 75 | + |
| 76 | +}); |
0 commit comments