Skip to content

Commit

Permalink
Adapt tests to changes in file model and improve wording
Browse files Browse the repository at this point in the history
  • Loading branch information
Martchus committed Jan 29, 2025
1 parent cd514bb commit 5b0c4c5
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 42 deletions.
2 changes: 1 addition & 1 deletion syncthingmodel/syncthingfilemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ QList<QAction *> SyncthingFileModel::selectionActions()
res << ignoreSelectedAction;

if (!m_localPath.isEmpty()) {
auto *const ignoreAndDeleteSelectedAction = new QAction(tr("Ignore checked items (and their children) and ensure they are locally deleted"), this);
auto *const ignoreAndDeleteSelectedAction = new QAction(tr("Ignore and locally delete checked items (and their children)"), this);
ignoreAndDeleteSelectedAction->setIcon(QIcon::fromTheme(QStringLiteral("list-remove")));
connect(ignoreAndDeleteSelectedAction, &QAction::triggered, this, [this]() { ignoreSelectedItems(true, true); });
res << ignoreAndDeleteSelectedAction;
Expand Down
51 changes: 26 additions & 25 deletions syncthingmodel/tests/models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,13 @@ void ModelTests::testFileModel()

// selection actions when selection mode enabled
actions = model.selectionActions();
QCOMPARE(actions.size(), 5);
QCOMPARE(actions.at(0)->text(), QStringLiteral("Discard selection and staged changes"));
QCOMPARE(actions.at(1)->text(), QStringLiteral("Ignore selected items (and their children)"));
QCOMPARE(actions.at(2)->text(), QStringLiteral("Include selected items (and their children)"));
QCOMPARE(actions.at(3)->text(), QStringLiteral("Ignore all items by default"));
QCOMPARE(actions.at(4)->text(), QStringLiteral("Remove ignore patterns matching against selected items (may affect other items as well)"));
QCOMPARE(actions.size(), 6);
QCOMPARE(actions.at(0)->text(), QStringLiteral("Uncheck all and discard staged changes"));
QCOMPARE(actions.at(1)->text(), QStringLiteral("Ignore checked items (and their children)"));
QCOMPARE(actions.at(2)->text(), QStringLiteral("Ignore and locally delete checked items (and their children)"));
QCOMPARE(actions.at(3)->text(), QStringLiteral("Include checked items (and their children)"));
QCOMPARE(actions.at(4)->text(), QStringLiteral("Ignore all items by default"));
QCOMPARE(actions.at(5)->text(), QStringLiteral("Remove ignore patterns matching checked items (may affect other items as well)"));
actions.at(1)->trigger(); // this won't do much in the test setup
actions.at(0)->trigger(); // disables selection mode
qDeleteAll(actions);
Expand Down Expand Up @@ -308,37 +309,37 @@ void ModelTests::testFileModel()

// test ignoring items by default
actions = model.selectionActions();
QVERIFY(actions.size() > 3);
QCOMPARE(actions.at(3)->text(), QStringLiteral("Ignore all items by default"));
actions.at(3)->trigger();
QVERIFY(actions.size() > 4);
QCOMPARE(actions.at(4)->text(), QStringLiteral("Ignore all items by default"));
actions.at(4)->trigger();
auto expectedDiff = QString(QChar('+') % model.m_ignoreAllByDefaultPattern % QChar('\n'));
auto expectedPatterns = QStringList({ QStringLiteral("/**") });
QCOMPARE(model.computeIgnorePatternDiff(), expectedDiff);
QCOMPARE(model.computeNewIgnorePatterns().ignore, expectedPatterns);

// test including items explicitly
QCOMPARE(actions.at(2)->text(), QStringLiteral("Include selected items (and their children)"));
QCOMPARE(actions.at(3)->text(), QStringLiteral("Include checked items (and their children)"));
model.setData(androidIdx2, Qt::Checked, Qt::CheckStateRole);
expectedDiff.prepend(QStringLiteral("+!/100ANDRO\n"));
expectedPatterns.prepend(QStringLiteral("!/100ANDRO"));
for (auto i = 0; i != 2; ++i) { // preform action twice; this should not lead to a duplicate
actions.at(2)->trigger();
actions.at(3)->trigger();
QCOMPARE(model.computeIgnorePatternDiff(), expectedDiff);
QCOMPARE(model.computeNewIgnorePatterns().ignore, expectedPatterns);
}
model.setData(androidIdx2, Qt::Unchecked, Qt::CheckStateRole); // should the item be automatically unchecked?
model.setData(cameraIdx2, Qt::Checked, Qt::CheckStateRole);
expectedDiff.insert(QStringLiteral("+!/100ANDRO\n").size(), QStringLiteral("+!/Camera\n"));
expectedPatterns.insert(1, QStringLiteral("!/Camera"));
actions.at(2)->trigger();
actions.at(3)->trigger();
QCOMPARE(model.computeIgnorePatternDiff(), expectedDiff);
QCOMPARE(model.computeNewIgnorePatterns().ignore, expectedPatterns);
model.setData(cameraIdx2, Qt::Unchecked, Qt::CheckStateRole); // should the item be automatically unchecked?

// test ignoring items explicitly
model.setData(model.index(1, 0, cameraIdx2), Qt::Checked, Qt::CheckStateRole);
model.setData(model.index(3, 0, cameraIdx2), Qt::Checked, Qt::CheckStateRole);
QCOMPARE(actions.at(1)->text(), QStringLiteral("Ignore selected items (and their children)"));
QCOMPARE(actions.at(1)->text(), QStringLiteral("Ignore checked items (and their children)"));
actions.at(1)->trigger();
expectedDiff.insert(
QStringLiteral("+!/100ANDRO\n").size(), QStringLiteral("+/Camera/IMG_20201213_122451.jpg\n+/Camera/IMG_20201213_122505.jpg\n"));
Expand All @@ -351,9 +352,9 @@ void ModelTests::testFileModel()
// note: Doing this makes not much sense after including items explicitly like the previous tests just did but this should of course work in general.
qDeleteAll(actions);
actions = model.selectionActions();
QVERIFY(actions.size() > 3);
QCOMPARE(actions.at(3)->text(), QStringLiteral("Include all items by default"));
actions.at(3)->trigger();
QVERIFY(actions.size() > 4);
QCOMPARE(actions.at(4)->text(), QStringLiteral("Include all items by default"));
actions.at(4)->trigger();
expectedDiff.chop(model.m_ignoreAllByDefaultPattern.size() + 2);
expectedPatterns.removeLast();
QCOMPARE(model.computeIgnorePatternDiff(), expectedDiff);
Expand All @@ -362,8 +363,8 @@ void ModelTests::testFileModel()
// test reviewing/applying changes
qDeleteAll(actions);
actions = model.selectionActions();
QVERIFY(actions.size() > 5);
QCOMPARE(actions.at(5)->text(), QStringLiteral("Review and apply staged changes"));
QVERIFY(actions.size() > 6);
QCOMPARE(actions.at(6)->text(), QStringLiteral("Review and apply staged changes"));
connect(
&model, &Data::SyncthingFileModel::actionNeedsConfirmation, this,
[&expectedDiff](QAction *action, const QString &message, const QString &diff, const QSet<QString> &localDeletions) {
Expand Down Expand Up @@ -391,7 +392,7 @@ void ModelTests::testFileModel()
QVERIFY(message.startsWith(QStringLiteral("Unable to change ignore patterns:")));
},
Qt::QueuedConnection);
actions.at(5)->trigger();
actions.at(6)->trigger();
m_timeout.start();
m_loop.exec();

Expand All @@ -406,9 +407,9 @@ void ModelTests::testFileModel()
model.m_isIgnoringAllByDefault = true;
qDeleteAll(actions);
actions = model.selectionActions();
QVERIFY(actions.size() > 4);
QCOMPARE(actions.at(3)->text(), QStringLiteral("Include all items by default"));
actions.at(3)->trigger();
QVERIFY(actions.size() > 5);
QCOMPARE(actions.at(4)->text(), QStringLiteral("Include all items by default"));
actions.at(4)->trigger();
expectedDiff = QStringLiteral(" !/100ANDRO\n /Camera/IMG_20201213_122451.jpg\n /Camera/IMG_20201213_122505.jpg\n !/Camera\n-")
% model.m_ignoreAllByDefaultPattern % QChar('\n');
QCOMPARE(model.computeIgnorePatternDiff(), expectedDiff);
Expand All @@ -418,8 +419,8 @@ void ModelTests::testFileModel()
model.resetMatchingIgnorePatterns();
model.setCheckState(rootIdx, Qt::Unchecked, true);
model.setCheckState(model.index(1, 0, cameraIdx2), Qt::Checked);
QCOMPARE(actions.at(4)->text(), QStringLiteral("Remove ignore patterns matching against selected items (may affect other items as well)"));
actions.at(4)->trigger();
QCOMPARE(actions.at(5)->text(), QStringLiteral("Remove ignore patterns matching checked items (may affect other items as well)"));
actions.at(5)->trigger();
const auto indexInDiff = expectedDiff.indexOf(QStringLiteral(" /Camera/IMG_20201213_122451.jpg"));
expectedDiff[indexInDiff] = QChar('-');
expectedPatterns.removeAt(1);
Expand All @@ -432,7 +433,7 @@ void ModelTests::testFileModel()
QCOMPARE(model.computeIgnorePatternDiff(), expectedDiff);
QCOMPARE(model.computeNewIgnorePatterns().ignore, expectedPatterns);
// remove the added-back pattern
actions.at(4)->trigger();
actions.at(5)->trigger();
expectedDiff[indexInDiff] = QChar('-');
expectedPatterns.removeAt(1);
QCOMPARE(model.computeIgnorePatternDiff(), expectedDiff);
Expand Down
10 changes: 5 additions & 5 deletions syncthingmodel/translations/syncthingmodel_cs_CZ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,6 @@
<source>Ignore checked items (and their children)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../syncthingfilemodel.cpp" line="809"/>
<source>Ignore checked items (and their children) and ensure they are locally deleted</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../syncthingfilemodel.cpp" line="815"/>
<source>Include checked items (and their children)</source>
Expand All @@ -527,6 +522,11 @@
<source>Include all items by default</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../syncthingfilemodel.cpp" line="809"/>
<source>Ignore and locally delete checked items (and their children)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../syncthingfilemodel.cpp" line="822"/>
<source>Ignore all items by default</source>
Expand Down
2 changes: 1 addition & 1 deletion syncthingmodel/translations/syncthingmodel_de_DE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@
</message>
<message>
<location filename="../syncthingfilemodel.cpp" line="809"/>
<source>Ignore checked items (and their children) and ensure they are locally deleted</source>
<source>Ignore and locally delete checked items (and their children)</source>
<translation type="unfinished"></translation>
</message>
<message>
Expand Down
10 changes: 5 additions & 5 deletions syncthingmodel/translations/syncthingmodel_en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,6 @@
<source>Ignore checked items (and their children)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../syncthingfilemodel.cpp" line="809"/>
<source>Ignore checked items (and their children) and ensure they are locally deleted</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../syncthingfilemodel.cpp" line="815"/>
<source>Include checked items (and their children)</source>
Expand All @@ -445,6 +440,11 @@
<source>Include all items by default</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../syncthingfilemodel.cpp" line="809"/>
<source>Ignore and locally delete checked items (and their children)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../syncthingfilemodel.cpp" line="822"/>
<source>Ignore all items by default</source>
Expand Down
10 changes: 5 additions & 5 deletions syncthingmodel/translations/syncthingmodel_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,6 @@
<source>Ignore checked items (and their children)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../syncthingfilemodel.cpp" line="809"/>
<source>Ignore checked items (and their children) and ensure they are locally deleted</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../syncthingfilemodel.cpp" line="815"/>
<source>Include checked items (and their children)</source>
Expand All @@ -539,6 +534,11 @@
<source>Include all items by default</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../syncthingfilemodel.cpp" line="809"/>
<source>Ignore and locally delete checked items (and their children)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../syncthingfilemodel.cpp" line="822"/>
<source>Ignore all items by default</source>
Expand Down

0 comments on commit 5b0c4c5

Please sign in to comment.