Skip to content

Commit cfe11f9

Browse files
[Uptime] Add client-side unit tests for remaining synthetics code (#80215)
* Test remaining branches in synthetics components. * Fix TS errors. * PR feedback. Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 818fbbf commit cfe11f9

File tree

9 files changed

+655
-14
lines changed

9 files changed

+655
-14
lines changed

x-pack/plugins/uptime/public/components/monitor/synthetics/__tests__/browser_expanded_row.test.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('BrowserExpandedRowComponent', () => {
2828

2929
it('returns empty step state when no journey', () => {
3030
expect(shallowWithIntl(<BrowserExpandedRowComponent />)).toMatchInlineSnapshot(
31-
`<EmptyStepState />`
31+
`<EmptyJourney />`
3232
);
3333
});
3434

@@ -43,7 +43,7 @@ describe('BrowserExpandedRowComponent', () => {
4343
}}
4444
/>
4545
)
46-
).toMatchInlineSnapshot(`<EmptyStepState />`);
46+
).toMatchInlineSnapshot(`<EmptyJourney />`);
4747
});
4848

4949
it('displays loading spinner when loading', () => {
@@ -111,6 +111,27 @@ describe('BrowserExpandedRowComponent', () => {
111111
`);
112112
});
113113

114+
it('handles case where synth type is somehow missing', () => {
115+
expect(
116+
shallowWithIntl(
117+
<BrowserExpandedRowComponent
118+
journey={{
119+
checkGroup: 'check_group',
120+
loading: false,
121+
steps: [
122+
{
123+
...defStep,
124+
synthetics: {
125+
type: undefined,
126+
},
127+
},
128+
],
129+
}}
130+
/>
131+
)
132+
).toMatchInlineSnapshot(`""`);
133+
});
134+
114135
it('renders console output step list when only console steps are present', () => {
115136
expect(
116137
shallowWithIntl(
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
8+
import React from 'react';
9+
import { ConsoleEvent } from '../console_event';
10+
11+
describe('ConsoleEvent component', () => {
12+
it('renders danger color for errors', () => {
13+
expect(
14+
shallowWithIntl(
15+
<ConsoleEvent
16+
event={{
17+
timestamp: '123',
18+
docId: '1',
19+
monitor: {
20+
id: 'MONITOR_ID',
21+
duration: {
22+
us: 123,
23+
},
24+
type: 'browser',
25+
status: 'down',
26+
},
27+
synthetics: {
28+
payload: {
29+
message: 'catastrophic error',
30+
},
31+
type: 'stderr',
32+
},
33+
}}
34+
/>
35+
)
36+
).toMatchInlineSnapshot(`
37+
<EuiFlexGroup>
38+
<EuiFlexItem
39+
grow={false}
40+
>
41+
123
42+
</EuiFlexItem>
43+
<EuiFlexItem
44+
grow={false}
45+
style={
46+
Object {
47+
"color": "#bd271e",
48+
}
49+
}
50+
>
51+
stderr
52+
</EuiFlexItem>
53+
<EuiFlexItem>
54+
catastrophic error
55+
</EuiFlexItem>
56+
</EuiFlexGroup>
57+
`);
58+
});
59+
60+
it('uses default color for non-errors', () => {
61+
expect(
62+
shallowWithIntl(
63+
<ConsoleEvent
64+
event={{
65+
timestamp: '123',
66+
docId: '1',
67+
monitor: {
68+
id: 'MONITOR_ID',
69+
duration: {
70+
us: 123,
71+
},
72+
type: 'browser',
73+
status: 'down',
74+
},
75+
synthetics: {
76+
payload: {
77+
message: 'not a catastrophic error',
78+
},
79+
type: 'cmd/status',
80+
},
81+
}}
82+
/>
83+
)
84+
).toMatchInlineSnapshot(`
85+
<EuiFlexGroup>
86+
<EuiFlexItem
87+
grow={false}
88+
>
89+
123
90+
</EuiFlexItem>
91+
<EuiFlexItem
92+
grow={false}
93+
style={
94+
Object {
95+
"color": undefined,
96+
}
97+
}
98+
>
99+
cmd/status
100+
</EuiFlexItem>
101+
<EuiFlexItem>
102+
not a catastrophic error
103+
</EuiFlexItem>
104+
</EuiFlexGroup>
105+
`);
106+
});
107+
});
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
8+
import React from 'react';
9+
import { ConsoleOutputEventList } from '../console_output_event_list';
10+
11+
describe('ConsoleOutputEventList component', () => {
12+
it('renders a component per console event', () => {
13+
expect(
14+
shallowWithIntl(
15+
<ConsoleOutputEventList
16+
journey={{
17+
checkGroup: 'check_group',
18+
loading: false,
19+
// 4 steps, three console, one step/end
20+
steps: [
21+
{
22+
timestamp: '123',
23+
docId: '1',
24+
monitor: {
25+
id: 'MON_ID',
26+
duration: {
27+
us: 10,
28+
},
29+
status: 'down',
30+
type: 'browser',
31+
},
32+
synthetics: {
33+
type: 'stderr',
34+
},
35+
},
36+
{
37+
timestamp: '124',
38+
docId: '2',
39+
monitor: {
40+
id: 'MON_ID',
41+
duration: {
42+
us: 10,
43+
},
44+
status: 'down',
45+
type: 'browser',
46+
},
47+
synthetics: {
48+
type: 'cmd/status',
49+
},
50+
},
51+
{
52+
timestamp: '124',
53+
docId: '2',
54+
monitor: {
55+
id: 'MON_ID',
56+
duration: {
57+
us: 10,
58+
},
59+
status: 'down',
60+
type: 'browser',
61+
},
62+
synthetics: {
63+
type: 'step/end',
64+
},
65+
},
66+
{
67+
timestamp: '125',
68+
docId: '3',
69+
monitor: {
70+
id: 'MON_ID',
71+
duration: {
72+
us: 10,
73+
},
74+
status: 'down',
75+
type: 'browser',
76+
},
77+
synthetics: {
78+
type: 'stdout',
79+
},
80+
},
81+
],
82+
}}
83+
/>
84+
).find('EuiCodeBlock')
85+
).toMatchInlineSnapshot(`
86+
<EuiCodeBlock>
87+
<ConsoleEvent
88+
event={
89+
Object {
90+
"docId": "1",
91+
"monitor": Object {
92+
"duration": Object {
93+
"us": 10,
94+
},
95+
"id": "MON_ID",
96+
"status": "down",
97+
"type": "browser",
98+
},
99+
"synthetics": Object {
100+
"type": "stderr",
101+
},
102+
"timestamp": "123",
103+
}
104+
}
105+
key="1_console-event-row"
106+
/>
107+
<ConsoleEvent
108+
event={
109+
Object {
110+
"docId": "2",
111+
"monitor": Object {
112+
"duration": Object {
113+
"us": 10,
114+
},
115+
"id": "MON_ID",
116+
"status": "down",
117+
"type": "browser",
118+
},
119+
"synthetics": Object {
120+
"type": "cmd/status",
121+
},
122+
"timestamp": "124",
123+
}
124+
}
125+
key="2_console-event-row"
126+
/>
127+
<ConsoleEvent
128+
event={
129+
Object {
130+
"docId": "3",
131+
"monitor": Object {
132+
"duration": Object {
133+
"us": 10,
134+
},
135+
"id": "MON_ID",
136+
"status": "down",
137+
"type": "browser",
138+
},
139+
"synthetics": Object {
140+
"type": "stdout",
141+
},
142+
"timestamp": "125",
143+
}
144+
}
145+
key="3_console-event-row"
146+
/>
147+
</EuiCodeBlock>
148+
`);
149+
});
150+
});
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
8+
import React from 'react';
9+
import { EmptyJourney } from '../empty_journey';
10+
11+
describe('EmptyJourney component', () => {
12+
it('omits check group element when undefined', () => {
13+
expect(shallowWithIntl(<EmptyJourney />)).toMatchInlineSnapshot(`
14+
<EuiEmptyPrompt
15+
body={
16+
<React.Fragment>
17+
<p>
18+
<FormattedMessage
19+
defaultMessage="This journey did not contain any steps."
20+
id="xpack.uptime.synthetics.emptyJourney.message.heading"
21+
values={Object {}}
22+
/>
23+
</p>
24+
<p>
25+
<FormattedMessage
26+
defaultMessage="There is no further information to display."
27+
id="xpack.uptime.synthetics.emptyJourney.message.footer"
28+
values={Object {}}
29+
/>
30+
</p>
31+
</React.Fragment>
32+
}
33+
iconType="cross"
34+
title={
35+
<h2>
36+
<FormattedMessage
37+
defaultMessage="There are no steps for this journey"
38+
id="xpack.uptime.synthetics.emptyJourney.title"
39+
values={Object {}}
40+
/>
41+
</h2>
42+
}
43+
/>
44+
`);
45+
});
46+
47+
it('includes check group element when present', () => {
48+
expect(shallowWithIntl(<EmptyJourney checkGroup="check_group" />)).toMatchInlineSnapshot(`
49+
<EuiEmptyPrompt
50+
body={
51+
<React.Fragment>
52+
<p>
53+
<FormattedMessage
54+
defaultMessage="This journey did not contain any steps."
55+
id="xpack.uptime.synthetics.emptyJourney.message.heading"
56+
values={Object {}}
57+
/>
58+
</p>
59+
<p>
60+
<FormattedMessage
61+
defaultMessage="The journey's check group is {codeBlock}."
62+
id="xpack.uptime.synthetics.emptyJourney.message.checkGroupField"
63+
values={
64+
Object {
65+
"codeBlock": <code>
66+
check_group
67+
</code>,
68+
}
69+
}
70+
/>
71+
</p>
72+
<p>
73+
<FormattedMessage
74+
defaultMessage="There is no further information to display."
75+
id="xpack.uptime.synthetics.emptyJourney.message.footer"
76+
values={Object {}}
77+
/>
78+
</p>
79+
</React.Fragment>
80+
}
81+
iconType="cross"
82+
title={
83+
<h2>
84+
<FormattedMessage
85+
defaultMessage="There are no steps for this journey"
86+
id="xpack.uptime.synthetics.emptyJourney.title"
87+
values={Object {}}
88+
/>
89+
</h2>
90+
}
91+
/>
92+
`);
93+
});
94+
});

0 commit comments

Comments
 (0)