From 8759e805ac466b287e1982bc82e7b92af3960bf3 Mon Sep 17 00:00:00 2001 From: c30016310 Date: Thu, 9 May 2024 17:48:07 +0800 Subject: [PATCH] Add TDD for fixed Trouble for previewtext Signed-off-by: c30016310 Change-Id: I2d289e84362bff44244c1336ff701aba27f1e90d --- .../pattern/text_input/text_input_test.cpp | 182 ++++++++++++++++++ 1 file changed, 182 insertions(+) diff --git a/test/unittest/core/pattern/text_input/text_input_test.cpp b/test/unittest/core/pattern/text_input/text_input_test.cpp index 3689ccdeca2..b6e9ac8f283 100644 --- a/test/unittest/core/pattern/text_input/text_input_test.cpp +++ b/test/unittest/core/pattern/text_input/text_input_test.cpp @@ -5353,4 +5353,186 @@ HWTEST_F(TextInputCursorTest, CheckPreviewTextValidate001, TestSize.Level1) FlushLayoutTask(frameNode_); EXPECT_FALSE(pattern_->CheckPreviewTextValidate({PREVIEW_THR})); } + +/** + * @tc.name: NeedDrawPreviewText001 + * @tc.desc: Test NeedDrawPreviewText before set preview text. + * @tc.type: FUNC + */ +HWTEST_F(TextInputCursorTest, NeedDrawPreviewText001, TestSize.Level1) +{ + /** + * @tc.steps: Create Text filed node with default text and placeholder + */ + CreateTextField(DEFAULT_TEXT); + GetFocus(); + + /** + * @tc.expected: Current caret position is end of text + */ + EXPECT_EQ(pattern_->GetCaretIndex(), static_cast(DEFAULT_TEXT.size())); + + /** + * @tc.expected: call NeedDrawPreviewText and check return false + */ + EXPECT_FALSE(pattern_->NeedDrawPreviewText()); + + /** + * @tc.steps:Set caretPosition and call NeedDrawPreviewText001 + * @tc.expected: check return true + */ + auto controller = pattern_->GetTextSelectController(); + controller->UpdateCaretIndex(5); + pattern_->SetPreviewTextOperation(PREVIEW_ONE); + EXPECT_TRUE(pattern_->NeedDrawPreviewText()); + FlushLayoutTask(frameNode_); +} + +/** + * @tc.name: FinishTextPreview001 + * @tc.desc: Test FinishTextPreview after set preview text. + * @tc.type: FUNC + */ +HWTEST_F(TextInputCursorTest, FinishTextPreview001, TestSize.Level1) +{ + /** + * @tc.steps: Create Text filed node with default text and placeholder + */ + CreateTextField(DEFAULT_TEXT); + GetFocus(); + + /** + * @tc.expected: Current caret position is end of text + */ + EXPECT_EQ(pattern_->GetCaretIndex(), static_cast(DEFAULT_TEXT.size())); + + /** + * @tc.steps:Set caretPosition and call SetPreviewTextOperation + * @tc.expected: check GetIsPreviewText return true + */ + auto controller = pattern_->GetTextSelectController(); + controller->UpdateCaretIndex(5); + pattern_->SetPreviewTextOperation(PREVIEW_ONE); + EXPECT_TRUE(pattern_->GetIsPreviewText()); + FlushLayoutTask(frameNode_); + + /** + * @tc.steps: call InitEditingValueText value is "" + * @tc.expected: check GetIsPreviewText return false + */ + pattern_->InitEditingValueText(""); + EXPECT_FALSE(pattern_->GetIsPreviewText()); + FlushLayoutTask(frameNode_); +} + +/** + * @tc.name: FinishTextPreview002 + * @tc.desc: Test FinishTextPreview after set preview text. + * @tc.type: FUNC + */ +HWTEST_F(TextInputCursorTest, FinishTextPreview002, TestSize.Level1) +{ + /** + * @tc.steps: Create Text filed node with default text and placeholder + */ + CreateTextField(DEFAULT_TEXT); + GetFocus(); + + /** + * @tc.expected: Current caret position is end of text + */ + EXPECT_EQ(pattern_->GetCaretIndex(), static_cast(DEFAULT_TEXT.size())); + + /** + * @tc.steps:Set caretPosition and call SetPreviewTextOperation + * @tc.expected: check GetIsPreviewText return true + */ + auto controller = pattern_->GetTextSelectController(); + controller->UpdateCaretIndex(5); + pattern_->SetPreviewTextOperation(PREVIEW_ONE); + EXPECT_TRUE(pattern_->GetIsPreviewText()); + FlushLayoutTask(frameNode_); + + /** + * @tc.steps: call HandleBlurEvent + * @tc.expected: check GetIsPreviewText return false + */ + pattern_->HandleBlurEvent(); + EXPECT_TRUE(pattern_->inputOperations_.front() == InputOperation::SET_PREVIEW_FINISH); + FlushLayoutTask(frameNode_); +} + +/** + * @tc.name: FinishTextPreview003 + * @tc.desc: Test FinishTextPreview after set preview text. + * @tc.type: FUNC + */ +HWTEST_F(TextInputCursorTest, FinishTextPreview003, TestSize.Level1) +{ + /** + * @tc.steps: Create Text filed node with default text and placeholder + */ + CreateTextField(DEFAULT_TEXT); + GetFocus(); + + /** + * @tc.expected: Current caret position is end of text + */ + EXPECT_EQ(pattern_->GetCaretIndex(), static_cast(DEFAULT_TEXT.size())); + + /** + * @tc.steps:Set caretPosition and call SetPreviewTextOperation + * @tc.expected: check GetIsPreviewText return true + */ + auto controller = pattern_->GetTextSelectController(); + controller->UpdateCaretIndex(5); + pattern_->SetPreviewTextOperation(PREVIEW_ONE); + EXPECT_TRUE(pattern_->GetIsPreviewText()); + FlushLayoutTask(frameNode_); + + /** + * @tc.steps: call InsertValueOperation + * @tc.expected: check GetIsPreviewText return false + */ + pattern_->InsertValueOperation(HELLO_TEXT); + EXPECT_TRUE(pattern_->inputOperations_.front() == InputOperation::SET_PREVIEW_FINISH); + FlushLayoutTask(frameNode_); +} + +/** + * @tc.name: FinishTextPreviewOperation001 + * @tc.desc: Test FinishTextPreview after set preview text. + * @tc.type: FUNC + */ +HWTEST_F(TextInputCursorTest, FinishTextPreviewOperation001, TestSize.Level1) +{ + /** + * @tc.steps: Create Text filed node with default text and placeholder + */ + CreateTextField(DEFAULT_TEXT); + GetFocus(); + + /** + * @tc.expected: Current caret position is end of text + */ + EXPECT_EQ(pattern_->GetCaretIndex(), static_cast(DEFAULT_TEXT.size())); + + /** + * @tc.steps:Set caretPosition and call SetPreviewTextOperation + * @tc.expected: check GetIsPreviewText return true + */ + auto controller = pattern_->GetTextSelectController(); + controller->UpdateCaretIndex(5); + pattern_->SetPreviewTextOperation(PREVIEW_ONE); + EXPECT_TRUE(pattern_->GetIsPreviewText()); + FlushLayoutTask(frameNode_); + + /** + * @tc.steps: call FinishTextPreviewOperation + * @tc.expected: check GetIsPreviewText return false + */ + pattern_->FinishTextPreviewOperation(); + EXPECT_FALSE(pattern_->GetIsPreviewText()); + FlushLayoutTask(frameNode_); +} } // namespace OHOS::Ace::NG