Fix width and height being set to zero when no max width and max height is set. (#709)

This commit is contained in:
Alexander Hudek 2021-05-13 04:49:53 -04:00 committed by GitHub
commit 8399cc1e57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 89 additions and 3 deletions

View file

@ -1,10 +1,11 @@
package options
import (
"github.com/wailsapp/wails/v2/pkg/options/windows"
"log"
"runtime"
"github.com/wailsapp/wails/v2/pkg/options/windows"
wailsruntime "github.com/wailsapp/wails/v2/internal/runtime"
"github.com/wailsapp/wails/v2/pkg/menu"
@ -63,13 +64,13 @@ func MergeDefaults(appoptions *App) {
if appoptions.Width < appoptions.MinWidth {
appoptions.Width = appoptions.MinWidth
}
if appoptions.Width > appoptions.MaxWidth {
if appoptions.MaxWidth > 0 && appoptions.Width > appoptions.MaxWidth {
appoptions.Width = appoptions.MaxWidth
}
if appoptions.Height < appoptions.MinHeight {
appoptions.Height = appoptions.MinHeight
}
if appoptions.Height > appoptions.MaxHeight {
if appoptions.MaxHeight > 0 && appoptions.Height > appoptions.MaxHeight {
appoptions.Height = appoptions.MaxHeight
}

View file

@ -0,0 +1,85 @@
package options
import (
"testing"
)
func TestMergeDefaultsWH(t *testing.T) {
tests := []struct {
name string
appoptions *App
wantWidth int
wantHeight int
}{
{
name: "No width and height",
appoptions: &App{},
wantWidth: Default.Width,
wantHeight: Default.Height,
},
{
name: "Basic width and height",
appoptions: &App{
Width: 800,
Height: 600,
},
wantWidth: 800,
wantHeight: 600,
},
{
name: "With MinWidth and MinHeight",
appoptions: &App{
Width: 200,
MinWidth: 800,
Height: 100,
MinHeight: 600,
},
wantWidth: 800,
wantHeight: 600,
},
{
name: "With MaxWidth and MaxHeight",
appoptions: &App{
Width: 900,
MaxWidth: 800,
Height: 700,
MaxHeight: 600,
},
wantWidth: 800,
wantHeight: 600,
},
{
name: "With MinWidth more than MaxWidth",
appoptions: &App{
Width: 900,
MinWidth: 900,
MaxWidth: 800,
Height: 600,
},
wantWidth: 800,
wantHeight: 600,
},
{
name: "With MinHeight more than MaxHeight",
appoptions: &App{
Width: 800,
Height: 700,
MinHeight: 900,
MaxHeight: 600,
},
wantWidth: 800,
wantHeight: 600,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
MergeDefaults(tt.appoptions)
if tt.appoptions.Width != tt.wantWidth {
t.Errorf("MergeDefaults().Width =%v, want %v", tt.appoptions.Width, tt.wantWidth)
}
if tt.appoptions.Height != tt.wantHeight {
t.Errorf("MergeDefaults().Height =%v, want %v", tt.appoptions.Height, tt.wantHeight)
}
})
}
}