1
1
namespace Fluent . Tests . Controls ;
2
2
3
3
using System . Linq ;
4
+ using System . Windows . Controls ;
5
+ using Fluent . Tests . Helper ;
4
6
using Fluent . Tests . TestClasses ;
5
7
using NUnit . Framework ;
6
8
using Size = System . Windows . Size ;
@@ -9,7 +11,7 @@ namespace Fluent.Tests.Controls;
9
11
public class RibbonTabsContainerTests
10
12
{
11
13
//private static readonly Size zeroSize = default;
12
- private const double ReferenceWidth = 326 ;
14
+ private const double ReferenceWidth = 320 ;
13
15
14
16
private const double ReferenceHeight = 25 ;
15
17
@@ -27,36 +29,38 @@ public void Empty()
27
29
[ Test ]
28
30
public void With_One_Tab ( )
29
31
{
30
- var container = new RibbonTabsContainer ( ) ;
32
+ var tabsContainer = new RibbonTabsContainer ( ) ;
31
33
var tabItem = new RibbonTabItem ( ) ;
32
- container . Children . Add ( tabItem ) ;
34
+ tabsContainer . Children . Add ( tabItem ) ;
35
+
36
+ var container = new ContentControl { Content = tabsContainer , Width = ReferenceWidth } ;
33
37
34
- using ( new TestRibbonWindow ( container ) { Width = ReferenceWidth } )
38
+ using ( new TestRibbonWindow ( container ) )
35
39
{
36
- Assert . That ( container . DesiredSize , Is . EqualTo ( new Size ( 18 , ReferenceHeight ) ) ) ;
40
+ Assert . That ( tabsContainer . DesiredSize , Is . EqualTo ( new Size ( 18 , ReferenceHeight ) ) ) ;
37
41
38
42
tabItem . Header = "ABC" ;
39
43
40
- container . UpdateLayout ( ) ;
44
+ tabsContainer . UpdateLayout ( ) ;
41
45
42
- Assert . That ( container . DesiredSize , Is . EqualTo ( new Size ( 42 , ReferenceHeight ) ) ) ;
46
+ Assert . That ( tabsContainer . DesiredSize , Is . EqualTo ( new Size ( 42 , ReferenceHeight ) ) ) ;
43
47
}
44
48
}
45
49
46
50
[ Test ]
47
51
public void With_Many_Tab ( )
48
52
{
49
- var container = new RibbonTabsContainer ( ) ;
53
+ var tabsContainer = new RibbonTabsContainer ( ) ;
50
54
51
55
var longestTab = new RibbonTabItem { Header = "Longest header text" } ;
52
56
var secondLongestTab = new RibbonTabItem { Header = "Header text" } ;
53
57
var middleTab = new RibbonTabItem { Header = "Header" } ;
54
58
var smallTab = new RibbonTabItem { Header = "Text" } ;
55
59
56
- container . Children . Add ( longestTab ) ;
57
- container . Children . Add ( secondLongestTab ) ;
58
- container . Children . Add ( middleTab ) ;
59
- container . Children . Add ( smallTab ) ;
60
+ tabsContainer . Children . Add ( longestTab ) ;
61
+ tabsContainer . Children . Add ( secondLongestTab ) ;
62
+ tabsContainer . Children . Add ( middleTab ) ;
63
+ tabsContainer . Children . Add ( smallTab ) ;
60
64
61
65
var childrenWidths = new [ ]
62
66
{
@@ -66,36 +70,26 @@ public void With_Many_Tab()
66
70
smallTab
67
71
} . Select ( x => x . DesiredSize . Width ) ;
68
72
69
- using ( var testWindow = new TestRibbonWindow ( container ) { Width = ReferenceWidth } )
70
- {
71
- Assert . That ( container . DesiredSize , Is . EqualTo ( new Size ( 310 , ReferenceHeight ) ) ) ;
72
- Assert . That ( container . ExtentWidth , Is . EqualTo ( container . ViewportWidth ) ) ;
73
-
74
- Assert . That ( childrenWidths , Is . EquivalentTo ( new [ ]
75
- {
76
- 129 ,
77
- 83 ,
78
- 57 ,
79
- 41
80
- } ) ) ;
73
+ var container = new ContentControl { Content = tabsContainer , Width = ReferenceWidth } ;
81
74
82
- container . Measure ( new Size ( 300 , ReferenceHeight ) ) ;
83
-
84
- Assert . That ( container . DesiredSize , Is . EqualTo ( new Size ( 300 , ReferenceHeight ) ) ) ;
85
- Assert . That ( container . ExtentWidth , Is . EqualTo ( container . ViewportWidth ) ) ;
75
+ using ( var testWindow = new TestRibbonWindow ( container ) )
76
+ {
77
+ Assert . That ( tabsContainer . DesiredSize , Is . EqualTo ( new Size ( 317 , ReferenceHeight ) ) ) ;
78
+ Assert . That ( tabsContainer . ExtentWidth , Is . EqualTo ( tabsContainer . ViewportWidth ) ) ;
86
79
87
80
Assert . That ( childrenWidths , Is . EquivalentTo ( new [ ]
88
81
{
89
- 129 ,
90
- 83 ,
91
- 57 ,
92
- 41
82
+ 131 ,
83
+ 85 ,
84
+ 59 ,
85
+ 42
93
86
} ) ) ;
94
87
95
- container . Measure ( new Size ( 299 , ReferenceHeight ) ) ;
88
+ container . Width = 300 ;
89
+ UIHelper . DoEvents ( ) ;
96
90
97
- Assert . That ( container . DesiredSize , Is . EqualTo ( new Size ( 299 , ReferenceHeight ) ) ) ;
98
- Assert . That ( container . ExtentWidth , Is . EqualTo ( container . ViewportWidth ) ) ;
91
+ Assert . That ( tabsContainer . DesiredSize , Is . EqualTo ( new Size ( 300 , ReferenceHeight ) ) ) ;
92
+ Assert . That ( tabsContainer . ExtentWidth , Is . EqualTo ( tabsContainer . ViewportWidth ) ) ;
99
93
100
94
Assert . That ( childrenWidths , Is . EquivalentTo ( new [ ]
101
95
{
@@ -105,10 +99,11 @@ public void With_Many_Tab()
105
99
38
106
100
} ) ) ;
107
101
108
- container . Measure ( new Size ( 290 , ReferenceHeight ) ) ;
102
+ container . Width = 299 ;
103
+ UIHelper . DoEvents ( ) ;
109
104
110
- Assert . That ( container . DesiredSize , Is . EqualTo ( new Size ( 290 , ReferenceHeight ) ) ) ;
111
- Assert . That ( container . ExtentWidth , Is . EqualTo ( container . ViewportWidth ) ) ;
105
+ Assert . That ( tabsContainer . DesiredSize , Is . EqualTo ( new Size ( 299 , ReferenceHeight ) ) ) ;
106
+ Assert . That ( tabsContainer . ExtentWidth , Is . EqualTo ( tabsContainer . ViewportWidth ) ) ;
112
107
113
108
Assert . That ( childrenWidths , Is . EquivalentTo ( new [ ]
114
109
{
@@ -118,10 +113,11 @@ public void With_Many_Tab()
118
113
38
119
114
} ) ) ;
120
115
121
- container . Measure ( new Size ( 289 , ReferenceHeight ) ) ;
116
+ container . Width = 290 ;
117
+ UIHelper . DoEvents ( ) ;
122
118
123
- Assert . That ( container . DesiredSize , Is . EqualTo ( new Size ( 289 , ReferenceHeight ) ) ) ;
124
- Assert . That ( container . ExtentWidth , Is . EqualTo ( container . ViewportWidth ) ) ;
119
+ Assert . That ( tabsContainer . DesiredSize , Is . EqualTo ( new Size ( 290 , ReferenceHeight ) ) ) ;
120
+ Assert . That ( tabsContainer . ExtentWidth , Is . EqualTo ( tabsContainer . ViewportWidth ) ) ;
125
121
126
122
Assert . That ( childrenWidths , Is . EquivalentTo ( new [ ]
127
123
{
@@ -131,10 +127,25 @@ public void With_Many_Tab()
131
127
36
132
128
} ) ) ;
133
129
134
- container . Measure ( new Size ( 230 , ReferenceHeight ) ) ;
130
+ container . Width = 289 ;
131
+ UIHelper . DoEvents ( ) ;
132
+
133
+ Assert . That ( tabsContainer . DesiredSize , Is . EqualTo ( new Size ( 289 , ReferenceHeight ) ) ) ;
134
+ Assert . That ( tabsContainer . ExtentWidth , Is . EqualTo ( tabsContainer . ViewportWidth ) ) ;
135
+
136
+ Assert . That ( childrenWidths , Is . EquivalentTo ( new [ ]
137
+ {
138
+ 123 ,
139
+ 77 ,
140
+ 53 ,
141
+ 36
142
+ } ) ) ;
143
+
144
+ container . Width = 230 ;
145
+ UIHelper . DoEvents ( ) ;
135
146
136
- Assert . That ( container . DesiredSize , Is . EqualTo ( new Size ( 230 , ReferenceHeight ) ) ) ;
137
- Assert . That ( container . ExtentWidth , Is . EqualTo ( 285 ) ) ;
147
+ Assert . That ( tabsContainer . DesiredSize , Is . EqualTo ( new Size ( 230 , ReferenceHeight ) ) ) ;
148
+ Assert . That ( tabsContainer . ExtentWidth , Is . EqualTo ( 285 ) ) ;
138
149
139
150
Assert . That ( childrenWidths , Is . EquivalentTo ( new [ ]
140
151
{
@@ -144,10 +155,11 @@ public void With_Many_Tab()
144
155
34
145
156
} ) ) ;
146
157
147
- container . Measure ( new Size ( 150 , ReferenceHeight ) ) ;
158
+ container . Width = 150 ;
159
+ UIHelper . DoEvents ( ) ;
148
160
149
- Assert . That ( container . DesiredSize , Is . EqualTo ( new Size ( 150 , ReferenceHeight ) ) ) ;
150
- Assert . That ( container . ExtentWidth , Is . EqualTo ( 285 ) ) ;
161
+ Assert . That ( tabsContainer . DesiredSize , Is . EqualTo ( new Size ( 150 , ReferenceHeight ) ) ) ;
162
+ Assert . That ( tabsContainer . ExtentWidth , Is . EqualTo ( 285 ) ) ;
151
163
152
164
Assert . That ( childrenWidths , Is . EquivalentTo ( new [ ]
153
165
{
@@ -157,10 +169,11 @@ public void With_Many_Tab()
157
169
34
158
170
} ) ) ;
159
171
160
- container . Measure ( new Size ( 130 , ReferenceHeight ) ) ;
172
+ container . Width = 130 ;
173
+ UIHelper . DoEvents ( ) ;
161
174
162
- Assert . That ( container . DesiredSize , Is . EqualTo ( new Size ( 130 , ReferenceHeight ) ) ) ;
163
- Assert . That ( container . ExtentWidth , Is . EqualTo ( 285 ) ) ;
175
+ Assert . That ( tabsContainer . DesiredSize , Is . EqualTo ( new Size ( 130 , ReferenceHeight ) ) ) ;
176
+ Assert . That ( tabsContainer . ExtentWidth , Is . EqualTo ( 285 ) ) ;
164
177
165
178
Assert . That ( childrenWidths , Is . EquivalentTo ( new [ ]
166
179
{
@@ -170,10 +183,11 @@ public void With_Many_Tab()
170
183
34
171
184
} ) ) ;
172
185
173
- container . Measure ( new Size ( 120 , ReferenceHeight ) ) ;
186
+ container . Width = 120 ;
187
+ UIHelper . DoEvents ( ) ;
174
188
175
- Assert . That ( container . DesiredSize , Is . EqualTo ( new Size ( 120 , ReferenceHeight ) ) ) ;
176
- Assert . That ( container . ExtentWidth , Is . EqualTo ( 282 ) ) ;
189
+ Assert . That ( tabsContainer . DesiredSize , Is . EqualTo ( new Size ( 120 , ReferenceHeight ) ) ) ;
190
+ Assert . That ( tabsContainer . ExtentWidth , Is . EqualTo ( 282 ) ) ;
177
191
178
192
Assert . That ( childrenWidths , Is . EquivalentTo ( new [ ]
179
193
{
@@ -182,6 +196,31 @@ public void With_Many_Tab()
182
196
51 ,
183
197
34
184
198
} ) ) ;
199
+
200
+ container . Width = 300 ;
201
+ UIHelper . DoEvents ( ) ;
202
+
203
+ Assert . That ( tabsContainer . DesiredSize , Is . EqualTo ( new Size ( 300 , ReferenceHeight ) ) ) ;
204
+ Assert . That ( tabsContainer . ExtentWidth , Is . EqualTo ( tabsContainer . ViewportWidth ) ) ;
205
+
206
+ Assert . That ( childrenWidths , Is . EquivalentTo ( new [ ]
207
+ {
208
+ 127 ,
209
+ 81 ,
210
+ 55 ,
211
+ 37
212
+ } ) ) ;
213
+
214
+ container . Width = ReferenceWidth ;
215
+ UIHelper . DoEvents ( ) ;
216
+
217
+ Assert . That ( childrenWidths , Is . EquivalentTo ( new [ ]
218
+ {
219
+ 131 ,
220
+ 85 ,
221
+ 59 ,
222
+ 42
223
+ } ) ) ;
185
224
}
186
225
}
187
226
}
0 commit comments