Commit 98256b1c authored by Volker Krause's avatar Volker Krause

Distinguish between batch changes and batch content changes

Most batch-based logic doesn't actually care if we add or remove elements
from the batch, but only cares for the actual content changing.
parent 62eb3c18
......@@ -183,6 +183,7 @@ private Q_SLOTS:
QSignalSpy batchAddSpy(&mgr, &ReservationManager::batchAdded);
QSignalSpy batchChangeSpy(&mgr, &ReservationManager::batchChanged);
QSignalSpy batchContentSpy(&mgr, &ReservationManager::batchContentChanged);
QSignalSpy batchRenameSpy(&mgr, &ReservationManager::batchRenamed);
QSignalSpy batchRemovedSpy(&mgr, &ReservationManager::batchRemoved);
......@@ -208,20 +209,22 @@ private Q_SLOTS:
batchChangeSpy.clear();
mgr.updateReservation(secId, res);
QCOMPARE(batchAddSpy.size(), 0);
QCOMPARE(batchChangeSpy.size(), 1);
QCOMPARE(batchChangeSpy.size(), 0);
QCOMPARE(batchContentSpy.size(), 1);
QCOMPARE(batchRenameSpy.size(), 0);
QCOMPARE(batchRemovedSpy.size(), 0);
QCOMPARE(batchChangeSpy.at(0).at(0), batchId);
QCOMPARE(batchContentSpy.at(0).at(0), batchId);
// de-batching by update, moving to new batch
flight.setDepartureTime(flight.departureTime().addYears(1));
res.setReservationFor(flight);
batchAddSpy.clear();
batchChangeSpy.clear();
batchContentSpy.clear();
mgr.updateReservation(secId, res);
QCOMPARE(batchAddSpy.size(), 1);
QCOMPARE(batchChangeSpy.size(), 1);
QCOMPARE(batchContentSpy.size(), 0);
QCOMPARE(batchRenameSpy.size(), 0);
QCOMPARE(batchRemovedSpy.size(), 0);
QCOMPARE(batchAddSpy.at(0).at(0), secId);
......@@ -236,6 +239,7 @@ private Q_SLOTS:
mgr.updateReservation(secId, res);
QCOMPARE(batchAddSpy.size(), 0);
QCOMPARE(batchChangeSpy.size(), 1);
QCOMPARE(batchContentSpy.size(), 0);
QCOMPARE(batchRenameSpy.size(), 0);
QCOMPARE(batchRemovedSpy.size(), 1);
QCOMPARE(batchChangeSpy.at(0).at(0), batchId);
......@@ -255,19 +259,21 @@ private Q_SLOTS:
batchRemovedSpy.clear();
mgr.updateReservation(batchId, res2);
QCOMPARE(batchAddSpy.size(), 0);
QCOMPARE(batchChangeSpy.size(), 1);
QCOMPARE(batchChangeSpy.size(), 0);
QCOMPARE(batchContentSpy.size(), 1);
QCOMPARE(batchRenameSpy.size(), 0);
QCOMPARE(batchRemovedSpy.size(), 0);
QCOMPARE(batchChangeSpy.at(0).at(0), batchId);
QCOMPARE(batchContentSpy.at(0).at(0), batchId);
// de-batch by changing the primary one renames the batch
flight2.setDepartureTime(flight2.departureTime().addYears(1));
res2.setReservationFor(flight2);
batchChangeSpy.clear();
batchContentSpy.clear();
mgr.updateReservation(batchId, res2);
QCOMPARE(batchAddSpy.size(), 1);
QCOMPARE(batchChangeSpy.size(), 0);
QCOMPARE(batchContentSpy.size(), 0);
QCOMPARE(batchRenameSpy.size(), 1);
QCOMPARE(batchRemovedSpy.size(), 0);
QCOMPARE(batchAddSpy.at(0).at(0), batchId);
......@@ -289,6 +295,7 @@ private Q_SLOTS:
mgr.updateReservation(batchId, res2);
QCOMPARE(batchAddSpy.size(), 0);
QCOMPARE(batchChangeSpy.size(), 1);
QCOMPARE(batchContentSpy.size(), 0);
QCOMPARE(batchRenameSpy.size(), 0);
QCOMPARE(batchRemovedSpy.size(), 1);
QCOMPARE(batchChangeSpy.at(0).at(0), secId);
......@@ -320,6 +327,7 @@ private Q_SLOTS:
mgr.removeBatch(batchId);
QCOMPARE(batchAddSpy.size(), 0);
QCOMPARE(batchChangeSpy.size(), 0);
QCOMPARE(batchContentSpy.size(), 0);
QCOMPARE(batchRenameSpy.size(), 0);
QCOMPARE(batchRemovedSpy.size(), 1);
QCOMPARE(batchRemovedSpy.at(0).at(0), batchId);
......
......@@ -417,7 +417,7 @@ void ReservationManager::updateBatch(const QString &resId, const QVariant &res)
// still in the same batch?
if (!oldBatchId.isEmpty() && oldBatchId == newBatchId) {
emit batchChanged(oldBatchId);
emit batchContentChanged(oldBatchId);
// no need to store here, as batching didn't actually change
return;
}
......
......@@ -69,7 +69,14 @@ Q_SIGNALS:
void reservationRemoved(const QString &id);
void batchAdded(const QString &batchId);
/** This is emitted when elements are added or removed from the batch,
* but its content otherwise stays untouched.
*/
void batchChanged(const QString &batchId);
/** This is emitted when the batch content changed, but the batching
* as such remains the same.
*/
void batchContentChanged(const QString &batchId);
/** This is emitted when the reservation with @p oldBatchId was removed and
* it has been used to identify a non-empty batch.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment