Add test for maxTags in FileTagModel
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 25 Apr 2023 03:45:08 +0000 (11:45 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 16 May 2023 10:23:33 +0000 (18:23 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
test/testfiletagmodel.cpp

index 5633b642cb66ab674d1805384cf394b507e16202..2cc7f28eba3f133e54d7d0028f54691db4884b8f 100644 (file)
@@ -121,6 +121,23 @@ private slots:
             QCOMPARE(tag.toString(), _expectedTags[i]);
         }
     }
+
+    void testModelMaxTags()
+    {
+        auto fileTagModel = FileTagModel(testFilePath, _account);
+        const auto fileTagModelTester = QAbstractItemModelTester(&fileTagModel);
+        QSignalSpy fileTagsChanged(&fileTagModel, &FileTagModel::totalTagsChanged);
+        fileTagsChanged.wait(1000);
+
+        constexpr auto testMaxTags = 3;
+        Q_ASSERT(testMaxTags < testNumTags);
+
+        QSignalSpy maxTagsChangedSpy(&fileTagModel, &FileTagModel::maxTagsChanged);
+        fileTagModel.setMaxTags(testMaxTags);
+        QCOMPARE(maxTagsChangedSpy.count(), 1);
+        QCOMPARE(fileTagModel.maxTags(), testMaxTags);
+        QCOMPARE(fileTagModel.rowCount(), testMaxTags);
+    }
 };
 
 QTEST_MAIN(TestFileTagModel)