Commit f5b0973c authored by Adriaan de Groot's avatar Adriaan de Groot 💬 Committed by Albert Astals Cid
Browse files

autotests: validate that KFormat does what the test expects

The test is checking for specific formatting, so before
failing in the widget-text tests, validate that KFormat
returns "Yesterday, ..." as text for a date that was yesterday.

(Spoiler alert: it does not)
parent 20b8adcd
......@@ -6,6 +6,9 @@
#include "filemetadatadatedisplaytest.h"
// This is an implementation detail of how dates are returned
#include <KFormat>
#include <QDateTime>
#include <QLabel>
#include <QMetaType>
......@@ -44,6 +47,24 @@ void FileMetadataDateDisplayTest::initTestCase()
QVERIFY(setFileTime(QFINDTESTDATA("samplefiles/testtagged.mp3"), QDateTime::currentDateTime().addYears(-10)));
}
void FileMetadataDateDisplayTest::validateDateFormats()
{
auto yesterday = QDateTime::currentDateTime().addDays(-1);
auto long_ago = QDateTime::currentDateTime().addYears(-10);
// This tests only the "short form" regular expressions also found in shouldDisplayLongAndShortDates_data()
auto yesterday_re = QRegularExpression(QStringLiteral("Yesterday, (?:[1-2][0-9]|[1-9]):[0-5][0-9] [AP]M"));
auto long_ago_re = QRegularExpression(QStringLiteral("(?:[1-3][0-9]|[1-9]) (?:[1-2][0-9]|[1-9]):[0-5][0-9] [AP]M"));
KFormat form;
auto yesterday_s = form.formatRelativeDateTime(yesterday, QLocale::ShortFormat);
auto long_ago_s = form.formatRelativeDateTime(long_ago, QLocale::ShortFormat);
QVERIFY(yesterday_re.match(yesterday_s).hasMatch());
QVERIFY(long_ago_re.match(long_ago_s).hasMatch());
}
void FileMetadataDateDisplayTest::shouldDisplayLongAndShortDates_data()
{
QTest::addColumn<Baloo::DateFormats>("format");
......
/*
SPDX-FileCopyrightText: 2018 Michael Heidelbach <ottwolt@gmail.com>
SPDX-FileCopyrightText: 2022 Adriaan de Groot <groot@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
......@@ -18,6 +19,9 @@ class FileMetadataDateDisplayTest : public QObject
private Q_SLOTS:
void initTestCase();
/// Validate that KFormat produces the expected date strings
void validateDateFormats();
void shouldDisplayLongAndShortDates();
void shouldDisplayLongAndShortDates_data();
......
Supports Markdown
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