@@ -11,6 +11,25 @@ local function percent(number, percentage)
11
11
return math.floor (number * percentage / 100 )
12
12
end
13
13
14
+ local function assert_size (popup , size , border_size )
15
+ if border_size and type (border_size ) ~= " table" then
16
+ border_size = {
17
+ width = size .width + 2 ,
18
+ height = size .height + 2 ,
19
+ }
20
+ end
21
+
22
+ local win_config = vim .api .nvim_win_get_config (popup .winid )
23
+ eq (win_config .width , size .width )
24
+ eq (win_config .height , size .height )
25
+
26
+ if popup .border .winid then
27
+ local border_win_config = vim .api .nvim_win_get_config (popup .border .winid )
28
+ eq (border_win_config .width , border_size .width )
29
+ eq (border_win_config .height , border_size .height )
30
+ end
31
+ end
32
+
14
33
describe (" nui.popup" , function ()
15
34
local popup
16
35
@@ -94,6 +113,59 @@ describe("nui.popup", function()
94
113
eq (popup .ns_id > 0 , true )
95
114
end )
96
115
116
+ describe (" o.size" , function ()
117
+ it (" supports integer" , function ()
118
+ popup = Popup ({
119
+ position = 0 ,
120
+ size = {
121
+ height = 8 ,
122
+ width = 20 ,
123
+ },
124
+ })
125
+
126
+ popup :mount ()
127
+
128
+ assert_size (popup , {
129
+ height = 8 ,
130
+ width = 20 ,
131
+ })
132
+ end )
133
+
134
+ it (" supports decimal number in (0,1)" , function ()
135
+ popup = Popup ({
136
+ position = 0 ,
137
+ size = {
138
+ height = 0.6 ,
139
+ width = 0.8 ,
140
+ },
141
+ })
142
+
143
+ popup :mount ()
144
+
145
+ assert_size (popup , {
146
+ height = percent (popup ._ .container_info .size .height , 60 ),
147
+ width = percent (popup ._ .container_info .size .width , 80 ),
148
+ })
149
+ end )
150
+
151
+ it (" supports percentage string" , function ()
152
+ popup = Popup ({
153
+ position = 0 ,
154
+ size = {
155
+ height = " 60%" ,
156
+ width = " 80%" ,
157
+ },
158
+ })
159
+
160
+ popup :mount ()
161
+
162
+ assert_size (popup , {
163
+ height = percent (popup ._ .container_info .size .height , 60 ),
164
+ width = percent (popup ._ .container_info .size .width , 80 ),
165
+ })
166
+ end )
167
+ end )
168
+
97
169
h .describe_flipping_feature (" lua_keymap" , " method :map" , function ()
98
170
it (" works before :mount" , function ()
99
171
local callback = spy .new (function () end )
@@ -545,25 +617,6 @@ describe("nui.popup", function()
545
617
end )
546
618
547
619
describe (" method :update_layout" , function ()
548
- local function assert_size (size , border_size )
549
- if border_size and type (border_size ) ~= " table" then
550
- border_size = {
551
- width = size .width + 2 ,
552
- height = size .height + 2 ,
553
- }
554
- end
555
-
556
- local win_config = vim .api .nvim_win_get_config (popup .winid )
557
- eq (win_config .width , size .width )
558
- eq (win_config .height , size .height )
559
-
560
- if popup .border .winid then
561
- local border_win_config = vim .api .nvim_win_get_config (popup .border .winid )
562
- eq (border_win_config .width , border_size .width )
563
- eq (border_win_config .height , border_size .height )
564
- end
565
- end
566
-
567
620
local function assert_position (position , container_winid )
568
621
container_winid = container_winid or vim .api .nvim_get_current_win ()
569
622
@@ -653,7 +706,7 @@ describe("nui.popup", function()
653
706
654
707
eq (type (popup .border .winid ), " nil" )
655
708
656
- assert_size (size )
709
+ assert_size (popup , size )
657
710
658
711
local new_size = {
659
712
width = size .width + 2 ,
@@ -662,7 +715,7 @@ describe("nui.popup", function()
662
715
663
716
popup :update_layout ({ size = new_size })
664
717
665
- assert_size (new_size )
718
+ assert_size (popup , new_size )
666
719
end )
667
720
668
721
it (" can change size (w/ complex border)" , function ()
@@ -688,7 +741,7 @@ describe("nui.popup", function()
688
741
689
742
eq (type (popup .border .winid ), " number" )
690
743
691
- assert_size (size , true )
744
+ assert_size (popup , size , true )
692
745
h .popup .assert_border_lines ({
693
746
size = size ,
694
747
border = { style = style },
@@ -705,7 +758,7 @@ describe("nui.popup", function()
705
758
706
759
popup :update_layout ({ size = new_size })
707
760
708
- assert_size (new_size , true )
761
+ assert_size (popup , new_size , true )
709
762
h .popup .assert_border_lines ({
710
763
size = new_size ,
711
764
border = { style = style },
@@ -808,7 +861,7 @@ describe("nui.popup", function()
808
861
809
862
popup :mount ()
810
863
811
- assert_size ({
864
+ assert_size (popup , {
812
865
width = percent (container_size .width , 50 ),
813
866
height = percent (container_size .height , 50 ),
814
867
})
@@ -829,7 +882,7 @@ describe("nui.popup", function()
829
882
830
883
popup :update_layout ()
831
884
832
- assert_size ({
885
+ assert_size (popup , {
833
886
width = percent (container_size .width , 50 ),
834
887
height = percent (container_size .height , 50 ),
835
888
})
0 commit comments