|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch B.V. under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch B.V. licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +import React from 'react'; |
| 20 | +import { mountWithIntl } from 'test_utils/enzyme_helpers'; |
| 21 | +import { ReactWrapper } from 'enzyme'; |
| 22 | +import { HitsCounter, HitsCounterProps } from './hits_counter'; |
| 23 | +// @ts-ignore |
| 24 | +import { findTestSubject } from '@elastic/eui/lib/test'; |
| 25 | + |
| 26 | +describe('hits counter', function() { |
| 27 | + let props: HitsCounterProps; |
| 28 | + let component: ReactWrapper<HitsCounterProps>; |
| 29 | + |
| 30 | + beforeAll(() => { |
| 31 | + props = { |
| 32 | + onResetQuery: jest.fn(), |
| 33 | + showResetButton: true, |
| 34 | + hits: 2, |
| 35 | + }; |
| 36 | + }); |
| 37 | + |
| 38 | + it('HitsCounter renders a button by providing the showResetButton property', () => { |
| 39 | + component = mountWithIntl(<HitsCounter {...props} />); |
| 40 | + expect(findTestSubject(component, 'resetSavedSearch').length).toBe(1); |
| 41 | + }); |
| 42 | + |
| 43 | + it('HitsCounter not renders a button when the showResetButton property is false', () => { |
| 44 | + component = mountWithIntl( |
| 45 | + <HitsCounter hits={2} showResetButton={false} onResetQuery={jest.fn()} /> |
| 46 | + ); |
| 47 | + expect(findTestSubject(component, 'resetSavedSearch').length).toBe(0); |
| 48 | + }); |
| 49 | + |
| 50 | + it('expect to render the number of hits', function() { |
| 51 | + component = mountWithIntl(<HitsCounter {...props} />); |
| 52 | + const hits = findTestSubject(component, 'discoverQueryHits'); |
| 53 | + expect(hits.text()).toBe('2'); |
| 54 | + }); |
| 55 | + |
| 56 | + it('expect to render 1,899 hits if 1899 hits given', function() { |
| 57 | + component = mountWithIntl( |
| 58 | + <HitsCounter hits={1899} showResetButton={false} onResetQuery={jest.fn()} /> |
| 59 | + ); |
| 60 | + const hits = findTestSubject(component, 'discoverQueryHits'); |
| 61 | + expect(hits.text()).toBe('1,899'); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should reset query', function() { |
| 65 | + component = mountWithIntl(<HitsCounter {...props} />); |
| 66 | + findTestSubject(component, 'resetSavedSearch').simulate('click'); |
| 67 | + expect(props.onResetQuery).toHaveBeenCalled(); |
| 68 | + }); |
| 69 | +}); |
0 commit comments