Skip to content

Commit

Permalink
Check that signals were correctly emitted in testDateBoundaries
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Sep 12, 2023
1 parent d491268 commit 877536f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/testdatefieldbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ private slots:
void testDateBoundaries()
{
Quick::DateFieldBackend backend;

QSignalSpy minimumDateChangedSpy(&backend, &Quick::DateFieldBackend::minimumDateChanged);
QSignalSpy maximumDateChangedSpy(&backend, &Quick::DateFieldBackend::maximumDateChanged);
QSignalSpy minimumDateMsecsChangedSpy(&backend, &Quick::DateFieldBackend::minimumDateMsecsChanged);
QSignalSpy maximumDateMsecsChangedSpy(&backend, &Quick::DateFieldBackend::maximumDateMsecsChanged);
QSignalSpy validDateChangedSpy(&backend, &Quick::DateFieldBackend::validDateChanged);

const auto minDate = QDate::currentDate().addDays(-5);
const auto maxDate = QDate::currentDate().addDays(5);
const auto minDateMs = minDate.startOfDay(Qt::UTC).toMSecsSinceEpoch();
Expand All @@ -59,6 +66,12 @@ private slots:
QCOMPARE(backend.minimumDateMsecs(), minDateMs);
QCOMPARE(backend.maximumDateMsecs(), maxDateMs);

QCOMPARE(minimumDateChangedSpy.count(), 1);
QCOMPARE(maximumDateChangedSpy.count(), 1);
QCOMPARE(minimumDateMsecsChangedSpy.count(), 1);
QCOMPARE(maximumDateMsecsChangedSpy.count(), 1);
QCOMPARE(validDateChangedSpy.count(), 2); // Changes per each min/max date set

// Reset and try when setting by MSecs
backend.setMinimumDate({});
backend.setMaximumDate({});
Expand All @@ -70,15 +83,23 @@ private slots:
QCOMPARE(backend.minimumDateMsecs(), minDateMs);
QCOMPARE(backend.maximumDateMsecs(), maxDateMs);

QCOMPARE(minimumDateChangedSpy.count(), 3);
QCOMPARE(maximumDateChangedSpy.count(), 3);
QCOMPARE(minimumDateMsecsChangedSpy.count(), 3);
QCOMPARE(maximumDateMsecsChangedSpy.count(), 3);
QCOMPARE(validDateChangedSpy.count(), 6);

// Since we default to the current date, the date should be valid
QVERIFY(backend.validDate());

// Now try with invalid dates
backend.setDate(invalidMinDate);
QVERIFY(!backend.validDate());
QCOMPARE(validDateChangedSpy.count(), 7);

backend.setDate(invalidMaxDate);
QVERIFY(!backend.validDate());
QCOMPARE(validDateChangedSpy.count(), 8);
}
};

Expand Down

0 comments on commit 877536f

Please sign in to comment.