Preview task-group selections until Meta is released
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "../pendingselection.h"
|
||||
|
||||
#include <QSignalSpy>
|
||||
#include <QStandardItemModel>
|
||||
#include <QTest>
|
||||
|
||||
class PendingSelectionTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
void singleWindowWaitsForRelease()
|
||||
{
|
||||
QStandardItemModel model(1, 1);
|
||||
PendingSelection selection(model);
|
||||
QSignalSpy activated(&selection, &PendingSelection::activationRequested);
|
||||
QSignalSpy previewed(&selection, &PendingSelection::previewRequested);
|
||||
selection.select(model.index(0, 0), true);
|
||||
QCOMPARE(previewed.count(), 1);
|
||||
QCOMPARE(activated.count(), 0);
|
||||
selection.finish();
|
||||
QCOMPARE(activated.count(), 1);
|
||||
}
|
||||
|
||||
void cancellationAllowsAnotherSelectionBeforeRelease()
|
||||
{
|
||||
QStandardItemModel model(2, 1);
|
||||
PendingSelection selection(model);
|
||||
QSignalSpy activated(&selection, &PendingSelection::activationRequested);
|
||||
selection.select(model.index(1, 0), true);
|
||||
selection.cancel();
|
||||
selection.select(model.index(0, 0), true);
|
||||
QCOMPARE(activated.count(), 0);
|
||||
selection.finish();
|
||||
QCOMPARE(activated.count(), 1);
|
||||
QCOMPARE(activated.first().first().value<QModelIndex>(), model.index(0, 0));
|
||||
}
|
||||
|
||||
void activatesOnlyFinalSelection()
|
||||
{
|
||||
QStandardItemModel model(3, 1);
|
||||
PendingSelection selection(model);
|
||||
QSignalSpy activated(&selection, &PendingSelection::activationRequested);
|
||||
QSignalSpy previewed(&selection, &PendingSelection::previewRequested);
|
||||
QSignalSpy hidden(&selection, &PendingSelection::previewHidden);
|
||||
|
||||
selection.select(model.index(0, 0), true);
|
||||
selection.select(model.index(1, 0), true);
|
||||
selection.select(model.index(2, 0), true);
|
||||
QCOMPARE(previewed.count(), 3);
|
||||
QCOMPARE(activated.count(), 0);
|
||||
selection.finish();
|
||||
QCOMPARE(hidden.count(), 1);
|
||||
QCOMPARE(activated.count(), 1);
|
||||
QCOMPARE(activated.first().first().value<QModelIndex>(), model.index(2, 0));
|
||||
selection.finish();
|
||||
QCOMPARE(activated.count(), 1);
|
||||
}
|
||||
|
||||
void switchingGroupsAbandonsPreviousSelection()
|
||||
{
|
||||
QStandardItemModel model;
|
||||
for (const auto &name : {"Dolphin", "Firefox"}) {
|
||||
auto *group = new QStandardItem(QString::fromLatin1(name));
|
||||
group->appendRow(new QStandardItem(QStringLiteral("first")));
|
||||
group->appendRow(new QStandardItem(QStringLiteral("second")));
|
||||
model.appendRow(group);
|
||||
}
|
||||
PendingSelection selection(model);
|
||||
QSignalSpy activated(&selection, &PendingSelection::activationRequested);
|
||||
selection.select(model.index(1, 0, model.index(0, 0)), true);
|
||||
const QModelIndex firefox = model.index(0, 0, model.index(1, 0));
|
||||
selection.select(firefox, true);
|
||||
QCOMPARE(activated.count(), 0);
|
||||
selection.finish();
|
||||
QCOMPARE(activated.count(), 1);
|
||||
QCOMPARE(activated.first().first().value<QModelIndex>(), firefox);
|
||||
}
|
||||
|
||||
void immediateActionReplacesPreview()
|
||||
{
|
||||
QStandardItemModel model(2, 1);
|
||||
PendingSelection selection(model);
|
||||
QSignalSpy activated(&selection, &PendingSelection::activationRequested);
|
||||
selection.select(model.index(0, 0), true);
|
||||
selection.select(model.index(1, 0), false);
|
||||
QCOMPARE(activated.count(), 1);
|
||||
QCOMPARE(activated.first().first().value<QModelIndex>(), model.index(1, 0));
|
||||
selection.finish();
|
||||
QCOMPARE(activated.count(), 1);
|
||||
}
|
||||
|
||||
void cancellationDoesNotActivate()
|
||||
{
|
||||
QStandardItemModel model(1, 1);
|
||||
PendingSelection selection(model);
|
||||
QSignalSpy activated(&selection, &PendingSelection::activationRequested);
|
||||
selection.select(model.index(0, 0), true);
|
||||
selection.cancel();
|
||||
selection.finish();
|
||||
selection.select(model.index(0, 0), true);
|
||||
selection.select({}, true);
|
||||
selection.finish();
|
||||
QCOMPARE(activated.count(), 0);
|
||||
}
|
||||
|
||||
void selectedWindowClosingCancels()
|
||||
{
|
||||
QStandardItemModel model(2, 1);
|
||||
PendingSelection selection(model);
|
||||
QSignalSpy activated(&selection, &PendingSelection::activationRequested);
|
||||
QSignalSpy hidden(&selection, &PendingSelection::previewHidden);
|
||||
selection.select(model.index(0, 0), true);
|
||||
model.removeRow(0);
|
||||
QVERIFY(!hidden.isEmpty());
|
||||
selection.finish();
|
||||
QCOMPARE(activated.count(), 0);
|
||||
}
|
||||
|
||||
void rowChangeKeepsSelectedWindow()
|
||||
{
|
||||
QStandardItemModel model(3, 1);
|
||||
model.setData(model.index(2, 0), QStringLiteral("selected"));
|
||||
PendingSelection selection(model);
|
||||
QSignalSpy activated(&selection, &PendingSelection::activationRequested);
|
||||
selection.select(model.index(2, 0), true);
|
||||
model.removeRow(0);
|
||||
selection.finish();
|
||||
QCOMPARE(activated.count(), 1);
|
||||
QCOMPARE(activated.first().first().value<QModelIndex>().data().toString(), QStringLiteral("selected"));
|
||||
}
|
||||
|
||||
void modelResetCancels()
|
||||
{
|
||||
QStandardItemModel model(1, 1);
|
||||
PendingSelection selection(model);
|
||||
QSignalSpy activated(&selection, &PendingSelection::activationRequested);
|
||||
selection.select(model.index(0, 0), true);
|
||||
model.clear();
|
||||
model.setRowCount(1);
|
||||
selection.finish();
|
||||
QCOMPARE(activated.count(), 0);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(PendingSelectionTest)
|
||||
#include "test-pendingselection.moc"
|
||||
Reference in New Issue
Block a user