1
0
mirror of https://github.com/altlinux/admc.git synced 2025-01-08 01:18:25 +03:00

add test for select classes widget

This commit is contained in:
Dmitry Degtyarev 2022-01-18 12:04:19 +04:00
parent b3ded130f8
commit e2289c80d3
4 changed files with 159 additions and 0 deletions

View File

@ -111,6 +111,7 @@ Tests for ADMC
%_bindir/admc_test_find_object_dialog
%_bindir/admc_test_rename_object_dialog
%_bindir/admc_test_create_object_dialog
%_bindir/admc_test_select_classes_widget
%changelog
* %(LC_TIME=C date "+%%a %%b %%d %%Y") %{?package_signer:%package_signer}%{!?package_signer:%packager} %version-%release

View File

@ -70,6 +70,7 @@ set(TEST_TARGETS
admc_test_find_object_dialog
admc_test_rename_object_dialog
admc_test_create_object_dialog
admc_test_select_classes_widget
)
foreach(target ${TEST_TARGETS})

View File

@ -0,0 +1,112 @@
/*
* ADMC - AD Management Center
*
* Copyright (C) 2020-2021 BaseALT Ltd.
* Copyright (C) 2020-2021 Dmitry Degtyarev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "admc_test_select_classes_widget.h"
#include "filter_widget/select_classes_widget.h"
#include "filter_widget/ui_select_classes_widget.h"
#include "filter_widget/class_filter_dialog.h"
#include "filter_widget/ui_class_filter_dialog.h"
void ADMCTestSelectClassesWidget::init() {
ADMCTest::init();
select_classes_widget = new SelectClassesWidget();
select_classes_widget->set_classes(filter_classes, filter_classes);
select_classes_widget->enable_filtering_all_classes();
add_widget(select_classes_widget);
select_button = select_classes_widget->ui->select_button;
classes_display = select_classes_widget->ui->classes_display;
}
void ADMCTestSelectClassesWidget::test_foo_data() {
QTest::addColumn<bool>("all_checked");
QTest::addColumn<QList<QString>>("specific_classes_checked");
QTest::addColumn<QString>("correct_display_string");
QTest::addColumn<QString>("correct_filter");
QTest::newRow("all only") << true << QList<QString>() << "All" << "";
// NOTE: all should override other checkboxes, even
// if they are checked
QTest::newRow("all + some specific") << true << QList<QString>({"User", "Group"}) << "All" << "";
QTest::newRow("User") << false << QList<QString>({"User"}) << "User" << "(objectClass=user)";
QTest::newRow("User + Group") << false << QList<QString>({"User", "Group"}) << "Group, User" << "(|(objectClass=user)(objectClass=group))";
}
void ADMCTestSelectClassesWidget::test_foo() {
QFETCH(bool, all_checked);
QFETCH(QList<QString>, specific_classes_checked);
QFETCH(QString, correct_display_string);
QFETCH(QString, correct_filter);
auto check_output_correctness = [&]() {
QCOMPARE(classes_display->text(), correct_display_string);
QCOMPARE(select_classes_widget->get_filter(), correct_filter);
};
auto get_class_checkbox_list = [](ClassFilterDialog *dialog) {
ClassFilterWidget * class_filter_widget = dialog->ui->class_filter_widget;
const QList<QCheckBox *> out = class_filter_widget->findChildren<QCheckBox *>();
return out;
};
// Check correctness of input->output
select_button->click();
ClassFilterDialog *class_filter_dialog = select_classes_widget->findChild<ClassFilterDialog *>();
QVERIFY(class_filter_dialog);
QVERIFY(QTest::qWaitForWindowExposed(class_filter_dialog, 1000));
QCheckBox *all_checkbox = class_filter_dialog->ui->all_checkbox;
all_checkbox->setChecked(all_checked);
const QList<QCheckBox *> class_checkbox_list = get_class_checkbox_list(class_filter_dialog);
for (QCheckBox *check : class_checkbox_list) {
const bool match = specific_classes_checked.contains(check->text());
check->setChecked(match);
}
class_filter_dialog->accept();
check_output_correctness();
// Check state saving/restoring
const QVariant state = select_classes_widget->save_state();
select_classes_widget->restore_state(state);
check_output_correctness();
// Check that reopening dialog retains state
select_button->click();
ClassFilterDialog *class_filter_dialog_2 = select_classes_widget->findChild<ClassFilterDialog *>();
QVERIFY(class_filter_dialog_2);
QVERIFY(QTest::qWaitForWindowExposed(class_filter_dialog_2, 1000));
class_filter_dialog_2->accept();
check_output_correctness();
}
QTEST_MAIN(ADMCTestSelectClassesWidget)

View File

@ -0,0 +1,45 @@
/*
* ADMC - AD Management Center
*
* Copyright (C) 2020-2021 BaseALT Ltd.
* Copyright (C) 2020-2021 Dmitry Degtyarev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ADMC_TEST_SELECT_CLASSES_WIDGET_H
#define ADMC_TEST_SELECT_CLASSES_WIDGET_H
#include "admc_test.h"
class SelectClassesWidget;
class QPushButton;
class QLineEdit;
class ADMCTestSelectClassesWidget : public ADMCTest {
Q_OBJECT
private slots:
void init() override;
void test_foo_data();
void test_foo();
private:
SelectClassesWidget *select_classes_widget;
QPushButton *select_button;
QLineEdit *classes_display;
};
#endif /* ADMC_TEST_SELECT_CLASSES_WIDGET_H */