flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mih...@apache.org
Subject git commit: [flex-tlf] [refs/heads/develop] - FLEX-34807 Strengthened test by making sure that the style of the pasted text is not altered. Currently these checks pass (leaving the ones which were are failing before).
Date Tue, 22 Sep 2015 16:34:02 GMT
Repository: flex-tlf
Updated Branches:
  refs/heads/develop 0f33c43a0 -> 9f606268b


FLEX-34807
Strengthened test by making sure that the style of the pasted text is not altered. Currently
these checks pass (leaving the ones which were are failing before).


Project: http://git-wip-us.apache.org/repos/asf/flex-tlf/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-tlf/commit/9f606268
Tree: http://git-wip-us.apache.org/repos/asf/flex-tlf/tree/9f606268
Diff: http://git-wip-us.apache.org/repos/asf/flex-tlf/diff/9f606268

Branch: refs/heads/develop
Commit: 9f606268b6f85ca5054c88549ba5b6ea0ec50ada
Parents: 0f33c43
Author: Mihai Chira <mihaic@apache.org>
Authored: Tue Sep 22 18:33:05 2015 +0200
Committer: Mihai Chira <mihaic@apache.org>
Committed: Tue Sep 22 18:33:05 2015 +0200

----------------------------------------------------------------------
 .../src/UnitTest/Tests/FLEX_34807_Test.as       | 102 +++++++++++++++----
 1 file changed, 85 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-tlf/blob/9f606268/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 7cd97ea..872250a 100644
--- a/automation_tests/src/UnitTest/Tests/FLEX_34807_Test.as
+++ b/automation_tests/src/UnitTest/Tests/FLEX_34807_Test.as
@@ -35,6 +35,7 @@ package UnitTest.Tests
     import flashx.textLayout.conversion.TextConverter;
     import flashx.textLayout.edit.TextScrap;
     import flashx.textLayout.elements.FlowElement;
+    import flashx.textLayout.elements.TextFlow;
     import flashx.textLayout.formats.ITextLayoutFormat;
     import flashx.textLayout.formats.TextLayoutFormat;
 
@@ -44,15 +45,18 @@ package UnitTest.Tests
 
     public class FLEX_34807_Test extends VellumTestCase
     {
-        private const PASTED_TEXT:String = '...Hello world!...';
-        private const PASTED_HTML:String = '...<i>Hello<b> world</b>!</i>...';
-        private const PASTE:TextScrap = new TextScrap(TextConverter.importToFlow(PASTED_HTML,
TextConverter.TEXT_FIELD_HTML_FORMAT));
+        private static const PASTED_TEXT:String = '|Hey world!|';
+        private static const PASTED_HTML:String = '<span style="fontSize:12">|<i>Hey<b>
world</b>!</i>|</span>';
+        private static const PASTE:TextScrap = new TextScrap(TextConverter.importToFlow(PASTED_HTML,
TextConverter.TEXT_FIELD_HTML_FORMAT));
+
+        private static var PASTE_CHAR_STYLES:Array = [];
 
         private var sourceAsPlainText:String;
         private var leftBefore:ITextLayoutFormat;
         private var rightBefore:ITextLayoutFormat;
         private var leftAfter:ITextLayoutFormat;
         private var rightAfter:ITextLayoutFormat;
+        private var initialTextLength:Number = NaN;
 
         public function FLEX_34807_Test()
         {
@@ -68,14 +72,27 @@ package UnitTest.Tests
         public static function setUpClass():void
         {
             FileRepository.readFile(TestConfig.getInstance().baseURL, "../../test/testFiles/markup/tlf/HtmlTest.xml");
+            analyseStylesOfPastedText();
+        }
+
+        private static function analyseStylesOfPastedText():void
+        {
+            for(var i:int = 0; i < PASTED_TEXT.length; i++)
+            {
+                PASTE_CHAR_STYLES.push(getFormatOfCharFromFlow(i, PASTE.textFlow));
+            }
         }
 
         [Before]
         override public function setUpTest():void
         {
             super.setUpTest();
+
             if(!sourceAsPlainText)
                 sourceAsPlainText = TextConverter.export(testApp.getTextFlow(), TextConverter.PLAIN_TEXT_FORMAT,
ConversionType.STRING_TYPE) as String;
+
+            if(isNaN(initialTextLength))
+                initialTextLength = SelManager.textFlow.textLength;
         }
 
         [After]
@@ -96,10 +113,28 @@ package UnitTest.Tests
 
             //then
             assertAdjacentTextFormatsNotAltered(0);
+            assertFormattingOfPastedTextNotAltered(0);
             assertTextPastedCorrectlyAndExistingTextNotChanged(0);
         }
 
         [Test]
+        public function paste_in_first_paragraph():void
+        {
+            //given
+            const PASTE_POSITION:int = 5; //after "There"
+            recordTextFormatsBeforeOperation(PASTE_POSITION);
+
+            //when
+            SelManager.selectRange(PASTE_POSITION, PASTE_POSITION);
+            SelManager.pasteTextScrap(PASTE);
+
+            //then
+            assertAdjacentTextFormatsNotAltered(PASTE_POSITION);
+            assertFormattingOfPastedTextNotAltered(PASTE_POSITION);
+            assertTextPastedCorrectlyAndExistingTextNotChanged(PASTE_POSITION);
+        }
+
+        [Test]
         public function paste_in_first_paragraph_in_middle_of_bold_section():void
         {
             //given
@@ -112,14 +147,32 @@ package UnitTest.Tests
 
             //then
             assertAdjacentTextFormatsNotAltered(PASTE_POSITION);
+            assertFormattingOfPastedTextNotAltered(PASTE_POSITION);
             assertTextPastedCorrectlyAndExistingTextNotChanged(PASTE_POSITION);
         }
 
         [Test]
-        public function paste_in_first_paragraph():void
+        public function paste_in_second_paragraph():void
         {
             //given
-            const PASTE_POSITION:int = 5; //after "There"
+            const PASTE_POSITION:int = 170;
+            recordTextFormatsBeforeOperation(PASTE_POSITION);
+
+            //when
+            SelManager.selectRange(PASTE_POSITION, PASTE_POSITION);
+            SelManager.pasteTextScrap(PASTE);
+
+            //then
+            assertAdjacentTextFormatsNotAltered(PASTE_POSITION);
+            assertFormattingOfPastedTextNotAltered(PASTE_POSITION);
+            assertTextPastedCorrectlyAndExistingTextNotChanged(PASTE_POSITION);
+        }
+
+        [Test]
+        public function paste_at_end():void
+        {
+            //given
+            const PASTE_POSITION:int = SelManager.textFlow.textLength - 1;
             recordTextFormatsBeforeOperation(PASTE_POSITION);
 
             //when
@@ -128,9 +181,19 @@ package UnitTest.Tests
 
             //then
             assertAdjacentTextFormatsNotAltered(PASTE_POSITION);
+            assertFormattingOfPastedTextNotAltered(PASTE_POSITION);
             assertTextPastedCorrectlyAndExistingTextNotChanged(PASTE_POSITION);
         }
 
+        private function assertFormattingOfPastedTextNotAltered(pastePosition:int):void
+        {
+            for(var i:int = 0; i < PASTED_TEXT.length; i++)
+            {
+                var formatOfPastedChar:ITextLayoutFormat = getFormatOfCharAt(pastePosition
+ i);
+                assertTrue("The style of the pasted text has been altered!", TextLayoutFormat.isEqual(PASTE_CHAR_STYLES[i],
formatOfPastedChar));
+            }
+        }
+
         private function assertAdjacentTextFormatsNotAltered(pastePosition:int):void
         {
             recordTextFormatsAfterOperation(pastePosition);
@@ -141,35 +204,40 @@ package UnitTest.Tests
         {
             if(pastePosition)
             {
-                assertNotNull(leftBefore);
-                assertNotNull(leftAfter);
-                assertTrue(TextLayoutFormat.isEqual(leftBefore, leftAfter));
+                assertNotNull("Couldn't manage to find the format of the character to the
left of the pasted text, before the paste operation!", leftBefore);
+                assertNotNull("Couldn't manage to find the format of the character to the
left of the pasted text, after the paste operation!", leftAfter);
+                assertTrue("The style of the original text has been altered! (left)", TextLayoutFormat.isEqual(leftBefore,
leftAfter));
             }
 
-            if(pastePosition < SelManager.textFlow.textLength - 1)
+            if(pastePosition < initialTextLength - 1)
             {
-                assertNotNull(rightBefore);
-                assertNotNull(rightAfter);
-                assertTrue(TextLayoutFormat.isEqual(rightBefore, rightAfter));
+                assertNotNull("Couldn't manage to find the format of the character to the
right of the pasted text, before the paste operation!", rightBefore);
+                assertNotNull("Couldn't manage to find the format of the character to the
right of the pasted text, after the paste operation!", rightAfter);
+                assertTrue("The style of the original text has been altered! (right)", 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;
+            rightBefore = pastePosition < initialTextLength - 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;
+            rightAfter = pastePosition < initialTextLength - 1 ? getFormatOfCharAt(pastePosition
+ 1 + PASTED_TEXT.length) : null;
+        }
+
+        private function getFormatOfCharAt(position:int, flow:TextFlow = null):ITextLayoutFormat
+        {
+            return getFormatOfCharFromFlow(position, flow || SelManager.textFlow);
         }
 
-        private function getFormatOfCharAt(pastePosition:int):ITextLayoutFormat
+        private static function getFormatOfCharFromFlow(position:int, flow:TextFlow):ITextLayoutFormat
         {
-            const charLeftOfPasteBeforeOperation:FlowElement = SelManager.textFlow.findLeaf(pastePosition);
-            return charLeftOfPasteBeforeOperation ? charLeftOfPasteBeforeOperation.format
: null;
+            const elementAtPosition:FlowElement = flow.findLeaf(position);
+            return elementAtPosition ? elementAtPosition.format : null;
         }
 
         private function assertTextPastedCorrectlyAndExistingTextNotChanged(pastePosition:int):void


Mime
View raw message