Repository: flex-tlf Updated Branches: refs/heads/develop 422b5536a -> 0f33c43a0
FLEX-34807 Improved unit test by checking that the adjacent styles / text formats are not changed by the paste operation. Project: http://git-wip-us.apache.org/repos/asf/flex-tlf/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-tlf/commit/7b3f374f Tree: http://git-wip-us.apache.org/repos/asf/flex-tlf/tree/7b3f374f Diff: http://git-wip-us.apache.org/repos/asf/flex-tlf/diff/7b3f374f Branch: refs/heads/develop Commit: 7b3f374f999cb91f1619546dbbe29764f238000c Parents: 422b553 Author: Mihai Chira <[email protected]> Authored: Tue Sep 22 17:06:51 2015 +0200 Committer: Mihai Chira <[email protected]> Committed: Tue Sep 22 17:06:51 2015 +0200 ---------------------------------------------------------------------- .../src/UnitTest/Tests/FLEX_34807_Test.as | 82 ++++++++++++++++---- 1 file changed, 68 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-tlf/blob/7b3f374f/automation_tests/src/UnitTest/Tests/FLEX_34807_Test.as ---------------------------------------------------------------------- diff --git a/automation_tests/src/UnitTest/Tests/FLEX_34807_Test.as b/automation_tests/src/UnitTest/Tests/FLEX_34807_Test.as index 99d0892..7cd97ea 100644 --- a/automation_tests/src/UnitTest/Tests/FLEX_34807_Test.as +++ b/automation_tests/src/UnitTest/Tests/FLEX_34807_Test.as @@ -34,8 +34,13 @@ package UnitTest.Tests import flashx.textLayout.conversion.ConversionType; import flashx.textLayout.conversion.TextConverter; import flashx.textLayout.edit.TextScrap; + import flashx.textLayout.elements.FlowElement; + import flashx.textLayout.formats.ITextLayoutFormat; + import flashx.textLayout.formats.TextLayoutFormat; import org.flexunit.asserts.assertEquals; + import org.flexunit.asserts.assertNotNull; + import org.flexunit.asserts.assertTrue; public class FLEX_34807_Test extends VellumTestCase { @@ -44,6 +49,10 @@ package UnitTest.Tests private const PASTE:TextScrap = new TextScrap(TextConverter.importToFlow(PASTED_HTML, TextConverter.TEXT_FIELD_HTML_FORMAT)); private var sourceAsPlainText:String; + private var leftBefore:ITextLayoutFormat; + private var rightBefore:ITextLayoutFormat; + private var leftAfter:ITextLayoutFormat; + private var rightAfter:ITextLayoutFormat; public function FLEX_34807_Test() { @@ -79,48 +88,93 @@ package UnitTest.Tests public function paste_in_beginning():void { //given - SelManager.selectFirstPosition(); + recordTextFormatsBeforeOperation(0); //when + SelManager.selectFirstPosition(); SelManager.pasteTextScrap(PASTE); //then - const result:String = TextConverter.export(testApp.getTextFlow(), TextConverter.PLAIN_TEXT_FORMAT, ConversionType.STRING_TYPE) as String; - assertAllTextHasBeenPasted(result, 0); + assertAdjacentTextFormatsNotAltered(0); + assertTextPastedCorrectlyAndExistingTextNotChanged(0); } [Test] - public function paste_in_first_paragraph():void + public function paste_in_first_paragraph_in_middle_of_bold_section():void { //given - const PASTE_POSITION:int = 5; //after "That" - SelManager.selectRange(PASTE_POSITION, PASTE_POSITION); + const PASTE_POSITION:int = 16; + recordTextFormatsBeforeOperation(PASTE_POSITION); //when + SelManager.selectRange(PASTE_POSITION, PASTE_POSITION); SelManager.pasteTextScrap(PASTE); //then - const result:String = TextConverter.export(testApp.getTextFlow(), TextConverter.PLAIN_TEXT_FORMAT, ConversionType.STRING_TYPE) as String; - assertAllTextHasBeenPasted(result, PASTE_POSITION); + assertAdjacentTextFormatsNotAltered(PASTE_POSITION); + assertTextPastedCorrectlyAndExistingTextNotChanged(PASTE_POSITION); } [Test] - public function paste_in_first_paragraph_in_middle_of_bold_section():void + public function paste_in_first_paragraph():void { //given - const PASTE_POSITION:int = 16; - SelManager.selectRange(PASTE_POSITION, PASTE_POSITION); + const PASTE_POSITION:int = 5; //after "There" + recordTextFormatsBeforeOperation(PASTE_POSITION); //when + SelManager.selectRange(PASTE_POSITION, PASTE_POSITION); SelManager.pasteTextScrap(PASTE); //then - const result:String = TextConverter.export(testApp.getTextFlow(), TextConverter.PLAIN_TEXT_FORMAT, ConversionType.STRING_TYPE) as String; - assertAllTextHasBeenPasted(result, PASTE_POSITION); + assertAdjacentTextFormatsNotAltered(PASTE_POSITION); + assertTextPastedCorrectlyAndExistingTextNotChanged(PASTE_POSITION); + } + + private function assertAdjacentTextFormatsNotAltered(pastePosition:int):void + { + recordTextFormatsAfterOperation(pastePosition); + assertAdjacentTextFormatsArePreserved(pastePosition); + } + + private function assertAdjacentTextFormatsArePreserved(pastePosition:int):void + { + if(pastePosition) + { + assertNotNull(leftBefore); + assertNotNull(leftAfter); + assertTrue(TextLayoutFormat.isEqual(leftBefore, leftAfter)); + } + + if(pastePosition < SelManager.textFlow.textLength - 1) + { + assertNotNull(rightBefore); + assertNotNull(rightAfter); + assertTrue(TextLayoutFormat.isEqual(rightBefore, rightAfter)); + } + } + + private function recordTextFormatsBeforeOperation(pastePosition:int):void + { + leftBefore = pastePosition ? getFormatOfCharAt(pastePosition - 1) : null; + rightBefore = pastePosition < SelManager.textFlow.textLength - 1 ? getFormatOfCharAt(pastePosition + 1) : null; + } + + private function recordTextFormatsAfterOperation(pastePosition:int):void + { + leftAfter = pastePosition ? getFormatOfCharAt(pastePosition - 1) : null; + rightAfter = pastePosition < SelManager.textFlow.textLength - PASTED_TEXT.length - 1 ? getFormatOfCharAt(pastePosition + 1 + PASTED_TEXT.length) : null; + } + + private function getFormatOfCharAt(pastePosition:int):ITextLayoutFormat + { + const charLeftOfPasteBeforeOperation:FlowElement = SelManager.textFlow.findLeaf(pastePosition); + return charLeftOfPasteBeforeOperation ? charLeftOfPasteBeforeOperation.format : null; } - private function assertAllTextHasBeenPasted(currentSourceAsPlainText:String, pastePosition:int):void + private function assertTextPastedCorrectlyAndExistingTextNotChanged(pastePosition:int):void { + const currentSourceAsPlainText:String = TextConverter.export(testApp.getTextFlow(), TextConverter.PLAIN_TEXT_FORMAT, ConversionType.STRING_TYPE) as String; assertEquals("Not all the pasted content appears in the new TextFlow!", sourceAsPlainText.substr(0, pastePosition) + PASTED_TEXT + sourceAsPlainText.substr(pastePosition), currentSourceAsPlainText); } }
