-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathcontextCard.spec.tsx
157 lines (147 loc) · 4.02 KB
/
contextCard.spec.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import {EventFixture} from 'sentry-fixture/event';
import {GroupFixture} from 'sentry-fixture/group';
import {ProjectFixture} from 'sentry-fixture/project';
import {render, screen} from 'sentry-test/reactTestingLibrary';
import ContextCard from 'sentry/components/events/contexts/contextCard';
import * as utils from 'sentry/components/events/contexts/utils';
describe('ContextCard', function () {
const group = GroupFixture();
const project = ProjectFixture();
it('renders the card with formatted context data', function () {
const event = EventFixture();
const alias = 'Things in my Vicinity';
const simpleContext = {
snack: 'peanut',
dinner: 'rice',
friend: 'noelle',
};
const structuredContext = {
'my dogs': ['cocoa', 'butter'],
book: {
title: 'This Is How You Lose the Time War',
pages: 208,
published: '2018-07-21T00:00:00.000Z',
},
};
const customContext = {
...simpleContext,
...structuredContext,
type: 'default',
};
render(
<ContextCard
type="default"
alias={alias}
value={customContext}
event={event}
group={group}
project={project}
/>
);
expect(screen.getByText(alias)).toBeInTheDocument();
Object.entries(simpleContext).forEach(([key, value]) => {
expect(screen.getByText(key)).toBeInTheDocument();
expect(screen.getByText(value)).toBeInTheDocument();
});
Object.entries(structuredContext).forEach(([key, value]) => {
expect(screen.getByText(key)).toBeInTheDocument();
expect(
screen.getByText(`${Object.values(value).length} items`)
).toBeInTheDocument();
});
});
it('renders with icons if able', function () {
const event = EventFixture();
const iconSpy = jest.spyOn(utils, 'getContextIcon');
const browserContext = {
type: 'browser',
name: 'firefox',
version: 'Infinity',
};
const browserCard = render(
<ContextCard
type="browser"
alias="browser"
value={browserContext}
event={event}
group={group}
project={project}
/>
);
expect(iconSpy.mock.results[0].value.props.name).toBe('firefox');
iconSpy.mockReset();
browserCard.unmount();
const unknownContext = {
type: 'default',
organization: 'acme',
tier: 'gold',
};
render(
<ContextCard
type="default"
alias="organization"
value={unknownContext}
event={event}
group={group}
project={project}
/>
);
expect(iconSpy.mock.results[0].value).toBeUndefined();
});
it('renders the annotated text and errors', function () {
const alias = 'broken';
const event = EventFixture({
_meta: {
contexts: {
[alias]: {
error: {
'': {
err: [
[
'invalid_data',
{
reason: 'expected something better',
},
],
],
val: 'worse',
},
},
redacted: {
'': {
chunks: [
{
remark: 'x',
rule_id: 'project:0',
text: '',
type: 'redaction',
},
],
len: 9,
rem: [['project:0', 'x', 0, 0]],
},
},
},
},
},
});
const errorContext = {
error: '',
redacted: '',
type: 'default',
};
render(
<ContextCard
type="default"
alias={alias}
value={errorContext}
event={event}
group={group}
project={project}
/>
);
expect(screen.getByText('<invalid>')).toBeInTheDocument();
expect(screen.getByTestId('annotated-text-error-icon')).toBeInTheDocument();
expect(screen.getByText('<redacted>')).toBeInTheDocument();
});
});