it('should set state to -1 after new route mounts', () => { const renderedComponent = mount( <ProgressBar percent={0} updateProgress={(noop) => noop} /> ); renderedComponent.setProps({ percent: 100 }); clock.tick(501); expect(renderedComponent.state().percent).toEqual(-1); });
it('should add new searches to the history cookie', () => { global.window.document.cookie = 'searchhistory=[]'; // reset search history cookie const stubQueryOne = {search: '?query_1.serviceName=root-service&time.preset=1h'}; const stubQueryTwo = {search: '?query_1.serviceName=new-root-service&query_1.error=true&time.preset=4h'}; const wrapper = mount(<MemoryRouter><UniversalSearch.WrappedComponent location={stubQueryOne} history={stubHistory}/></MemoryRouter>); expect(wrapper.find('Autosuggest').first().instance().props.uiState.searchHistory.length).to.equal(0); wrapper.setProps({ children: React.cloneElement(wrapper.props().children, { location: stubQueryTwo }) }); expect(wrapper.find('Autosuggest').first().instance().props.uiState.searchHistory.length).to.equal(1); });
test("when value prop changes to `null`, selection is cleared", () => { const wrapper = mount(<Select options={OPTIONS} value="c" />); expect(wrapper.html().indexOf(">C</div>")).not.toBe(-1); wrapper.setProps({ value: null }); expect(wrapper.html().indexOf(">Select...</div>")).not.toBe(-1); });
it('should call action callback after click on project information button', () => { const { component, actions } = renderComponent(); const buttons = component.find(Button); const table = component.find('table').at(1); component.setProps({ activeProjects: ACTIVE_PROJECTS, }); const updateProjectButton = buttons.at(1); const firstRow = table.find('tr').at(0); firstRow.simulate('click'); updateProjectButton.simulate('click'); expect(actions.goToProjectPage).to.have.property('callCount', 1); });
it('should update chips and time preset when location changes', () => { const stubQueryOne = {search: '?query_1.serviceName=root-service&time.preset=1h'}; const stubQueryTwo = {search: '?query_1.serviceName=new-root-service&query_2.error=true&time.preset=4h'}; const wrapper = mount(<MemoryRouter><UniversalSearch.WrappedComponent location={stubQueryOne} history={stubHistory}/></MemoryRouter>); expect(wrapper.find('Autosuggest').first().instance().props.uiState.queries.length).to.equal(1); wrapper.setProps({ children: React.cloneElement(wrapper.props().children, { location: stubQueryTwo }) }); // Ensure that chips were updated with the location change expect(wrapper.find('Autosuggest').first().instance().props.uiState.queries.length).to.equal(2); });
it('should display results if jobListings.length is not zero', () => { let jobListings = [{descriptionText:"Hey", descriptionHasTech:["css","html"]}, {descriptionText:"Ho", descriptionHasTech:["c", "c++"]}]; wrapper.setProps({jobListings:jobListings}); expect(wrapper.find('#no-results')).to.have.length(0); expect(wrapper.find('#search-results-container')).to.have.length(1); });
test('hide when showAddPost is false', t => { const wrapper = mountWithIntl( <PostCreateWidget {...props} /> ); wrapper.setProps({ showAddPost: false }); t.falsy(wrapper.hasClass('appear')); });
describe('getSecretWord calls', () => { test('getSecretWord gets called on App mount', () => { setup() // check to see if secret word was updated expect(mockGetSecretWord).toHaveBeenCalled() }) test('does not update on app update', () => { const wrapper = setup() // need to clear after setup so starting fresh mockGetSecretWord.mockClear() // still cannot use update() because won't trigger useEffect (issue 2091) wrapper.setProps() expect(mockGetSecretWord).not.toHaveBeenCalled() }) })
it('should call componentWillReceiveProps', () => { sinon.spy(ProgressBar.prototype, 'componentWillReceiveProps'); const renderedComponent = mount( // eslint-disable-line <ProgressBar percent={0} updateProgress={(noop) => noop} /> ); renderedComponent.setProps({ percent: 50 }); expect(ProgressBar.prototype.componentWillReceiveProps.calledOnce).toEqual(true); ProgressBar.prototype.componentWillReceiveProps.restore(); });
it('when not collapsed and then collapses height changes', () => { Collapsible.prototype.getHeight.mockReturnValue('100px'); const wrapper = mount( <Collapsible> <div>100</div> </Collapsible>, ); jest.runTimersToTime(401); expect(wrapper.find('.collapsible')).toHaveStyle('height', '100px'); expect(wrapper.find('.collapsible')).toHaveStyle('overflow', 'visible'); // Collapse it wrapper.setProps({ collapsed: true }); jest.runTimersToTime(401); expect(wrapper.find('.collapsible')).toHaveStyle('height', 0); expect(wrapper.find('.collapsible')).toHaveStyle('overflow', 'hidden'); });
it('should modify row when selected', () => { const { fullDOM } = setup() fullDOM.setProps({ selection: {selection__players: [1]}}) fullDOM.update() expect(fullDOM.find('.player-list__row--selected').length).toBe(1) expect(fullDOM.find('.player-list__row--selected button').text()).toBe('-') })
it('should set state to -1 after new route mounts', () => { const renderedComponent = mount( <ProgressBar percent={0} updateProgress={(noop) => noop} /> ); renderedComponent.setProps({ percent: 100 }); clock.tick(501); expect(renderedComponent.state().percent).toEqual(-1); });
it('should call componentWillReceiveProps', () => { sinon.spy(ProgressBar.prototype, 'componentWillReceiveProps'); const renderedComponent = mount( // eslint-disable-line <ProgressBar percent={0} updateProgress={(noop) => noop} /> ); renderedComponent.setProps({ percent: 50 }); expect(ProgressBar.prototype.componentWillReceiveProps.calledOnce).toEqual(true); ProgressBar.prototype.componentWillReceiveProps.restore(); });
test("when value prop changes to `null`, selection is cleared", () => { const wrapper = mount(<Select options={OPTIONS} value="c" />); expect(wrapper.html().indexOf(">C</div>")).not.toBe(-1); wrapper.setProps({ value: null }); expect(wrapper.html().indexOf(">Select...</div>")).not.toBe(-1); });
it('should display results if jobListings.length is not zero', () => { let jobListings = [{descriptionText:"Hey", descriptionHasTech:["css","html"]}, {descriptionText:"Ho", descriptionHasTech:["c", "c++"]}]; wrapper.setProps({jobListings:jobListings}); expect(wrapper.find('#no-results')).to.have.length(0); expect(wrapper.find('#search-results-container')).to.have.length(1); });