flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mih...@apache.org
Subject [3/3] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34837 Added unit test which reproduces the bug from the DataGrid side. NOTE: this unit test works in IntelliJ - i.e. fails as expected -, but fails in the SDK with the message "UIImpersonator doesn
Date Fri, 24 Jul 2015 18:08:55 GMT
FLEX-34837
Added unit test which reproduces the bug from the DataGrid side.
NOTE: this unit test works in IntelliJ - i.e. fails as expected -, but fails in the SDK with
the message "UIImpersonator doesn't work correctly!" because FlexUnit is not compiled for
Flex projects (so UIImpersonator doesn't act as it does locally). When we release a new version
of FlexUnit we can correct this.


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

Branch: refs/heads/develop
Commit: e32044cdb698f5da962c1f527e97f8cbe6f9f77a
Parents: e8e6e8c
Author: Mihai Chira <mihaic@apache.org>
Authored: Fri Jul 24 20:05:18 2015 +0200
Committer: Mihai Chira <mihaic@apache.org>
Committed: Fri Jul 24 20:05:18 2015 +0200

----------------------------------------------------------------------
 .../components/DataGrid_FLEX_34837_Tests.as     | 201 +++++++++++++++++++
 1 file changed, 201 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/e32044cd/frameworks/projects/spark/tests/spark/components/DataGrid_FLEX_34837_Tests.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/spark/tests/spark/components/DataGrid_FLEX_34837_Tests.as
b/frameworks/projects/spark/tests/spark/components/DataGrid_FLEX_34837_Tests.as
new file mode 100644
index 0000000..5696429
--- /dev/null
+++ b/frameworks/projects/spark/tests/spark/components/DataGrid_FLEX_34837_Tests.as
@@ -0,0 +1,201 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+package spark.components {
+    import mx.collections.ArrayCollection;
+    import mx.collections.ArrayList;
+    import mx.collections.IList;
+    import mx.collections.ListCollectionView;
+
+    import org.flexunit.asserts.assertEquals;
+    import org.flexunit.asserts.assertNotNull;
+    import org.fluint.uiImpersonation.UIImpersonator;
+
+    import spark.components.gridClasses.GridColumn;
+    import spark.formatters.DateTimeFormatter;
+
+    public class DataGrid_FLEX_34837_Tests {
+        private var _sut:DataGrid;
+
+        [Before]
+        public function setUp():void
+        {
+            _sut = new DataGrid();
+        }
+
+        [After]
+        public function tearDown():void
+        {
+            _sut = null;
+        }
+
+        [Test]
+        public function test_removing_selected_item_on_complex_field_sorted_grid_after_renaming_it():void
+        {
+            //given
+            var streetColumn:GridColumn = new GridColumn("address.street");
+            _sut.columns = new ArrayCollection([streetColumn]);
+
+            const tenObjects:IList = generateVOs(10);
+            const firstObject:FLEX_34837_VO = tenObjects.getItemAt(0) as FLEX_34837_VO;
+            const dataProvider:ListCollectionView = new ListCollectionView(tenObjects);
+
+            //when
+            UIImpersonator.addChild(_sut);
+            assertNotNull("UIImpersonator doesn't work correctly!", _sut.grid);
+            _sut.dataProvider = dataProvider;
+            _sut.sortByColumns(new <int>[0]); //sort by address.street
+            firstObject.address.street = "zzz"; //should move it at the end of the list
+
+            //then
+            assertEquals("The object should have moved to the end of the list!", dataProvider.length
- 1, dataProvider.getItemIndex(firstObject));
+            dataProvider.removeItemAt(dataProvider.getItemIndex(firstObject)); //make sure
there's no RTE
+            assertEquals("The item wasn't removed!", 9, dataProvider.length);
+        }
+
+        [Test]
+        public function test_removing_selected_item_on_complex_field_sorted_grid_with_formatter_after_renaming_it():void
+        {
+            //given
+            var dateColumn:GridColumn = new GridColumn("address.dateMovedIn");
+            var dateTimeFormatter:DateTimeFormatter = new DateTimeFormatter();
+            dateTimeFormatter.dateTimePattern = "MMMM"; //Full month name
+            dateColumn.formatter = dateTimeFormatter;
+
+            _sut.columns = new ArrayCollection([dateColumn]);
+
+            const tenObjects:IList = generateVOs(10);
+            const dataProvider:ListCollectionView = new ListCollectionView(tenObjects);
+
+            //when
+            UIImpersonator.addChild(_sut);
+            assertNotNull("UIImpersonator doesn't work correctly!", _sut.grid);
+            _sut.dataProvider = dataProvider;
+            _sut.sortByColumns(new <int>[0]); //sort by address.dateMovedIn, in effect
by month name
+
+            //then
+            const aprilObject:FLEX_34837_VO = tenObjects.getItemAt(3) as FLEX_34837_VO;
+            assertEquals(0, dataProvider.getItemIndex(aprilObject));
+
+            //when
+            const septemberObject:FLEX_34837_VO = tenObjects.getItemAt(8) as FLEX_34837_VO;
+            septemberObject.address.dateMovedIn = new Date(2000, 3, 2); //"April"; should
move it at the start of the list
+
+            const firstObject:FLEX_34837_VO = tenObjects.getItemAt(0) as FLEX_34837_VO;
+            firstObject.address.dateMovedIn = new Date(2000, 8, 2); //"September"; should
move it at the end of the list
+
+            //then
+            assertEquals("The object should have moved to the end of the list!", dataProvider.length
- 1, dataProvider.getItemIndex(firstObject));
+            dataProvider.removeItemAt(dataProvider.getItemIndex(firstObject)); //make sure
there's no RTE
+            assertEquals("The item wasn't removed!", 9, dataProvider.length);
+        }
+
+        [Test]
+        public function test_removing_selected_item_on_multiple_field_sorted_grid_with_formatter_changed_after_first_sort_and_after_renaming():void
+        {
+            //given
+            var dateColumn:GridColumn = new GridColumn("address.dateMovedIn");
+            _sut.columns = new ArrayCollection([dateColumn]);
+
+            const tenObjects:IList = generateVOs(10);
+            const dataProvider:ListCollectionView = new ListCollectionView(tenObjects);
+
+            //when
+            UIImpersonator.addChild(_sut);
+            assertNotNull("UIImpersonator doesn't work correctly!", _sut.grid);
+            _sut.dataProvider = dataProvider;
+
+            var dateTimeFormatter:DateTimeFormatter = new DateTimeFormatter();
+            dateTimeFormatter.dateTimePattern = "MMMM"; //Full month name
+            dateColumn.formatter = dateTimeFormatter; //this should re-sort the items in
the grid according to the month
+
+            _sut.sortByColumns(new <int>[0]); //sort by address.dateMovedIn
+
+            //then
+            const aprilObject:FLEX_34837_VO = tenObjects.getItemAt(3) as FLEX_34837_VO;
+            assertEquals(0, dataProvider.getItemIndex(aprilObject));
+
+            //when
+            const septemberObject:FLEX_34837_VO = tenObjects.getItemAt(8) as FLEX_34837_VO;
+            septemberObject.address.dateMovedIn = new Date(2000, 3, 2); //"April"; should
move it at the start of the list
+
+            const firstObject:FLEX_34837_VO = tenObjects.getItemAt(0) as FLEX_34837_VO;
+            firstObject.address.dateMovedIn = new Date(2000, 8, 2); //"September"; should
move it at the end of the list
+
+            //then
+            assertEquals("The object should have moved to the end of the list!", dataProvider.length
- 1, dataProvider.getItemIndex(firstObject));
+            dataProvider.removeItemAt(dataProvider.getItemIndex(firstObject)); //make sure
there's no RTE
+            assertEquals("The item wasn't removed!", 9, dataProvider.length);
+        }
+
+        private static function generateVOs(no:int, reverse:Boolean = false):IList
+        {
+            return generateObjects(no, reverse, generateOneObject);
+        }
+
+        private static function generateObjects(no:int, reverse:Boolean, generator:Function):IList
+        {
+            var result:Array = [];
+            for(var i:int = 0; i < no; i++)
+            {
+                result.push(generator(i));
+            }
+
+            if(reverse)
+                result.reverse();
+
+            return new ArrayList(result);
+        }
+
+        private static function generateOneObject(i:Number):FLEX_34837_VO
+        {
+            return new FLEX_34837_VO(i, "Object", "Street");
+        }
+    }
+}
+
+[Bindable]
+class FLEX_34837_VO
+{
+    public var name:String;
+    public var address:FLEX_34837_AddressVO;
+    public var index:Number;
+
+    public function FLEX_34837_VO(index:Number, namePrefix:String, streetPrefix:String)
+    {
+        this.index = index;
+        this.name = namePrefix + index;
+        this.address = new FLEX_34837_AddressVO(streetPrefix + index, Math.floor(index),
new Date(2000 + Math.floor(index), Math.floor(index), 1, 0, 0, 0, 1));
+    }
+}
+
+[Bindable]
+class FLEX_34837_AddressVO
+{
+    public var street:String;
+    public var houseNumber:int;
+    public var dateMovedIn:Date;
+
+    public function FLEX_34837_AddressVO(street:String, houseNumber:int, dateMovedIn:Date)
+    {
+        this.street = street;
+        this.houseNumber = houseNumber;
+        this.dateMovedIn = dateMovedIn;
+    }
+}
\ No newline at end of file


Mime
View raw message