|
| 1 | +/* global jest, describe, beforeEach, it, expect, spyOn */ |
| 2 | + |
| 3 | +jest.dontMock('reflux'); |
| 4 | +jest.dontMock('../../actions/actions.js'); |
| 5 | +jest.dontMock('../../components/search-input.js'); |
| 6 | +jest.dontMock('../../stores/auth.js'); |
| 7 | + |
| 8 | +var React = require('react/addons'); |
| 9 | +var TestUtils = React.addons.TestUtils; |
| 10 | + |
| 11 | +describe('Test for Search Input Component', function () { |
| 12 | + |
| 13 | + var Actions, AuthStore, SearchInput; |
| 14 | + |
| 15 | + beforeEach(function () { |
| 16 | + // Mock Electron's window.require |
| 17 | + // and remote.require('shell') |
| 18 | + window.require = function () { |
| 19 | + return { |
| 20 | + require: function () { |
| 21 | + return { |
| 22 | + openExternal: function () { |
| 23 | + return {}; |
| 24 | + } |
| 25 | + }; |
| 26 | + } |
| 27 | + }; |
| 28 | + }; |
| 29 | + |
| 30 | + // Mock localStorage |
| 31 | + window.localStorage = { |
| 32 | + item: false, |
| 33 | + getItem: function () { |
| 34 | + return this.item; |
| 35 | + } |
| 36 | + }; |
| 37 | + |
| 38 | + Actions = require('../../actions/actions.js'); |
| 39 | + AuthStore = require('../../stores/auth.js'); |
| 40 | + SearchInput = require('../../components/search-input.js'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('Should make a search', function () { |
| 44 | + |
| 45 | + spyOn(Actions, 'updateSearchTerm'); |
| 46 | + spyOn(Actions, 'clearSearchTerm'); |
| 47 | + |
| 48 | + var instance = TestUtils.renderIntoDocument(<SearchInput />); |
| 49 | + |
| 50 | + var wrapper = TestUtils.scryRenderedDOMComponentsWithClass(instance, 'search-wrapper'); |
| 51 | + expect(wrapper.length).toBe(1); |
| 52 | + |
| 53 | + instance.clearSearch(); |
| 54 | + |
| 55 | + instance.onChange({ |
| 56 | + target: { |
| 57 | + value: 'hello' |
| 58 | + } |
| 59 | + }); |
| 60 | + |
| 61 | + expect(Actions.updateSearchTerm).toHaveBeenCalledWith('hello'); |
| 62 | + }); |
| 63 | + |
| 64 | + it('Should clear the search', function () { |
| 65 | + spyOn(Actions, 'clearSearchTerm'); |
| 66 | + |
| 67 | + var instance = TestUtils.renderIntoDocument(<SearchInput />); |
| 68 | + var clearButton = TestUtils.scryRenderedDOMComponentsWithClass(instance, 'octicon-x')[0]; |
| 69 | + |
| 70 | + expect(Actions.clearSearchTerm).not.toHaveBeenCalled(); |
| 71 | + |
| 72 | + TestUtils.Simulate.click(clearButton); |
| 73 | + |
| 74 | + expect(Actions.clearSearchTerm).toHaveBeenCalled(); |
| 75 | + }); |
| 76 | + |
| 77 | +}); |
0 commit comments