wails/v3/pkg/application/parameter_test.go
Lea Anthony 2604ecc0f8
test(v3): add comprehensive unit tests for pkg/application (#4827)
* 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>
2025-12-27 09:53:24 +11:00

118 lines
2.3 KiB
Go

package application
import (
"reflect"
"testing"
)
func TestParameter_IsType(t *testing.T) {
param := &Parameter{
Name: "test",
TypeName: "string",
}
if !param.IsType("string") {
t.Error("IsType should return true for matching type")
}
if param.IsType("int") {
t.Error("IsType should return false for non-matching type")
}
}
func TestParameter_IsError(t *testing.T) {
errorParam := &Parameter{
Name: "err",
TypeName: "error",
}
if !errorParam.IsError() {
t.Error("IsError should return true for error type")
}
stringParam := &Parameter{
Name: "s",
TypeName: "string",
}
if stringParam.IsError() {
t.Error("IsError should return false for non-error type")
}
}
func TestNewParameter(t *testing.T) {
stringType := reflect.TypeOf("")
param := newParameter("myParam", stringType)
if param.Name != "myParam" {
t.Errorf("Name = %q, want %q", param.Name, "myParam")
}
if param.TypeName != "string" {
t.Errorf("TypeName = %q, want %q", param.TypeName, "string")
}
if param.ReflectType != stringType {
t.Error("ReflectType not set correctly")
}
}
func TestCallError_Error(t *testing.T) {
err := &CallError{
Kind: ReferenceError,
Message: "test error",
}
if err.Error() != "test error" {
t.Errorf("Error() = %q, want %q", err.Error(), "test error")
}
}
func TestCallError_Kinds(t *testing.T) {
tests := []struct {
kind ErrorKind
expected string
}{
{ReferenceError, "ReferenceError"},
{TypeError, "TypeError"},
{RuntimeError, "RuntimeError"},
}
for _, tt := range tests {
if string(tt.kind) != tt.expected {
t.Errorf("ErrorKind = %q, want %q", string(tt.kind), tt.expected)
}
}
}
func TestCallError_WithCause(t *testing.T) {
cause := map[string]string{"detail": "some detail"}
err := &CallError{
Kind: RuntimeError,
Message: "runtime error occurred",
Cause: cause,
}
if err.Error() != "runtime error occurred" {
t.Error("Error() should return the message")
}
if err.Cause == nil {
t.Error("Cause should be set")
}
}
func TestCallOptions_Fields(t *testing.T) {
opts := CallOptions{
MethodID: 12345,
MethodName: "TestService.Method",
}
if opts.MethodID != 12345 {
t.Error("MethodID not set correctly")
}
if opts.MethodName != "TestService.Method" {
t.Error("MethodName not set correctly")
}
}