| 139 | } |
| 140 | |
| 141 | void ModelTests::testFileModel() |
| 142 | { |
| 143 | auto row = 0; |
| 144 | const auto dirId = QStringLiteral("GXWxf-3zgnU"); |
| 145 | const auto *dirInfo = m_connection.findDirInfo(dirId, row); |
| 146 | QVERIFY(dirInfo); |
| 147 | QCOMPARE(dirInfo->displayName(), QStringLiteral("A folder")); |
| 148 | |
| 149 | // test behavior of empty/unpopulated model |
| 150 | auto model = Data::SyncthingFileModel(m_connection, *dirInfo); |
| 151 | model.setRecursiveSelectionEnabled(true); |
| 152 | QCOMPARE(model.rowCount(QModelIndex()), 1); |
| 153 | const auto rootIdx = QPersistentModelIndex(model.index(0, 0)); |
| 154 | QVERIFY(rootIdx.isValid()); |
| 155 | QCOMPARE(rootIdx.data(Data::SyncthingFileModel::NameRole).toString(), dirInfo->displayName()); |
| 156 | QVERIFY(!model.index(1, 0).isValid()); |
| 157 | QCOMPARE(model.rowCount(rootIdx), 1); |
| 158 | QCOMPARE(model.index(0, 0, rootIdx).data(), QStringLiteral("Loading…")); |
| 159 | QCOMPARE(model.index(1, 0, rootIdx).data(), QVariant()); |
| 160 | QVERIFY2(!model.canFetchMore(rootIdx), "cannot fetch more when already loading"); |
| 161 | |
| 162 | // wait until the root has been updated |
| 163 | connect(&model, &Data::SyncthingFileModel::fetchQueueEmpty, this, [this]() { |
| 164 | m_timeout.stop(); |
| 165 | m_loop.quit(); |
| 166 | }); |
| 167 | m_timeout.start(); |
| 168 | m_loop.exec(); |
| 169 | |
| 170 | QVERIFY(rootIdx.isValid()); |
| 171 | QCOMPARE(model.rowCount(rootIdx), 2); |
| 172 | QCOMPARE(rootIdx.sibling(rootIdx.row(), 4).data(Qt::ToolTipRole), QStringLiteral("Exists locally and globally")); |
| 173 | |
| 174 | // test access to nested folders |
| 175 | const auto androidIdx = QPersistentModelIndex(model.index(0, 0, rootIdx)); |
| 176 | const auto cameraIdx = QPersistentModelIndex(model.index(1, 0, rootIdx)); |
| 177 | const auto nestedIdx = QPersistentModelIndex(model.index(0, 0, cameraIdx)); |
| 178 | const auto initialAndroidPtr = androidIdx.internalPointer(); |
| 179 | const auto initialCameraPtr = cameraIdx.internalPointer(); |
| 180 | QVERIFY(androidIdx.isValid()); |
| 181 | QVERIFY(cameraIdx.isValid()); |
| 182 | QCOMPARE(androidIdx.parent(), rootIdx); |
| 183 | QCOMPARE(cameraIdx.parent(), rootIdx); |
| 184 | QCOMPARE(nestedIdx.parent(), cameraIdx); |
| 185 | QCOMPARE(model.rowCount(androidIdx), 0); |
| 186 | QCOMPARE(model.rowCount(cameraIdx), 5); |
| 187 | QCOMPARE(androidIdx.data(), QStringLiteral("100ANDRO")); |
| 188 | QCOMPARE(cameraIdx.data(), QStringLiteral("Camera")); |
| 189 | QCOMPARE(model.index(0, 0, cameraIdx).data(), QStringLiteral("IMG_20201114_124821.jpg")); |
| 190 | QVERIFY(model.index(0, 0, cameraIdx).data(Qt::DecorationRole).canConvert<QIcon>()); |
| 191 | QCOMPARE(model.index(0, 1, cameraIdx).data(), QStringLiteral("10.19 MiB")); |
| 192 | QCOMPARE(model.index(0, 2, cameraIdx).data(), QStringLiteral("2020-12-16 22:31:34.500")); |
| 193 | QCOMPARE(model.index(0, 3, cameraIdx).data(), QVariant()); |
| 194 | QVERIFY(model.index(0, 4, cameraIdx).data(Qt::DecorationRole).canConvert<QPixmap>()); |
| 195 | QCOMPARE(model.index(0, 4, cameraIdx).data(Qt::ToolTipRole), QStringLiteral("Exists only globally")); |
| 196 | QCOMPARE(model.index(1, 0, cameraIdx).data(), QStringLiteral("IMG_20201213_122451.jpg")); |
| 197 | QCOMPARE(model.index(2, 0, cameraIdx).data(), QStringLiteral("IMG_20201213_122504.jpg")); |
| 198 | QCOMPARE(model.index(3, 0, cameraIdx).data(), QStringLiteral("IMG_20201213_122505.jpg")); |
nothing calls this directly
no test coverage detected