Skip to content

Commit b72ca14

Browse files
committed
test: 更新单元测试
1 parent 52cb960 commit b72ca14

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

test/UnitTest/Components/TimePickerTest.cs

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -102,44 +102,35 @@ public async Task OnClickConfirm_Ok()
102102
}
103103

104104
[Fact]
105-
public void TimePickerCell_StyleName_CultureInvariant()
105+
public async Task TimePickerCell_StyleName_CultureInvariant()
106106
{
107-
// Save original culture
107+
// 保存老的 Culture 设置
108108
var originalCulture = CultureInfo.CurrentCulture;
109109
var originalUICulture = CultureInfo.CurrentUICulture;
110-
111-
try
112-
{
113-
// Set culture to Turkish which uses comma as decimal separator
114-
var turkishCulture = new CultureInfo("tr-TR");
115-
CultureInfo.CurrentCulture = turkishCulture;
116-
CultureInfo.CurrentUICulture = turkishCulture;
117-
118-
var cut = Context.RenderComponent<TimePickerCell>(pb =>
119-
{
120-
pb.Add(a => a.ViewMode, TimePickerCellViewMode.Hour);
121-
pb.Add(a => a.Value, TimeSpan.FromHours(2.5));
122-
});
123-
124-
// Call OnHeightCallback to set internal height
125-
cut.InvokeAsync(() => cut.Instance.OnHeightCallback(36.59375));
126-
127-
// The StyleName property should use dots, not commas, even in Turkish culture
128-
var styleElement = cut.Find("ul.time-spinner-list");
129-
var style = styleElement.GetAttribute("style");
130-
131-
// CSS should use dots for decimal values, not commas
132-
Assert.Contains(".", style);
133-
Assert.DoesNotContain(",", style);
134-
135-
// Should contain valid translateY with dot decimal separator
136-
Assert.Matches(@"transform:\s*translateY\(-?\d+\.\d*px\);", style);
137-
}
138-
finally
110+
111+
// 设置为土耳其文化环境 小数点使用逗号
112+
var trCulture = new CultureInfo("tr-TR");
113+
CultureInfo.CurrentCulture = trCulture;
114+
CultureInfo.CurrentUICulture = trCulture;
115+
116+
var cut = Context.RenderComponent<TimePickerCell>(pb =>
139117
{
140-
// Restore original culture
141-
CultureInfo.CurrentCulture = originalCulture;
142-
CultureInfo.CurrentUICulture = originalUICulture;
143-
}
118+
pb.Add(a => a.ViewMode, TimePickerCellViewMode.Hour);
119+
pb.Add(a => a.Value, TimeSpan.FromHours(2.5));
120+
});
121+
122+
// 调用 OnHeightCallback 方法设置高度
123+
await cut.InvokeAsync(() => cut.Instance.OnHeightCallback(12.25));
124+
cut.SetParametersAndRender();
125+
126+
// 检查高度样式是否正确生成应该是用点而不是逗号
127+
var styleElement = cut.Find("ul.time-spinner-list");
128+
var style = styleElement.GetAttribute("style");
129+
130+
Assert.Contains("-24.5px", style);
131+
132+
// 恢复当前线程文化设置
133+
CultureInfo.CurrentCulture = originalCulture;
134+
CultureInfo.CurrentUICulture = originalUICulture;
144135
}
145136
}

0 commit comments

Comments
 (0)