!37672 【tdd】datepicker覆盖率提升

Merge pull request !37672 from jiangzhijun8/master
This commit is contained in:
openharmony_ci 2024-07-15 12:16:51 +00:00 committed by Gitee
commit faa323498c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 249 additions and 0 deletions

View File

@ -1997,4 +1997,106 @@ HWTEST_F(DatePickerTestUpdate, DisappearTextStyle001, TestSize.Level1)
EXPECT_EQ(selectedStyle.GetFontSize(), pickerProperty->GetDisappearFontSize().value());
EXPECT_EQ(Ace::FontWeight::MEDIUM, pickerProperty->GetDisappearWeight().value());
}
/**
* @tc.name: ShowContentRowButton001
* @tc.desc: Test DatePickerTestUpdate ShowContentRowButton.
* @tc.type: FUNC
*/
HWTEST_F(DatePickerTestUpdate, ShowContentRowButton001, TestSize.Level1)
{
bool isFirstPage = true;
CreateDatePickerColumnNode();
DatePickerDialogView::ShowContentRowButton(columnNode_, isFirstPage);
}
/**
* @tc.name: ShowContentRowButton002
* @tc.desc: Test DatePickerTestUpdate ShowContentRowButton.
* @tc.type: FUNC
*/
HWTEST_F(DatePickerTestUpdate, ShowContentRowButton002, TestSize.Level1)
{
bool isFirstPage = false;
CreateDatePickerColumnNode();
DatePickerDialogView::ShowContentRowButton(columnNode_, isFirstPage);
}
/**
* @tc.name: UpdateNextButtonMargin001
* @tc.desc: Test DatePickerTestUpdate UpdateNextButtonMargin.
* @tc.type: FUNC
*/
HWTEST_F(DatePickerTestUpdate, UpdateNextButtonMargin001, TestSize.Level1)
{
auto buttonNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<ButtonPattern>(); });
CHECK_NULL_VOID(buttonNode);
auto layoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
RefPtr<ButtonLayoutProperty> buttonLayoutProperty = AceType::DynamicCast<ButtonLayoutProperty>(layoutProperty);
ASSERT_NE(buttonLayoutProperty, nullptr);
DatePickerDialogView::UpdateNextButtonMargin(buttonLayoutProperty);
}
/**
* @tc.name: HandleMouseEvent001
* @tc.desc: Test DatePickerTestUpdate HandleMouseEvent.
* @tc.type: FUNC
*/
HWTEST_F(DatePickerTestUpdate, HandleMouseEvent001, TestSize.Level1)
{
bool isHover = true;
auto titleButtonRow = DatePickerDialogView::CreateTitleButtonRowNode();
DatePickerDialogView::HandleMouseEvent(titleButtonRow, isHover);
}
/**
* @tc.name: HandleMouseEvent002
* @tc.desc: Test DatePickerTestUpdate HandleMouseEvent.
* @tc.type: FUNC
*/
HWTEST_F(DatePickerTestUpdate, HandleMouseEvent002, TestSize.Level1)
{
bool isHover = false;
auto titleButtonRow = DatePickerDialogView::CreateTitleButtonRowNode();
DatePickerDialogView::HandleMouseEvent(titleButtonRow, isHover);
}
/**
* @tc.name: HandleLunarDayChange001
* @tc.desc: Test DatePickerTestUpdate HandleLunarDayChange.
* @tc.type: FUNC
*/
HWTEST_F(DatePickerTestUpdate, HandleLunarDayChange001, TestSize.Level1)
{
uint32_t index = 0;
bool isAdd = true;
auto theme = MockPipelineContext::GetCurrent()->GetTheme<PickerTheme>();
DatePickerModel::GetInstance()->CreateDatePicker(theme);
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
ASSERT_NE(frameNode, nullptr);
auto pickerProperty = frameNode->GetLayoutProperty<DataPickerRowLayoutProperty>();
auto datePickerPattern = frameNode->GetPattern<DatePickerPattern>();
ASSERT_NE(datePickerPattern, nullptr);
datePickerPattern->HandleLunarDayChange(isAdd, index);
}
/**
* @tc.name: HandleLunarDayChange002
* @tc.desc: Test DatePickerTestUpdate HandleLunarDayChange.
* @tc.type: FUNC
*/
HWTEST_F(DatePickerTestUpdate, HandleLunarDayChange002, TestSize.Level1)
{
uint32_t index = 0;
bool isAdd = false;
auto theme = MockPipelineContext::GetCurrent()->GetTheme<PickerTheme>();
DatePickerModel::GetInstance()->CreateDatePicker(theme);
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
ASSERT_NE(frameNode, nullptr);
auto pickerProperty = frameNode->GetLayoutProperty<DataPickerRowLayoutProperty>();
auto datePickerPattern = frameNode->GetPattern<DatePickerPattern>();
ASSERT_NE(datePickerPattern, nullptr);
datePickerPattern->HandleLunarDayChange(isAdd, index);
}
} // namespace OHOS::Ace::NG

View File

@ -1232,6 +1232,25 @@ HWTEST_F(TimePickerPatternTestUpdate, TimePickerDialogView025, TestSize.Level1)
auto testval3 = layoutProperty->GetFontSizeValue();
EXPECT_EQ(testval3, Dimension(100));
}
/**
* @tc.name: getRadius
* @tc.desc: TimePickerDialogView026用例使用
* @tc.type: FUNC
*/
NG::BorderRadiusProperty getRadius()
{
int calcvalue = 100;
NG::BorderRadiusProperty radius;
CalcDimension radiusCalc(calcvalue, static_cast<DimensionUnit>(1));
radius.radiusTopLeft = radiusCalc;
radius.radiusTopRight = radiusCalc;
radius.radiusBottomLeft = radiusCalc;
radius.radiusBottomRight = radiusCalc;
radius.multiValued = true;
return radius;
}
/**
* @tc.name: TimePickerDialogView026
* @tc.desc: Test UpdateButtonStyle.
@ -1239,12 +1258,17 @@ HWTEST_F(TimePickerPatternTestUpdate, TimePickerDialogView025, TestSize.Level1)
*/
HWTEST_F(TimePickerPatternTestUpdate, TimePickerDialogView026, TestSize.Level1)
{
uint32_t color = 0;
Color colorVal = Color(color);
std::vector<ButtonInfo> buttonInfos;
ButtonInfo info1;
ButtonInfo info2;
ButtonInfo info3;
info1.fontSize = Dimension(100);
info1.fontColor = Color::GREEN;
info1.fontFamily = { "unknown" };
info1.backgroundColor = colorVal;
info1.borderRadius = getRadius();
info2.fontSize = Dimension(0);
info2.fontColor = Color::FOREGROUND;
info3.fontSize = Dimension(1);
@ -1477,6 +1501,46 @@ HWTEST_F(TimePickerPatternTestUpdate, SetNormalTextStyle001, TestSize.Level1)
TimePickerModelNG::SetNormalTextStyle(frameNode, theme, textStyle);
}
/**
* @tc.name: SetNormalTextStyle002
* @tc.desc: Test TimePickerPatternTestUpdate SetNormalTextStyle.
* @tc.type: FUNC
*/
HWTEST_F(TimePickerPatternTestUpdate, SetNormalTextStyle002, TestSize.Level1)
{
std::string weight = "FontWeight.Medium";
std::string fontFamily = "";
std::string FORMAT_FONT = "%s|%s|%s";
std::string fontSize = "";
std::string fontInfo =
StringUtils::FormatString(FORMAT_FONT.c_str(), fontSize.c_str(), weight.c_str(), fontFamily.c_str());
uint32_t color = 0;
int32_t POS_0 = 0;
int32_t POS_1 = 1;
int32_t POS_2 = 2;
const char delimiter = '|';
int32_t style = 0;
const std::vector<OHOS::Ace::FontStyle> FONT_STYLES = { OHOS::Ace::FontStyle::NORMAL,
OHOS::Ace::FontStyle::ITALIC };
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
auto theme = MockPipelineContext::GetCurrent()->GetTheme<PickerTheme>();
ASSERT_NE(theme, nullptr);
NG::PickerTextStyle textStyle;
std::vector<std::string> res;
std::string fontValues = std::string(fontInfo);
StringUtils::StringSplitter(fontValues, delimiter, res);
textStyle.fontSize = StringUtils::StringToCalcDimension(res[POS_0], false, DimensionUnit::FP);
if (style >= 0 && style < static_cast<int32_t>(FONT_STYLES.size())) {
textStyle.fontStyle = FONT_STYLES[style];
} else {
textStyle.fontStyle = FONT_STYLES[0];
}
textStyle.fontFamily = Framework::ConvertStrToFontFamilies(res[POS_2]);
textStyle.fontWeight = StringUtils::StringToFontWeight(res[POS_1]);
textStyle.textColor = Color(color);
TimePickerModelNG::SetNormalTextStyle(frameNode, theme, textStyle);
}
/**
* @tc.name: SetSelectedTextStyle001
* @tc.desc: Test TimePickerPatternTestUpdate SetSelectedTextStyle.
@ -1517,6 +1581,46 @@ HWTEST_F(TimePickerPatternTestUpdate, SetSelectedTextStyle001, TestSize.Level1)
TimePickerModelNG::SetSelectedTextStyle(frameNode, theme, textStyle);
}
/**
* @tc.name: SetSelectedTextStyle002
* @tc.desc: Test TimePickerPatternTestUpdate SetSelectedTextStyle.
* @tc.type: FUNC
*/
HWTEST_F(TimePickerPatternTestUpdate, SetSelectedTextStyle002, TestSize.Level1)
{
std::string weight = "FontWeight.Medium";
std::string fontFamily = "";
std::string FORMAT_FONT = "%s|%s|%s";
std::string fontSize = "";
std::string fontInfo =
StringUtils::FormatString(FORMAT_FONT.c_str(), fontSize.c_str(), weight.c_str(), fontFamily.c_str());
uint32_t color = 0;
int32_t POS_0 = 0;
int32_t POS_1 = 1;
int32_t POS_2 = 2;
const char delimiter = '|';
int32_t style = 0;
const std::vector<OHOS::Ace::FontStyle> FONT_STYLES = { OHOS::Ace::FontStyle::NORMAL,
OHOS::Ace::FontStyle::ITALIC };
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
auto theme = MockPipelineContext::GetCurrent()->GetTheme<PickerTheme>();
ASSERT_NE(theme, nullptr);
NG::PickerTextStyle textStyle;
std::vector<std::string> res;
std::string fontValues = std::string(fontInfo);
StringUtils::StringSplitter(fontValues, delimiter, res);
textStyle.fontSize = StringUtils::StringToCalcDimension(res[POS_0], false, DimensionUnit::FP);
if (style >= 0 && style < static_cast<int32_t>(FONT_STYLES.size())) {
textStyle.fontStyle = FONT_STYLES[style];
} else {
textStyle.fontStyle = FONT_STYLES[0];
}
textStyle.fontFamily = Framework::ConvertStrToFontFamilies(res[POS_2]);
textStyle.fontWeight = StringUtils::StringToFontWeight(res[POS_1]);
textStyle.textColor = Color(color);
TimePickerModelNG::SetSelectedTextStyle(frameNode, theme, textStyle);
}
/**
* @tc.name: SetDateTimeOptions001
* @tc.desc: Test TimePickerPatternTestUpdate SetDateTimeOptions.
@ -1617,4 +1721,47 @@ HWTEST_F(TimePickerPatternTestUpdate, OnWindowHide001, TestSize.Level1)
columnPattern_->OnWindowHide();
}
/**
* @tc.name: SetIsEnableHapticFeedback001
* @tc.desc: Test TimePickerPatternTestUpdate SetIsEnableHapticFeedback.
* @tc.type: FUNC
*/
HWTEST_F(TimePickerPatternTestUpdate, SetIsEnableHapticFeedback001, TestSize.Level1)
{
bool isEnableHapticFeedback = true;
TimePickerModelNG::GetInstance()->SetIsEnableHapticFeedback(isEnableHapticFeedback);
}
/**
* @tc.name: SetIsEnableHapticFeedback002
* @tc.desc: Test TimePickerPatternTestUpdate SetIsEnableHapticFeedback.
* @tc.type: FUNC
*/
HWTEST_F(TimePickerPatternTestUpdate, SetIsEnableHapticFeedback002, TestSize.Level1)
{
bool isEnableHapticFeedback = true;
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
TimePickerModelNG::SetIsEnableHapticFeedback(frameNode, isEnableHapticFeedback);
}
/**
* @tc.name: GetCurrentTime001
* @tc.desc: Test TimePickerPatternTestUpdate GetCurrentTime.
* @tc.type: FUNC
*/
HWTEST_F(TimePickerPatternTestUpdate, GetCurrentTime001, TestSize.Level1)
{
auto theme = MockPipelineContext::GetCurrent()->GetTheme<PickerTheme>();
ASSERT_NE(theme, nullptr);
TimePickerModelNG::GetInstance()->CreateTimePicker(theme);
auto pickerFrameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
ASSERT_NE(pickerFrameNode, nullptr);
pickerFrameNode->MarkModifyDone();
auto timePickerRowPattern = pickerFrameNode->GetPattern<TimePickerRowPattern>();
ASSERT_NE(timePickerRowPattern, nullptr);
timePickerRowPattern->SetHasSecond(true);
timePickerRowPattern->GetCurrentTime();
}
} // namespace OHOS::Ace::NG