mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-15 23:25:49 +01:00
* test(v3): add comprehensive unit tests for pkg/application Add 11 new test files to improve test coverage of the pkg/application package from 13.6% to 17.7%. New test files: - context_test.go: Context struct operations - services_test.go: Service management and lifecycle - parameter_test.go: Parameter and CallError types - dialogs_test.go: Dialog utilities and button methods - webview_window_options_test.go: Window options and constants - application_options_test.go: ChainMiddleware and app config - keys_test.go: Keyboard accelerator parsing - single_instance_test.go: Single instance management and encryption - menuitem_internal_test.go: Menu item internal functions - menu_internal_test.go: Menu internal functions - screenmanager_internal_test.go: Screen geometry and transformations The 40% target was not fully achievable because ~50% of the codebase is platform-specific code that can only be tested on respective platforms. Tests focus on pure Go logic, utility functions, and data structures that can be tested cross-platform. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: address CodeRabbit review comments - dialogs_test.go: improve ID recycling test to verify either recycled ID (id3 == id1) or new unique ID (id3 > id2) - keys_test.go: make accelerator String() tests platform-agnostic by checking suffix patterns rather than exact platform-specific strings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: normalize temp dir path for macOS compatibility in test os.TempDir() returns a trailing slash on macOS, causing path comparison to fail. Use filepath.Clean() to normalize both paths. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore: remove REVIEW.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore: simplify changelog entry 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
120 lines
2.9 KiB
Go
120 lines
2.9 KiB
Go
package application
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestNewContext(t *testing.T) {
|
|
ctx := newContext()
|
|
if ctx == nil {
|
|
t.Fatal("newContext() returned nil")
|
|
}
|
|
if ctx.data == nil {
|
|
t.Error("newContext() should initialize data map")
|
|
}
|
|
}
|
|
|
|
func TestContext_ClickedMenuItem_NotExists(t *testing.T) {
|
|
ctx := newContext()
|
|
result := ctx.ClickedMenuItem()
|
|
if result != nil {
|
|
t.Error("ClickedMenuItem() should return nil when not set")
|
|
}
|
|
}
|
|
|
|
func TestContext_ClickedMenuItem_Exists(t *testing.T) {
|
|
ctx := newContext()
|
|
menuItem := &MenuItem{label: "Test"}
|
|
ctx.withClickedMenuItem(menuItem)
|
|
|
|
result := ctx.ClickedMenuItem()
|
|
if result == nil {
|
|
t.Fatal("ClickedMenuItem() should return the menu item")
|
|
}
|
|
if result != menuItem {
|
|
t.Error("ClickedMenuItem() should return the same menu item")
|
|
}
|
|
}
|
|
|
|
func TestContext_IsChecked_NotSet(t *testing.T) {
|
|
ctx := newContext()
|
|
if ctx.IsChecked() {
|
|
t.Error("IsChecked() should return false when not set")
|
|
}
|
|
}
|
|
|
|
func TestContext_IsChecked_True(t *testing.T) {
|
|
ctx := newContext()
|
|
ctx.withChecked(true)
|
|
if !ctx.IsChecked() {
|
|
t.Error("IsChecked() should return true when set to true")
|
|
}
|
|
}
|
|
|
|
func TestContext_IsChecked_False(t *testing.T) {
|
|
ctx := newContext()
|
|
ctx.withChecked(false)
|
|
if ctx.IsChecked() {
|
|
t.Error("IsChecked() should return false when set to false")
|
|
}
|
|
}
|
|
|
|
func TestContext_ContextMenuData_Empty(t *testing.T) {
|
|
ctx := newContext()
|
|
result := ctx.ContextMenuData()
|
|
if result != "" {
|
|
t.Errorf("ContextMenuData() should return empty string when not set, got %q", result)
|
|
}
|
|
}
|
|
|
|
func TestContext_ContextMenuData_Exists(t *testing.T) {
|
|
ctx := newContext()
|
|
data := &ContextMenuData{Data: "test-data"}
|
|
ctx.withContextMenuData(data)
|
|
|
|
result := ctx.ContextMenuData()
|
|
if result != "test-data" {
|
|
t.Errorf("ContextMenuData() = %q, want %q", result, "test-data")
|
|
}
|
|
}
|
|
|
|
func TestContext_ContextMenuData_NilData(t *testing.T) {
|
|
ctx := newContext()
|
|
ctx.withContextMenuData(nil)
|
|
|
|
result := ctx.ContextMenuData()
|
|
if result != "" {
|
|
t.Errorf("ContextMenuData() should return empty string for nil data, got %q", result)
|
|
}
|
|
}
|
|
|
|
func TestContext_ContextMenuData_WrongType(t *testing.T) {
|
|
ctx := newContext()
|
|
// Manually set wrong type to test type assertion
|
|
ctx.data[contextMenuData] = 123
|
|
|
|
result := ctx.ContextMenuData()
|
|
if result != "" {
|
|
t.Errorf("ContextMenuData() should return empty string for non-string type, got %q", result)
|
|
}
|
|
}
|
|
|
|
func TestContext_WithClickedMenuItem_Chaining(t *testing.T) {
|
|
ctx := newContext()
|
|
menuItem := &MenuItem{label: "Test"}
|
|
|
|
returnedCtx := ctx.withClickedMenuItem(menuItem)
|
|
if returnedCtx != ctx {
|
|
t.Error("withClickedMenuItem should return the same context for chaining")
|
|
}
|
|
}
|
|
|
|
func TestContext_WithContextMenuData_Chaining(t *testing.T) {
|
|
ctx := newContext()
|
|
data := &ContextMenuData{Data: "test"}
|
|
|
|
returnedCtx := ctx.withContextMenuData(data)
|
|
if returnedCtx != ctx {
|
|
t.Error("withContextMenuData should return the same context for chaining")
|
|
}
|
|
}
|