Skip to content

Commit

Permalink
test: remove test configs after completion
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenvukhang committed Feb 6, 2023
1 parent 7bd42b0 commit 6f3c468
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
25 changes: 14 additions & 11 deletions test/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

QTEST_MAIN(TestGui)

void TestGui::authenticate()
void TestGui::authenticate(MainWindow *app)
{
QPushButton *change_token = app.ui->pushButton_changeToken;
QPushButton *change_token = app->ui->pushButton_changeToken;
QTest::mouseClick(change_token, Qt::MouseButton::LeftButton);
QTest::keyClicks(app.ui->lineEdit_accessToken, "valid");
QTest::keyClicks(app->ui->lineEdit_accessToken, "valid");
}

void TestGui::access_token_entry_test()
{
QSignalSpy auth_tries(app.canvas, &ICanvas::authenticate_done);
MainWindow *app = create_app();
QSignalSpy auth_tries(app->canvas, &ICanvas::authenticate_done);

QPushButton *change_token = app.ui->pushButton_changeToken;
QPushButton *change_token = app->ui->pushButton_changeToken;

// click on "Change Token"
QTest::mouseClick(change_token, Qt::MouseButton::LeftButton);
Expand All @@ -23,18 +24,19 @@ void TestGui::access_token_entry_test()
QVERIFY(change_token->isHidden());

// enter a valid token
QTest::keyClicks(app.ui->lineEdit_accessToken, "valid");
QTest::keyClicks(app->ui->lineEdit_accessToken, "valid");

QCOMPARE(auth_tries.count(), 5);

QCOMPARE(app.ui->label_authenticationStatus->text(), "authenticated!");
QCOMPARE(app->ui->label_authenticationStatus->text(), "authenticated!");
QVERIFY(change_token->isEnabled());
QVERIFY(!change_token->isHidden());
}

void TestGui::fetch_courses_test()
{
authenticate();
MainWindow *app = create_app();
authenticate(app);
std::string expected[] = {
"#0|Linear Algebra: {\n"
" #20010|course files: {\n"
Expand All @@ -56,15 +58,16 @@ void TestGui::fetch_courses_test()
" }\n"
"}",
};
for (auto t : app.course_trees)
for (auto t : app->course_trees)
QCOMPARE(QString(t.to_string().c_str()), QString(expected[t.id].c_str()));
}

void TestGui::fetch_courses_ui_test()
{
authenticate();
MainWindow *app = create_app();
authenticate(app);

TreeModel *model = app.ui->treeView->model();
TreeModel *model = app->ui->treeView->model();
QCOMPARE(model->childrenCount(), 3);

TreeIndex ptr = model->index(0, 0);
Expand Down
31 changes: 26 additions & 5 deletions test/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,44 @@
#include "fake_canvas.h"

#include <algorithm>
#include <filesystem>
#include <mutex>
#include <vector>

class TestGui : public QObject
{
Q_OBJECT
int id = 1;
std::mutex id_mtx;
std::vector<QString> tmp_settings;

public:
TestGui() : app(new FakeCanvas(), "canvas-sync-test.ini"){};

MainWindow app;

// convenience routines
void authenticate();
void authenticate(MainWindow *app);
MainWindow *create_app()
{
return new MainWindow(new FakeCanvas(), settings_file());
}
QString settings_file()
{
this->id_mtx.lock();
QString result = QString("canvas-sync-test-%1.ini").arg(this->id++);
tmp_settings.push_back(MainWindow::settings_path + '/' + result);
this->id_mtx.unlock();
return result;
}

private slots: // tests
void access_token_entry_test();
void fetch_courses_test();
void fetch_courses_ui_test();
void cleanupTestCase()
{
this->id_mtx.lock();
for (auto i : this->tmp_settings)
std::filesystem::remove(i.toStdString());
this->id_mtx.unlock();
};
};

#endif

0 comments on commit 6f3c468

Please sign in to comment.