2021-06-29 17:32:54 +04:00
/*
* ADMC - AD Management Center
*
2022-04-06 15:59:32 +04:00
* Copyright ( C ) 2020 - 2022 BaseALT Ltd .
* Copyright ( C ) 2020 - 2022 Dmitry Degtyarev
2021-06-29 17:32:54 +04:00
*
* 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_object_dialog.h"
2021-06-30 13:29:43 +04:00
# include "admc_test_select_base_widget.h"
2021-08-31 13:54:14 +04:00
# include "console_impls/object_impl.h"
2021-06-30 13:29:43 +04:00
# include "filter_widget/select_base_widget.h"
2021-06-30 14:24:51 +04:00
# include "select_object_dialog.h"
2021-11-04 15:04:38 +04:00
# include "select_object_match_dialog.h"
2021-10-18 12:29:43 +04:00
# include "ui_select_object_dialog.h"
# include "ui_select_object_match_dialog.h"
2021-06-29 17:32:54 +04:00
# include <QLineEdit>
2021-06-30 14:24:51 +04:00
# include <QPushButton>
2021-06-29 17:32:54 +04:00
# include <QTreeView>
void ADMCTestSelectObjectDialog : : init ( ) {
ADMCTest : : init ( ) ;
2021-06-30 13:29:43 +04:00
dialog = new SelectObjectDialog ( { CLASS_USER } , SelectObjectDialogMultiSelection_Yes , parent_widget ) ;
2021-06-29 17:32:54 +04:00
dialog - > open ( ) ;
QVERIFY ( QTest : : qWaitForWindowExposed ( dialog , 1000 ) ) ;
2021-10-18 12:29:43 +04:00
SelectBaseWidget * select_base_widget = dialog - > ui - > select_base_widget ;
2021-06-30 13:29:43 +04:00
select_base_widget_add ( select_base_widget , test_arena_dn ( ) ) ;
2021-10-18 12:29:43 +04:00
edit = dialog - > ui - > name_edit ;
add_button = dialog - > ui - > add_button ;
2021-06-29 17:32:54 +04:00
}
void ADMCTestSelectObjectDialog : : empty ( ) {
const QList < QString > selected = dialog - > get_selected ( ) ;
QVERIFY ( selected . isEmpty ( ) ) ;
}
void ADMCTestSelectObjectDialog : : no_matches ( ) {
const QString dn = test_object_dn ( TEST_USER , CLASS_USER ) ;
const bool create_success = ad . object_add ( dn , CLASS_USER ) ;
QVERIFY ( create_success ) ;
edit - > setText ( " no-match " ) ;
add_button - > click ( ) ;
2021-06-30 13:09:27 +04:00
close_message_box ( ) ;
2021-06-29 17:32:54 +04:00
const QList < QString > selected = dialog - > get_selected ( ) ;
QVERIFY ( selected . isEmpty ( ) ) ;
}
void ADMCTestSelectObjectDialog : : one_match ( ) {
const QString dn = test_object_dn ( TEST_USER , CLASS_USER ) ;
const bool create_success = ad . object_add ( dn , CLASS_USER ) ;
QVERIFY ( create_success ) ;
edit - > setText ( TEST_USER ) ;
add_button - > click ( ) ;
const QList < QString > selected = dialog - > get_selected ( ) ;
2021-10-01 13:20:09 +04:00
QCOMPARE ( selected . size ( ) , 1 ) ;
if ( selected . size ( ) = = 1 ) {
QCOMPARE ( selected [ 0 ] , dn ) ;
}
2021-06-29 17:32:54 +04:00
}
void ADMCTestSelectObjectDialog : : multiple_matches ( ) {
const QString dn1 = test_object_dn ( QString ( TEST_USER ) + " 1 " , CLASS_USER ) ;
const bool create_success1 = ad . object_add ( dn1 , CLASS_USER ) ;
QVERIFY ( create_success1 ) ;
const QString dn2 = test_object_dn ( QString ( TEST_USER ) + " 2 " , CLASS_USER ) ;
const bool create_success2 = ad . object_add ( dn2 , CLASS_USER ) ;
QVERIFY ( create_success2 ) ;
2021-06-30 13:09:27 +04:00
select_object_in_multi_match_dialog ( TEST_USER , dn2 ) ;
const QList < QString > selected = dialog - > get_selected ( ) ;
2021-10-01 14:23:56 +04:00
QCOMPARE ( selected , QList < QString > ( { dn2 } ) ) ;
2021-06-30 13:09:27 +04:00
}
// Adding same object two times should open message box
// warning about duplicate and also not add it twice
void ADMCTestSelectObjectDialog : : one_match_duplicate ( ) {
const QString dn = test_object_dn ( TEST_USER , CLASS_USER ) ;
const bool create_success = ad . object_add ( dn , CLASS_USER ) ;
QVERIFY ( create_success ) ;
edit - > setText ( TEST_USER ) ;
add_button - > click ( ) ;
const QList < QString > selected_first = dialog - > get_selected ( ) ;
2021-10-01 14:23:56 +04:00
QCOMPARE ( selected_first , QList < QString > ( { dn } ) ) ;
2021-06-30 13:09:27 +04:00
2021-06-29 17:32:54 +04:00
edit - > setText ( TEST_USER ) ;
2021-06-30 13:09:27 +04:00
add_button - > click ( ) ;
close_message_box ( ) ;
const QList < QString > selected_second = dialog - > get_selected ( ) ;
2021-10-01 14:23:56 +04:00
QCOMPARE ( selected_second , QList < QString > ( { dn } ) ) ;
2021-06-30 13:09:27 +04:00
}
// Duplicates should also be processed for multiple match
// case
void ADMCTestSelectObjectDialog : : multiple_match_duplicate ( ) {
const QString dn1 = test_object_dn ( QString ( TEST_USER ) + " 1 " , CLASS_USER ) ;
const bool create_success1 = ad . object_add ( dn1 , CLASS_USER ) ;
QVERIFY ( create_success1 ) ;
const QString dn2 = test_object_dn ( QString ( TEST_USER ) + " 2 " , CLASS_USER ) ;
const bool create_success2 = ad . object_add ( dn2 , CLASS_USER ) ;
QVERIFY ( create_success2 ) ;
select_object_in_multi_match_dialog ( TEST_USER , dn2 ) ;
2021-06-30 14:24:51 +04:00
2021-06-30 13:09:27 +04:00
const QList < QString > selected_first = dialog - > get_selected ( ) ;
2021-10-01 14:23:56 +04:00
QCOMPARE ( selected_first , QList < QString > ( { dn2 } ) ) ;
2021-06-30 13:09:27 +04:00
select_object_in_multi_match_dialog ( TEST_USER , dn2 ) ;
const QList < QString > selected_second = dialog - > get_selected ( ) ;
2021-10-01 14:23:56 +04:00
QCOMPARE ( selected_second , QList < QString > ( { dn2 } ) ) ;
2021-06-30 13:09:27 +04:00
}
void ADMCTestSelectObjectDialog : : select_object_in_multi_match_dialog ( const QString & name , const QString & dn ) {
edit - > setText ( name ) ;
2021-06-29 17:32:54 +04:00
add_button - > click ( ) ;
auto match_dialog = dialog - > findChild < SelectObjectMatchDialog * > ( ) ;
2021-10-01 14:23:56 +04:00
QVERIFY ( match_dialog ) ;
2021-06-29 17:32:54 +04:00
2021-10-18 12:29:43 +04:00
QTreeView * match_dialog_view = match_dialog - > ui - > view ;
2021-06-29 17:32:54 +04:00
2021-06-30 13:09:27 +04:00
wait_for_find_results_to_load ( match_dialog_view ) ;
navigate_until_object ( match_dialog_view , dn , ObjectRole_DN ) ;
2021-06-29 17:32:54 +04:00
2021-10-18 12:29:43 +04:00
match_dialog - > accept ( ) ;
2021-06-29 17:32:54 +04:00
2021-06-30 13:09:27 +04:00
close_message_box ( ) ;
2021-06-29 17:32:54 +04:00
}
QTEST_MAIN ( ADMCTestSelectObjectDialog )