github.com/AlpineAIO/wails/v2@v2.0.0-beta.32.0.20240505041856-1047a8fa5fef/pkg/options/options_test.go (about)

     1  package options
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestMergeDefaultsWH(t *testing.T) {
     8  	tests := []struct {
     9  		name       string
    10  		appoptions *App
    11  		wantWidth  int
    12  		wantHeight int
    13  	}{
    14  		{
    15  			name:       "No width and height",
    16  			appoptions: &App{},
    17  			wantWidth:  1024,
    18  			wantHeight: 768,
    19  		},
    20  		{
    21  			name: "Basic width and height",
    22  			appoptions: &App{
    23  				Width:  800,
    24  				Height: 600,
    25  			},
    26  			wantWidth:  800,
    27  			wantHeight: 600,
    28  		},
    29  		{
    30  			name: "With MinWidth and MinHeight",
    31  			appoptions: &App{
    32  				Width:     200,
    33  				MinWidth:  800,
    34  				Height:    100,
    35  				MinHeight: 600,
    36  			},
    37  			wantWidth:  800,
    38  			wantHeight: 600,
    39  		},
    40  		{
    41  			name: "With MaxWidth and MaxHeight",
    42  			appoptions: &App{
    43  				Width:     900,
    44  				MaxWidth:  800,
    45  				Height:    700,
    46  				MaxHeight: 600,
    47  			},
    48  			wantWidth:  800,
    49  			wantHeight: 600,
    50  		},
    51  		{
    52  			name: "With MinWidth more than MaxWidth",
    53  			appoptions: &App{
    54  				Width:    900,
    55  				MinWidth: 900,
    56  				MaxWidth: 800,
    57  				Height:   600,
    58  			},
    59  			wantWidth:  800,
    60  			wantHeight: 600,
    61  		},
    62  		{
    63  			name: "With MinHeight more than MaxHeight",
    64  			appoptions: &App{
    65  				Width:     800,
    66  				Height:    700,
    67  				MinHeight: 900,
    68  				MaxHeight: 600,
    69  			},
    70  			wantWidth:  800,
    71  			wantHeight: 600,
    72  		},
    73  	}
    74  	for _, tt := range tests {
    75  		t.Run(tt.name, func(t *testing.T) {
    76  			MergeDefaults(tt.appoptions)
    77  			if tt.appoptions.Width != tt.wantWidth {
    78  				t.Errorf("MergeDefaults().Width =%v, want %v", tt.appoptions.Width, tt.wantWidth)
    79  			}
    80  			if tt.appoptions.Height != tt.wantHeight {
    81  				t.Errorf("MergeDefaults().Height =%v, want %v", tt.appoptions.Height, tt.wantHeight)
    82  			}
    83  		})
    84  	}
    85  }