|
| 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/repository.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 Repository Component', function () { |
| 14 | + |
| 15 | + var Actions, Repository; |
| 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 | + Repository = require('../../components/repository.js'); |
| 42 | + }); |
| 43 | + |
| 44 | + it('Should render the Repository component', function () { |
| 45 | + |
| 46 | + var repoDetails = [{ |
| 47 | + 'repository': { |
| 48 | + 'full_name': 'ekonstantinidis/gitify', |
| 49 | + 'owner': { |
| 50 | + 'avatar_url': 'http://avatar.url' |
| 51 | + } |
| 52 | + }, |
| 53 | + 'subject': { |
| 54 | + 'type': 'Issue' |
| 55 | + } |
| 56 | + }]; |
| 57 | + |
| 58 | + var instance = TestUtils.renderIntoDocument( |
| 59 | + <Repository |
| 60 | + repo={repoDetails} |
| 61 | + repoName='ekonstantinidis/gitify' |
| 62 | + key='ekonstantinidis/gitify' /> |
| 63 | + ); |
| 64 | + |
| 65 | + expect(instance.props.repo[0].repository.full_name).toBe('ekonstantinidis/gitify'); |
| 66 | + expect(instance.getAvatar).toBeDefined(); |
| 67 | + expect(instance.openBrowser).toBeDefined(); |
| 68 | + |
| 69 | + // Get Avatar |
| 70 | + var avatar = instance.getAvatar(); |
| 71 | + expect(avatar).toBe('http://avatar.url'); |
| 72 | + |
| 73 | + // Open Browser |
| 74 | + instance.openBrowser(); |
| 75 | + |
| 76 | + }); |
| 77 | + |
| 78 | +}); |
0 commit comments