Basic system tests for ListView sections
authorDamian Jansen <damian.jansen@nokia.com>
Fri, 23 Mar 2012 01:09:30 +0000 (11:09 +1000)
committerQt by Nokia <qt-info@nokia.com>
Mon, 26 Mar 2012 00:55:20 +0000 (02:55 +0200)
Change-Id: I3f33aa77a4bbe87a832066bd1f527521dfa543ff
Reviewed-by: Natalia Shubina <natalia.shubina@nokia.com>
Reviewed-by: Bea Lam <bea.lam@nokia.com>
tests/system/sys_listview.qtt
tests/testapplications/listview/sections.qml [new file with mode: 0644]

index efd116f..ca10e1a 100644 (file)
 
 testcase = {
 
+    using_section_delegates: function()
+    {
+        // Test Meta-data
+        testTitle = "Using and changing section delegate properties";
+        testBinary = "sections.qml";
+        testSource: "$QTDIR/qtdeclarative/tests/system/listview";
+        testGoal = "Verify that a Component can be set as a section header, using various properties for different collections.";
+        testPreconditions = "None";
+        testGroups = "BAT,QtQuick 2.0";
+
+        // Test Steps
+        prompt(twiki('---+++ ' + testTitle + '<br><br>
+        *Goal:* ' + testGoal + '<br>
+        *Pre-Requisites:* ' + testPreconditions + '<br>
+        *Tested Binary:* ' + testBinary + '<br>
+    | *Step* | *Verification* |
+    | Run '+testBinary+' | Application has started, showing a ListView |
+    | | The view shows a single character section header for each element |
+    | Press the Criteria button | The section headers now show the full name of each item |
+    | Press Property | The section headers now show the id value for the items |
+    | Press Criteria | The section headers now only show i - the first character of id |
+    | Press Property | The section headers show the first character of the item names |'));
+    },
+
+    updating_sections: function()
+    {
+        // Test Meta-data
+        testTitle = "Updating Collected Sections";
+        testBinary = "sections.qml";
+        testSource: "$QTDIR/qtdeclarative/tests/system/listview";
+        testGoal = "Verify that a section is updated when items are added.";
+        testPreconditions = "None";
+        testGroups = "BAT,QtQuick 2.0";
+
+        // Test Steps
+        prompt(twiki('---+++ ' + testTitle + '<br><br>
+        *Goal:* ' + testGoal + '<br>
+        *Pre-Requisites:* ' + testPreconditions + '<br>
+        *Tested Binary:* ' + testBinary + '<br>
+    | *Step* | *Verification* |
+    | Run '+testBinary+' | Application has started, showing a ListView |
+    | | The view shows a single character section header for each element |
+    | Press the + button | A duplicate of every name is added |
+    |  | Each duplicate is place in the same section as the original |'));
+    },
+
+    changing_section_delegates: function()
+    {
+        // Test Meta-data
+        testTitle = "Changing Section Delegates";
+        testBinary = "sections.qml";
+        testSource: "$QTDIR/qtdeclarative/tests/system/listview";
+        testGoal = "Verify that a section delegate can be changed.";
+        testPreconditions = "None";
+        testGroups = "BAT,QtQuick 2.0";
+
+        // Test Steps
+        prompt(twiki('---+++ ' + testTitle + '<br><br>
+        *Goal:* ' + testGoal + '<br>
+        *Pre-Requisites:* ' + testPreconditions + '<br>
+        *Tested Binary:* ' + testBinary + '<br>
+    | *Step* | *Verification* |
+    | Run '+testBinary+' | Application has started, showing a ListView |
+    | | The view shows a single character section header for each element |
+    | Press the Delegate button | The section headers now show as light blue rectangles |
+    | Press the Criteria button | The headers show as full names, still within light blue rectangles |'));
+    },
+
     altering_listview_primary_properties: function()
     {
         // Test Meta-data
diff --git a/tests/testapplications/listview/sections.qml b/tests/testapplications/listview/sections.qml
new file mode 100644 (file)
index 0000000..1251e8e
--- /dev/null
@@ -0,0 +1,197 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+**   * Redistributions of source code must retain the above copyright
+**     notice, this list of conditions and the following disclaimer.
+**   * Redistributions in binary form must reproduce the above copyright
+**     notice, this list of conditions and the following disclaimer in
+**     the documentation and/or other materials provided with the
+**     distribution.
+**   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+**     the names of its contributors may be used to endorse or promote
+**     products derived from this software without specific prior written
+**     permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+Rectangle {
+    height: 400
+    width: 300
+    property int sets: 1
+
+    ListModel {
+        id: listmodel
+        Component.onCompleted: addNames()
+    }
+
+    ListView {
+        id: listview
+        model: listmodel
+        height: 300
+        width: 200
+        clip: true
+        anchors.centerIn: parent
+
+        section.delegate: del1
+        section.criteria: ViewSection.FirstCharacter
+        section.property: "name"
+        delegate: Rectangle {
+            height: 50
+            width: 200
+            color: "gold"
+            border.color: "black"
+            Text {
+                anchors.centerIn: parent
+                text: model.name+" ["+model.id+"]"
+                color: "black"
+                font.bold: true
+            }
+        }
+    }
+
+    function addNames() {
+        var names = ["Alpha","Bravo","Charlie","Delta","Echo","Foxtrot",
+                     "Golf","Hotel","India","Juliet","Kilo","Lima","Mike",
+                     "November","Oscar","Papa","Quebec","Romeo","Sierra","Tango",
+                     "Uniform","Victor","Whiskey","XRay","Yankee","Zulu"];
+        for (var i=0;i<names.length;++i)
+            listmodel.insert(sets*i, {"name":names[i], "id": "id"+i});
+        sets++;
+    }
+
+    Component {
+        id: del1
+        Rectangle {
+            height: 50
+            width: 200
+            color: "white"
+            border.color: "black"
+            border.width: 3
+            Text {
+                anchors.centerIn: parent
+                text: section
+            }
+        }
+    }
+
+    Component {
+        id: del2
+        Rectangle {
+            height: 50
+            width: 200
+            color: "lightsteelblue"
+            border.color: "orange"
+            Text {
+                anchors.centerIn: parent
+                text: section
+            }
+        }
+    }
+
+    Rectangle {
+        anchors.fill: listview
+        color: "transparent"
+        border.color: "green"
+        border.width: 3
+    }
+
+    Row {
+        spacing: 3
+        Rectangle {
+            height: 40
+            width: 70
+            color: "blue"
+            Text {
+                color: "white"
+                anchors.centerIn: parent
+                text: "Criteria"
+            }
+            radius: 5
+            MouseArea {
+                anchors.fill: parent
+                onClicked: {
+                    listview.section.criteria = listview.section.criteria == ViewSection.FirstCharacter ?
+                           ViewSection.FullString : ViewSection.FirstCharacter
+                }
+            }
+        }
+        Rectangle {
+            height: 40
+            width: 70
+            color: "blue"
+            Text {
+                color: "white"
+                anchors.centerIn: parent
+                text: "Property"
+            }
+            radius: 5
+            MouseArea {
+                anchors.fill: parent
+                onClicked: {
+                    listview.section.property = listview.section.property == "name" ? "id" : "name";
+                    console.log(listview.section.property)
+                }
+            }
+        }
+        Rectangle {
+            height: 40
+            width: 75
+            color: "blue"
+            Text {
+                color: "white"
+                anchors.centerIn: parent
+                text: "Delegate"
+            }
+            radius: 5
+            MouseArea {
+                anchors.fill: parent
+                onClicked: {
+                    console.log("Change delegate")
+                    listview.section.delegate = listview.section.delegate == del1 ? del2 : del1
+                }
+            }
+        }
+        Rectangle {
+            height: 40
+            width: 40
+            color: "blue"
+            Text {
+                color: "white"
+                anchors.centerIn: parent
+                text: "+"
+                font.bold: true
+            }
+            radius: 5
+            MouseArea {
+                anchors.fill: parent
+                onClicked: { addNames(); }
+            }
+        }
+    }
+}