Add missing Wails application stub tests
This commit is contained in:
parent
d47d143201
commit
85dc7849b2
4 changed files with 251 additions and 0 deletions
|
|
@ -56,6 +56,43 @@ func TestApplication_MenuRole_String_Ugly(t *testing.T) {
|
|||
assert.Equal(t, "unknown", MenuRole(999).String())
|
||||
}
|
||||
|
||||
func TestApplication_MenuItem_OnClick_Good(t *testing.T) {
|
||||
called := 0
|
||||
item := &MenuItem{}
|
||||
|
||||
item.OnClick(func(*Context) {
|
||||
called++
|
||||
})
|
||||
require.NotNil(t, item.onClick)
|
||||
item.onClick(&Context{})
|
||||
|
||||
assert.Equal(t, 1, called)
|
||||
}
|
||||
|
||||
func TestApplication_MenuItem_OnClick_Bad(t *testing.T) {
|
||||
item := &MenuItem{}
|
||||
|
||||
item.OnClick(nil)
|
||||
|
||||
assert.Nil(t, item.onClick)
|
||||
}
|
||||
|
||||
func TestApplication_MenuItem_OnClick_Ugly(t *testing.T) {
|
||||
called := 0
|
||||
item := &MenuItem{}
|
||||
|
||||
item.OnClick(func(*Context) {
|
||||
called++
|
||||
})
|
||||
item.OnClick(func(*Context) {
|
||||
called++
|
||||
})
|
||||
require.NotNil(t, item.onClick)
|
||||
item.onClick(&Context{})
|
||||
|
||||
assert.Equal(t, 1, called)
|
||||
}
|
||||
|
||||
func TestApplication_Menu_Good(t *testing.T) {
|
||||
menu := NewMenu()
|
||||
menuItem := menu.Add("Open")
|
||||
|
|
@ -90,6 +127,34 @@ func TestApplication_Menu_Ugly(t *testing.T) {
|
|||
assert.Equal(t, "Nested", menu.Items[0].Label)
|
||||
}
|
||||
|
||||
func TestApplication_MenuManager_SetApplicationMenu_Good(t *testing.T) {
|
||||
manager := &MenuManager{}
|
||||
menu := NewMenu()
|
||||
|
||||
manager.SetApplicationMenu(menu)
|
||||
|
||||
assert.Same(t, menu, manager.applicationMenu)
|
||||
}
|
||||
|
||||
func TestApplication_MenuManager_SetApplicationMenu_Bad(t *testing.T) {
|
||||
manager := &MenuManager{}
|
||||
|
||||
manager.SetApplicationMenu(nil)
|
||||
|
||||
assert.Nil(t, manager.applicationMenu)
|
||||
}
|
||||
|
||||
func TestApplication_MenuManager_SetApplicationMenu_Ugly(t *testing.T) {
|
||||
manager := &MenuManager{}
|
||||
first := NewMenu()
|
||||
second := NewMenu()
|
||||
|
||||
manager.SetApplicationMenu(first)
|
||||
manager.SetApplicationMenu(second)
|
||||
|
||||
assert.Same(t, second, manager.applicationMenu)
|
||||
}
|
||||
|
||||
func TestApplication_SystemTray_Good(t *testing.T) {
|
||||
tray := (&SystemTrayManager{}).New()
|
||||
menu := NewMenu()
|
||||
|
|
|
|||
105
stubs/wails/pkg/application/webview_window_options_test.go
Normal file
105
stubs/wails/pkg/application/webview_window_options_test.go
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
package application
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestWebviewWindowOptions_Constants_Good(t *testing.T) {
|
||||
assert.Equal(t, WindowStateNormal, WindowState(0))
|
||||
assert.Equal(t, WindowStateMinimised, WindowState(1))
|
||||
assert.Equal(t, WindowStateMaximised, WindowState(2))
|
||||
assert.Equal(t, WindowStateFullscreen, WindowState(3))
|
||||
assert.Equal(t, WindowCentered, WindowStartPosition(0))
|
||||
assert.Equal(t, WindowXY, WindowStartPosition(1))
|
||||
assert.Equal(t, BackgroundTypeSolid, BackgroundType(0))
|
||||
assert.Equal(t, BackgroundTypeTransparent, BackgroundType(1))
|
||||
assert.Equal(t, BackgroundTypeTranslucent, BackgroundType(2))
|
||||
assert.Equal(t, Auto, BackdropType(0))
|
||||
assert.Equal(t, None, BackdropType(1))
|
||||
assert.Equal(t, Mica, BackdropType(2))
|
||||
assert.Equal(t, Acrylic, BackdropType(3))
|
||||
assert.Equal(t, Tabbed, BackdropType(4))
|
||||
assert.Equal(t, SystemDefault, Theme(0))
|
||||
assert.Equal(t, Dark, Theme(1))
|
||||
assert.Equal(t, Light, Theme(2))
|
||||
assert.Equal(t, MacBackdropNormal, MacBackdrop(0))
|
||||
assert.Equal(t, MacBackdropTransparent, MacBackdrop(1))
|
||||
assert.Equal(t, MacBackdropTranslucent, MacBackdrop(2))
|
||||
assert.Equal(t, MacBackdropLiquidGlass, MacBackdrop(3))
|
||||
assert.Equal(t, MacToolbarStyleAutomatic, MacToolbarStyle(0))
|
||||
assert.Equal(t, MacToolbarStyleUnifiedCompact, MacToolbarStyle(4))
|
||||
assert.Equal(t, LiquidGlassStyleAutomatic, MacLiquidGlassStyle(0))
|
||||
assert.Equal(t, LiquidGlassStyleVibrant, MacLiquidGlassStyle(3))
|
||||
assert.Equal(t, WebviewGpuPolicyAlways, WebviewGpuPolicy(0))
|
||||
assert.Equal(t, WebviewGpuPolicyNever, WebviewGpuPolicy(2))
|
||||
assert.Equal(t, LinuxMenuStyleMenuBar, LinuxMenuStyle(0))
|
||||
assert.Equal(t, LinuxMenuStylePrimaryMenu, LinuxMenuStyle(1))
|
||||
assert.Equal(t, DefaultAppearance, MacAppearanceType(""))
|
||||
assert.Equal(t, NSAppearanceNameDarkAqua, MacAppearanceType("NSAppearanceNameDarkAqua"))
|
||||
}
|
||||
|
||||
func TestWebviewWindowOptions_Constants_Bad(t *testing.T) {
|
||||
assert.Equal(t, MacTitleBarDefault, MacTitleBar{})
|
||||
assert.Equal(t, MacTitleBarHidden, MacTitleBar{
|
||||
AppearsTransparent: true,
|
||||
HideTitle: true,
|
||||
FullSizeContent: true,
|
||||
})
|
||||
assert.Equal(t, MacTitleBarHiddenInset, MacTitleBar{
|
||||
AppearsTransparent: true,
|
||||
HideTitle: true,
|
||||
FullSizeContent: true,
|
||||
UseToolbar: true,
|
||||
HideToolbarSeparator: true,
|
||||
})
|
||||
assert.Equal(t, MacTitleBarHiddenInsetUnified, MacTitleBar{
|
||||
AppearsTransparent: true,
|
||||
HideTitle: true,
|
||||
FullSizeContent: true,
|
||||
UseToolbar: true,
|
||||
HideToolbarSeparator: true,
|
||||
ToolbarStyle: MacToolbarStyleUnified,
|
||||
})
|
||||
assert.Equal(t, NSVisualEffectMaterialAuto, NSVisualEffectMaterial(-1))
|
||||
assert.Equal(t, MacWindowLevelNormal, MacWindowLevel("normal"))
|
||||
assert.Equal(t, MacWindowCollectionBehaviorCanJoinAllSpaces, MacWindowCollectionBehavior(1))
|
||||
assert.Equal(t, MacWindowCollectionBehaviorFullScreenAuxiliary, MacWindowCollectionBehavior(1<<8))
|
||||
}
|
||||
|
||||
func TestWebviewWindowOptions_Constants_Ugly(t *testing.T) {
|
||||
options := WebviewWindowOptions{
|
||||
Name: "main",
|
||||
Title: "Main",
|
||||
URL: "https://example.invalid",
|
||||
HTML: "<h1>Hello</h1>",
|
||||
JS: "window.__ready = true",
|
||||
Width: 800,
|
||||
Height: 600,
|
||||
X: 10,
|
||||
Y: 20,
|
||||
MinWidth: 320,
|
||||
MinHeight: 240,
|
||||
MaxWidth: 1920,
|
||||
MaxHeight: 1080,
|
||||
Frameless: true,
|
||||
Hidden: true,
|
||||
AlwaysOnTop: true,
|
||||
DisableResize: true,
|
||||
EnableFileDrop: true,
|
||||
BackgroundColour: NewRGBA(1, 2, 3, 4),
|
||||
}
|
||||
|
||||
require.Equal(t, "main", options.Name)
|
||||
assert.Equal(t, "Main", options.Title)
|
||||
assert.Equal(t, 800, options.Width)
|
||||
assert.Equal(t, 600, options.Height)
|
||||
assert.True(t, options.Frameless)
|
||||
assert.True(t, options.Hidden)
|
||||
assert.True(t, options.AlwaysOnTop)
|
||||
assert.True(t, options.DisableResize)
|
||||
assert.True(t, options.EnableFileDrop)
|
||||
assert.Equal(t, RGBA{Red: 1, Green: 2, Blue: 3, Alpha: 4}, options.BackgroundColour)
|
||||
}
|
||||
57
stubs/wails/pkg/application/window_manager_expanded_test.go
Normal file
57
stubs/wails/pkg/application/window_manager_expanded_test.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package application
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestWindowManagerExpanded_Get_Good(t *testing.T) {
|
||||
manager := &WindowManager{}
|
||||
first := manager.NewWithOptions(WebviewWindowOptions{Name: "first"})
|
||||
second := manager.NewWithOptions(WebviewWindowOptions{Name: "second"})
|
||||
|
||||
require.Same(t, first, manager.Get("first"))
|
||||
require.Same(t, second, manager.Get("second"))
|
||||
assert.Len(t, manager.GetAll(), 2)
|
||||
}
|
||||
|
||||
func TestWindowManagerExpanded_Get_Bad(t *testing.T) {
|
||||
manager := &WindowManager{}
|
||||
|
||||
assert.Nil(t, manager.Get("missing"))
|
||||
}
|
||||
|
||||
func TestWindowManagerExpanded_Get_Ugly(t *testing.T) {
|
||||
manager := &WindowManager{}
|
||||
first := manager.NewWithOptions(WebviewWindowOptions{Name: "dup"})
|
||||
second := manager.NewWithOptions(WebviewWindowOptions{Name: "dup"})
|
||||
|
||||
assert.Same(t, first, manager.Get("dup"))
|
||||
assert.NotSame(t, first, second)
|
||||
}
|
||||
|
||||
func TestWindowManagerExpanded_GetByID_Good(t *testing.T) {
|
||||
manager := &WindowManager{}
|
||||
first := manager.NewWithOptions(WebviewWindowOptions{Name: "first"})
|
||||
second := manager.NewWithOptions(WebviewWindowOptions{Name: "second"})
|
||||
|
||||
assert.Same(t, first, manager.GetByID(1))
|
||||
assert.Same(t, second, manager.GetByID(2))
|
||||
}
|
||||
|
||||
func TestWindowManagerExpanded_GetByID_Bad(t *testing.T) {
|
||||
manager := &WindowManager{}
|
||||
|
||||
assert.Nil(t, manager.GetByID(99))
|
||||
}
|
||||
|
||||
func TestWindowManagerExpanded_GetByID_Ugly(t *testing.T) {
|
||||
manager := &WindowManager{}
|
||||
manager.NewWithOptions(WebviewWindowOptions{Name: "first"})
|
||||
manager.NewWithOptions(WebviewWindowOptions{Name: "second"})
|
||||
|
||||
assert.Nil(t, manager.GetByID(0))
|
||||
assert.Nil(t, manager.GetByID(3))
|
||||
}
|
||||
24
stubs/wails/pkg/application/window_test.go
Normal file
24
stubs/wails/pkg/application/window_test.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package application
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestWindow_Interface_Good(t *testing.T) {
|
||||
var _ Window = (*WebviewWindow)(nil)
|
||||
var _ Window = (*BrowserWindow)(nil)
|
||||
}
|
||||
|
||||
func TestWindow_Interface_Bad(t *testing.T) {
|
||||
var w Window
|
||||
|
||||
assert.Nil(t, w)
|
||||
}
|
||||
|
||||
func TestWindow_Interface_Ugly(t *testing.T) {
|
||||
var w Window = (*WebviewWindow)(nil)
|
||||
|
||||
assert.False(t, w == nil)
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue