|
| 1 | +/* global jest, describe, beforeEach, it, expect, spyOn */ |
| 2 | + |
| 3 | +jest.dontMock('reflux'); |
| 4 | +jest.dontMock('../../actions/actions.js'); |
| 5 | +jest.dontMock('../../components/settings.js'); |
| 6 | +jest.dontMock('../../stores/settings.js'); |
| 7 | + |
| 8 | +var React = require('react/addons'); |
| 9 | +var TestUtils = React.addons.TestUtils; |
| 10 | + |
| 11 | +describe('Test for Settings Component', function () { |
| 12 | + |
| 13 | + var Actions, SettingsStore, Settings; |
| 14 | + |
| 15 | + beforeEach(function () { |
| 16 | + // Mock Electron's window.require |
| 17 | + // and remote.require('shell') |
| 18 | + window.require = function () { |
| 19 | + return { |
| 20 | + sendChannel: function () { |
| 21 | + return; |
| 22 | + } |
| 23 | + }; |
| 24 | + }; |
| 25 | + |
| 26 | + // Mock localStorage |
| 27 | + window.localStorage = { |
| 28 | + item: false, |
| 29 | + getItem: function () { |
| 30 | + return this.item; |
| 31 | + } |
| 32 | + }; |
| 33 | + |
| 34 | + Actions = require('../../actions/actions.js'); |
| 35 | + SettingsStore = require('../../stores/settings.js'); |
| 36 | + Settings = require('../../components/settings.js'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('Should render the settings component', function () { |
| 40 | + |
| 41 | + spyOn(Actions, 'setSetting'); |
| 42 | + |
| 43 | + var instance = TestUtils.renderIntoDocument(<Settings />); |
| 44 | + |
| 45 | + expect(instance.state.participating).toBeFalsy(); |
| 46 | + expect(instance.toggleParticipating).toBeDefined(); |
| 47 | + expect(instance.appQuit).toBeDefined(); |
| 48 | + |
| 49 | + instance.toggleParticipating({ |
| 50 | + target: { |
| 51 | + checked: true |
| 52 | + } |
| 53 | + }); |
| 54 | + expect(Actions.setSetting).toHaveBeenCalledWith('participating', true); |
| 55 | + |
| 56 | + instance.appQuit(); |
| 57 | + }); |
| 58 | + |
| 59 | +}); |
0 commit comments