|
| 1 | +// Copyright (c) 2020 The Jaeger Authors. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +import React from 'react'; |
| 16 | +import { shallow } from 'enzyme'; |
| 17 | +import TraceName from './TraceName'; |
| 18 | +import { fetchedState } from '../../constants'; |
| 19 | + |
| 20 | +describe('<TraceName>', () => { |
| 21 | + let wrapper; |
| 22 | + let defaultProps; |
| 23 | + |
| 24 | + beforeEach(() => { |
| 25 | + defaultProps = {}; |
| 26 | + wrapper = shallow(<TraceName {...defaultProps} />); |
| 27 | + }); |
| 28 | + |
| 29 | + it('renders with default props', () => { |
| 30 | + expect(wrapper).toMatchSnapshot(); |
| 31 | + }); |
| 32 | + |
| 33 | + it('renders with className', () => { |
| 34 | + const props = { ...defaultProps, className: 'TEST-CLASS-NAME' }; |
| 35 | + wrapper = shallow(<TraceName {...props} />); |
| 36 | + |
| 37 | + expect(wrapper).toMatchSnapshot(); |
| 38 | + }); |
| 39 | + |
| 40 | + it('renders with traceName', () => { |
| 41 | + const props = { ...defaultProps, traceName: 'TEST-TRACE-NAME' }; |
| 42 | + wrapper = shallow(<TraceName {...props} />); |
| 43 | + |
| 44 | + expect(wrapper).toMatchSnapshot(); |
| 45 | + }); |
| 46 | + |
| 47 | + it('renders in loading state', () => { |
| 48 | + const props = { ...defaultProps, state: fetchedState.LOADING }; |
| 49 | + wrapper = shallow(<TraceName {...props} />); |
| 50 | + |
| 51 | + expect(wrapper).toMatchSnapshot(); |
| 52 | + }); |
| 53 | + |
| 54 | + it('renders in error state', () => { |
| 55 | + const props = { ...defaultProps, state: fetchedState.ERROR, error: 'TEST-ERROR-MESSAGE' }; |
| 56 | + wrapper = shallow(<TraceName {...props} />); |
| 57 | + |
| 58 | + expect(wrapper).toMatchSnapshot(); |
| 59 | + }); |
| 60 | + |
| 61 | + it('renders error object in error state', () => { |
| 62 | + const props = { ...defaultProps, state: fetchedState.ERROR, error: new Error('ERROR-OBJECT-MESSAGE') }; |
| 63 | + wrapper = shallow(<TraceName {...props} />); |
| 64 | + |
| 65 | + expect(wrapper).toMatchSnapshot(); |
| 66 | + }); |
| 67 | + |
| 68 | + it('renders empty string error in error state', () => { |
| 69 | + const props = { ...defaultProps, state: fetchedState.ERROR, error: '' }; |
| 70 | + wrapper = shallow(<TraceName {...props} />); |
| 71 | + |
| 72 | + expect(wrapper).toMatchSnapshot(); |
| 73 | + }); |
| 74 | + |
| 75 | + it('renders error object with empty message in error state', () => { |
| 76 | + const props = { ...defaultProps, state: fetchedState.ERROR, error: new Error('') }; |
| 77 | + wrapper = shallow(<TraceName {...props} />); |
| 78 | + |
| 79 | + expect(wrapper).toMatchSnapshot(); |
| 80 | + }); |
| 81 | +}); |
0 commit comments