aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTim Jenssen <tim.jenssen@qt.io>2020-08-13 08:34:24 +0200
committerTim Jenssen <tim.jenssen@qt.io>2020-08-13 06:39:40 +0000
commit4fe5b923cddc9110094a883b5b7dd3051d8c8d90 (patch)
tree34e3984ab983882423bc563542a041b99b35f065 /tests
parent24ca17f714ec133acc2bf0fd93c051ef730d69dc (diff)
parentdc870f538dd3e11464a3ece179edf024161e14ba (diff)
Merge remote-tracking branch 'origin/qds-1.59' into 4.13
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qmldesigner/coretests/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmldesigner/coretests/coretests.pro6
-rw-r--r--tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp24
-rw-r--r--tests/auto/qml/qmldesigner/testconnectionmanager.cpp72
-rw-r--r--tests/auto/qml/qmldesigner/testconnectionmanager.h56
-rw-r--r--tests/unit/unittest/listmodeleditor-test.cpp461
6 files changed, 592 insertions, 28 deletions
diff --git a/tests/auto/qml/qmldesigner/coretests/CMakeLists.txt b/tests/auto/qml/qmldesigner/coretests/CMakeLists.txt
index 83f9da98a0..fb22fbf06b 100644
--- a/tests/auto/qml/qmldesigner/coretests/CMakeLists.txt
+++ b/tests/auto/qml/qmldesigner/coretests/CMakeLists.txt
@@ -17,4 +17,5 @@ add_qtc_test(tst_qml_testcore
../testview.cpp ../testview.h
testrewriterview.cpp testrewriterview.h
tst_testcore.cpp tst_testcore.h
+ ../testconnectionmanager.cpp ../testconnectionmanager.h
)
diff --git a/tests/auto/qml/qmldesigner/coretests/coretests.pro b/tests/auto/qml/qmldesigner/coretests/coretests.pro
index 7afb0fda2e..c179025da5 100644
--- a/tests/auto/qml/qmldesigner/coretests/coretests.pro
+++ b/tests/auto/qml/qmldesigner/coretests/coretests.pro
@@ -61,11 +61,13 @@ TEMPLATE = app
SOURCES += \
../testview.cpp \
testrewriterview.cpp \
- tst_testcore.cpp
+ tst_testcore.cpp \
+ ../testconnectionmanager.cpp
HEADERS += \
../testview.h \
testrewriterview.h \
- tst_testcore.h
+ tst_testcore.h \
+ ../testconnectionmanager.h
RESOURCES += ../data/testfiles.qrc
diff --git a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp
index fc5d9dcfa9..965d9b7aee 100644
--- a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp
+++ b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp
@@ -46,11 +46,12 @@
#include <stylesheetmerger.h>
#include <QDebug>
+#include "../testconnectionmanager.h"
#include "../testview.h"
-#include <variantproperty.h>
#include <abstractproperty.h>
#include <bindingproperty.h>
#include <nodeproperty.h>
+#include <variantproperty.h>
#include <nodelistproperty.h>
#include <nodeabstractproperty.h>
@@ -1999,8 +2000,9 @@ void tst_TestCore::testModelRemoveNode()
QVERIFY(view.data());
model->attachView(view.data());
- NodeInstanceView *nodeInstanceView = new NodeInstanceView(model.data(), NodeInstanceServerInterface::TestModus);
- model->attachView(nodeInstanceView);
+ TestConnectionManager connectionManager;
+ NodeInstanceView nodeInstanceView{connectionManager};
+ model->attachView(&nodeInstanceView);
QCOMPARE(view->rootModelNode().directSubModelNodes().count(), 0);
@@ -2051,7 +2053,7 @@ void tst_TestCore::testModelRemoveNode()
childNode = view->createModelNode("QtQuick.Item", 1, 1);
childNode.destroy();
- model->detachView(nodeInstanceView);
+ model->detachView(&nodeInstanceView);
}
void tst_TestCore::reparentingNode()
@@ -6140,17 +6142,21 @@ void tst_TestCore::testInstancesAttachToExistingModel()
// Attach NodeInstanceView
- QScopedPointer<NodeInstanceView> instanceView(new NodeInstanceView(0, NodeInstanceServerInterface::TestModus));
- QVERIFY(instanceView.data());
- model->attachView(instanceView.data());
+ TestConnectionManager connectionManager;
+
+ NodeInstanceView instanceView{connectionManager};
- NodeInstance rootInstance = instanceView->instanceForModelNode(rootNode);
- NodeInstance rectangleInstance = instanceView->instanceForModelNode(rectangleNode);
+ model->attachView(&instanceView);
+
+ NodeInstance rootInstance = instanceView.instanceForModelNode(rootNode);
+ NodeInstance rectangleInstance = instanceView.instanceForModelNode(rectangleNode);
QVERIFY(rootInstance.isValid());
QVERIFY(rectangleInstance.isValid());
QCOMPARE(QVariant(100), rectangleInstance.property("width"));
QVERIFY(rootInstance.instanceId() >= 0);
QVERIFY(rectangleInstance.instanceId() >= 0);
+
+ model->detachView(&instanceView);
}
void tst_TestCore::testQmlModelAddMultipleStates()
diff --git a/tests/auto/qml/qmldesigner/testconnectionmanager.cpp b/tests/auto/qml/qmldesigner/testconnectionmanager.cpp
new file mode 100644
index 0000000000..f637fb1f1a
--- /dev/null
+++ b/tests/auto/qml/qmldesigner/testconnectionmanager.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "testconnectionmanager.h"
+#include "synchronizecommand.h"
+
+#include <QLocalSocket>
+
+namespace QmlDesigner {
+
+TestConnectionManager::TestConnectionManager()
+{
+ m_connections.emplace_back("Editor", "editormode");
+}
+
+void TestConnectionManager::writeCommand(const QVariant &command)
+{
+ TestConnectionManager::writeCommand(command);
+
+ m_writeCommandCounter++;
+
+ static int synchronizeId = 0;
+ synchronizeId++;
+ SynchronizeCommand synchronizeCommand(synchronizeId);
+
+ QLocalSocket *socket = m_connections.front().socket.get();
+
+ writeCommandToIODevice(QVariant::fromValue(synchronizeCommand), socket, m_writeCommandCounter);
+ m_writeCommandCounter++;
+
+ while (socket->waitForReadyRead(100)) {
+ readDataStream(m_connections.front());
+ if (m_synchronizeId == synchronizeId)
+ return;
+ }
+}
+
+void TestConnectionManager::dispatchCommand(const QVariant &command, Connection &connection)
+{
+ static const int synchronizeCommandType = QMetaType::type("SynchronizeCommand");
+
+ if (command.userType() == synchronizeCommandType) {
+ SynchronizeCommand synchronizeCommand = command.value<SynchronizeCommand>();
+ m_synchronizeId = synchronizeCommand.synchronizeId();
+ } else {
+ ConnectionManager::dispatchCommand(command, connection);
+ }
+}
+
+} // namespace QmlDesigner
diff --git a/tests/auto/qml/qmldesigner/testconnectionmanager.h b/tests/auto/qml/qmldesigner/testconnectionmanager.h
new file mode 100644
index 0000000000..6ea44c1c1d
--- /dev/null
+++ b/tests/auto/qml/qmldesigner/testconnectionmanager.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include <connectionmanager.h>
+
+#include <QFile>
+#include <QPointer>
+#include <QProcess>
+#include <QTimer>
+
+QT_BEGIN_NAMESPACE
+class QLocalServer;
+class QLocalSocket;
+QT_END_NAMESPACE
+
+namespace QmlDesigner {
+
+class TestConnectionManager final : public ConnectionManager
+{
+public:
+ TestConnectionManager();
+
+ void writeCommand(const QVariant &command) override;
+
+protected:
+ void dispatchCommand(const QVariant &command, Connection &connection) override;
+
+private:
+ int m_synchronizeId = -1;
+};
+
+} // namespace QmlDesigner
diff --git a/tests/unit/unittest/listmodeleditor-test.cpp b/tests/unit/unittest/listmodeleditor-test.cpp
index ca0913f865..bdd5e9c070 100644
--- a/tests/unit/unittest/listmodeleditor-test.cpp
+++ b/tests/unit/unittest/listmodeleditor-test.cpp
@@ -31,14 +31,17 @@
#include <qmldesigner/components/listmodeleditor/listmodeleditormodel.h>
#include <qmldesigner/designercore/include/abstractview.h>
+#include <qmldesigner/designercore/include/bindingproperty.h>
#include <qmldesigner/designercore/include/model.h>
#include <qmldesigner/designercore/include/nodelistproperty.h>
+#include <qmldesigner/designercore/include/nodeproperty.h>
#include <qmldesigner/designercore/include/variantproperty.h>
namespace {
using QmlDesigner::AbstractProperty;
using QmlDesigner::AbstractView;
+using QmlDesigner::ListModelEditorModel;
using QmlDesigner::ModelNode;
MATCHER_P2(HasItem,
@@ -93,6 +96,7 @@ public:
emptyListModelNode = mockView.createModelNode("QtQml.Models.ListModel", 2, 15);
+ listViewNode = mockView.createModelNode("QtQuick.ListView", 2, 15);
listModelNode = mockView.createModelNode("QtQml.Models.ListModel", 2, 15);
mockView.rootModelNode().defaultNodeListProperty().reparentHere(listModelNode);
element1 = createElement({{"name", "foo"}, {"value", 1}, {"value2", 42}});
@@ -172,10 +176,20 @@ public:
return properties;
}
+ QModelIndex index(int row, int column) const { return model.index(row, column); }
+
+ QList<ModelNode> elements(const ModelNode &node) const
+ {
+ return node.defaultNodeListProperty().toModelNodeList();
+ }
+
protected:
std::unique_ptr<QmlDesigner::Model> designerModel{QmlDesigner::Model::create("QtQuick.Item", 1, 1)};
NiceMock<MockListModelEditorView> mockView;
- QmlDesigner::ListModelEditorModel model;
+ QmlDesigner::ListModelEditorModel model{
+ [&] { return mockView.createModelNode("QtQml.Models.ListModel", 2, 15); },
+ [&] { return mockView.createModelNode("QtQml.Models.ListElement", 2, 15); }};
+ ModelNode listViewNode;
ModelNode listModelNode;
ModelNode emptyListModelNode;
ModelNode element1;
@@ -427,7 +441,7 @@ TEST_F(ListModelEditor, RemoveColumnRemovesDisplayValues)
{
model.setListModel(listModelNode);
- model.removeColumn(2);
+ model.removeColumns({index(0, 2)});
ASSERT_THAT(displayValues(),
ElementsAre(ElementsAre(IsInvalid(), "foo", 42),
@@ -442,14 +456,14 @@ TEST_F(ListModelEditor, RemoveColumnRemovesProperties)
EXPECT_CALL(mockView, propertiesRemoved(ElementsAre(IsAbstractProperty(element2, "image"))));
EXPECT_CALL(mockView, propertiesRemoved(ElementsAre(IsAbstractProperty(element3, "image"))));
- model.removeColumn(0);
+ model.removeColumns({index(0, 0)});
}
TEST_F(ListModelEditor, RemoveColumnRemovesPropertyName)
{
model.setListModel(listModelNode);
- model.removeColumn(1);
+ model.removeColumns({index(0, 1)});
ASSERT_THAT(model.propertyNames(), ElementsAre("image", "value", "value2"));
}
@@ -458,7 +472,7 @@ TEST_F(ListModelEditor, RemoveRowRemovesDisplayValues)
{
model.setListModel(listModelNode);
- model.removeRow(1);
+ model.removeRows({index(1, 0)});
ASSERT_THAT(displayValues(),
ElementsAre(ElementsAre(IsInvalid(), "foo", 1, 42),
@@ -471,7 +485,7 @@ TEST_F(ListModelEditor, RemoveRowRemovesElementInListModel)
EXPECT_CALL(mockView, nodeRemoved(Eq(element2), _, _));
- model.removeRow(1);
+ model.removeRows({index(1, 0)});
}
TEST_F(ListModelEditor, ConvertStringFloatToFloat)
@@ -721,7 +735,7 @@ TEST_F(ListModelEditor, RemoveColumnAfterRenameColumn)
model.setListModel(listModelNode);
model.renameColumn(1, "mood");
- model.removeColumn(1);
+ model.removeColumns({index(0, 1)});
ASSERT_THAT(properties(),
ElementsAre(UnorderedElementsAre(IsVariantProperty("value", 1),
@@ -909,44 +923,457 @@ TEST_F(ListModelEditor, RemoveLastRow)
model.addColumn("mood");
model.addRow();
- model.removeRow(0);
+ model.removeRows({index(0, 0)});
ASSERT_THAT(displayValues(), IsEmpty());
}
-TEST_F(ListModelEditor, RemoveLastColumn)
+TEST_F(ListModelEditor, RemoveLastEmptyRow)
{
model.setListModel(emptyListModelNode);
model.addColumn("mood");
model.addRow();
+ model.removeColumns({index(0, 0)});
- model.removeColumn(0);
+ model.removeRows({index(0, 0)});
ASSERT_THAT(displayValues(), ElementsAre(IsEmpty()));
}
-TEST_F(ListModelEditor, RemoveLastEmptyColumn)
+TEST_F(ListModelEditor, RemoveLastColumn)
{
model.setListModel(emptyListModelNode);
model.addColumn("mood");
model.addRow();
- model.removeRow(0);
- model.removeColumn(0);
+ model.removeColumns({index(0, 0)});
- ASSERT_THAT(displayValues(), IsEmpty());
+ ASSERT_THAT(displayValues(), ElementsAre(IsEmpty()));
}
-TEST_F(ListModelEditor, RemoveLastEmptyRow)
+TEST_F(ListModelEditor, RemoveLastEmptyColumn)
{
model.setListModel(emptyListModelNode);
model.addColumn("mood");
model.addRow();
- model.removeColumn(0);
+ model.removeRows({index(0, 0)});
- model.removeRow(0);
+ model.removeColumns({index(0, 0)});
ASSERT_THAT(displayValues(), IsEmpty());
}
+TEST_F(ListModelEditor, RemoveColumns)
+{
+ model.setListModel(listModelNode);
+ model.removeColumns({index(0, 1), index(0, 3), index(1, 1), index(0, 4)});
+
+ ASSERT_THAT(properties(),
+ ElementsAre(UnorderedElementsAre(IsVariantProperty("value", 1)),
+ UnorderedElementsAre(IsVariantProperty("image", "pic.png"),
+ IsVariantProperty("value", 4)),
+ UnorderedElementsAre(IsVariantProperty("image", "pic.png"),
+ IsVariantProperty("value", 111))));
+}
+
+TEST_F(ListModelEditor, RemoveRows)
+{
+ model.setListModel(listModelNode);
+
+ model.removeRows({index(1, 0), index(2, 0), index(3, 0), index(2, 0)});
+
+ ASSERT_THAT(properties(),
+ ElementsAre(UnorderedElementsAre(IsVariantProperty("name", "foo"),
+ IsVariantProperty("value", 1),
+ IsVariantProperty("value2", 42))));
+}
+
+TEST_F(ListModelEditor, FilterColumns)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(0, 0), index(1, 1), index(0, 2), index(0, 1)};
+
+ auto columns = ListModelEditorModel::filterColumns(indices);
+
+ ASSERT_THAT(columns, ElementsAre(0, 1, 2));
+}
+
+TEST_F(ListModelEditor, FilterColumnsInvalidColumns)
+{
+ QList<QModelIndex> indices = {index(0, 0), index(1, 1), index(0, 2), index(0, 1)};
+
+ auto columns = ListModelEditorModel::filterColumns(indices);
+
+ ASSERT_THAT(columns, IsEmpty());
+}
+
+TEST_F(ListModelEditor, FilterColumnsEmptyInput)
+{
+ QList<QModelIndex> indices;
+
+ auto columns = ListModelEditorModel::filterColumns(indices);
+
+ ASSERT_THAT(columns, IsEmpty());
+}
+
+TEST_F(ListModelEditor, FilterRows)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(0, 0), index(1, 1), index(2, 2), index(0, 1)};
+
+ auto rows = ListModelEditorModel::filterRows(indices);
+
+ ASSERT_THAT(rows, ElementsAre(0, 1, 2));
+}
+
+TEST_F(ListModelEditor, FilterRowsInvalidColumns)
+{
+ QList<QModelIndex> indices = {index(0, 0), index(1, 1), index(2, 2), index(0, 1)};
+
+ auto rows = ListModelEditorModel::filterRows(indices);
+
+ ASSERT_THAT(rows, IsEmpty());
+}
+
+TEST_F(ListModelEditor, FilterRowsEmptyInput)
+{
+ QList<QModelIndex> indices;
+
+ auto rows = ListModelEditorModel::filterRows(indices);
+
+ ASSERT_THAT(rows, IsEmpty());
+}
+
+TEST_F(ListModelEditor, CannotMoveEmptyRowsUp)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(-1, 1)};
+
+ model.moveRowsUp(indices);
+
+ ASSERT_THAT(elements(listModelNode), ElementsAre(element1, element2, element3));
+}
+
+TEST_F(ListModelEditor, MoveRowUp)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(1, 1), index(1, 2), index(1, 0)};
+
+ model.moveRowsUp(indices);
+
+ ASSERT_THAT(elements(listModelNode), ElementsAre(element2, element1, element3));
+}
+
+TEST_F(ListModelEditor, MoveRowsUp)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(1, 1), index(2, 2), index(1, 0)};
+
+ model.moveRowsUp(indices);
+
+ ASSERT_THAT(elements(listModelNode), ElementsAre(element2, element3, element1));
+}
+
+TEST_F(ListModelEditor, CannotMoveFirstRowsUp)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(0, 1), index(1, 2), index(0, 0)};
+
+ model.moveRowsUp(indices);
+
+ ASSERT_THAT(elements(listModelNode), ElementsAre(element1, element2, element3));
+}
+
+TEST_F(ListModelEditor, CannotMoveEmptyRowsUpDisplayValues)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(-1, 1)};
+
+ model.moveRowsUp(indices);
+
+ ASSERT_THAT(displayValues(),
+ ElementsAre(ElementsAre(IsInvalid(), "foo", 1, 42),
+ ElementsAre("pic.png", "bar", 4, IsInvalid()),
+ ElementsAre("pic.png", "poo", 111, IsInvalid())));
+}
+
+TEST_F(ListModelEditor, CannotMoveFirstRowUpDisplayValues)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(0, 1), index(1, 2), index(0, 0)};
+
+ model.moveRowsUp(indices);
+
+ ASSERT_THAT(displayValues(),
+ ElementsAre(ElementsAre(IsInvalid(), "foo", 1, 42),
+ ElementsAre("pic.png", "bar", 4, IsInvalid()),
+ ElementsAre("pic.png", "poo", 111, IsInvalid())));
+}
+
+TEST_F(ListModelEditor, MoveRowsUpDisplayValues)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(1, 1), index(2, 2), index(1, 0)};
+
+ model.moveRowsUp(indices);
+
+ ASSERT_THAT(displayValues(),
+ ElementsAre(ElementsAre("pic.png", "bar", 4, IsInvalid()),
+ ElementsAre("pic.png", "poo", 111, IsInvalid()),
+ ElementsAre(IsInvalid(), "foo", 1, 42)));
+}
+
+TEST_F(ListModelEditor, NoSelectionAfterCannotMoveLastRowsDown)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(0, 1), index(1, 2), index(0, 0)};
+
+ auto selection = model.moveRowsUp(indices);
+
+ ASSERT_THAT(selection.indexes(), IsEmpty());
+}
+
+TEST_F(ListModelEditor, NoSelectionAfterMoveEmptyRowsDown)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(-1, 1)};
+
+ auto selection = model.moveRowsUp(indices);
+
+ ASSERT_THAT(selection.indexes(), IsEmpty());
+}
+
+TEST_F(ListModelEditor, SelectionAfterMoveRowsDown)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(1, 1), index(2, 2), index(1, 0)};
+
+ auto selection = model.moveRowsUp(indices);
+
+ ASSERT_THAT(selection.indexes(),
+ ElementsAre(index(0, 0),
+ index(0, 1),
+ index(0, 2),
+ index(0, 3),
+ index(1, 0),
+ index(1, 1),
+ index(1, 2),
+ index(1, 3)));
+}
+
+TEST_F(ListModelEditor, CannotMoveEmptyRowsDown)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(-1, 1)};
+
+ model.moveRowsDown(indices);
+
+ ASSERT_THAT(elements(listModelNode), ElementsAre(element1, element2, element3));
+}
+
+TEST_F(ListModelEditor, MoveRowDown)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(1, 1), index(1, 2), index(1, 0)};
+
+ model.moveRowsDown(indices);
+
+ ASSERT_THAT(elements(listModelNode), ElementsAre(element1, element3, element2));
+}
+
+TEST_F(ListModelEditor, MoveRowsDown)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(1, 1), index(0, 2), index(1, 0)};
+
+ model.moveRowsDown(indices);
+
+ ASSERT_THAT(elements(listModelNode), ElementsAre(element3, element1, element2));
+}
+
+TEST_F(ListModelEditor, CannotMoveLastRowsDown)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(2, 1), index(1, 2), index(2, 0)};
+
+ model.moveRowsDown(indices);
+
+ ASSERT_THAT(elements(listModelNode), ElementsAre(element1, element2, element3));
+}
+
+TEST_F(ListModelEditor, CannotMoveEmptyRowsDownDisplayValues)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(-1, 1)};
+
+ model.moveRowsDown(indices);
+
+ ASSERT_THAT(displayValues(),
+ ElementsAre(ElementsAre(IsInvalid(), "foo", 1, 42),
+ ElementsAre("pic.png", "bar", 4, IsInvalid()),
+ ElementsAre("pic.png", "poo", 111, IsInvalid())));
+}
+
+TEST_F(ListModelEditor, CannotMoveLastRowDownDisplayValues)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(2, 1), index(1, 2), index(2, 0)};
+
+ model.moveRowsDown(indices);
+
+ ASSERT_THAT(displayValues(),
+ ElementsAre(ElementsAre(IsInvalid(), "foo", 1, 42),
+ ElementsAre("pic.png", "bar", 4, IsInvalid()),
+ ElementsAre("pic.png", "poo", 111, IsInvalid())));
+}
+
+TEST_F(ListModelEditor, MoveRowsDownDisplayValues)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(1, 1), index(0, 2), index(1, 0)};
+
+ model.moveRowsDown(indices);
+
+ ASSERT_THAT(displayValues(),
+ ElementsAre(ElementsAre("pic.png", "poo", 111, IsInvalid()),
+ ElementsAre(IsInvalid(), "foo", 1, 42),
+ ElementsAre("pic.png", "bar", 4, IsInvalid())));
+}
+
+TEST_F(ListModelEditor, NoSelectionAfterCannotMoveLastRowsUp)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(2, 1), index(1, 2), index(2, 0)};
+
+ auto selection = model.moveRowsDown(indices);
+
+ ASSERT_THAT(selection.indexes(), IsEmpty());
+}
+
+TEST_F(ListModelEditor, NoSelectionAfterMoveEmptyRowsUp)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(-1, 1)};
+
+ auto selection = model.moveRowsDown(indices);
+
+ ASSERT_THAT(selection.indexes(), IsEmpty());
+}
+
+TEST_F(ListModelEditor, SelectionAfterMoveRowsUp)
+{
+ model.setListModel(listModelNode);
+ QList<QModelIndex> indices = {index(1, 1), index(0, 2), index(1, 0)};
+
+ auto selection = model.moveRowsDown(indices);
+
+ ASSERT_THAT(selection.indexes(),
+ ElementsAre(index(1, 0),
+ index(1, 1),
+ index(1, 2),
+ index(1, 3),
+ index(2, 0),
+ index(2, 1),
+ index(2, 2),
+ index(2, 3)));
+}
+
+TEST_F(ListModelEditor, ListViewHasNoModel)
+{
+ model.setListView(listViewNode);
+
+ ASSERT_THAT(listViewNode.nodeProperty("model").modelNode().type(), Eq("QtQml.Models.ListModel"));
+}
+
+TEST_F(ListModelEditor, ListViewHasModelInside)
+{
+ listViewNode.nodeProperty("model").reparentHere(listModelNode);
+
+ model.setListView(listViewNode);
+
+ ASSERT_THAT(displayValues(),
+ ElementsAre(ElementsAre(IsInvalid(), "foo", 1, 42),
+ ElementsAre("pic.png", "bar", 4, IsInvalid()),
+ ElementsAre("pic.png", "poo", 111, IsInvalid())));
+}
+
+TEST_F(ListModelEditor, ListViewHasModelBinding)
+{
+ listModelNode.setIdWithoutRefactoring("listModel");
+ listViewNode.bindingProperty("model").setExpression("listModel");
+
+ model.setListView(listViewNode);
+
+ ASSERT_THAT(displayValues(),
+ ElementsAre(ElementsAre(IsInvalid(), "foo", 1, 42),
+ ElementsAre("pic.png", "bar", 4, IsInvalid()),
+ ElementsAre("pic.png", "poo", 111, IsInvalid())));
+}
+
+TEST_F(ListModelEditor, AddBooleanDisplayValues)
+{
+ model.setListModel(listModelNode);
+
+ model.setValue(0, 1, true);
+
+ ASSERT_THAT(displayValues(),
+ ElementsAre(ElementsAre(IsInvalid(), true, 1, 42),
+ ElementsAre("pic.png", "bar", 4, IsInvalid()),
+ ElementsAre("pic.png", "poo", 111, IsInvalid())));
+}
+
+TEST_F(ListModelEditor, AddBooleanProperties)
+{
+ model.setListModel(listModelNode);
+
+ model.setValue(0, 1, true);
+
+ ASSERT_THAT(properties(),
+ ElementsAre(UnorderedElementsAre(IsVariantProperty("name", "foo"),
+ IsVariantProperty("value", true),
+ IsVariantProperty("value2", 42)),
+ UnorderedElementsAre(IsVariantProperty("image", "pic.png"),
+ IsVariantProperty("name", "bar"),
+ IsVariantProperty("value", 4)),
+ UnorderedElementsAre(IsVariantProperty("image", "pic.png"),
+ IsVariantProperty("name", "poo"),
+ IsVariantProperty("value", 111))));
+}
+
+TEST_F(ListModelEditor, AddTrueAsStringProperties)
+{
+ model.setListModel(listModelNode);
+
+ model.setValue(0, 1, "true");
+
+ ASSERT_THAT(properties(),
+ ElementsAre(UnorderedElementsAre(IsVariantProperty("name", true),
+ IsVariantProperty("value", 1),
+ IsVariantProperty("value2", 42)),
+ UnorderedElementsAre(IsVariantProperty("image", "pic.png"),
+ IsVariantProperty("name", "bar"),
+ IsVariantProperty("value", 4)),
+ UnorderedElementsAre(IsVariantProperty("image", "pic.png"),
+ IsVariantProperty("name", "poo"),
+ IsVariantProperty("value", 111))));
+}
+
+TEST_F(ListModelEditor, AddFalseAsStringProperties)
+{
+ model.setListModel(listModelNode);
+
+ model.setValue(0, 1, "false");
+
+ ASSERT_THAT(properties(),
+ ElementsAre(UnorderedElementsAre(IsVariantProperty("name", false),
+ IsVariantProperty("value", 1),
+ IsVariantProperty("value2", 42)),
+ UnorderedElementsAre(IsVariantProperty("image", "pic.png"),
+ IsVariantProperty("name", "bar"),
+ IsVariantProperty("value", 4)),
+ UnorderedElementsAre(IsVariantProperty("image", "pic.png"),
+ IsVariantProperty("name", "poo"),
+ IsVariantProperty("value", 111))));
+}
+
} // namespace