diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp index d9d8c9b51e417e5398427e3d7e827e5ea6e3af9d..3fa244e4874d7901ed0b94b2e51c50e7e31e1ed5 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp @@ -128,14 +128,19 @@ bool MainWindowPresenter::isAnyBatchAutoreducing() const { } void MainWindowPresenter::addNewBatch(IBatchView *batchView) { + // Remember the instrument name so we can re-set it (it will otherwise + // get overridden by the instrument list default in the new batch) + auto const instrument = instrumentName(); m_batchPresenters.emplace_back(m_batchPresenterFactory->make(batchView)); m_batchPresenters.back()->acceptMainPresenter(this); - initNewBatch(m_batchPresenters.back().get()); + initNewBatch(m_batchPresenters.back().get(), instrument); } -void MainWindowPresenter::initNewBatch(IBatchPresenter *batchPresenter) { +void MainWindowPresenter::initNewBatch(IBatchPresenter *batchPresenter, + std::string const &instrument) { batchPresenter->initInstrumentList(); + batchPresenter->notifyInstrumentChanged(instrument); // starts in the paused state batchPresenter->reductionPaused(); diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h index aac7bed1ba97cde42da00a571c1e72cd3e5c6b4a..89c4e491cdf7a4c167880d19e1a1d79265e10609 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h @@ -72,7 +72,8 @@ private: void showHelp(); void addNewBatch(IBatchView *batchView); - void initNewBatch(IBatchPresenter *batchPresenter); + void initNewBatch(IBatchPresenter *batchPresenter, + std::string const &instrument); void changeInstrument(std::string const &instrumentName); void updateInstrument(const std::string &instrumentName); diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/QtMainWindowView.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/QtMainWindowView.cpp index ae99ce4ac6464cb262f979a74e6a3bcf27978272..b37a149bb24a569aa4c5c85c7d0128a1c3238d03 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/QtMainWindowView.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/QtMainWindowView.cpp @@ -87,11 +87,10 @@ void QtMainWindowView::initLayout() { auto makeRunsTablePresenter = RunsTablePresenterFactory( instruments, thetaTolerance, std::move(plotter)); - auto defaultInstrumentIndex = getDefaultInstrumentIndex(instruments); auto messageHandler = this; auto makeRunsPresenter = RunsPresenterFactory(std::move(makeRunsTablePresenter), thetaTolerance, - instruments, defaultInstrumentIndex, messageHandler); + instruments, messageHandler); auto makeEventPresenter = EventPresenterFactory(); auto makeSaveSettingsPresenter = SavePresenterFactory(); diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/IRunsView.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/IRunsView.h index 9f3fe08b875c34c5d6a96bd33f4587803aef9728..cccfd0b683704775530f435f1a2a58b6b9f94062 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/IRunsView.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/IRunsView.h @@ -80,8 +80,8 @@ public: virtual ISearchModel &mutableSearchResults() = 0; // Setter methods - virtual void setInstrumentList(const std::vector<std::string> &instruments, - int defaultInstrumentIndex) = 0; + virtual void + setInstrumentList(const std::vector<std::string> &instruments) = 0; virtual void updateMenuEnabledState(bool isProcessing) = 0; virtual void setAutoreduceButtonEnabled(bool enabled) = 0; virtual void setAutoreducePauseButtonEnabled(bool enabled) = 0; diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/QtRunsView.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/QtRunsView.cpp index a30614271bf254dda18fa990a29bfeb749b25147..f891cede32d207c67e33b4e8f8d99332f3b03f86 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/QtRunsView.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/QtRunsView.cpp @@ -171,11 +171,10 @@ void QtRunsView::setStopMonitorButtonEnabled(bool enabled) { Set the list of available instruments to search for and updates the list of available instruments in the table view @param instruments : The list of instruments available -@param defaultInstrumentIndex : The index of the instrument to have selected by default */ -void QtRunsView::setInstrumentList(const std::vector<std::string> &instruments, - int defaultInstrumentIndex) { +void QtRunsView::setInstrumentList( + const std::vector<std::string> &instruments) { m_ui.comboSearchInstrument->clear(); for (auto &&instrument : instruments) m_ui.comboSearchInstrument->addItem(QString::fromStdString(instrument)); diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/QtRunsView.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/QtRunsView.h index 55c9c69e8a104fad9b71bd995c464d040912330d..b8894c94fe1f26413a339c7757031ca4324c20bd 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/QtRunsView.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/QtRunsView.h @@ -51,8 +51,7 @@ public: ISearchModel &mutableSearchResults() override; // Setter methods - void setInstrumentList(const std::vector<std::string> &instruments, - int defaultInstrumentIndex) override; + void setInstrumentList(const std::vector<std::string> &instruments) override; void updateMenuEnabledState(bool isProcessing) override; void setAutoreduceButtonEnabled(bool enabled) override; void setAutoreducePauseButtonEnabled(bool enabled) override; diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.cpp index 89b1ed1a4d74b0083ffc21faa1117e88ae8eb720..9cbf9d2dcb3ce335884adda129db435c5546b1ad 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.cpp @@ -40,22 +40,18 @@ namespace ISISReflectometry { * summed in a reduction. * @param instruments The names of the instruments to show as options for the * search. - * @param defaultInstrumentIndex The index of the instrument to have selected by - * default. * @param messageHandler :: A handler to pass messages to the user */ RunsPresenter::RunsPresenter( IRunsView *mainView, ProgressableView *progressableView, const RunsTablePresenterFactory &makeRunsTablePresenter, double thetaTolerance, std::vector<std::string> const &instruments, - int defaultInstrumentIndex, IMessageHandler *messageHandler) + IMessageHandler *messageHandler) : m_runNotifier(std::make_unique<CatalogRunNotifier>(mainView)), m_searcher(std::make_unique<QtCatalogSearcher>(mainView)), m_view(mainView), m_progressView(progressableView), m_mainPresenter(nullptr), m_messageHandler(messageHandler), - m_instruments(instruments), - m_defaultInstrumentIndex(defaultInstrumentIndex), - m_thetaTolerance(thetaTolerance) { + m_instruments(instruments), m_thetaTolerance(thetaTolerance) { assert(m_view != nullptr); m_view->subscribe(this); @@ -80,8 +76,7 @@ void RunsPresenter::acceptMainPresenter(IBatchPresenter *mainPresenter) { } void RunsPresenter::initInstrumentList() { - m_view->setInstrumentList(m_instruments, m_defaultInstrumentIndex); - m_view->setSearchInstrument(m_mainPresenter->instrumentName()); + m_view->setInstrumentList(m_instruments); } RunsTable const &RunsPresenter::runsTable() const { diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.h index 26bff04c749c34775771235f789d66c0ad0c5e7a..25233dadf10d17e644feae155da9532f09daf2ea 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.h @@ -59,7 +59,7 @@ public: const RunsTablePresenterFactory &makeRunsTablePresenter, double thetaTolerance, std::vector<std::string> const &instruments, - int defaultInstrumentIndex, IMessageHandler *messageHandler); + IMessageHandler *messageHandler); RunsPresenter(RunsPresenter const &) = delete; ~RunsPresenter() override; RunsPresenter const &operator=(RunsPresenter const &) = delete; @@ -136,8 +136,6 @@ private: IMessageHandler *m_messageHandler; /// The list of instruments std::vector<std::string> m_instruments; - /// The default index in the instrument list - int m_defaultInstrumentIndex; /// The tolerance used when looking up settings by theta double m_thetaTolerance; diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenterFactory.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenterFactory.h index 23a73f39ef08ee3e957c06ed81a905e4aced22f7..710885170246a11e0eadada055ccae64002d7533 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenterFactory.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenterFactory.h @@ -23,24 +23,22 @@ public: RunsPresenterFactory( // cppcheck-suppress passedByValue RunsTablePresenterFactory runsTablePresenterFactory, double thetaTolerance, std::vector<std::string> instruments, - int defaultInstrumentIndex, IMessageHandler *messageHandler) + IMessageHandler *messageHandler) : m_runsTablePresenterFactory(std::move(runsTablePresenterFactory)), m_thetaTolerance(std::move(thetaTolerance)), m_instruments(std::move(instruments)), - m_defaultInstrumentIndex(std::move(defaultInstrumentIndex)), m_messageHandler(messageHandler) {} std::unique_ptr<IRunsPresenter> make(IRunsView *view) { return std::make_unique<RunsPresenter>( view, view, m_runsTablePresenterFactory, m_thetaTolerance, - m_instruments, m_defaultInstrumentIndex, m_messageHandler); + m_instruments, m_messageHandler); } private: RunsTablePresenterFactory m_runsTablePresenterFactory; double m_thetaTolerance; std::vector<std::string> m_instruments; - int m_defaultInstrumentIndex; IMessageHandler *m_messageHandler; }; } // namespace ISISReflectometry diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/QtRunsTableView.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/QtRunsTableView.cpp index 3e133f1afc36fe9b6852954cf8e788e093deaeb1..008490c75bedcd3f48e3b12ca1931b89d2db9e50 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/QtRunsTableView.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/QtRunsTableView.cpp @@ -16,8 +16,7 @@ namespace MantidQt { namespace CustomInterfaces { namespace ISISReflectometry { -QtRunsTableView::QtRunsTableView(std::vector<std::string> const &instruments, - int defaultInstrumentIndex) +QtRunsTableView::QtRunsTableView(std::vector<std::string> const &instruments) : m_jobs(), m_instruments(instruments) { m_ui.setupUi(this); m_ui.progressBar->setRange(0, 100); @@ -32,7 +31,6 @@ QtRunsTableView::QtRunsTableView(std::vector<std::string> const &instruments, for (auto &&instrument : m_instruments) m_ui.instrumentSelector->addItem(QString::fromStdString(instrument)); - m_ui.instrumentSelector->setCurrentIndex(defaultInstrumentIndex); connect(m_ui.filterBox, SIGNAL(textChanged(QString const &)), this, SLOT(onFilterChanged(QString const &))); @@ -299,7 +297,7 @@ RunsTableViewFactory::RunsTableViewFactory( : m_instruments(instruments) {} QtRunsTableView *RunsTableViewFactory::operator()() const { - return new QtRunsTableView(m_instruments, defaultInstrumentFromConfig()); + return new QtRunsTableView(m_instruments); } int RunsTableViewFactory::indexOfElseFirst( @@ -310,11 +308,6 @@ int RunsTableViewFactory::indexOfElseFirst( }) .get_value_or(0); } - -int RunsTableViewFactory::defaultInstrumentFromConfig() const { - return indexOfElseFirst(Mantid::Kernel::ConfigService::Instance().getString( - "default.instrument")); -} } // namespace ISISReflectometry } // namespace CustomInterfaces } // namespace MantidQt diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/QtRunsTableView.h b/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/QtRunsTableView.h index 057b880d01cba238c59f428bd71e5ebe022c57c7..0d6cbf4983a9f172fb4615f95332ce68a2dd4f23 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/QtRunsTableView.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/QtRunsTableView.h @@ -22,8 +22,7 @@ class MANTIDQT_ISISREFLECTOMETRY_DLL QtRunsTableView : public QWidget, public IRunsTableView { Q_OBJECT public: - explicit QtRunsTableView(std::vector<std::string> const &instruments, - int defaultInstrumentIndex); + explicit QtRunsTableView(std::vector<std::string> const &instruments); void subscribe(RunsTableViewSubscriber *notifyee) override; void setProgress(int value) override; void resetFilterBox() override; diff --git a/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h index 892f3d48e8e709efa697989dabb43f746ef087e5..fd46fcb305fc806050ebe945b3272510ee2bbba9 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h @@ -284,6 +284,7 @@ private: void expectBatchAdded(MockBatchPresenter *batchPresenter) { EXPECT_CALL(*batchPresenter, acceptMainPresenter(_)).Times(1); EXPECT_CALL(*batchPresenter, initInstrumentList()).Times(1); + EXPECT_CALL(*batchPresenter, notifyInstrumentChanged(_)).Times(1); EXPECT_CALL(*batchPresenter, reductionPaused()).Times(1); EXPECT_CALL(*batchPresenter, anyBatchAutoreductionPaused()).Times(1); } diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Runs/MockRunsView.h b/qt/scientific_interfaces/test/ISISReflectometry/Runs/MockRunsView.h index ea8653a5cbff4bb16cd1621f43e4f6f3864a1587..e81eb749ef99004ef53f03db3b0eb92bf3086f52 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/Runs/MockRunsView.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/Runs/MockRunsView.h @@ -29,7 +29,7 @@ public: MOCK_METHOD0(searchResults, ISearchModel const &()); MOCK_METHOD0(mutableSearchResults, ISearchModel &()); - MOCK_METHOD2(setInstrumentList, void(const std::vector<std::string> &, int)); + MOCK_METHOD1(setInstrumentList, void(const std::vector<std::string> &)); MOCK_METHOD1(updateMenuEnabledState, void(bool)); MOCK_METHOD1(setAutoreduceButtonEnabled, void(bool)); MOCK_METHOD1(setAutoreducePauseButtonEnabled, void(bool)); diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Runs/RunsPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/Runs/RunsPresenterTest.h index 78553edce869801596dc051fb4dbf8774ea9a17e..b09ebf9e819a5e0949efc42d16d7d70a27b14ab6 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/Runs/RunsPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/Runs/RunsPresenterTest.h @@ -71,23 +71,8 @@ public: } void testInitInstrumentListUpdatesView() { - auto const defaultInstrumentIndex = 0; auto presenter = makePresenter(); - EXPECT_CALL(m_view, - setInstrumentList(m_instruments, defaultInstrumentIndex)) - .Times(1); - presenter.initInstrumentList(); - verifyAndClear(); - } - - void testInitInstrumentListSetsCorrectInstrumentInView() { - auto const defaultInstrumentIndex = 0; - auto presenter = makePresenter(); - auto const instrument = std::string("POLREF"); - EXPECT_CALL(m_mainPresenter, instrumentName()) - .Times(1) - .WillOnce(Return(instrument)); - EXPECT_CALL(m_view, setSearchInstrument(instrument)).Times(1); + EXPECT_CALL(m_view, setInstrumentList(m_instruments)).Times(1); presenter.initInstrumentList(); verifyAndClear(); } @@ -594,15 +579,12 @@ private: const RunsTablePresenterFactory &makeRunsTablePresenter, double thetaTolerance, std::vector<std::string> const &instruments, - int defaultInstrumentIndex, IMessageHandler *messageHandler) : RunsPresenter(mainView, progressView, makeRunsTablePresenter, - thetaTolerance, instruments, defaultInstrumentIndex, - messageHandler) {} + thetaTolerance, instruments, messageHandler) {} }; RunsPresenterFriend makePresenter() { - auto const defaultInstrumentIndex = 0; #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) IPythonRunner *pythonRunner = new MockPythonRunner(); Plotter plotter(pythonRunner); @@ -611,9 +593,9 @@ private: #endif auto makeRunsTablePresenter = RunsTablePresenterFactory( m_instruments, m_thetaTolerance, std::move(plotter)); - auto presenter = RunsPresenterFriend( - &m_view, &m_progressView, makeRunsTablePresenter, m_thetaTolerance, - m_instruments, defaultInstrumentIndex, &m_messageHandler); + auto presenter = + RunsPresenterFriend(&m_view, &m_progressView, makeRunsTablePresenter, + m_thetaTolerance, m_instruments, &m_messageHandler); presenter.acceptMainPresenter(&m_mainPresenter); presenter.m_tablePresenter.reset(new NiceMock<MockRunsTablePresenter>()); diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Runs/RunsPresenterTest.h.orig b/qt/scientific_interfaces/test/ISISReflectometry/Runs/RunsPresenterTest.h.orig deleted file mode 100644 index 5e19fe613646345a311580273cd60e32827d0569..0000000000000000000000000000000000000000 --- a/qt/scientific_interfaces/test/ISISReflectometry/Runs/RunsPresenterTest.h.orig +++ /dev/null @@ -1,958 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source -// & Institut Laue - Langevin -// SPDX - License - Identifier: GPL - 3.0 + -#ifndef MANTID_CUSTOMINTERFACES_RUNSPRESENTERTEST_H -#define MANTID_CUSTOMINTERFACES_RUNSPRESENTERTEST_H - -#include "../../../ISISReflectometry/GUI/Runs/RunsPresenter.h" -#include "../../../ISISReflectometry/Reduction/RunsTable.h" -#include "../../../ISISReflectometry/TestHelpers/ModelCreationHelper.h" -#include "../ReflMockObjects.h" -#include "../RunsTable/MockRunsTablePresenter.h" -#include "../RunsTable/MockRunsTableView.h" -#include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/FrameworkManager.h" -#include "MantidDataObjects/TableWorkspace.h" -#include "MantidKernel/ConfigService.h" -#include "MantidQtWidgets/Common/Batch/MockJobTreeView.h" -#include "MantidQtWidgets/Common/MockAlgorithmRunner.h" -#include "MantidQtWidgets/Common/MockProgressableView.h" -#include "MockRunsView.h" -#include <cxxtest/TestSuite.h> -#include <gmock/gmock.h> -#include <gtest/gtest.h> - -using namespace MantidQt::CustomInterfaces::ISISReflectometry; -using namespace MantidQt::CustomInterfaces::ISISReflectometry:: - ModelCreationHelper; -using Mantid::DataObjects::TableWorkspace; -using testing::AtLeast; -using testing::Mock; -using testing::NiceMock; -using testing::Return; -using testing::ReturnRef; -using testing::_; - -//===================================================================================== -// Functional tests -//===================================================================================== -class RunsPresenterTest : public CxxTest::TestSuite { -public: - // This pair of boilerplate methods prevent the suite being created statically - // This means the constructor isn't called when running other tests - static RunsPresenterTest *createSuite() { return new RunsPresenterTest(); } - static void destroySuite(RunsPresenterTest *suite) { delete suite; } - - RunsPresenterTest() - : m_thetaTolerance(0.01), m_instruments{"INTER", "SURF", "CRISP", - "POLREF", "OFFSPEC"}, - m_view(), m_runsTableView(), m_progressView(), m_messageHandler(), - m_searcher(nullptr), m_pythonRunner(), m_runNotifier(nullptr), - m_runsTable(m_instruments, m_thetaTolerance, ReductionJobs()), - m_searchString("test search string"), m_searchResult("", "", "") { - Mantid::API::FrameworkManager::Instance(); - ON_CALL(m_view, table()).WillByDefault(Return(&m_runsTableView)); - ON_CALL(m_runsTableView, jobs()).WillByDefault(ReturnRef(m_jobs)); - } - - void testCreatePresenterSubscribesToView() { - EXPECT_CALL(m_view, subscribe(_)).Times(1); - auto presenter = makePresenter(); - verifyAndClear(); - } - - void testCreatePresenterGetsRunsTableView() { - EXPECT_CALL(m_view, table()).Times(1); - auto presenter = makePresenter(); - verifyAndClear(); - } - - void testCreatePresenterSetsInstrumentList() { - auto const defaultInstrumentIndex = 0; - EXPECT_CALL(m_view, - setInstrumentList(m_instruments, defaultInstrumentIndex)) - .Times(1); - auto presenter = makePresenter(); - verifyAndClear(); - } - - void testCreatePresenterUpdatesView() { - expectUpdateViewWhenMonitorStopped(); - auto presenter = makePresenter(); - verifyAndClear(); - } - - void testSettingsChanged() { - auto presenter = makePresenter(); - EXPECT_CALL(*m_runsTablePresenter, settingsChanged()).Times(1); - presenter.settingsChanged(); - verifyAndClear(); - } - - void testStartingSearchClearsPreviousResults() { - auto presenter = makePresenter(); - EXPECT_CALL(*m_searcher, reset()).Times(AtLeast(1)); - presenter.notifySearch(); - verifyAndClear(); - } - - void testStartingSearchDisablesSearchInputs() { - auto presenter = makePresenter(); - EXPECT_CALL(*m_searcher, searchInProgress()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(true)); - EXPECT_CALL(m_view, setSearchTextEntryEnabled(false)).Times(1); - EXPECT_CALL(m_view, setSearchButtonEnabled(false)).Times(1); - EXPECT_CALL(m_view, setAutoreduceButtonEnabled(false)).Times(1); - presenter.notifySearch(); - verifyAndClear(); - } - - void testNotifySearchResultsEnablesSearchInputs() { - auto presenter = makePresenter(); - EXPECT_CALL(*m_searcher, searchInProgress()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - EXPECT_CALL(m_view, setSearchTextEntryEnabled(true)).Times(1); - EXPECT_CALL(m_view, setSearchButtonEnabled(true)).Times(1); - EXPECT_CALL(m_view, setAutoreduceButtonEnabled(true)).Times(1); - presenter.notifySearchComplete(); - verifyAndClear(); - } - - void testSearchUsesCorrectSearchProperties() { - auto presenter = makePresenter(); - auto searchString = std::string("test search string"); - auto instrument = std::string("test instrument"); - EXPECT_CALL(m_view, getSearchString()) - .Times(1) - .WillOnce(Return(searchString)); - expectSearchInstrument(instrument); - EXPECT_CALL(*m_searcher, startSearchAsync(searchString, instrument, - ISearcher::SearchType::MANUAL)) - .Times(1); - presenter.notifySearch(); - verifyAndClear(); - } - - void testSearchWithEmptyStringDoesNotStartSearch() { - auto presenter = makePresenter(); - auto searchString = std::string(""); - EXPECT_CALL(m_view, getSearchString()) - .Times(1) - .WillOnce(Return(searchString)); - EXPECT_CALL(*m_searcher, startSearchAsync(_, _, _)).Times(0); - presenter.notifySearch(); - verifyAndClear(); - } - - void testSearchCatalogLoginFails() { - auto presenter = makePresenter(); - EXPECT_CALL(m_view, getSearchString()) - .Times(1) - .WillOnce(Return(m_searchString)); - EXPECT_CALL(*m_searcher, startSearchAsync(m_searchString, _, _)) - .Times(1) - .WillOnce(Return(false)); - EXPECT_CALL(m_messageHandler, - giveUserCritical("Catalog login failed", "Error")) - .Times(1); - presenter.notifySearch(); - verifyAndClear(); - } - - void testSearchSucceeds() { - auto presenter = makePresenter(); - EXPECT_CALL(m_view, getSearchString()) - .Times(1) - .WillOnce(Return(m_searchString)); - EXPECT_CALL(*m_searcher, startSearchAsync(m_searchString, _, _)) - .Times(1) - .WillOnce(Return(true)); - EXPECT_CALL(m_messageHandler, giveUserCritical(_, _)).Times(0); - - presenter.notifySearch(); - verifyAndClear(); - } - - void testNotifyReductionResumed() { - auto presenter = makePresenter(); - EXPECT_CALL(m_mainPresenter, notifyReductionResumed()).Times(AtLeast(1)); - presenter.notifyReductionResumed(); - verifyAndClear(); - } - - void testNotifyReductionPaused() { - auto presenter = makePresenter(); - EXPECT_CALL(m_mainPresenter, notifyReductionPaused()); - presenter.notifyReductionPaused(); - verifyAndClear(); - } - - void testNotifyAutoreductionResumed() { - auto presenter = makePresenter(); - EXPECT_CALL(m_mainPresenter, notifyAutoreductionResumed()); - presenter.notifyAutoreductionResumed(); - verifyAndClear(); - } - - void testNotifyAutoreductionPaused() { - auto presenter = makePresenter(); - EXPECT_CALL(m_mainPresenter, notifyAutoreductionPaused()); - presenter.notifyAutoreductionPaused(); - verifyAndClear(); - } - - const std::string autoReductionSearch = "1120015"; - - void testResumeAutoreductionWithNewSettings() { - auto presenter = makePresenter(); - expectAutoreductionSettingsChanged(); - expectClearExistingTable(); - expectCheckForNewRuns(); - presenter.resumeAutoreduction(); - verifyAndClear(); - } - - void testResumeAutoreductionWithSameSettings() { - auto presenter = makePresenter(); - ON_CALL(m_view, getSearchString()) - .WillByDefault(Return(autoReductionSearch)); - expectAutoreductionSettingsUnchanged(); - expectDoNotClearExistingTable(); - expectCheckForNewRuns(); - presenter.resumeAutoreduction(); - verifyAndClear(); - } - - void testResumeAutoreductionWarnsUserIfTableChanged() { - auto presenter = makePresenter(); - auto runsTable = makeRunsTableWithContent(); - ON_CALL(m_view, getSearchString()) - .WillByDefault(Return(autoReductionSearch)); - expectAutoreductionSettingsChanged(); - expectRunsTableWithContent(runsTable); - expectUserRespondsYes(); - expectCheckForNewRuns(); - presenter.resumeAutoreduction(); - verifyAndClear(); - } - - void testResumeAutoreductionDoesNotWarnUserIfTableEmpty() { - auto presenter = makePresenter(); - ON_CALL(m_view, getSearchString()) - .WillByDefault(Return(autoReductionSearch)); - expectAutoreductionSettingsChanged(); - EXPECT_CALL(m_messageHandler, askUserYesNo(_, _)).Times(0); - expectCheckForNewRuns(); - presenter.resumeAutoreduction(); - verifyAndClear(); - } - - void testResumeAutoreductionCancelledByUserIfTableChanged() { - auto presenter = makePresenter(); - ON_CALL(m_view, getSearchString()) - .WillByDefault(Return(autoReductionSearch)); - auto runsTable = makeRunsTableWithContent(); - expectAutoreductionSettingsChanged(); - expectRunsTableWithContent(runsTable); - expectUserRespondsNo(); - expectDoNotStartAutoreduction(); - presenter.resumeAutoreduction(); - verifyAndClear(); - } - - void testResumeAutoreductionCancelledIfSearchStringIsEmpty() { - auto presenter = makePresenter(); - ON_CALL(m_view, getSearchString()).WillByDefault(Return("")); - auto runsTable = makeRunsTableWithContent(); - expectDoNotStartAutoreduction(); - presenter.resumeAutoreduction(); - verifyAndClear(); - } - - void testAutoreductionResumed() { - auto presenter = makePresenter(); - expectWidgetsEnabledForAutoreducing(); - EXPECT_CALL(*m_runsTablePresenter, autoreductionResumed()).Times(1); - presenter.autoreductionResumed(); - verifyAndClear(); - } - - void testAutoreductionPaused() { - auto presenter = makePresenter(); - EXPECT_CALL(*m_runNotifier, stopPolling()).Times(1); - EXPECT_CALL(*m_runsTablePresenter, autoreductionPaused()).Times(1); - expectWidgetsEnabledForPaused(); - presenter.autoreductionPaused(); - verifyAndClear(); - } - - void testAutoreductionCompleted() { - auto presenter = makePresenter(); - EXPECT_CALL(*m_runNotifier, startPolling()).Times(1); - expectWidgetsEnabledForAutoreducing(); - presenter.autoreductionCompleted(); - verifyAndClear(); - } - - void testAutoreductionDisabledWhenAnotherBatchAutoreducing() { - auto presenter = makePresenter(); - expectAutoreduceButtonDisabledWhenAnotherBatchAutoreducing(); - presenter.anyBatchAutoreductionResumed(); - verifyAndClear(); - } - - void testAutoreductionDisabledWhenAnotherBatchNotAutoreducing() { - auto presenter = makePresenter(); - expectAutoreduceButtonEnabledWhenAnotherBatchNotAutoreducing(); - presenter.anyBatchAutoreductionPaused(); - verifyAndClear(); - } - - void testNotifyCheckForNewRuns() { - auto presenter = makePresenter(); - expectCheckForNewRuns(); - presenter.notifyCheckForNewRuns(); - verifyAndClear(); - } - - void testNotifySearchResultsResizesColumnsWhenNotAutoreducing() { - auto presenter = makePresenter(); - expectIsNotAutoreducing(); - EXPECT_CALL(m_view, resizeSearchResultsColumnsToContents()).Times(1); - presenter.notifySearchComplete(); - verifyAndClear(); - } - - void testNotifySearchResultsDoesNotResizeColumnsWhenAutoreducing() { - auto presenter = makePresenter(); - expectIsAutoreducing(); - EXPECT_CALL(m_view, resizeSearchResultsColumnsToContents()).Times(0); - presenter.notifySearchComplete(); - verifyAndClear(); - } - - void testNotifySearchResultsResumesReductionWhenAutoreducing() { - auto presenter = makePresenter(); - expectIsAutoreducing(); - EXPECT_CALL(m_mainPresenter, notifyReductionResumed()).Times(AtLeast(1)); - presenter.notifySearchComplete(); - verifyAndClear(); - } - - void testNotifySearchResultsTransfersRowsWhenAutoreducing() { - auto presenter = makePresenter(); - expectIsAutoreducing(); - // Transfer some valid rows - auto rowsToTransfer = std::set<int>{0, 1, 2}; - EXPECT_CALL(m_view, getAllSearchRows()) - .Times(1) - .WillOnce(Return(rowsToTransfer)); - auto searchResult = - SearchResult("12345", "Test run th=0.5", "test location"); - for (auto rowIndex : rowsToTransfer) - EXPECT_CALL(*m_searcher, getSearchResult(rowIndex)) - .Times(1) - .WillOnce(ReturnRef(searchResult)); - EXPECT_CALL(m_messageHandler, giveUserCritical(_, _)).Times(0); - presenter.notifySearchComplete(); - verifyAndClear(); - } - - void testTransferWithNoRowsSelected() { - auto presenter = makePresenter(); - auto const selectedRows = std::set<int>({}); - EXPECT_CALL(m_view, getSelectedSearchRows()) - .Times(1) - .WillOnce(Return(selectedRows)); - EXPECT_CALL(m_messageHandler, - giveUserCritical("Please select at least one run to transfer.", - "No runs selected")) - .Times(1); - presenter.notifyTransfer(); - verifyAndClear(); - } - - void testTransferWithAutoreductionRunning() { - auto presenter = makePresenter(); - expectGetValidSearchRowSelection(); - expectIsAutoreducing(); - expectCreateEndlessProgressIndicator(); - presenter.notifyTransfer(); - verifyAndClear(); - } - - void testTransferWithAutoreductionStopped() { - auto presenter = makePresenter(); - expectGetValidSearchRowSelection(); - expectIsNotAutoreducing(); - expectCreatePercentageProgressIndicator(); - presenter.notifyTransfer(); - verifyAndClear(); - } - - void testTransferSetsErrorForInvalidRows() { - auto presenter = makePresenter(); - expectGetValidSearchRowSelection(); - EXPECT_CALL(*m_searcher, setSearchResultError(3, _)).Times(1); - EXPECT_CALL(*m_searcher, setSearchResultError(5, _)).Times(1); - presenter.notifyTransfer(); - verifyAndClear(); - } - -<<<<<<< HEAD - void testTransferUpdatesTablePresenter() { - auto presenter = makePresenter(); - auto expectedJobs = expectGetValidSearchResult(); - EXPECT_CALL(*m_runsTablePresenter, mergeAdditionalJobs(expectedJobs)) - .Times(1); - presenter.notifyTransfer(); - verifyAndClear(); - } - - void testInstrumentChanged() { -======= - void testInstrumentChangedRequestedGetsInstrumentAndNotifiesMainPresenter() { ->>>>>>> Only reset search results when instrument changed - auto presenter = makePresenter(); - auto const instrument = std::string("TEST-instrumnet"); - expectSearchInstrument(instrument); - EXPECT_CALL(m_mainPresenter, notifyInstrumentChangedRequested(instrument)) - .Times(1); - presenter.notifyInstrumentChangedRequested(); - verifyAndClear(); - } - - void testInstrumentChangedRequestedWithGivenNameNotifiesMainPresenter() { - auto presenter = makePresenter(); - auto const instrument = std::string("TEST-instrumnet"); - EXPECT_CALL(m_mainPresenter, notifyInstrumentChangedRequested(instrument)) - .Times(1); - presenter.notifyInstrumentChangedRequested(instrument); - verifyAndClear(); - } - - void testInstrumentChangedUpdatesView() { - auto presenter = makePresenter(); - auto const instrument = std::string("TEST-instrumnet"); - EXPECT_CALL(m_view, setSearchInstrument(instrument)).Times(1); - presenter.notifyInstrumentChanged(instrument); - verifyAndClear(); - } - - void testInstrumentChangedUpdatesChildPresenter() { - auto presenter = makePresenter(); - auto const instrument = std::string("TEST-instrumnet"); - EXPECT_CALL(*m_runsTablePresenter, notifyInstrumentChanged(instrument)) - .Times(1); - presenter.notifyInstrumentChanged(instrument); - verifyAndClear(); - } - - void testInstrumentChangedClearsPreviousSearchResults() { - auto presenter = makePresenter(); - auto const instrument = std::string("TEST-instrumnet"); - EXPECT_CALL(*m_searcher, reset()).Times(1); - presenter.notifyInstrumentChanged(instrument); - verifyAndClear(); - } - - void testNotifyRowStateChanged() { - auto presenter = makePresenter(); - EXPECT_CALL(*m_runsTablePresenter, notifyRowStateChanged()).Times(1); - presenter.notifyRowStateChanged(); - verifyAndClear(); - } - - void testNotifyRowStateChangedItem() { - auto presenter = makePresenter(); - auto row = makeRow(); - EXPECT_CALL(*m_runsTablePresenter, notifyRowStateChanged(_)).Times(1); - presenter.notifyRowStateChanged(row); - verifyAndClear(); - } - - void testNotifyRowOutputsChanged() { - auto presenter = makePresenter(); - EXPECT_CALL(*m_runsTablePresenter, notifyRowOutputsChanged()).Times(1); - presenter.notifyRowOutputsChanged(); - verifyAndClear(); - } - - void testNotifyRowOutputsChangedItem() { - auto presenter = makePresenter(); - auto row = makeRow(); - EXPECT_CALL(*m_runsTablePresenter, notifyRowOutputsChanged(_)).Times(1); - presenter.notifyRowOutputsChanged(row); - verifyAndClear(); - } - - void testPercentCompleteIsRequestedFromMainPresenter() { - auto presenter = makePresenter(); - auto progress = 33; - EXPECT_CALL(m_mainPresenter, percentComplete()) - .Times(1) - .WillOnce(Return(progress)); - TS_ASSERT_EQUALS(presenter.percentComplete(), progress); - verifyAndClear(); - } - - void testStartMonitorStartsAlgorithmRunner() { - auto presenter = makePresenter(); - expectStartingLiveDataSucceeds(); - auto algRunner = expectGetAlgorithmRunner(); - EXPECT_CALL(*algRunner, startAlgorithmImpl(_)).Times(1); - presenter.notifyStartMonitor(); - verifyAndClear(); - } - - void testStartMonitorUpdatesView() { - auto presenter = makePresenter(); - expectStartingLiveDataSucceeds(); - expectUpdateViewWhenMonitorStarting(); - presenter.notifyStartMonitor(); - verifyAndClear(); - } - - void testStartMonitorSetsAlgorithmProperties() { - auto presenter = makePresenter(); - auto instrument = std::string("INTER"); - expectGetLiveDataOptions(instrument); - auto algRunner = expectGetAlgorithmRunner(); - presenter.notifyStartMonitor(); - auto expected = defaultLiveMonitorAlgorithmOptions(instrument); - assertAlgorithmPropertiesContainOptions(expected, algRunner); - verifyAndClear(); - } - - void testStartMonitorSetsDefaultPostProcessingProperties() { - auto presenter = makePresenter(); - auto options = defaultLiveMonitorReductionOptions(); - expectGetLiveDataOptions(options); - auto algRunner = expectGetAlgorithmRunner(); - presenter.notifyStartMonitor(); - assertPostProcessingPropertiesContainOptions(options, algRunner); - verifyAndClear(); - } - - void testStartMonitorSetsUserSpecifiedPostProcessingProperties() { - auto presenter = makePresenter(); - auto options = AlgorithmRuntimeProps{{"Prop1", "val1"}, {"Prop2", "val2"}}; - expectGetLiveDataOptions(options); - auto algRunner = expectGetAlgorithmRunner(); - presenter.notifyStartMonitor(); - assertPostProcessingPropertiesContainOptions(options, algRunner); - verifyAndClear(); - } - - void testStopMonitorUpdatesView() { - auto presenter = makePresenter(); - presenter.m_monitorAlg = - AlgorithmManager::Instance().createUnmanaged("MonitorLiveData"); - expectUpdateViewWhenMonitorStopped(); - presenter.notifyStopMonitor(); - TS_ASSERT_EQUALS(presenter.m_monitorAlg, nullptr); - verifyAndClear(); - } - - void testMonitorNotRunningAfterStartMonitorFails() { - auto presenter = makePresenter(); - auto algRunner = expectGetAlgorithmRunner(); - - // Ideally we should have a mock algorithm but for now just create the real - // one but don't run it so that it will fail to find the results - auto startMonitorAlg = - AlgorithmManager::Instance().createUnmanaged("StartLiveData"); - startMonitorAlg->initialize(); - EXPECT_CALL(*algRunner, getAlgorithm()) - .Times(1) - .WillOnce(Return(startMonitorAlg)); - expectUpdateViewWhenMonitorStopped(); - presenter.notifyStartMonitorComplete(); - verifyAndClear(); - } - -private: - class RunsPresenterFriend : public RunsPresenter { - friend class RunsPresenterTest; - - public: - RunsPresenterFriend(IRunsView *mainView, ProgressableView *progressView, - const RunsTablePresenterFactory &makeRunsTablePresenter, - double thetaTolerance, - std::vector<std::string> const &instruments, - int defaultInstrumentIndex, - IMessageHandler *messageHandler) - : RunsPresenter(mainView, progressView, makeRunsTablePresenter, - thetaTolerance, instruments, defaultInstrumentIndex, - messageHandler) {} - }; - - RunsPresenterFriend makePresenter() { - auto const defaultInstrumentIndex = 0; -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - IPythonRunner *pythonRunner = new MockPythonRunner(); - Plotter plotter(pythonRunner); -#else - Plotter plotter; -#endif - auto makeRunsTablePresenter = RunsTablePresenterFactory( - m_instruments, m_thetaTolerance, std::move(plotter)); - auto presenter = RunsPresenterFriend( - &m_view, &m_progressView, makeRunsTablePresenter, m_thetaTolerance, - m_instruments, defaultInstrumentIndex, &m_messageHandler); - - presenter.acceptMainPresenter(&m_mainPresenter); - presenter.m_tablePresenter.reset(new NiceMock<MockRunsTablePresenter>()); - m_runsTablePresenter = dynamic_cast<NiceMock<MockRunsTablePresenter> *>( - presenter.m_tablePresenter.get()); - presenter.m_runNotifier.reset(new NiceMock<MockRunNotifier>()); - m_runNotifier = dynamic_cast<NiceMock<MockRunNotifier> *>( - presenter.m_runNotifier.get()); - presenter.m_searcher.reset(new NiceMock<MockSearcher>()); - m_searcher = - dynamic_cast<NiceMock<MockSearcher> *>(presenter.m_searcher.get()); - - // Return an empty table by default - ON_CALL(*m_runsTablePresenter, runsTable()) - .WillByDefault(ReturnRef(m_runsTable)); - return presenter; - } - - RunsTable makeRunsTableWithContent() { - auto reductionJobs = oneGroupWithARowModel(); - return RunsTable(m_instruments, m_thetaTolerance, reductionJobs); - } - - void verifyAndClear() { - TS_ASSERT(Mock::VerifyAndClearExpectations(&m_view)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&m_runsTableView)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&m_progressView)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&m_messageHandler)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&m_pythonRunner)); - TS_ASSERT(Mock::VerifyAndClearExpectations(m_runNotifier)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&m_jobs)); - } - - AlgorithmRuntimeProps - defaultLiveMonitorAlgorithmOptions(const std::string &instrument) { - return AlgorithmRuntimeProps{ - {"Instrument", instrument}, - {"OutputWorkspace", "IvsQ_binned_live"}, - {"AccumulationWorkspace", "TOF_live"}, - {"AccumulationMethod", "Replace"}, - {"UpdateEvery", "20"}, - {"PostProcessingAlgorithm", "ReflectometryReductionOneLiveData"}, - {"RunTransitionBehavior", "Restart"}, - }; - } - - AlgorithmRuntimeProps defaultLiveMonitorReductionOptions( - std::string instrument = std::string("OFFSPEC")) { - return AlgorithmRuntimeProps{ - {"GetLiveValueAlgorithm", "GetLiveInstrumentValue"}, - {"InputWorkspace", "TOF_live"}, - {"Instrument", instrument}}; - } - - void expectRunsTableWithContent(RunsTable &runsTable) { - EXPECT_CALL(*m_runsTablePresenter, runsTable()) - .Times(1) - .WillOnce(ReturnRef(runsTable)); - } - - void expectUpdateViewWhenMonitorStarting() { - EXPECT_CALL(m_view, setStartMonitorButtonEnabled(false)); - EXPECT_CALL(m_view, setStopMonitorButtonEnabled(false)); - } - - void expectUpdateViewWhenMonitorStarted() { - EXPECT_CALL(m_view, setStartMonitorButtonEnabled(false)); - EXPECT_CALL(m_view, setStopMonitorButtonEnabled(true)); - } - - void expectUpdateViewWhenMonitorStopped() { - EXPECT_CALL(m_view, setStartMonitorButtonEnabled(true)); - EXPECT_CALL(m_view, setStopMonitorButtonEnabled(false)); - } - - void expectStopAutoreduction() { - EXPECT_CALL(*m_runNotifier, stopPolling()).Times(1); - } - - void expectAutoreductionSettingsChanged() { - EXPECT_CALL(*m_searcher, - searchSettingsChanged(_, _, ISearcher::SearchType::AUTO)) - .WillOnce(Return(true)); - } - - void expectAutoreductionSettingsUnchanged() { - EXPECT_CALL(*m_searcher, - searchSettingsChanged(_, _, ISearcher::SearchType::AUTO)) - .WillOnce(Return(false)); - } - - void expectClearExistingTable() { - EXPECT_CALL(*m_searcher, reset()).Times(1); - EXPECT_CALL(*m_runsTablePresenter, notifyRemoveAllRowsAndGroupsRequested()) - .Times(1); - } - - void expectDoNotClearExistingTable() { - EXPECT_CALL(*m_searcher, reset()).Times(0); - EXPECT_CALL(*m_runsTablePresenter, notifyRemoveAllRowsAndGroupsRequested()) - .Times(0); - } - - void expectUserRespondsYes() { - EXPECT_CALL(m_messageHandler, askUserYesNo(_, _)) - .Times(1) - .WillOnce(Return(true)); - } - - void expectUserRespondsNo() { - EXPECT_CALL(m_messageHandler, askUserYesNo(_, _)) - .Times(1) - .WillOnce(Return(false)); - } - - void expectCheckForNewRuns() { - EXPECT_CALL(*m_runNotifier, stopPolling()).Times(1); - EXPECT_CALL(m_view, getSearchString()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(m_searchString)); - EXPECT_CALL(*m_searcher, startSearchAsync(m_searchString, _, - ISearcher::SearchType::AUTO)) - .Times(1) - .WillOnce(Return(true)); - EXPECT_CALL(m_messageHandler, giveUserCritical(_, _)).Times(0); - } - - void expectDoNotStartAutoreduction() { - EXPECT_CALL(*m_runNotifier, stopPolling()).Times(0); - EXPECT_CALL(*m_searcher, startSearchAsync(_, _, _)).Times(0); - } - - void expectGetValidSearchRowSelection() { - // Select a couple of rows with random indices - auto row1Index = 3; - auto row2Index = 5; - auto const selectedRows = std::set<int>({row1Index, row2Index}); - EXPECT_CALL(m_view, getSelectedSearchRows()) - .Times(1) - .WillOnce(Return(selectedRows)); - m_searchResult = SearchResult("", "", ""); - for (auto rowIndex : selectedRows) - EXPECT_CALL(*m_searcher, getSearchResult(rowIndex)) - .Times(1) - .WillOnce(ReturnRef(m_searchResult)); - } - - // Set up a valid search result with content and return the corresponding - // model - ReductionJobs - expectGetValidSearchResult(std::string const &run = "13245", - std::string const &groupName = "Test group 1", - double theta = 0.5) { - // Set a selected row in the search results table - auto const rowIndex = 0; - auto const selectedRows = std::set<int>({rowIndex}); - EXPECT_CALL(m_view, getSelectedSearchRows()) - .Times(1) - .WillOnce(Return(selectedRows)); - // Set the expected result from the search results model - auto const title = groupName + std::string("th=") + std::to_string(theta); - m_searchResult = SearchResult(run, title, ""); - EXPECT_CALL(*m_searcher, getSearchResult(rowIndex)) - .Times(1) - .WillOnce(ReturnRef(m_searchResult)); - // Construct the corresponding model expected in the main table - auto jobs = ReductionJobs(); - auto group = Group(groupName); - group.appendRow(Row({run}, theta, TransmissionRunPair(), RangeInQ(), - boost::none, ReductionOptionsMap(), - ReductionWorkspaces({run}, TransmissionRunPair()))); - jobs.appendGroup(group); - return jobs; - } - - void expectCreateEndlessProgressIndicator() { - EXPECT_CALL(m_progressView, clearProgress()).Times(1); - EXPECT_CALL(m_progressView, setProgressRange(_, _)).Times(2); - } - - void expectCreatePercentageProgressIndicator() { - EXPECT_CALL(m_progressView, clearProgress()).Times(1); - EXPECT_CALL(m_progressView, setProgressRange(_, _)).Times(2); - } - - void expectWidgetsEnabledForAutoreducing() { - expectIsNotProcessing(); - expectIsAutoreducing(); - EXPECT_CALL(m_view, updateMenuEnabledState(false)); - EXPECT_CALL(m_view, setInstrumentComboEnabled(false)); - EXPECT_CALL(m_view, setSearchTextEntryEnabled(false)); - EXPECT_CALL(m_view, setSearchButtonEnabled(false)); - EXPECT_CALL(m_view, setAutoreduceButtonEnabled(false)); - EXPECT_CALL(m_view, setAutoreducePauseButtonEnabled(true)); - EXPECT_CALL(m_view, setTransferButtonEnabled(false)); - } - - void expectWidgetsEnabledForProcessing() { - expectIsProcessing(); - expectIsNotAutoreducing(); - EXPECT_CALL(m_view, updateMenuEnabledState(true)); - EXPECT_CALL(m_view, setInstrumentComboEnabled(false)); - EXPECT_CALL(m_view, setSearchTextEntryEnabled(false)); - EXPECT_CALL(m_view, setSearchButtonEnabled(false)); - EXPECT_CALL(m_view, setAutoreduceButtonEnabled(false)); - EXPECT_CALL(m_view, setAutoreducePauseButtonEnabled(false)); - EXPECT_CALL(m_view, setTransferButtonEnabled(false)); - } - - void expectWidgetsEnabledForProcessingAndAutoreducing() { - expectIsProcessing(); - expectIsAutoreducing(); - EXPECT_CALL(m_view, updateMenuEnabledState(true)); - EXPECT_CALL(m_view, setInstrumentComboEnabled(false)); - EXPECT_CALL(m_view, setSearchTextEntryEnabled(false)); - EXPECT_CALL(m_view, setSearchButtonEnabled(false)); - EXPECT_CALL(m_view, setAutoreduceButtonEnabled(false)); - EXPECT_CALL(m_view, setAutoreducePauseButtonEnabled(true)); - EXPECT_CALL(m_view, setTransferButtonEnabled(false)); - } - - void expectWidgetsEnabledForPaused() { - expectIsNotProcessing(); - expectIsNotAutoreducing(); - EXPECT_CALL(m_view, updateMenuEnabledState(false)); - EXPECT_CALL(m_view, setInstrumentComboEnabled(true)); - EXPECT_CALL(m_view, setSearchTextEntryEnabled(true)); - EXPECT_CALL(m_view, setSearchButtonEnabled(true)); - EXPECT_CALL(m_view, setAutoreduceButtonEnabled(true)); - EXPECT_CALL(m_view, setAutoreducePauseButtonEnabled(false)); - EXPECT_CALL(m_view, setTransferButtonEnabled(true)); - } - - void expectAutoreduceButtonDisabledWhenAnotherBatchAutoreducing() { - expectIsNotProcessing(); - expectIsNotAutoreducing(); - EXPECT_CALL(m_mainPresenter, isAnyBatchAutoreducing()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(true)); - EXPECT_CALL(m_view, setAutoreduceButtonEnabled(false)); - EXPECT_CALL(m_view, setAutoreducePauseButtonEnabled(false)); - } - - void expectAutoreduceButtonEnabledWhenAnotherBatchNotAutoreducing() { - expectIsNotProcessing(); - expectIsNotAutoreducing(); - EXPECT_CALL(m_mainPresenter, isAnyBatchAutoreducing()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - EXPECT_CALL(m_view, setAutoreduceButtonEnabled(true)); - EXPECT_CALL(m_view, setAutoreducePauseButtonEnabled(false)); - } - - void expectIsAutoreducing() { - EXPECT_CALL(m_mainPresenter, isAutoreducing()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(true)); - ON_CALL(m_mainPresenter, isAnyBatchAutoreducing()) - .WillByDefault(Return(true)); - } - - void expectIsNotAutoreducing() { - EXPECT_CALL(m_mainPresenter, isAutoreducing()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - ON_CALL(m_mainPresenter, isAnyBatchAutoreducing()) - .WillByDefault(Return(false)); - } - - void expectIsProcessing() { - EXPECT_CALL(m_mainPresenter, isProcessing()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(true)); - } - - void expectIsNotProcessing() { - EXPECT_CALL(m_mainPresenter, isProcessing()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - } - - void expectSearchInstrument(std::string const &instrument) { - ON_CALL(m_view, getSearchInstrument()).WillByDefault(Return(instrument)); - } - - void expectGetLiveDataOptions( - AlgorithmRuntimeProps options = AlgorithmRuntimeProps(), - std::string const &instrument = std::string("OFFSPEC")) { - expectSearchInstrument(instrument); - EXPECT_CALL(m_mainPresenter, rowProcessingProperties()) - .Times(1) - .WillOnce(Return(options)); - } - - void expectGetLiveDataOptions(std::string const &instrument) { - expectGetLiveDataOptions(AlgorithmRuntimeProps(), instrument); - } - - boost::shared_ptr<NiceMock<MockAlgorithmRunner>> expectGetAlgorithmRunner() { - // Get the algorithm runner - auto algRunner = boost::make_shared<NiceMock<MockAlgorithmRunner>>(); - ON_CALL(m_view, getMonitorAlgorithmRunner()) - .WillByDefault(Return(algRunner)); - return algRunner; - } - - void expectStartingLiveDataSucceeds() { - // The view must return valid reduction options and algorithm runner for - // the presenter to be able to run live data - expectGetLiveDataOptions(); - expectGetAlgorithmRunner(); - } - - void assertAlgorithmPropertiesContainOptions( - AlgorithmRuntimeProps const &expected, - boost::shared_ptr<NiceMock<MockAlgorithmRunner>> &algRunner) { - auto alg = algRunner->algorithm(); - for (auto const &kvp : expected) - TS_ASSERT_EQUALS(alg->getPropertyValue(kvp.first), kvp.second); - } - - void assertPostProcessingPropertiesContainOptions( - AlgorithmRuntimeProps &expected, - boost::shared_ptr<NiceMock<MockAlgorithmRunner>> &algRunner) { - auto alg = algRunner->algorithm(); - auto resultString = alg->getPropertyValue("PostProcessingProperties"); - auto result = parseKeyValueString(resultString, ";"); - for (auto const &kvp : expected) { - TS_ASSERT(result.find(kvp.first) != result.end()); - TS_ASSERT_EQUALS(result[kvp.first], expected[kvp.first]); - } - } - - double m_thetaTolerance; - std::vector<std::string> m_instruments; - NiceMock<MockRunsView> m_view; - NiceMock<MockRunsTableView> m_runsTableView; - NiceMock<MockRunsTablePresenter> *m_runsTablePresenter; - NiceMock<MockBatchPresenter> m_mainPresenter; - NiceMock<MockProgressableView> m_progressView; - NiceMock<MockMessageHandler> m_messageHandler; - NiceMock<MockSearcher> *m_searcher; - MockPythonRunner *m_pythonRunner; - MockRunNotifier *m_runNotifier; - NiceMock<MantidQt::MantidWidgets::Batch::MockJobTreeView> m_jobs; - RunsTable m_runsTable; - std::string m_searchString; - SearchResult m_searchResult; -}; - -#endif /* MANTID_CUSTOMINTERFACES_RUNSPRESENTERTEST_H */