From 5df2b0efdc3db8369f2b2b097bc905f3d71a74ab Mon Sep 17 00:00:00 2001 From: Tianer Zhou Date: Thu, 11 Jul 2024 11:31:54 +0800 Subject: [PATCH] add layoutMode test Signed-off-by: Tianer Zhou Change-Id: I55ad3519a0d7d1c447827f11409996180c717554 --- .../waterflow/water_flow_sw_layout_test.cpp | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/unittest/core/pattern/waterflow/water_flow_sw_layout_test.cpp b/test/unittest/core/pattern/waterflow/water_flow_sw_layout_test.cpp index 91d501a97c5..39f58b19930 100644 --- a/test/unittest/core/pattern/waterflow/water_flow_sw_layout_test.cpp +++ b/test/unittest/core/pattern/waterflow/water_flow_sw_layout_test.cpp @@ -692,4 +692,39 @@ HWTEST_F(WaterFlowSWTest, ResetSections001, TestSize.Level1) EXPECT_EQ(info_->segmentTails_.size(), 1); EXPECT_EQ(info_->margins_.size(), 1); } + +/** + * @tc.name: ChangeLayoutMode001 + * @tc.desc: change WaterFlow layout mode + * @tc.type: FUNC + */ +HWTEST_F(WaterFlowSWTest, ChangeLayoutMode001, TestSize.Level1) +{ + Create( + [](WaterFlowModelNG model) { + ViewAbstract::SetWidth(CalcLength(400.0f)); + ViewAbstract::SetHeight(CalcLength(600.f)); + CreateItem(60); + }, + false); + auto secObj = pattern_->GetOrCreateWaterFlowSections(); + secObj->ChangeData(0, 0, SECTION_5); + MockPipelineContext::GetCurrent()->FlushBuildFinishCallbacks(); + FlushLayoutTask(frameNode_); + + UpdateCurrentOffset(-205.0f); + EXPECT_EQ(info_->startIndex_, 3); + EXPECT_EQ(info_->endIndex_, 11); + + EXPECT_EQ(pattern_->layoutInfo_->Mode(), WaterFlowLayoutMode::SLIDING_WINDOW); + pattern_->SetLayoutMode(WaterFlowLayoutMode::TOP_DOWN); + FlushLayoutTask(frameNode_); + EXPECT_EQ(pattern_->layoutInfo_->startIndex_, 0); + + UpdateCurrentOffset(-205.0f); + EXPECT_EQ(pattern_->layoutInfo_->startIndex_, 3); + pattern_->SetLayoutMode(WaterFlowLayoutMode::SLIDING_WINDOW); + FlushLayoutTask(frameNode_); + EXPECT_EQ(pattern_->layoutInfo_->startIndex_, 0); +} } // namespace OHOS::Ace::NG