>From b67e7d5b47f874f142d6d782492737be1bc9e222 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 4 Mar 2015 13:31:44 +0100 Subject: [PATCH 1/2] Change the "Date of Birth" field in the default update test. This field, unlike the previously used "MEC avoidance" one, is present in all the skins and so allows the test to pass with all of them. Also avoid hard coding the exact location of the field, which is skin-dependent, but rather locate it by name using the recently added wx_test_focus_controller_child(). --- wx_test_default_update.cpp | 100 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 79 insertions(+), 21 deletions(-) diff --git a/wx_test_default_update.cpp b/wx_test_default_update.cpp index 8c6210d..16c66fd 100644 --- a/wx_test_default_update.cpp +++ b/wx_test_default_update.cpp @@ -30,8 +30,12 @@ #include "configurable_settings.hpp" #include "mvc_controller.hpp" #include "wx_test_case.hpp" +#include "wx_test_new.hpp" #include "wx_test_statusbar.hpp" +#include +#include +#include #include #include @@ -41,8 +45,10 @@ /// /// Load the default input file, using its special command. /// -/// Change its "MEC avoidance" option. This particular option is used -/// because it is available for almost any life insurance product. +/// Change its "DateOfBirth" option. This particular option is used because it +/// is available for any life insurance product as the date of birth is a field +/// of such central importance. +/// /// Save the changed file; make sure the appropriate message appears /// on the status bar. Make sure the saved file exists in its /// configured directory. @@ -51,11 +57,9 @@ { wxUIActionSimulator ui; - // Change the "MEC avoidance" option in the first page of the defaults - // dialog. ui.Char('t', wxMOD_CONTROL); // "File|Default" - struct change_mec_avoidance_in_defaults_dialog + struct change_dob_in_defaults_dialog :public wxExpectModalBase { virtual int OnInvoked(MvcController* dialog) const @@ -63,23 +67,48 @@ dialog->Show(); wxYield(); - wxUIActionSimulator ui; - - // Go to the first page: as the dialog remembers its last opened - // page, it might not open on it. - ui.Char(WXK_HOME); + wxWindow* const dob_window = wx_test_focus_controller_child + (*dialog + ,"DateOfBirth" + ); + + // We need to ensure that the "Date Of Birthday" field is enabled + // by triggering the value of "Use Date Of Birthday" if necessary. + wxWindow* const usedob_window = wx_test_focus_controller_child + (*dialog + ,"UseDOB" + ); + + if (!dob_window->IsEnabled()) + { + ToggleUseDOB(usedob_window); + } + + // Entering the target date into a wxDatePickerCtrl using + // wxUIActionSimulator is too difficult: different sequences of + // keys are required depending on the graphical toolkit used and + // also depending on the current locale, so just cheat and put the + // date directly into the control. + wxDatePickerCtrl* const dob = dynamic_cast + (dob_window + ); + LMI_ASSERT_WITH_MSG + (dob + ,"\"DateOfBirth\" field is expected to be a wxDatePickerCtrl" + ); + + dob->SetValue(wxDateTime(13, wxDateTime::Jan, 1956)); wxYield(); - // Select the first button of the "MEC avoidance" radio box. - ui.Char(WXK_TAB); - ui.Char(WXK_TAB); - wxYield(); - - // Change its value: it doesn't matter which button is selected, - // pressing the down arrow will always toggle the selection in a - // radio box with two buttons. - ui.Char(WXK_DOWN); - wxYield(); + // We also need to modify some field interactively to make the + // dialog "notice" that something has changed and even making + // wxDatePickerCtrl dirty is difficult using wxUIActionSimulator as + // it has very different keyboard interfaces under MSW and GTK, so + // reuse the "UseDOB" check or radio box: we don't actually change + // anything by toggling it twice, but doing this updates the value + // of the "DateOfBirth" field as a side effect. + ToggleUseDOB(usedob_window); + ToggleUseDOB(usedob_window); return wxID_OK; } @@ -88,11 +117,40 @@ { return "defaults dialog"; } + + // Helper method toggling the value of the "UseDOB" field which can be + // represented by either a check box or a two element radio box + // depending on the skin used. + static void ToggleUseDOB(wxWindow* usedob_window) + { + wxUIActionSimulator ui; + + if(dynamic_cast(usedob_window)) + { + // Just selecting the other button is sufficient to toggle + // the value of a 2 element radio box under MSW, but under + // GTK we also have to explicitly check it by pressing + // Space or Enter and as it doesn't do anything under MSW, we + // just do it unconditionally to avoid conditional compilation. + ui.Char(WXK_DOWN); + ui.Char(WXK_SPACE); + } + else if(dynamic_cast(usedob_window)) + { + ui.Char(WXK_SPACE); + } + else + { + throw std::runtime_error("\"UseDOB\" field has unknown type"); + } + + wxYield(); + } }; wxTEST_DIALOG (wxYield() - ,change_mec_avoidance_in_defaults_dialog() + ,change_dob_in_defaults_dialog() ); // Save the default document. -- 2.1.0