|
| 1 | +/* global jest, describe, beforeEach, it, expect */ |
| 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 Notification Component', function () { |
| 14 | + |
| 15 | + var apiRequests, Actions, AuthStore, SingleNotification, 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 | + apiRequests = require('../../utils/api-requests.js'); |
| 41 | + Actions = require('../../actions/actions.js'); |
| 42 | + AuthStore = require('../../stores/auth.js'); |
| 43 | + SingleNotification = require('../../components/notification.js'); |
| 44 | + NotificationsStore = require('../../stores/notifications.js'); |
| 45 | + }); |
| 46 | + |
| 47 | + it('Should render a notification component (Issue)', function () { |
| 48 | + |
| 49 | + var notification = { |
| 50 | + 'id': '123123123', |
| 51 | + 'repository': { |
| 52 | + 'full_name': 'ekonstantinidis/gitify', |
| 53 | + 'owner': { |
| 54 | + 'avatar_url': 'http://avatar.url' |
| 55 | + } |
| 56 | + }, |
| 57 | + 'subject': { |
| 58 | + 'type': 'Issue', |
| 59 | + 'url': 'http://www.github.com/ekonstantinidis/gitify/pulls/26/' |
| 60 | + } |
| 61 | + }; |
| 62 | + |
| 63 | + var instance = TestUtils.renderIntoDocument( |
| 64 | + <SingleNotification |
| 65 | + notification={notification} |
| 66 | + key={notification.id} />); |
| 67 | + |
| 68 | + expect(instance.state.readClass).toBe('row notification'); |
| 69 | + expect(instance.state.read).toBeFalsy(); |
| 70 | + expect(instance.openBrowser).toBeDefined(); |
| 71 | + expect(instance.markAsRead).toBeDefined(); |
| 72 | + |
| 73 | + // Open Browser |
| 74 | + instance.openBrowser(); |
| 75 | + |
| 76 | + }); |
| 77 | + |
| 78 | + it('Should render a notification component (PullRequest)', function () { |
| 79 | + |
| 80 | + var notification = { |
| 81 | + 'id': '123123123', |
| 82 | + 'repository': { |
| 83 | + 'full_name': 'ekonstantinidis/gitify', |
| 84 | + 'owner': { |
| 85 | + 'avatar_url': 'http://avatar.url' |
| 86 | + } |
| 87 | + }, |
| 88 | + 'subject': { |
| 89 | + 'type': 'PullRequest', |
| 90 | + 'url': 'http://www.github.com/ekonstantinidis/gitify/pulls/26/' |
| 91 | + } |
| 92 | + }; |
| 93 | + |
| 94 | + var instance = TestUtils.renderIntoDocument( |
| 95 | + <SingleNotification |
| 96 | + notification={notification} |
| 97 | + key={notification.id} />); |
| 98 | + |
| 99 | + expect(instance.state.readClass).toBe('row notification'); |
| 100 | + expect(instance.state.read).toBeFalsy(); |
| 101 | + expect(instance.openBrowser).toBeDefined(); |
| 102 | + expect(instance.markAsRead).toBeDefined(); |
| 103 | + |
| 104 | + }); |
| 105 | + |
| 106 | + it('Should render a notification component (OtherType)', function () { |
| 107 | + |
| 108 | + var notification = { |
| 109 | + 'id': '123123123', |
| 110 | + 'repository': { |
| 111 | + 'full_name': 'ekonstantinidis/gitify', |
| 112 | + 'owner': { |
| 113 | + 'avatar_url': 'http://avatar.url' |
| 114 | + } |
| 115 | + }, |
| 116 | + 'subject': { |
| 117 | + 'type': 'OtherType', |
| 118 | + 'url': 'http://www.github.com/ekonstantinidis/gitify/pulls/26/' |
| 119 | + } |
| 120 | + }; |
| 121 | + |
| 122 | + var instance = TestUtils.renderIntoDocument( |
| 123 | + <SingleNotification |
| 124 | + notification={notification} |
| 125 | + key={notification.id} />); |
| 126 | + |
| 127 | + expect(instance.state.readClass).toBe('row notification'); |
| 128 | + expect(instance.state.read).toBeFalsy(); |
| 129 | + expect(instance.openBrowser).toBeDefined(); |
| 130 | + expect(instance.markAsRead).toBeDefined(); |
| 131 | + |
| 132 | + }); |
| 133 | + |
| 134 | +}); |
0 commit comments