Files
go-extractor/promote_test.go
Steve Dudenhoeffer 00ff7ea830
All checks were successful
CI / test (pull_request) Successful in 1m11s
CI / vet (pull_request) Successful in 1m28s
CI / build (pull_request) Successful in 1m30s
feat: add MouseDown/MouseUp methods to InteractiveBrowser
Enables drag operations (mousedown → mousemove → mouseup) needed for
slider captchas and other drag-based interactions.

Closes #79

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 15:35:36 +00:00

58 lines
2.4 KiB
Go

package extractor
import (
"errors"
"testing"
)
// mockInteractiveBrowser implements InteractiveBrowser for testing without Playwright.
type mockInteractiveBrowser struct{}
func (m mockInteractiveBrowser) Navigate(string) (string, error) { return "", nil }
func (m mockInteractiveBrowser) GoBack() (string, error) { return "", nil }
func (m mockInteractiveBrowser) GoForward() (string, error) { return "", nil }
func (m mockInteractiveBrowser) URL() string { return "" }
func (m mockInteractiveBrowser) MouseClick(float64, float64, string) error { return nil }
func (m mockInteractiveBrowser) MouseDown(float64, float64, string) error { return nil }
func (m mockInteractiveBrowser) MouseUp(float64, float64, string) error { return nil }
func (m mockInteractiveBrowser) MouseMove(float64, float64) error { return nil }
func (m mockInteractiveBrowser) MouseWheel(float64, float64) error { return nil }
func (m mockInteractiveBrowser) KeyboardType(string) error { return nil }
func (m mockInteractiveBrowser) KeyboardPress(string) error { return nil }
func (m mockInteractiveBrowser) KeyboardInsertText(string) error { return nil }
func (m mockInteractiveBrowser) Screenshot(int) ([]byte, error) { return nil, nil }
func (m mockInteractiveBrowser) Cookies() ([]Cookie, error) { return nil, nil }
func (m mockInteractiveBrowser) Close() error { return nil }
func TestPromoteToInteractive_NonPromotable(t *testing.T) {
doc := &mockDocument{}
_, err := PromoteToInteractive(doc)
if !errors.Is(err, ErrNotPromotable) {
t.Fatalf("expected ErrNotPromotable, got: %v", err)
}
}
func TestPromoteToInteractive_AlreadyDetached(t *testing.T) {
d := &document{detached: true}
_, err := PromoteToInteractive(d)
if !errors.Is(err, ErrAlreadyDetached) {
t.Fatalf("expected ErrAlreadyDetached, got: %v", err)
}
}
func TestDemoteToDocument_NonDemotable(t *testing.T) {
ib := &mockInteractiveBrowser{}
_, err := DemoteToDocument(ib)
if !errors.Is(err, ErrNotDemotable) {
t.Fatalf("expected ErrNotDemotable, got: %v", err)
}
}
func TestDemoteToDocument_AlreadyDetached(t *testing.T) {
ib := &interactiveBrowser{detached: true}
_, err := DemoteToDocument(ib)
if !errors.Is(err, ErrAlreadyDetached) {
t.Fatalf("expected ErrAlreadyDetached, got: %v", err)
}
}