Skip to content

tests(ourlogs): Add basic tests for ourlogs in trace details #97553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
tests(ourlogs): Add basic tests for ourlogs in trace details
  • Loading branch information
Zylphrex committed Aug 9, 2025
commit 0617508dc545dd917f3af2b7c7ce0866e5e03b67
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import {useRef} from 'react';
import {OrganizationFixture} from 'sentry-fixture/organization';

import {render, screen} from 'sentry-test/reactTestingLibrary';

import {
TraceViewLogsDataProvider,
TraceViewLogsSection,
} from 'sentry/views/performance/newTraceDetails/traceOurlogs';

const TRACE_SLUG = '00000000000000000000000000000000';

function Component({traceSlug}: {traceSlug: string}) {
const ref = useRef(null);
return (
<TraceViewLogsDataProvider traceSlug={traceSlug}>
<TraceViewLogsSection scrollContainer={ref} />
</TraceViewLogsDataProvider>
);
}

describe('TraceViewLogsSection', function () {
beforeEach(function () {
// the search query combobox is firing updates and causing console.errors
jest.spyOn(console, 'error').mockImplementation(() => {});
});

afterEach(function () {
jest.clearAllMocks();
MockApiClient.clearMockResponses();
});

it('renders empty logs', async function () {
const organization = OrganizationFixture({features: ['ourlogs-enabled']});
const mockRequest = MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/trace-logs/`,
body: {
data: [],
meta: {},
},
});
render(<Component traceSlug={TRACE_SLUG} />, {organization});

expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();

expect(mockRequest).toHaveBeenCalledTimes(1);

// without waiting a few ticks, the test fails just before the
// promise corresponding to the request resolves
// by adding some ticks, it forces the test to wait a little longer
// until the promise is resolved
for (let i = 0; i < 10; i++) {
await tick();
}

expect(screen.getByText(/No logs found/)).toBeInTheDocument();
});

it('renders some logs', async function () {
const now = new Date();
const organization = OrganizationFixture({features: ['ourlogs-enabled']});
const mockRequest = MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/trace-logs/`,
body: {
data: [
{
'sentry.item_id': '11111111111111111111111111111111',
'project.id': 1,
trace: TRACE_SLUG,
severity_number: 0,
severity: 'info',
timestamp: now.toISOString(),
'tags[sentry.timestamp_precise,number]': now.getTime() * 1e6,
message: 'i am a log',
},
],
meta: {},
},
});
render(<Component traceSlug={TRACE_SLUG} />, {organization});

expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();

expect(mockRequest).toHaveBeenCalledTimes(1);

// without waiting a few ticks, the test fails just before the
// promise corresponding to the request resolves
// by adding some ticks, it forces the test to wait a little longer
// until the promise is resolved
for (let i = 0; i < 10; i++) {
await tick();
}

expect(screen.getByText(/i am a log/)).toBeInTheDocument();
});
});
Loading