Skip to content

Commit

Permalink
Add a test for the various ways of setting a date on datefieldbackend
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
  • Loading branch information
claucambra committed Sep 12, 2023
1 parent 877536f commit 4f6d963
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions test/testdatefieldbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ class TestDateFieldBackend : public QObject
{
Q_OBJECT

private:
static constexpr auto dateStringFormat = "dd/MM/yyyy";

private slots:
void testDefaultBehaviour()
{
constexpr auto dateStringFormat = "dd/MM/yyyy";

Quick::DateFieldBackend backend;
backend._dateFormat = dateStringFormat;

Expand Down Expand Up @@ -101,6 +102,49 @@ private slots:
QVERIFY(!backend.validDate());
QCOMPARE(validDateChangedSpy.count(), 8);
}

void testDateSettingMethods()
{
Quick::DateFieldBackend backend;

QSignalSpy dateChangedSpy(&backend, &Quick::DateFieldBackend::dateChanged);
QSignalSpy dateMsecsChangedSpy(&backend, &Quick::DateFieldBackend::dateMsecsChanged);
QSignalSpy dateStringChangedSpy(&backend, &Quick::DateFieldBackend::dateStringChanged);

const auto testDate = QDate::currentDate().addDays(800);
const auto testDateMsecs = testDate.startOfDay(Qt::UTC).toMSecsSinceEpoch();
const auto testDateString = testDate.toString(dateStringFormat);

backend.setDate(testDate);
QCOMPARE(backend.date(), testDate);
QCOMPARE(dateChangedSpy.count(), 1);
QCOMPARE(dateMsecsChangedSpy.count(), 1);
QCOMPARE(dateStringChangedSpy.count(), 1);

backend.setDate({});
QVERIFY(backend.date() != testDate);
QCOMPARE(dateChangedSpy.count(), 2);
QCOMPARE(dateMsecsChangedSpy.count(), 2);
QCOMPARE(dateStringChangedSpy.count(), 2);

backend.setDateMsecs(testDateMsecs);
QCOMPARE(backend.date(), testDate);
QCOMPARE(dateChangedSpy.count(), 3);
QCOMPARE(dateMsecsChangedSpy.count(), 3);
QCOMPARE(dateStringChangedSpy.count(), 3);

backend.setDate({});
QVERIFY(backend.date() != testDate);
QCOMPARE(dateChangedSpy.count(), 4);
QCOMPARE(dateMsecsChangedSpy.count(), 4);
QCOMPARE(dateStringChangedSpy.count(), 4);

backend.setDateString(testDateString);
QCOMPARE(backend.date(), testDate);
QCOMPARE(dateChangedSpy.count(), 5);
QCOMPARE(dateMsecsChangedSpy.count(), 5);
QCOMPARE(dateStringChangedSpy.count(), 5);
}
};

QTEST_MAIN(TestDateFieldBackend)
Expand Down

0 comments on commit 4f6d963

Please sign in to comment.