diff --git a/test/unittest/core/pattern/indexer/arcindexer_pattern_test_ng.cpp b/test/unittest/core/pattern/indexer/arcindexer_pattern_test_ng.cpp index fceb0c5f130ff5aa495c94a6806a3a04520a03a6..1c19b7a4aea38053b656bad8a183b5e5597b114c 100644 --- a/test/unittest/core/pattern/indexer/arcindexer_pattern_test_ng.cpp +++ b/test/unittest/core/pattern/indexer/arcindexer_pattern_test_ng.cpp @@ -57,6 +57,8 @@ std::vector CREATE_ARRAY = { "AAAAAAAA", "BBBB", "C", "D", "E", "FF "MMMMMMMM", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; std::vector CREATE_ARRAY_1 = { "A", "B", "C", "D", "E", "F", "G", "H", "I" }; std::vector CREATE_ARRAY_2 = { "#", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L" }; +std::vector LONG_ARRAY = { "AAAAAAAA", "BBBB", "C", "D", "E", "FFFFF", "G", "H", "I", "J", "K", "L", + "MMMMMMMM", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "ED", "FJ", "OMD", "MDL", "PCL" }; constexpr double DEFAULT_POSIITON_X = -23.0; constexpr double DEFAULT_POSIITON_Y = 44.0; @@ -70,7 +72,7 @@ public: void TearDown() override; void GetInstance(); - void Create(const std::function& callback = nullptr, + IndexerModelNG Create(const std::function& callback = nullptr, std::vector arrayValue = CREATE_ARRAY, int32_t selected = 0); float GetFirstChildOffsetY(); AssertionResult Selected(int32_t expectSelected); @@ -125,7 +127,7 @@ void ArcindexerPatternTestNg::GetInstance() contentModifier_ = AceType::MakeRefPtr(); } -void ArcindexerPatternTestNg::Create( +IndexerModelNG ArcindexerPatternTestNg::Create( const std::function& callback, std::vector arrayValue, int32_t selected) { IndexerModelNG model; @@ -135,6 +137,7 @@ void ArcindexerPatternTestNg::Create( } GetInstance(); FlushUITasks(frameNode_); + return model; } float ArcindexerPatternTestNg::GetFirstChildOffsetY() @@ -1572,4 +1575,816 @@ HWTEST_F(ArcindexerPatternTestNg, ArcExpandedAnimation001, TestSize.Level1) arcIndexerPattern->ArcExpandedAnimation(0); EXPECT_EQ(arcIndexerPattern->contentModifier_->sweepAngle_->Get(), 360.0f); } + +/** + * @tc.name: UpdateIndexerRender001 + * @tc.desc: Test arc indexer pattern UpdateIndexerRender function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, UpdateIndexerRender001, TestSize.Level1) +{ + Create(nullptr, CREATE_ARRAY, 0); + auto indexerRenderContext = frameNode_->GetRenderContext(); + + /** + * @tc.steps: step1. Test with arcRadius_ 15. + * @tc.expected: UpdateIndexerRender correct. + */ + pattern_->arcRadius_ = 15.f; + auto indexerRadius = Dimension(pattern_->arcRadius_, DimensionUnit::VP); + pattern_->UpdateIndexerRender(); + EXPECT_EQ(indexerRenderContext->GetBorderRadius()->radiusTopLeft.value(), indexerRadius); + EXPECT_EQ(indexerRenderContext->GetBorderRadius()->radiusTopRight.value(), indexerRadius); + EXPECT_EQ(indexerRenderContext->GetBorderRadius()->radiusBottomLeft.value(), indexerRadius); + EXPECT_EQ(indexerRenderContext->GetBorderRadius()->radiusBottomRight.value(), indexerRadius); + EXPECT_EQ(indexerRenderContext->GetBackgroundColor().value(), Color::TRANSPARENT); + + /** + * @tc.steps: step2. Test with arcRadius_ 180. + * @tc.expected: UpdateIndexerRender correct. + */ + pattern_->arcRadius_ = 180.f; + indexerRadius = Dimension(pattern_->arcRadius_, DimensionUnit::VP); + pattern_->UpdateIndexerRender(); + EXPECT_EQ(indexerRenderContext->GetBorderRadius()->radiusTopLeft.value(), indexerRadius); + EXPECT_EQ(indexerRenderContext->GetBorderRadius()->radiusTopRight.value(), indexerRadius); + EXPECT_EQ(indexerRenderContext->GetBorderRadius()->radiusBottomLeft.value(), indexerRadius); + EXPECT_EQ(indexerRenderContext->GetBorderRadius()->radiusBottomRight.value(), indexerRadius); + EXPECT_EQ(indexerRenderContext->GetBackgroundColor().value(), Color::TRANSPARENT); +} + +/** + * @tc.name: UpdateIndexerNodeOpacityByIdx001 + * @tc.desc: Test arc indexer pattern UpdateIndexerNodeOpacityByIdx function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, UpdateIndexerNodeOpacityByIdx001, TestSize.Level1) +{ + Create(nullptr, CREATE_ARRAY, 0); + auto renderContext = frameNode_->GetRenderContext(); + + /** + * @tc.steps: step1. Test with currectCollapsingMode_ == lastCollapsingMode_. + * @tc.expected: Opacity not changed. + */ + renderContext->UpdateOpacity(2.0f); + pattern_->currectCollapsingMode_ = ArcIndexerCollapsingMode::FOUR; + pattern_->lastCollapsingMode_ = ArcIndexerCollapsingMode::FOUR; + pattern_->UpdateIndexerNodeOpacityByIdx(renderContext, 2); + EXPECT_EQ(renderContext->GetOpacity(), 2.0f); + + /** + * @tc.steps: step2. Test with currectCollapsingMode_ != lastCollapsingMode_. + * @tc.expected: Opacity changed. + */ + pattern_->currectCollapsingMode_ = ArcIndexerCollapsingMode::NONE; + pattern_->lastCollapsingMode_ = ArcIndexerCollapsingMode::FOUR; + pattern_->UpdateIndexerNodeOpacityByIdx(renderContext, 5); + EXPECT_EQ(renderContext->GetOpacity(), 0.0f); + + /** + * @tc.steps: step3. Test with currectCollapsingMode_ != lastCollapsingMode_. + * @tc.expected: Opacity not changed. + */ + renderContext->UpdateOpacity(2.0f); + pattern_->currectCollapsingMode_ = ArcIndexerCollapsingMode::FOUR; + pattern_->lastCollapsingMode_ = ArcIndexerCollapsingMode::NONE; + pattern_->UpdateIndexerNodeOpacityByIdx(renderContext, 5); + EXPECT_EQ(renderContext->GetOpacity(), 2.0f); +} + +/** + * @tc.name: UpdateBubbleView001 + * @tc.desc: Test arc indexer pattern UpdateBubbleView function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, UpdateBubbleView001, TestSize.Level1) +{ + Create(nullptr, CREATE_ARRAY, 0); + pattern_->popupNode_ = pattern_->CreatePopupNode(); + + /** + * @tc.steps: step1. Test with func UpdateBubbleView. + * @tc.expected: renderContext set correct. + */ + pattern_->UpdateBubbleView(); + auto borderRadius = Dimension(ARC_BUBBLE_BOX_RADIUS, DimensionUnit::VP); + auto textRenderContext = pattern_->popupNode_->GetRenderContext(); + EXPECT_EQ(textRenderContext->GetBorderRadius()->radiusBottomRight, borderRadius); + EXPECT_EQ(textRenderContext->GetBorderRadius()->radiusBottomLeft, borderRadius); + EXPECT_EQ(textRenderContext->GetBorderRadius()->radiusTopLeft, borderRadius); + EXPECT_EQ(textRenderContext->GetBorderRadius()->radiusTopRight, borderRadius); + EXPECT_EQ(textRenderContext->GetBackShadow()->GetBlurRadius(), 0); + EXPECT_EQ(textRenderContext->GetBackShadow()->GetOffset().GetX(), 0); + EXPECT_EQ(textRenderContext->GetBackShadow()->GetOffset().GetY(), 10); + EXPECT_EQ(textRenderContext->GetBackShadow()->GetColor(), Color(0x26000000)); + EXPECT_EQ(textRenderContext->GetBackShadow()->GetShadowType(), ShadowType::COLOR); +} + +/** + * @tc.name: FireOnSelect002 + * @tc.desc: Test arc indexer pattern FireOnSelect function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, FireOnSelect002, TestSize.Level1) +{ + int32_t selected = -1; + int32_t changeSelected = -1; + int32_t creatChangeSelected = -1; + OnSelectedEvent onSelected = [&selected](int32_t selectedIndex) { selected = selectedIndex; }; + OnSelectedEvent changeEvent = [&changeSelected](int32_t selectedIndex) { changeSelected = selectedIndex; }; + OnSelectedEvent creatChangeEvent = [&creatChangeSelected]( + int32_t selectedIndex) { creatChangeSelected = selectedIndex; }; + IndexerModelNG model = Create(nullptr, CREATE_ARRAY, 0); + model.SetOnSelected(std::move(onSelected)); + model.SetChangeEvent(std::move(changeEvent)); + model.SetCreatChangeEvent(std::move(creatChangeEvent)); + + /** + * @tc.steps: step1. Test with func FireOnSelect. + * @tc.expected: lastFireSelectIndex_ 2. + */ + pattern_->selected_ = 1; + pattern_->FireOnSelect(2, false); + EXPECT_EQ(selected, -1); + EXPECT_EQ(changeSelected, -1); + EXPECT_EQ(creatChangeSelected, -1); + EXPECT_EQ(pattern_->lastFireSelectIndex_, 2); + EXPECT_FALSE(pattern_->lastIndexFromPress_); +} + +/** + * @tc.name: BuildFullArrayValue001 + * @tc.desc: Test arc indexer pattern BuildFullArrayValue function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, BuildFullArrayValue001, TestSize.Level1) +{ + Create(nullptr, std::vector(), 0); + + /** + * @tc.steps: step1. Test with CREATE_ARRAY_2. + * @tc.expected: arcArrayValue_ correct. + */ + pattern_->fullArrayValue_ = CREATE_ARRAY_2; + pattern_->fullCount_ = CREATE_ARRAY_2.size(); + pattern_->autoCollapse_ = true; + pattern_->BuildFullArrayValue(); + std::vector expectValue = CREATE_ARRAY_2; + std::vector arrayValue; + expectValue.push_back("<"); + for (auto item : pattern_->arcArrayValue_) { + arrayValue.push_back(item.first); + } + EXPECT_EQ(arrayValue, expectValue); + + /** + * @tc.steps: step2. Test with fullCount_ < ARC_INDEXER_COLLAPSE_ITEM_COUNT and autoCollapse_ false. + * @tc.expected: arcArrayValue_ correct. + */ + std::vector array = { "A", "B" }; + pattern_->fullArrayValue_ = array; + pattern_->fullCount_ = array.size(); + pattern_->autoCollapse_ = false; + pattern_->BuildFullArrayValue(); + arrayValue.clear(); + expectValue = array; + for (auto item : pattern_->arcArrayValue_) { + arrayValue.push_back(item.first); + } + EXPECT_EQ(arrayValue, expectValue); + + /** + * @tc.steps: step3. Test with fullCount_ < ARC_INDEXER_COLLAPSE_ITEM_COUNT and autoCollapse_ true. + * @tc.expected: arcArrayValue_ correct. + */ + pattern_->autoCollapse_ = true; + pattern_->BuildFullArrayValue(); + arrayValue.clear(); + for (auto item : pattern_->arcArrayValue_) { + arrayValue.push_back(item.first); + } + EXPECT_EQ(arrayValue, expectValue); +} + +/** + * @tc.name: ApplyFourPlusOneMode001 + * @tc.desc: Test arc indexer pattern ApplyFourPlusOneMode function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, ApplyFourPlusOneMode001, TestSize.Level1) +{ + Create(nullptr, CREATE_ARRAY_2, 0); + pattern_->autoCollapse_ = true; + std::vector arrayvalue; + std::vector expectValue = CREATE_ARRAY_2; + + /** + * @tc.steps: step1. Test with CREATE_ARRAY_2. + * @tc.expected: arcArrayValue_ correct. + */ + expectValue.push_back(">"); + pattern_->currectCollapsingMode_ = ArcIndexerCollapsingMode::FOUR; + pattern_->startIndex_ = 0; + pattern_->endIndex_ = CREATE_ARRAY_2.size(); + pattern_->selected_ = 2; + pattern_->ApplyFourPlusOneMode(); + for (auto item : pattern_->arcArrayValue_) { + arrayvalue.push_back(item.first); + } + EXPECT_EQ(arrayvalue, expectValue); + EXPECT_EQ(pattern_->startIndex_, 0); + EXPECT_EQ(pattern_->endIndex_, 13); + + /** + * @tc.steps: step2. Test with startIndex_ and endIndex_ changed. + * @tc.expected: arcArrayValue_ correct. + */ + arrayvalue.clear(); + pattern_->startIndex_ = 0; + pattern_->endIndex_ = 15; + pattern_->selected_ = CREATE_ARRAY_2.size(); + pattern_->ApplyFourPlusOneMode(); + expectValue = { "I", "J", "K", "L", ">" }; + for (auto item : pattern_->arcArrayValue_) { + arrayvalue.push_back(item.first); + } + EXPECT_EQ(arrayvalue, expectValue); + EXPECT_EQ(pattern_->startIndex_, 9); + EXPECT_EQ(pattern_->endIndex_, 13); +} + +/** + * @tc.name: ApplyFourPlusOneMode002 + * @tc.desc: Test arc indexer pattern ApplyFourPlusOneMode function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, ApplyFourPlusOneMode002, TestSize.Level1) +{ + Create(nullptr, CREATE_ARRAY_2, 0); + pattern_->autoCollapse_ = true; + std::vector arrayvalue; + std::vector expectValue; + + /** + * @tc.steps: step1. Test with startIndex_ and endIndex_ changed. + * @tc.expected: arcArrayValue_ correct. + */ + arrayvalue.clear(); + pattern_->startIndex_ = 3; + pattern_->endIndex_ = 10; + pattern_->selected_ = 0; + pattern_->ApplyFourPlusOneMode(); + expectValue = { "#", "A", "B", "C", ">" }; + for (auto item : pattern_->arcArrayValue_) { + arrayvalue.push_back(item.first); + } + EXPECT_EQ(arrayvalue, expectValue); + EXPECT_EQ(pattern_->startIndex_, 0); + EXPECT_EQ(pattern_->endIndex_, 4); + + /** + * @tc.steps: step2. Test with startIndex_ and endIndex_ changed. + * @tc.expected: arcArrayValue_ correct. + */ + arrayvalue.clear(); + pattern_->startIndex_ = 2; + pattern_->endIndex_ = 8; + pattern_->selected_ = 9; + pattern_->ApplyFourPlusOneMode(); + expectValue = { "F", "G", "H", "I", ">" }; + for (auto item : pattern_->arcArrayValue_) { + arrayvalue.push_back(item.first); + } + EXPECT_EQ(arrayvalue, expectValue); + EXPECT_EQ(pattern_->startIndex_, 6); + EXPECT_EQ(pattern_->endIndex_, 10); +} + +/** + * @tc.name: ApplyFourPlusOneMode003 + * @tc.desc: Test arc indexer pattern ApplyFourPlusOneMode function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, ApplyFourPlusOneMode003, TestSize.Level1) +{ + Create(nullptr, LONG_ARRAY, 0); + pattern_->autoCollapse_ = true; + std::vector arrayvalue; + std::vector expectValue = LONG_ARRAY; + + /** + * @tc.steps: step1. Test with LONG_ARRAY. + * @tc.expected: arcArrayValue_ correct. + */ + for (int32_t i = 0; i < LONG_ARRAY.size() - ARC_INDEXER_ITEM_MAX_COUNT; ++i) { + expectValue.pop_back(); + } + expectValue.push_back(">"); + pattern_->currectCollapsingMode_ = ArcIndexerCollapsingMode::FOUR; + pattern_->startIndex_ = 0; + pattern_->endIndex_ = LONG_ARRAY.size() + 1; + pattern_->selected_ = 4; + pattern_->ApplyFourPlusOneMode(); + for (auto item : pattern_->arcArrayValue_) { + arrayvalue.push_back(item.first); + } + EXPECT_EQ(arrayvalue, expectValue); + EXPECT_EQ(pattern_->startIndex_, 0); + EXPECT_EQ(pattern_->endIndex_, 29); + + /** + * @tc.steps: step2. Test with startIndex_ and endIndex_ changed. + * @tc.expected: arcArrayValue_ correct. + */ + arrayvalue.clear(); + pattern_->startIndex_ = 3; + pattern_->endIndex_ = 17; + pattern_->selected_ = CREATE_ARRAY_2.size() + 1; + pattern_->ApplyFourPlusOneMode(); + expectValue = { "D", "E", "FFFFF", "G", "H", "I", "J", "K", "L", "MMMMMMMM", "N", "O", "P", "Q", ">" }; + for (auto item : pattern_->arcArrayValue_) { + arrayvalue.push_back(item.first); + } + EXPECT_EQ(arrayvalue, expectValue); + EXPECT_EQ(pattern_->startIndex_, 3); + EXPECT_EQ(pattern_->endIndex_, 17); +} + +/** + * @tc.name: ApplyFourPlusOneMode004 + * @tc.desc: Test arc indexer pattern ApplyFourPlusOneMode function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, ApplyFourPlusOneMode004, TestSize.Level1) +{ + Create(nullptr, LONG_ARRAY, 0); + pattern_->autoCollapse_ = true; + std::vector arrayvalue; + std::vector expectValue; + + /** + * @tc.steps: step1. Test with startIndex_ and endIndex_ changed. + * @tc.expected: arcArrayValue_ correct. + */ + arrayvalue.clear(); + pattern_->startIndex_ = 6; + pattern_->endIndex_ = 7; + pattern_->selected_ = 1; + pattern_->ApplyFourPlusOneMode(); + expectValue = { "BBBB", "C", "D", "E", ">" }; + for (auto item : pattern_->arcArrayValue_) { + arrayvalue.push_back(item.first); + } + EXPECT_EQ(arrayvalue, expectValue); + EXPECT_EQ(pattern_->startIndex_, 1); + EXPECT_EQ(pattern_->endIndex_, 5); + + /** + * @tc.steps: step2. Test with startIndex_ and endIndex_ changed. + * @tc.expected: arcArrayValue_ correct. + */ + arrayvalue.clear(); + pattern_->startIndex_ = 8; + pattern_->endIndex_ = 17; + pattern_->selected_ = 19; + pattern_->ApplyFourPlusOneMode(); + expectValue = { "Q", "R", "S", "T", ">" }; + for (auto item : pattern_->arcArrayValue_) { + arrayvalue.push_back(item.first); + } + EXPECT_EQ(arrayvalue, expectValue); + EXPECT_EQ(pattern_->startIndex_, 16); + EXPECT_EQ(pattern_->endIndex_, 20); +} + +/** + * @tc.name: ResetArrayValue001 + * @tc.desc: Test arc indexer pattern ResetArrayValue function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, ResetArrayValue001, TestSize.Level1) +{ + Create(nullptr, std::vector(), 7); + bool isModeChanged = false; + std::vector arrayValue; + std::vector expectValue; + + /** + * @tc.steps: step2. Test with LONG_ARRAY and autoCollapse_ true. + * @tc.expected: arcArrayValue_ correct. + */ + isModeChanged = true; + pattern_->autoCollapse_ = true; + pattern_->fullArrayValue_ = LONG_ARRAY; + layoutProperty_->UpdateUsingPopup(true); + pattern_->currectCollapsingMode_ = ArcIndexerCollapsingMode::FOUR; + pattern_->startIndex_ = 8; + pattern_->endIndex_ = 17; + pattern_->ResetArrayValue(isModeChanged); + EXPECT_EQ(pattern_->fullCount_, LONG_ARRAY.size()); + EXPECT_EQ(pattern_->sharpItemCount_, 0); + EXPECT_EQ(pattern_->itemCount_, 5); + EXPECT_TRUE(pattern_->isPopup_); + EXPECT_EQ(pattern_->startIndex_, 0); + EXPECT_EQ(pattern_->endIndex_, 4); + for (auto item : pattern_->arcArrayValue_) { + arrayValue.push_back(item.first); + } + expectValue = { "AAAAAAAA", "BBBB", "C", "D", ">" }; + EXPECT_EQ(arrayValue, expectValue); + + /** + * @tc.steps: step2. Test with LONG_ARRAY and autoCollapse_ false. + * @tc.expected: arcArrayValue_ correct. + */ + pattern_->autoCollapse_ = true; + pattern_->currectCollapsingMode_ = ArcIndexerCollapsingMode::NONE; + pattern_->ResetArrayValue(isModeChanged); + EXPECT_EQ(pattern_->fullCount_, LONG_ARRAY.size()); + EXPECT_EQ(pattern_->sharpItemCount_, 0); + EXPECT_EQ(pattern_->itemCount_, LONG_ARRAY.size() - 1); + EXPECT_EQ(pattern_->endIndex_, 4); + expectValue = LONG_ARRAY; + for (int32_t i = 0; i < LONG_ARRAY.size() - ARC_INDEXER_ITEM_MAX_COUNT; ++i) { + expectValue.pop_back(); + } + expectValue.push_back("<"); + arrayValue.clear(); + for (auto item : pattern_->arcArrayValue_) { + arrayValue.push_back(item.first); + } + EXPECT_EQ(arrayValue, expectValue); +} + +/** + * @tc.name: FireAccessbilityExpanded001 + * @tc.desc: Test arc indexer pattern FireAccessbilityExpanded function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, FireAccessbilityExpanded001, TestSize.Level1) +{ + Create(nullptr, LONG_ARRAY, 0); + + /** + * @tc.steps: step1. Test with func FireAccessbilityExpanded. + * @tc.expected: currectCollapsingMode_ correct. + */ + pattern_->currectCollapsingMode_ = ArcIndexerCollapsingMode::FOUR; + pattern_->FireAccessbilityExpanded(); + EXPECT_FALSE(pattern_->isNewHeightCalculated_); + EXPECT_TRUE(pattern_->isClickActionFire_); + EXPECT_EQ(pattern_->lastCollapsingMode_, ArcIndexerCollapsingMode::NONE); + EXPECT_EQ(pattern_->currectCollapsingMode_, ArcIndexerCollapsingMode::NONE); +} + +/** + * @tc.name: FireAccessbilityCollapsed001 + * @tc.desc: Test arc indexer pattern FireAccessbilityCollapsed function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, FireAccessbilityCollapsed001, TestSize.Level1) +{ + Create(nullptr, LONG_ARRAY, 0); + + /** + * @tc.steps: step1. Test with func FireAccessbilityCollapsed. + * @tc.expected: currectCollapsingMode_ correct. + */ + pattern_->currectCollapsingMode_ = ArcIndexerCollapsingMode::NONE; + pattern_->FireAccessbilityCollapsed(); + EXPECT_FALSE(pattern_->isNewHeightCalculated_); + EXPECT_TRUE(pattern_->isClickActionFire_); + EXPECT_EQ(pattern_->lastCollapsingMode_, ArcIndexerCollapsingMode::FOUR); + EXPECT_EQ(pattern_->currectCollapsingMode_, ArcIndexerCollapsingMode::FOUR); +} + +/** + * @tc.name: OnDirtyLayoutWrapperSwap001 + * @tc.desc: Test arc indexer pattern OnDirtyLayoutWrapperSwap function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, OnDirtyLayoutWrapperSwap001, TestSize.Level1) +{ + Create(nullptr, LONG_ARRAY, 0); + DirtySwapConfig dirtySwapConfig; + dirtySwapConfig.skipLayout = false; + dirtySwapConfig.skipMeasure = false; + RefPtr geometryNode = AceType::MakeRefPtr(); + RefPtr layoutWrapper = + AceType::MakeRefPtr(frameNode_, geometryNode, layoutProperty_); + auto algorithm = AceType::MakeRefPtr(); + auto layoutAlgorithmWrapper = AceType::MakeRefPtr(algorithm); + layoutWrapper->layoutAlgorithm_ = layoutAlgorithmWrapper; + + /** + * @tc.steps: step1. Test with autoCollapse_ true. + * @tc.expected: currectCollapsingMode_ correct. + */ + algorithm->arcCenter_ = OffsetF(10.f, 10.f); + algorithm->sweepAngle_ = 10; + algorithm->arcRadius_ = 20; + algorithm->itemRadius_ = 10; + algorithm->actualSize_ = 5; + algorithm->stepAngle_ = 20; + algorithm->startAngle_ = 20; + pattern_->autoCollapse_ = true; + pattern_->arcIndexerSize_ = 2; + pattern_->OnDirtyLayoutWrapperSwap(layoutWrapper, dirtySwapConfig); + EXPECT_EQ(pattern_->strokeWidth_, pattern_->lastItemSize_); + EXPECT_EQ(pattern_->arcRadius_, 20); + EXPECT_EQ(pattern_->arcCenter_, OffsetF(10.f, 10.f)); + EXPECT_EQ(pattern_->sweepAngle_, 10); + EXPECT_EQ(pattern_->arcIndexerSize_, 5); + EXPECT_EQ(pattern_->stepAngle_, 20); + EXPECT_EQ(pattern_->startAngle_, 20); + EXPECT_TRUE(pattern_->isNewHeightCalculated_); + + /** + * @tc.steps: step1. Test with autoCollapse_ false. + * @tc.expected: currectCollapsingMode_ correct. + */ + algorithm->stepAngle_ = 10; + algorithm->startAngle_ = 10; + pattern_->autoCollapse_ = false; + pattern_->stepAngle_ = 10; + pattern_->startAngle_ = 10; + pattern_->OnDirtyLayoutWrapperSwap(layoutWrapper, dirtySwapConfig); + EXPECT_TRUE(pattern_->initialized_); +} + +/** + * @tc.name: OnDirtyLayoutWrapperSwap002 + * @tc.desc: Test arc indexer pattern OnDirtyLayoutWrapperSwap function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, OnDirtyLayoutWrapperSwap002, TestSize.Level1) +{ + Create(nullptr, LONG_ARRAY, 0); + DirtySwapConfig dirtySwapConfig; + dirtySwapConfig.skipLayout = false; + dirtySwapConfig.skipMeasure = false; + RefPtr geometryNode = AceType::MakeRefPtr(); + RefPtr layoutWrapper = + AceType::MakeRefPtr(frameNode_, geometryNode, layoutProperty_); + auto algorithm = AceType::MakeRefPtr(); + auto layoutAlgorithmWrapper = AceType::MakeRefPtr(algorithm); + layoutWrapper->layoutAlgorithm_ = layoutAlgorithmWrapper; + + /** + * @tc.steps: step1. Test with stepAngle_ changed. + * @tc.expected: stepAngle_ correct. + */ + algorithm->actualSize_ = 5; + algorithm->stepAngle_ = 10; + algorithm->startAngle_ = 10; + pattern_->stepAngle_ = 20; + pattern_->autoCollapse_ = false; + pattern_->arcIndexerSize_ = 5; + pattern_->startAngle_ = 10; + pattern_->OnDirtyLayoutWrapperSwap(layoutWrapper, dirtySwapConfig); + EXPECT_EQ(pattern_->arcIndexerSize_, 5); + EXPECT_EQ(pattern_->stepAngle_, 10); + EXPECT_EQ(pattern_->startAngle_, 10); + + /** + * @tc.steps: step2. Test with startAngle_ changed. + * @tc.expected: startAngle_ correct. + */ + algorithm->actualSize_ = 4; + algorithm->stepAngle_ = 10; + algorithm->startAngle_ = 20; + pattern_->stepAngle_ = 10; + pattern_->autoCollapse_ = false; + pattern_->arcIndexerSize_ = 4; + pattern_->startAngle_ = 10; + pattern_->OnDirtyLayoutWrapperSwap(layoutWrapper, dirtySwapConfig); + EXPECT_EQ(pattern_->arcIndexerSize_, 4); + EXPECT_EQ(pattern_->stepAngle_, 10); + EXPECT_EQ(pattern_->startAngle_, 20); +} + +/** + * @tc.name: OnTouchDown001 + * @tc.desc: Test arc indexer pattern OnTouchDown function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, OnTouchDown001, TestSize.Level1) +{ + Create(nullptr, LONG_ARRAY, 0); + TouchEventInfo info = TouchEventInfo("touch"); + TouchLocationInfo touchLocationInfo = TouchLocationInfo(1); + touchLocationInfo.SetLocalLocation(Offset(50.f, 50.f)); + touchLocationInfo.SetTouchType(TouchType::DOWN); + info.AddTouchLocationInfo(std::move(touchLocationInfo)); + + /** + * @tc.steps: step1. Test with nextSelectIndex < itemCount_. + * @tc.expected: selected correct. + */ + pattern_->stepAngle_ = 20; + pattern_->autoCollapse_ = true; + pattern_->arcCenter_ = OffsetF(20.f, 20.f); + pattern_->selected_ = 5; + pattern_->startAngle_ = 0; + pattern_->OnTouchDown(info); + EXPECT_EQ(pattern_->selected_, 2); + + /** + * @tc.steps: step2. Test with nextSelectIndex == itemCount_. + * @tc.expected: selected not changed. + */ + touchLocationInfo.SetLocalLocation(Offset(15.f, 25.f)); + info.AddTouchLocationInfo(std::move(touchLocationInfo)); + pattern_->selected_ = 5; + pattern_->OnTouchDown(info); + EXPECT_EQ(pattern_->selected_, 5); +} + +/** + * @tc.name: OnTouchUp002 + * @tc.desc: Test arc indexer pattern OnTouchUp function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, OnTouchUp002, TestSize.Level1) +{ + Create(nullptr, LONG_ARRAY, 0); + TouchEventInfo info = TouchEventInfo("touch"); + TouchLocationInfo touchLocationInfo = TouchLocationInfo(1); + touchLocationInfo.SetLocalLocation(Offset(50.f, 50.f)); + touchLocationInfo.SetTouchType(TouchType::DOWN); + info.AddTouchLocationInfo(std::move(touchLocationInfo)); + + /** + * @tc.steps: step1. Test with func OnTouchUp. + * @tc.expected: selected correct. + */ + pattern_->OnTouchUp(info); + EXPECT_EQ(pattern_->childPressIndex_, -1); + EXPECT_EQ(pattern_->childFocusIndex_, -1); +} + +/** + * @tc.name: ItemSelectedChangedAnimation001 + * @tc.desc: Test arc indexer pattern ItemSelectedChangedAnimation function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, ItemSelectedChangedAnimation001, TestSize.Level1) +{ + Create(nullptr, LONG_ARRAY, 0); + + /** + * @tc.steps: step1. Test with selected 2. + * @tc.expected: animateSelected_ and lastSelected_ correct. + */ + auto selectedFrameNode = AceType::DynamicCast(frameNode_->GetChildAtIndex(2)); + auto renderContext = selectedFrameNode->GetRenderContext(); + auto pipelineContext = frameNode_->GetContext(); + auto indexerTheme = pipelineContext->GetTheme(); + pattern_->selected_ = 2; + pattern_->lastSelected_ = 0; + pattern_->ItemSelectedChangedAnimation(); + EXPECT_EQ(pattern_->animateSelected_, 2); + EXPECT_EQ(pattern_->lastSelected_, 2); + EXPECT_EQ(renderContext->GetBackgroundColor(), Color::TRANSPARENT); + + /** + * @tc.steps: step2. Test with selected 5. + * @tc.expected: animateSelected_ and lastSelected_ correct. + */ + selectedFrameNode = AceType::DynamicCast(frameNode_->GetChildAtIndex(4)); + renderContext = selectedFrameNode->GetRenderContext(); + pattern_->selected_ = 5; + pattern_->lastSelected_ = 2; + pattern_->ItemSelectedChangedAnimation(); + EXPECT_EQ(pattern_->animateSelected_, 5); + EXPECT_EQ(pattern_->lastSelected_, 2); + EXPECT_EQ(renderContext->GetBackgroundColor(), Color::TRANSPARENT); +} + +/** + * @tc.name: ShowBubble001 + * @tc.desc: Test arc indexer pattern ShowBubble function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, ShowBubble001, TestSize.Level1) +{ + Create(nullptr, LONG_ARRAY, 2); + auto layoutProperty = frameNode_->GetLayoutProperty(); + layoutProperty->UpdateUsingPopup(true); + + /** + * @tc.steps: step1. Test with ShowBubble true. + * @tc.expected: popupnode_ correct. + */ + pattern_->ShowBubble(true); + EXPECT_NE(pattern_->popupNode_, nullptr); + auto renderContext = pattern_->popupNode_->GetRenderContext(); + EXPECT_EQ(renderContext->GetOpacity(), 1); +} + +/** + * @tc.name: BuildArrayValueItems001 + * @tc.desc: Test arc indexer pattern BuildArrayValueItems function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, BuildArrayValueItems001, TestSize.Level1) +{ + IndexerModelNG model = Create(nullptr, std::vector(), 0); + auto layoutProperty = frameNode_->GetLayoutProperty(); + layoutProperty->UpdateAutoCollapse(true); + std::vector arrayValueStrs; + + /** + * @tc.steps: step1. Test with CREATE_ARRAY. + * @tc.expected: arrayValueItems correct. + */ + pattern_->fullArrayValue_ = CREATE_ARRAY; + pattern_->autoCollapse_ = true; + pattern_->fullCount_ = CREATE_ARRAY.size(); + pattern_->currectCollapsingMode_ = ArcIndexerCollapsingMode::FOUR; + pattern_->selected_ = 2; + pattern_->startIndex_ = 3; + pattern_->ApplyFourPlusOneMode(); + pattern_->BuildArrayValueItems(); + for (auto item : pattern_->arcArrayValue_) { + arrayValueStrs.push_back(item.first); + } + arrayValueStrs.pop_back(); + EXPECT_EQ(layoutProperty->GetActualArrayValue(), arrayValueStrs); + auto children = frameNode_->GetChildren(); + auto childCount = static_cast(children.size()); + EXPECT_EQ(childCount, pattern_->arcArrayValue_.size()); + EXPECT_TRUE(layoutProperty->GetIsPopup()); +} + +/** + * @tc.name: BuildArrayValueItems002 + * @tc.desc: Test arc indexer pattern BuildArrayValueItems function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, BuildArrayValueItems002, TestSize.Level1) +{ + IndexerModelNG model = Create(nullptr, std::vector(), 0); + auto layoutProperty = frameNode_->GetLayoutProperty(); + layoutProperty->UpdateAutoCollapse(true); + std::vector arrayValueStrs; + + /** + * @tc.steps: step1. Test with LONG_ARRAY. + * @tc.expected: arrayValueItems correct. + */ + pattern_->fullArrayValue_ = LONG_ARRAY; + pattern_->autoCollapse_ = true; + pattern_->fullCount_ = LONG_ARRAY.size(); + pattern_->currectCollapsingMode_ = ArcIndexerCollapsingMode::FOUR; + pattern_->selected_ = 7; + pattern_->endIndex_ = 5; + pattern_->ApplyFourPlusOneMode(); + pattern_->BuildArrayValueItems(); + for (auto item : pattern_->arcArrayValue_) { + arrayValueStrs.push_back(item.first); + } + arrayValueStrs.pop_back(); + EXPECT_EQ(layoutProperty->GetActualArrayValue(), arrayValueStrs); + auto children = frameNode_->GetChildren(); + auto childCount = static_cast(children.size()); + EXPECT_EQ(childCount, pattern_->arcArrayValue_.size()); + EXPECT_TRUE(layoutProperty->GetIsPopup()); +} + +/** + * @tc.name: BuildArrayValueItems003 + * @tc.desc: Test arc indexer pattern BuildArrayValueItems function. + * @tc.type: FUNC + */ +HWTEST_F(ArcindexerPatternTestNg, BuildArrayValueItems003, TestSize.Level1) +{ + IndexerModelNG model = Create(nullptr, std::vector(), 0); + auto layoutProperty = frameNode_->GetLayoutProperty(); + layoutProperty->UpdateAutoCollapse(true); + std::vector arrayValueStrs; + + /** + * @tc.steps: step1. Test with LONG_ARRAY and autoCollapse_ false. + * @tc.expected: arrayValueItems correct. + */ + pattern_->fullArrayValue_ = LONG_ARRAY; + pattern_->autoCollapse_ = false; + pattern_->fullCount_ = LONG_ARRAY.size(); + pattern_->currectCollapsingMode_ = ArcIndexerCollapsingMode::NONE; + pattern_->selected_ = 7; + pattern_->endIndex_ = 5; + pattern_->BuildFullArrayValue(); + pattern_->BuildArrayValueItems(); + for (auto item : pattern_->arcArrayValue_) { + arrayValueStrs.push_back(item.first); + } + arrayValueStrs.pop_back(); + EXPECT_EQ(layoutProperty->GetActualArrayValue(), arrayValueStrs); + auto children = frameNode_->GetChildren(); + auto childCount = static_cast(children.size()); + EXPECT_EQ(childCount, pattern_->arcArrayValue_.size()); + EXPECT_TRUE(layoutProperty->GetIsPopup()); +} } // namespace OHOS::Ace::NG