- Add WriteFile method to mock filesystem (non-atomic path, creates files) - Implement WriteFileAtomic in mock with temp file + rename pattern using .tmp/ directory, matching real filesystem semantics - Update WriteFileTask.Execute() to use WriteFileAtomic - Update FlushAll() to use WriteFileAtomic - Fix mock to create files on write (matching os.WriteFile behavior) - Update tests to match new semantics (create-if-not-exists)
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package editor
|
|
|
|
import (
|
|
"testing"
|
|
"pad/internal/ui"
|
|
)
|
|
|
|
func TestEditorLayout_Filename(t *testing.T) {
|
|
// Setup: Reset state
|
|
TheState = NewState()
|
|
|
|
// Set a filename
|
|
expectedFilename := "test.txt"
|
|
TheState.Editor.Filename = expectedFilename
|
|
|
|
// Run layout
|
|
screenWidth := ui.Dp(400)
|
|
screenHeight := ui.Dp(800)
|
|
elements := EditorLayout(screenWidth, screenHeight, false)
|
|
|
|
// Find top bar (assuming it's the first container element)
|
|
topBar := elements[0].(ui.Container)
|
|
|
|
// Find filename label (assuming it's the first label in the top bar)
|
|
filenameLabel := topBar.Children[0].(ui.Label)
|
|
|
|
if filenameLabel.Text != expectedFilename {
|
|
t.Errorf("expected filename %q, got %q", expectedFilename, filenameLabel.Text)
|
|
}
|
|
}
|
|
|
|
func TestEditorLayout_DefaultFilename(t *testing.T) {
|
|
// Setup: Reset state
|
|
TheState = NewState()
|
|
|
|
// Filename is empty
|
|
TheState.Editor.Filename = ""
|
|
|
|
// Run layout
|
|
screenWidth := ui.Dp(400)
|
|
screenHeight := ui.Dp(800)
|
|
elements := EditorLayout(screenWidth, screenHeight, false)
|
|
|
|
// Find top bar (assuming it's the first container element)
|
|
topBar := elements[0].(ui.Container)
|
|
|
|
// Find filename label (assuming it's the first label in the top bar)
|
|
filenameLabel := topBar.Children[0].(ui.Label)
|
|
|
|
expectedDefault := "untitled.txt"
|
|
if filenameLabel.Text != expectedDefault {
|
|
t.Errorf("expected default filename %q, got %q", expectedDefault, filenameLabel.Text)
|
|
}
|
|
}
|