it('suggestions should disappear when an outside click occurs', () => { const wrapper = mount(<Autosuggest options={stubOptions} uiState={createStubUiStateStore()} search={() => {}} serviceStore={createServiceStubStore()} operationStore={createOperationStubStore()}/>); const input = wrapper.find('.usb-searchbar__input'); input.prop('onFocus')({target: {value: ''}}); const dummy = document.createElement('div'); wrapper.instance().handleOutsideClick(dummy); expect(wrapper.instance().state.suggestionStrings.length).to.equal(0); });
describe('Avatar component', () => { test('should display image', () => { const wrapper = mount(<Avatar />); expect(wrapper.find('img').filterWhere(img => img.prop('alt') === 'avatar-img')).toHaveLength(1); }); });
it('should be able to add a chip with whitespace', () => { const spy = sinon.spy(Autosuggest.prototype, 'addChipToPendingQueries'); const wrapper = mount(<Autosuggest options={stubOptions} uiState={createStubUiStateStore()} search={() => {}} serviceStore={createServiceStubStore()} operationStore={createOperationStubStore()}/>); expect(spy.callCount).to.equal(0); const input = wrapper.find('.usb-searchbar__input'); wrapper.instance().inputRef.value = 'serviceName="whitespace test"'; input.prop('onKeyDown')({keyCode: 32, preventDefault: () => {}}); const pendingQuery = wrapper.instance().props.uiState.pendingQuery; expect(spy.callCount).to.equal(1); expect(pendingQuery.length).to.equal(1); Autosuggest.prototype.addChipToPendingQueries.restore(); });
it('should execute readMoreClicked when JobListing handleReadMoreClick is called', () => { wrapper.find('JobListing').prop('handleReadMoreClick')(0); expect(readMoreClickedSpy.calledOnce); });
describe('renders className prop', () => { it('defaults button css class to btn', () => { const wrapper = mount(<Button />); expect(wrapper.prop('className')).toEqual('btn'); }); it('renders button css className prop if present', () => { const wrapper = mount(<Button className="btn btn--border" />); expect(wrapper.prop('className')).toEqual('btn btn--border'); }); });
it('should change suggestion when input is changed', () => { const wrapper = mount(<Autosuggest options={stubOptions} uiState={createStubUiStateStore()} search={() => {}} serviceStore={createServiceStubStore()} operationStore={createOperationStubStore()}/>); expect(wrapper.instance().state.suggestionStrings.length).to.equal(0); const input = wrapper.find('.usb-searchbar__input'); input.prop('onChange')({target: {value: 'err'}}); expect(wrapper.instance().state.suggestionStrings.length).to.equal(1); });
describe('<ListItem />', () => { it('should have a className', () => { const renderedComponent = mount(<ListItem className="test" />); expect(renderedComponent.find('li').prop('className')).toBeDefined(); }); it('should render the content passed to it', () => { const content = (<div>Hello world!</div>); const renderedComponent = mount( <ListItem item={content} /> ); expect(renderedComponent.contains(content)).toBe(true); }); });
it('suggestions should disappear when escape is pressed', () => { const wrapper = mount(<Autosuggest options={stubOptions} uiState={createStubUiStateStore()} search={() => {}} serviceStore={createServiceStubStore()} operationStore={createOperationStubStore()}/>); const input = wrapper.find('.usb-searchbar__input'); input.prop('onFocus')({target: {value: ''}}); input.prop('onKeyDown')({keyCode: 27, preventDefault: () => {}}); expect(wrapper.instance().state.suggestionStrings.length).to.equal(0); });
it('should populate suggestions when input is focused', () => { const wrapper = mount(<Autosuggest options={stubOptions} uiState={createStubUiStateStore()} search={() => {}} serviceStore={createServiceStubStore()} operationStore={createOperationStubStore()}/>); expect(wrapper.instance().state.suggestionStrings.length).to.equal(0); const input = wrapper.find('.usb-searchbar__input'); input.prop('onFocus')({target: {value: ''}}); expect(wrapper.instance().state.suggestionStrings.length).to.equal(4); });
it('should change be able to suggest when encapsulating value in quotations', () => { const wrapper = mount(<Autosuggest options={stubOptions} uiState={createStubUiStateStore()} search={() => {}} serviceStore={createServiceStubStore()} operationStore={createOperationStubStore()}/>); expect(wrapper.instance().state.suggestionStrings.length).to.equal(0); const input = wrapper.find('.usb-searchbar__input'); input.prop('onChange')({target: {value: 'error="tr'}}); expect(wrapper.instance().state.suggestionStrings.length).to.equal(1); });
it('should be able to add a chip by pressing space bar', () => { const spy = sinon.spy(Autosuggest.prototype, 'addChipToPendingQueries'); const wrapper = mount(<Autosuggest options={stubOptions} uiState={createStubUiStateStore()} search={() => {}} serviceStore={createServiceStubStore()} operationStore={createOperationStubStore()}/>); expect(spy.callCount).to.equal(0); const input = wrapper.find('.usb-searchbar__input'); wrapper.instance().inputRef.value = 'serviceName=test'; input.prop('onKeyDown')({keyCode: 32, preventDefault: () => {}}); const pendingQuery = wrapper.instance().props.uiState.pendingQuery; expect(spy.callCount).to.equal(1); expect(pendingQuery.length).to.equal(1); Autosuggest.prototype.addChipToPendingQueries.restore(); });
it('should execute readMoreClicked when JobListing handleReadMoreClick is called', () => { wrapper.find('JobListing').prop('handleReadMoreClick')(0); expect(readMoreClickedSpy.calledOnce); });