Skip to content

Commit e1f1692

Browse files
Zylphrexandrewshie-sentry
authored andcommitted
tests(ourlogs): Add basic tests for ourlogs in events sections (#97554)
1 parent a2bf192 commit e1f1692

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import {EventFixture} from 'sentry-fixture/event';
2+
import {GroupFixture} from 'sentry-fixture/group';
3+
import {OrganizationFixture} from 'sentry-fixture/organization';
4+
import {ProjectFixture} from 'sentry-fixture/project';
5+
6+
import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
7+
8+
import {OurlogsSection} from 'sentry/components/events/ourlogs/ourlogsSection';
9+
10+
const TRACE_ID = '00000000000000000000000000000000';
11+
12+
const organization = OrganizationFixture({features: ['ourlogs-enabled']});
13+
const project = ProjectFixture();
14+
const group = GroupFixture();
15+
const event = EventFixture({
16+
size: 1,
17+
dateCreated: '2019-03-20T00:00:00.000Z',
18+
errors: [],
19+
entries: [],
20+
tags: [
21+
{key: 'environment', value: 'dev'},
22+
{key: 'mechanism', value: 'ANR'},
23+
],
24+
contexts: {
25+
app: {
26+
app_start_time: '2021-08-31T15:14:21Z',
27+
device_app_hash: '0b77c3f2567d65fe816e1fa7013779fbe3b51633',
28+
build_type: 'test',
29+
app_identifier: 'io.sentry.sample.iOS-Swift',
30+
app_name: 'iOS-Swift',
31+
app_version: '7.2.3',
32+
app_build: '390',
33+
app_id: 'B2690307-FDD1-3D34-AA1E-E280A9C2406C',
34+
type: 'app',
35+
},
36+
device: {
37+
family: 'iOS',
38+
model: 'iPhone13,4',
39+
model_id: 'D54pAP',
40+
memory_size: 5987008512,
41+
free_memory: 154435584,
42+
usable_memory: 4706893824,
43+
storage_size: 127881465856,
44+
boot_time: '2021-08-29T06:05:51Z',
45+
timezone: 'CEST',
46+
type: 'device',
47+
},
48+
os: {
49+
name: 'iOS',
50+
version: '14.7.1',
51+
build: '18G82',
52+
kernel_version:
53+
'Darwin Kernel Version 20.6.0: Mon Jun 21 21:23:35 PDT 2021; root:xnu-7195.140.42~10/RELEASE_ARM64_T8101',
54+
rooted: false,
55+
type: 'os',
56+
},
57+
trace: {
58+
trace_id: TRACE_ID,
59+
span_id: 'b0e6f15b45c36b12',
60+
op: 'ui.action.click',
61+
type: 'trace',
62+
},
63+
},
64+
});
65+
66+
describe('OurlogsSection', function () {
67+
beforeEach(function () {
68+
// the search query combobox is firing updates and causing console.errors
69+
jest.spyOn(console, 'error').mockImplementation(() => {});
70+
});
71+
72+
it('renders empty', function () {
73+
const mockRequest = MockApiClient.addMockResponse({
74+
url: `/organizations/${organization.slug}/trace-logs/`,
75+
body: {
76+
data: [],
77+
meta: {},
78+
},
79+
});
80+
render(<OurlogsSection event={event} project={project} group={group} />, {
81+
organization,
82+
});
83+
expect(mockRequest).toHaveBeenCalledTimes(1);
84+
expect(screen.queryByText(/Logs/)).not.toBeInTheDocument();
85+
});
86+
87+
it('renders logs', async function () {
88+
const now = new Date();
89+
const mockRequest = MockApiClient.addMockResponse({
90+
url: `/organizations/${organization.slug}/trace-logs/`,
91+
body: {
92+
data: [
93+
{
94+
'sentry.item_id': '11111111111111111111111111111111',
95+
'project.id': 1,
96+
trace: TRACE_ID,
97+
severity_number: 0,
98+
severity: 'info',
99+
timestamp: now.toISOString(),
100+
'tags[sentry.timestamp_precise,number]': now.getTime() * 1e6,
101+
message: 'i am a log',
102+
},
103+
],
104+
meta: {},
105+
},
106+
});
107+
render(<OurlogsSection event={event} project={project} group={group} />, {
108+
organization,
109+
});
110+
expect(mockRequest).toHaveBeenCalledTimes(1);
111+
112+
// without waiting a few ticks, the test fails just before the
113+
// promise corresponding to the request resolves
114+
// by adding some ticks, it forces the test to wait a little longer
115+
// until the promise is resolved
116+
for (let i = 0; i < 10; i++) {
117+
await tick();
118+
}
119+
120+
expect(screen.getByText(/i am a log/)).toBeInTheDocument();
121+
122+
expect(
123+
screen.queryByRole('complementary', {name: 'logs drawer'})
124+
).not.toBeInTheDocument();
125+
126+
await userEvent.click(screen.getByText(/i am a log/));
127+
128+
const aside = screen.getByRole('complementary', {name: 'logs drawer'});
129+
expect(aside).toBeInTheDocument();
130+
131+
expect(within(aside).getByText(/i am a log/)).toBeInTheDocument();
132+
});
133+
});

0 commit comments

Comments
 (0)