Files
supabase/apps/studio/tests/features/explain-visualizer/ExplainVisualizer.utils.test.ts
Ali Waseem b100272376 chore(sql-editor): remove Pretty Explain feature (#47981)
Removes the SQL Editor Pretty Explain feature — the Explain tab, the Run
EXPLAIN ANALYZE action + shortcut, and its dead plumbing. It's been
gated off behind the `DisablePrettyExplainOnSqlEditor` kill switch for
weeks with no usage or complaints.

`ExplainVisualizer` / `isExplainQuery` are kept — they're used
independently by Query Insights, Query Performance, and the EditorPanel
quick-runner. Manually-run `EXPLAIN` queries still render as raw rows in
the Results tab.

Typecheck, lint, and all affected unit tests pass.

Closes FE-3930

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Changes**
* Removed the SQL editor’s EXPLAIN execution workflow, including its
toolbar action, keyboard shortcut, utility tab, and visual query-plan
display.
  * Simplified query execution to focus on standard results and charts.
* Improved result clearing when switching databases and refined
execution error handling.
* Updated SQL editor state and tests to reflect the streamlined
experience.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-07-16 11:04:34 +08:00

47 lines
1.3 KiB
TypeScript

import { describe, expect, test } from 'vitest'
import {
formatNodeDuration,
isExplainQuery,
} from '@/components/interfaces/ExplainVisualizer/ExplainVisualizer.utils'
describe('isExplainQuery', () => {
test('returns true for valid EXPLAIN result rows', () => {
const rows = [{ 'QUERY PLAN': 'Seq Scan on users' }]
expect(isExplainQuery(rows)).toBe(true)
})
test('returns true for JSON format EXPLAIN result rows', () => {
// JSON format returns an array/object in the QUERY PLAN column
const rows = [{ 'QUERY PLAN': [{ Plan: { 'Node Type': 'Seq Scan' } }] }]
expect(isExplainQuery(rows)).toBe(true)
})
test('returns false for empty array', () => {
expect(isExplainQuery([])).toBe(false)
})
test('returns false for regular query results', () => {
const rows = [{ id: 1, name: 'John' }]
expect(isExplainQuery(rows)).toBe(false)
})
})
describe('formatNodeDuration', () => {
test('returns "-" for undefined', () => {
expect(formatNodeDuration(undefined)).toBe('-')
})
test('formats seconds for large values', () => {
expect(formatNodeDuration(1500)).toBe('1.50s')
})
test('formats milliseconds for medium values', () => {
expect(formatNodeDuration(25.5)).toBe('25.50ms')
})
test('formats microseconds for small values', () => {
expect(formatNodeDuration(0.0005)).toBe('0.5µs')
})
})