[go: up one dir, main page]

Add comprehensive test suite for utils.lua module

Overview

The utils.lua module contains critical utility functions but has no test coverage. This module is ~326 lines and provides core functionality used throughout the plugin.

Functions Needing Tests

Notebook Discovery

  • find_notebook_zk() - Find .zk directory by searching upward
    • Test: finds .zk in current directory
    • Test: finds .zk in parent directories
    • Test: uses ZK_NOTEBOOK_DIR environment variable
    • Test: returns nil when not found
    • Test: handles buffer filepath vs cwd priority

File Operations

  • move_to_trash(path) - Move file to trash

    • Test: uses gio when available
    • Test: uses trash-put when available
    • Test: returns error when no trash utility
    • Test: handles trash command failures
  • hard_delete(path) - Delete file permanently

    • Test: deletes existing file
    • Test: handles non-existent file
    • Test: returns proper success/failure status
  • close_buf_for_path(path) - Close buffers for file

    • Test: closes buffer with exact path match
    • Test: handles absolute vs relative paths
    • Test: handles multiple buffers for same file

Template/Snippet Operations

  • get_templates() - List available templates

    • Test: finds templates in .zk/templates/
    • Test: filters for .md files only
    • Test: returns error when .zk not found
    • Test: returns error when templates dir missing
    • Test: returns error when no templates found
  • get_snippets() - List available snippets

    • Test: finds snippets in .zk/snippets/
    • Test: filters for .md files only
    • Test: returns error when .zk not found
    • Test: returns error when snippets dir missing
    • Test: returns error when no snippets found

Visual Selection

  • get_visual_selection() - Get selected text
    • Test: retrieves single-line selection
    • Test: retrieves multi-line selection
    • Test: handles invalid mark positions
    • Test: trims whitespace correctly
    • Test: returns nil for empty selection

Picker Integration

  • show_picker(opts) - Display picker UI
    • Test: uses telescope when configured
    • Test: uses fzf-lua when configured
    • Test: uses fzf when configured
    • Test: uses vim.ui.select as default
    • Test: handles format_item function
    • Test: handles get_ordinal function
    • Test: calls on_select callback with selection

Helper Functions

  • first_heading(path) - Extract first markdown heading

    • Test: finds # heading
    • Test: skips non-heading lines
    • Test: returns nil when no heading found
    • Test: handles files with many lines
  • get_picker() - Get configured picker name

    • Test: reads from zk-nvim config
    • Test: defaults to "select" when not configured

Test File Location

tests/zk-extras/utils_spec.lua

Priority

High - This module is foundational to most plugin functionality