File indexing completed on 2024-11-24 05:13:18

0001 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 #include <QSignalSpy>
0005 #include <QtTest/QtTest>
0006 
0007 #include <controller.h>
0008 
0009 class ControllerTest : public QObject
0010 {
0011     Q_OBJECT
0012 
0013 private Q_SLOTS:
0014     void initTestCase()
0015     {
0016     }
0017 
0018     void testToggle()
0019     {
0020         Controller controller;
0021         QVERIFY(!controller.running());
0022         QCOMPARE(controller.text(), QStringLiteral("25:00"));
0023 
0024         controller.start();
0025         QVERIFY(controller.running());
0026         QCOMPARE(controller.text(), QStringLiteral("25:00"));
0027 
0028         controller.toggle();
0029         QVERIFY(!controller.running());
0030 
0031         controller.toggle();
0032         QVERIFY(controller.running());
0033 
0034         controller.reset();
0035         QVERIFY(!controller.running());
0036         QCOMPARE(controller.text(), QStringLiteral("25:00"));
0037     }
0038 
0039     void testUpdate()
0040     {
0041         Config::self()->setIntervalTime(1);
0042 
0043         Controller controller;
0044         controller.setMinuteDuration(3);
0045         QVERIFY(!controller.running());
0046 
0047         controller.start();
0048         QVERIFY(controller.running());
0049         QCOMPARE(controller.text(), QStringLiteral("01:00"));
0050 
0051         QSignalSpy spy(&controller, &Controller::textChanged);
0052         spy.wait(5000);
0053         QCOMPARE(controller.text(), QStringLiteral("00:02"));
0054 
0055         QSignalSpy spy2(&controller, &Controller::textChanged);
0056         spy.wait(5000);
0057         QCOMPARE(controller.text(), QStringLiteral("00:01"));
0058 
0059         QSignalSpy spy3(&controller, &Controller::textChanged);
0060         spy.wait(5000);
0061         QCOMPARE(controller.text(), QStringLiteral("00:00"));
0062 
0063         QSignalSpy spy4(&controller, &Controller::textChanged);
0064         spy.wait(5000);
0065         QCOMPARE(controller.text(), QStringLiteral("00:14"));
0066         QVERIFY(controller.onBreak());
0067     }
0068 };
0069 
0070 QTEST_MAIN(ControllerTest)
0071 #include "controllertest.moc"