Skip to content

Commit e9aa698

Browse files
authored
Add coverage around existing TraceName component (#626)
Signed-off-by: Tim Klever <Tim.V.Klever@aexp.com>
1 parent 7f4c562 commit e9aa698

File tree

2 files changed

+177
-0
lines changed

2 files changed

+177
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
});
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`<TraceName> renders empty string error in error state 1`] = `
4+
<span
5+
className="TraceName is-error "
6+
>
7+
<BreakableText
8+
className="BreakableText"
9+
text="Error: Unknown error"
10+
wordRegexp={/\\\\W\\*\\\\w\\+\\\\W\\*/g}
11+
/>
12+
</span>
13+
`;
14+
15+
exports[`<TraceName> renders error object in error state 1`] = `
16+
<span
17+
className="TraceName is-error "
18+
>
19+
<BreakableText
20+
className="BreakableText"
21+
text="ERROR-OBJECT-MESSAGE"
22+
wordRegexp={/\\\\W\\*\\\\w\\+\\\\W\\*/g}
23+
/>
24+
</span>
25+
`;
26+
27+
exports[`<TraceName> renders error object with empty message in error state 1`] = `
28+
<span
29+
className="TraceName is-error "
30+
>
31+
<BreakableText
32+
className="BreakableText"
33+
text="Error"
34+
wordRegexp={/\\\\W\\*\\\\w\\+\\\\W\\*/g}
35+
/>
36+
</span>
37+
`;
38+
39+
exports[`<TraceName> renders in error state 1`] = `
40+
<span
41+
className="TraceName is-error "
42+
>
43+
<BreakableText
44+
className="BreakableText"
45+
text="TEST-ERROR-MESSAGE"
46+
wordRegexp={/\\\\W\\*\\\\w\\+\\\\W\\*/g}
47+
/>
48+
</span>
49+
`;
50+
51+
exports[`<TraceName> renders in loading state 1`] = `
52+
<span
53+
className="TraceName "
54+
>
55+
<LoadingIndicator
56+
centered={false}
57+
small={true}
58+
/>
59+
</span>
60+
`;
61+
62+
exports[`<TraceName> renders with className 1`] = `
63+
<span
64+
className="TraceName TEST-CLASS-NAME"
65+
>
66+
<BreakableText
67+
className="BreakableText"
68+
text="<trace-without-root-span>"
69+
wordRegexp={/\\\\W\\*\\\\w\\+\\\\W\\*/g}
70+
/>
71+
</span>
72+
`;
73+
74+
exports[`<TraceName> renders with default props 1`] = `
75+
<span
76+
className="TraceName "
77+
>
78+
<BreakableText
79+
className="BreakableText"
80+
text="<trace-without-root-span>"
81+
wordRegexp={/\\\\W\\*\\\\w\\+\\\\W\\*/g}
82+
/>
83+
</span>
84+
`;
85+
86+
exports[`<TraceName> renders with traceName 1`] = `
87+
<span
88+
className="TraceName "
89+
>
90+
<BreakableText
91+
className="BreakableText"
92+
text="TEST-TRACE-NAME"
93+
wordRegexp={/\\\\W\\*\\\\w\\+\\\\W\\*/g}
94+
/>
95+
</span>
96+
`;

0 commit comments

Comments
 (0)