github.com/secoba/wails/v2@v2.6.4/internal/frontend/desktop/windows/dialog_test.go (about)

     1  //go:build windows
     2  
     3  package windows
     4  
     5  import (
     6  	"testing"
     7  
     8  	"github.com/secoba/wails/v2/internal/frontend"
     9  	"golang.org/x/sys/windows"
    10  )
    11  
    12  func Test_calculateMessageDialogFlags(t *testing.T) {
    13  	tests := []struct {
    14  		name    string
    15  		options frontend.MessageDialogOptions
    16  		want    uint32
    17  	}{
    18  		{
    19  			name: "Test Info Dialog",
    20  			options: frontend.MessageDialogOptions{
    21  				Type: frontend.InfoDialog,
    22  			},
    23  			want: windows.MB_OK | windows.MB_ICONINFORMATION,
    24  		},
    25  		{
    26  			name: "Test Error Dialog",
    27  			options: frontend.MessageDialogOptions{
    28  				Type: frontend.ErrorDialog,
    29  			},
    30  			want: windows.MB_ICONERROR | windows.MB_OK,
    31  		},
    32  		{
    33  			name: "Test Question Dialog",
    34  			options: frontend.MessageDialogOptions{
    35  				Type: frontend.QuestionDialog,
    36  			},
    37  			want: windows.MB_YESNO,
    38  		},
    39  		{
    40  			name: "Test Question Dialog with default cancel",
    41  			options: frontend.MessageDialogOptions{
    42  				Type:          frontend.QuestionDialog,
    43  				DefaultButton: "No",
    44  			},
    45  			want: windows.MB_YESNO | windows.MB_DEFBUTTON2,
    46  		},
    47  		{
    48  			name: "Test Question Dialog with default cancel (lowercase)",
    49  			options: frontend.MessageDialogOptions{
    50  				Type:          frontend.QuestionDialog,
    51  				DefaultButton: "no",
    52  			},
    53  			want: windows.MB_YESNO | windows.MB_DEFBUTTON2,
    54  		},
    55  		{
    56  			name: "Test Warning Dialog",
    57  			options: frontend.MessageDialogOptions{
    58  				Type: frontend.WarningDialog,
    59  			},
    60  			want: windows.MB_OK | windows.MB_ICONWARNING,
    61  		},
    62  		{
    63  			name: "Test Error Dialog",
    64  			options: frontend.MessageDialogOptions{
    65  				Type: frontend.ErrorDialog,
    66  			},
    67  			want: windows.MB_ICONERROR | windows.MB_OK,
    68  		},
    69  	}
    70  	for _, tt := range tests {
    71  		t.Run(tt.name, func(t *testing.T) {
    72  			if got := calculateMessageDialogFlags(tt.options); got != tt.want {
    73  				t.Errorf("calculateMessageDialogFlags() = %v, want %v", got, tt.want)
    74  			}
    75  		})
    76  	}
    77  }