1package content
2
3import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7
8 "github.com/bnema/dumber/internal/domain/entity"
9)
10
11// ---------------------------------------------------------------------------
12// DetectPopupType
13// ---------------------------------------------------------------------------
14
15func TestDetectPopupType_BlankIsTab(t *testing.T) {
16 t.Parallel()
17
18 assert.Equal(t, PopupTypeTab, DetectPopupType("_blank"))
19}
20
21func TestDetectPopupType_EmptyIsPopup(t *testing.T) {
22 t.Parallel()
23
24 assert.Equal(t, PopupTypePopup, DetectPopupType(""))
25}
26
27func TestDetectPopupType_NamedFrameIsPopup(t *testing.T) {
28 t.Parallel()
29
30 assert.Equal(t, PopupTypePopup, DetectPopupType("myFrame"))
31}
32
33// ---------------------------------------------------------------------------
34// PopupType.String()
35// ---------------------------------------------------------------------------
36
37func TestPopupTypeString_Tab(t *testing.T) {
38 t.Parallel()
39
40 assert.Equal(t, "tab", PopupTypeTab.String())
41}
42
43func TestPopupTypeString_Popup(t *testing.T) {
44 t.Parallel()
45
46 assert.Equal(t, "popup", PopupTypePopup.String())
47}
48
49func TestPopupTypeString_Unknown(t *testing.T) {
50 t.Parallel()
51
52 assert.Equal(t, "unknown", PopupType(99).String())
53}
54
55// ---------------------------------------------------------------------------
56// GetBehavior
57// ---------------------------------------------------------------------------
58
59func TestGetBehavior_NilConfigReturnsSplit(t *testing.T) {
60 t.Parallel()
61
62 assert.Equal(t, entity.PopupBehaviorSplit, GetBehavior(PopupTypeTab, nil))
63 assert.Equal(t, entity.PopupBehaviorSplit, GetBehavior(PopupTypePopup, nil))
64}
65
66func TestGetBehavior_TabPopup_DefaultConfig(t *testing.T) {
67 t.Parallel()
68
69 // BlankTargetBehavior is empty → falls through to default "stacked"
70 cfg := &entity.BrowsingContextConfig{}
71 assert.Equal(t, entity.PopupBehaviorStacked, GetBehavior(PopupTypeTab, cfg))
72}
73
74func TestGetBehavior_TabPopup_SplitConfig(t *testing.T) {
75 t.Parallel()
76
77 cfg := &entity.BrowsingContextConfig{BlankTargetBehavior: "split"}
78 assert.Equal(t, entity.PopupBehaviorSplit, GetBehavior(PopupTypeTab, cfg))
79}
80
81func TestGetBehavior_TabPopup_StackedConfig(t *testing.T) {
82 t.Parallel()
83
84 cfg := &entity.BrowsingContextConfig{BlankTargetBehavior: "stacked"}
85 assert.Equal(t, entity.PopupBehaviorStacked, GetBehavior(PopupTypeTab, cfg))
86}
87
88func TestGetBehavior_TabPopup_TabbedConfig(t *testing.T) {
89 t.Parallel()
90
91 cfg := &entity.BrowsingContextConfig{BlankTargetBehavior: "tabbed"}
92 assert.Equal(t, entity.PopupBehaviorTabbed, GetBehavior(PopupTypeTab, cfg))
93}
94
95func TestGetBehavior_JSPopup_UsesBehaviorField(t *testing.T) {
96 t.Parallel()
97
98 cfg := &entity.BrowsingContextConfig{Behavior: entity.PopupBehaviorWindowed}
99 assert.Equal(t, entity.PopupBehaviorWindowed, GetBehavior(PopupTypePopup, cfg))
100}
101
102func TestGetBehavior_JSPopup_DefaultConfig(t *testing.T) {
103 t.Parallel()
104
105 // Behavior zero-value is empty string; GetBehavior returns it as-is.
106 cfg := &entity.BrowsingContextConfig{}
107 assert.Equal(t, entity.PopupBehavior(""), GetBehavior(PopupTypePopup, cfg))
108}
109
110func TestGetBehavior_TabPopup_BlocksWhenOpenInNewPaneFalse(t *testing.T) {
111 t.Parallel()
112
113 // GetBehavior itself does not honor OpenInNewPane — that is enforced by
114 // handlePopupCreate. GetBehavior still returns the configured value.
115 cfg := &entity.BrowsingContextConfig{
116 OpenInNewPane: false,
117 BlankTargetBehavior: "split",
118 }
119 assert.Equal(t, entity.PopupBehaviorSplit, GetBehavior(PopupTypeTab, cfg))
120}