wrapper .find('.t_a_tag') .first() .simulate('click') })
xit('should reload the graphs upon selecting a separate time', () => { const operationStore = createOperationStubStore(stubSearchResults, stubOperationResults, fulfilledPromise, stubQuery, stubQuery); const wrapper = mount(<MemoryRouter> <TrendsDetailsStubComponent store={operationStore} location={stubLocation} serviceName={stubService} opName={stubOperation} /> </MemoryRouter>); wrapper.find('.btn-default').first().simulate('click'); expect(operationStore.fetchTrends.callCount).to.equal(2); expect(wrapper.find('.chart-container')).to.have.length(3); expect(wrapper.find('#trend-row-container')).to.have.length(1); });
it('should allow whitelisted keys with a period in them', () => { const stubQuery = {search: '?query_1.test.key=root-service'}; const wrapper = mount(<MemoryRouter><UniversalSearch.WrappedComponent location={stubQuery} history={stubHistory}/></MemoryRouter>); expect(wrapper.find('Autosuggest').first().instance().props.uiState.queries.length).to.equal(1); });
test('Entries submitted', () => { initialState.ui.storyIndex = 0; const output = mount(<WordsPanel/>); output.find('[type="submit"]').first().simulate('click'); const actions = getDispatchArguments(); const expectedActions = [ setShowStory(true), setOutput('Story 1: v1 v2 v3 end') ]; expect(actions.sort(sorter)).toEqual(expectedActions.sort(sorter)); });
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); });
it('update suggestion string index on suggestion mouseover', () => { const wrapper = mount(<Autosuggest options={stubOptions} uiState={createStubUiStateStore()} search={() => {}} serviceStore={createServiceStubStore()} operationStore={createOperationStubStore()}/>); wrapper.instance().updateFieldKv({target: {value: 'e'}}); wrapper.update(); const firstSuggestion = wrapper.find('.usb-suggestions__field').first(); firstSuggestion.simulate('mouseEnter'); expect(wrapper.instance().state.suggestionIndex).to.equal(0); });
it('Calls onClick event on click of a board square', () => { const squares = Array(9).fill(null); const onClick = jest.fn(); const wrapper = mount( <Board squares={squares} onClick={onClick}/> ); wrapper.find('button.square').first().simulate('click'); expect(onClick).toHaveBeenCalledWith(0); });
it("sets error when attempting to save an empty title field", () => { const wrapper = render(); wrapper.find("form").simulate("submit"); const error = wrapper.find(".alert").first(); expect(error.text()).toBe("Title is required"); });
it('onFocus and onBlur sets style', () => { const wrapper = mount(<Select options={options} placeholder="Choose" />); const $select = wrapper.find('select'); expect(wrapper.find('.selected-option')).not.toHaveClassName('focus'); $select.first().simulate('focus'); expect(wrapper.find('.selected-option')).toHaveClassName('focus'); $select.first().simulate('blur'); expect(wrapper.find('.selected-option')).not.toHaveClassName('focus'); });
it('it should show clear button and clear value when click that button', () => { const wrapper = mount(<Autocompleter />); wrapper.find('input').simulate('change', {target: {value: 'a'}}); let clearIcon = wrapper.find('svg').first(); clearIcon.simulate('click'); expect(wrapper.state('search')).toBe(''); });
it('if onchange before invalid then error hidden', () => { const wrapper = mount(<Field id="email" name="email" type="email" />); const $input = wrapper.find('input'); $input.instance().value = 'notanemail'; $input.first().simulate('change', { target: { value: 'notanemail' } }); expect(wrapper).toHaveState('invalid', false); expect(wrapper).toHaveState('errorMessage', ''); // Activate validation and show message $input.instance().dispatchEvent(new window.Event('invalid', { bubbles: true })); expect(wrapper).toHaveState('invalid', true); expect(wrapper).toHaveState('errorMessage', 'This value is not an email.'); });
it('should update the picker upon selecting a preset', () => { const wrapper = mount(<Autosuggest options={stubOptions} uiState={createStubUiStateStore()} search={() => {}} serviceStore={createServiceStubStore()} operationStore={createOperationStubStore()}/>); wrapper.find('.usb-timepicker__button').simulate('click'); wrapper.find('.timerange-picker__preset').first().simulate('click'); expect(wrapper.instance().props.uiState.timeWindow.timePreset).to.equal('5m'); });
it('renders job list anchor link', () => { const wrapper = mount( <Provider store={store}> <Router> <App /> </Router> </Provider> ); const anchor = wrapper.find(Route).find('JobsListingContainer').find('Job').find('a').first(); expect(anchor.text() == "View"); })
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('if no invalid event then error hidden', () => { const wrapper = mount(<Field id="email" name="email" type="email" />); const $input = wrapper.find('input'); $input.instance().value = 'notanemail'; $input.first().simulate('change', { target: { value: 'notanemail' } }); expect(wrapper).toHaveState('invalid', false); expect(wrapper).toHaveState('errorMessage', ''); expect(wrapper.find('.field-error')).not.toExist(); });