Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions static/app/views/explore/logs/useLogsQueryTruncate.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,42 @@ describe('useLogsQueryTruncate', () => {
it('rounds the formula result up to the next power of two', () => {
mockUseWindowSize.mockReturnValue({innerWidth: 6400, innerHeight: 1080});
const {result} = renderHookWithProviders(() => useLogsQueryTruncate());
expect(result.current).toBe(512);
expect(result.current).toBe(1024);
});

it('returns the exact value when the formula result is already a power of two', () => {
mockUseWindowSize.mockReturnValue({innerWidth: 4096, innerHeight: 1080});
mockUseWindowSize.mockReturnValue({innerWidth: 3072, innerHeight: 1080});
const {result} = renderHookWithProviders(() => useLogsQueryTruncate());
expect(result.current).toBe(256);
});

it('does not shrink the truncation length when the viewport shrinks', () => {
mockUseWindowSize.mockReturnValue({innerWidth: 6400, innerHeight: 1080});
const {result, rerender} = renderHookWithProviders(() => useLogsQueryTruncate());
expect(result.current).toBe(512);
expect(result.current).toBe(1024);

mockUseWindowSize.mockReturnValue({innerWidth: 3200, innerHeight: 1080});
rerender();
expect(result.current).toBe(512);
expect(result.current).toBe(1024);
});

it('does not recompute when the viewport grows within the same power of two', () => {
mockUseWindowSize.mockReturnValue({innerWidth: 3200, innerHeight: 1080});
const {result, rerender} = renderHookWithProviders(() => useLogsQueryTruncate());
expect(result.current).toBe(256);
expect(result.current).toBe(512);

mockUseWindowSize.mockReturnValue({innerWidth: 4096, innerHeight: 1080});
mockUseWindowSize.mockReturnValue({innerWidth: 6000, innerHeight: 1080});
rerender();
expect(result.current).toBe(256);
expect(result.current).toBe(512);
});

it('grows the truncation length when the viewport grows past the next power of two', () => {
mockUseWindowSize.mockReturnValue({innerWidth: 4096, innerHeight: 1080});
mockUseWindowSize.mockReturnValue({innerWidth: 3200, innerHeight: 1080});
const {result, rerender} = renderHookWithProviders(() => useLogsQueryTruncate());
expect(result.current).toBe(256);
expect(result.current).toBe(512);

mockUseWindowSize.mockReturnValue({innerWidth: 8192, innerHeight: 1080});
rerender();
expect(result.current).toBe(512);
expect(result.current).toBe(1024);
});
});
2 changes: 1 addition & 1 deletion static/app/views/explore/logs/useLogsQueryTruncate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {useWindowSize} from 'sentry/utils/window/useWindowSize';

export function useLogsQueryTruncate(): number {
const {innerWidth} = useWindowSize();
const target = Math.max(128, Math.floor(innerWidth / 16));
const target = Math.max(128, Math.floor(innerWidth / 12));

// Round up to the next power of two so small viewport changes don't shift the
// truncation length and trigger a re-query.
Expand Down
Loading