diff --git a/buildconfig/CMake/CppCheck_Suppressions.txt.in b/buildconfig/CMake/CppCheck_Suppressions.txt.in index 04adbe564dc4..dbd17bf3c5a6 100644 --- a/buildconfig/CMake/CppCheck_Suppressions.txt.in +++ b/buildconfig/CMake/CppCheck_Suppressions.txt.in @@ -766,7 +766,6 @@ missingOverride:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/G missingOverride:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/Preview/PreviewModel.h:31 missingOverride:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/IRunsView.h:66 missingOverride:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/QtCatalogSearcher.h:32 -constVariableReference:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.cpp:545 missingOverride:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/IRunsTableView.h:31 constVariablePointer:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/RunsTablePresenter.cpp:510 constVariableReference:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/RunsTablePresenter.cpp:749 diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.cpp index 407372a4082e..44aee463d0e1 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.cpp @@ -72,8 +72,8 @@ BatchPresenter::BatchPresenter( */ void BatchPresenter::acceptMainPresenter(IMainWindowPresenter *mainPresenter) { m_mainPresenter = mainPresenter; } -void BatchPresenter::initInstrumentList(const std::string &selectedInstrument) { - m_runsPresenter->initInstrumentList(selectedInstrument); +std::string BatchPresenter::initInstrumentList(const std::string &selectedInstrument) { + return m_runsPresenter->initInstrumentList(selectedInstrument); } bool BatchPresenter::requestClose() const { return true; } diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.h index d5b2db33c105..e9ca1be0df85 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.h @@ -59,7 +59,7 @@ class MANTIDQT_ISISREFLECTOMETRY_DLL BatchPresenter : public IBatchPresenter, // IBatchPresenter overrides void acceptMainPresenter(IMainWindowPresenter *mainPresenter) override; - void initInstrumentList(const std::string &selectedInstrument = "") override; + std::string initInstrumentList(const std::string &selectedInstrument = "") override; void notifyPauseReductionRequested() override; void notifyResumeReductionRequested() override; void notifyResumeAutoreductionRequested() override; diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/IBatchPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/IBatchPresenter.h index 69ed639f0c30..382043f3dd78 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/IBatchPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/IBatchPresenter.h @@ -32,7 +32,7 @@ class IBatchPresenter { virtual ~IBatchPresenter() = default; virtual void acceptMainPresenter(IMainWindowPresenter *mainPresenter) = 0; - virtual void initInstrumentList(const std::string &selectedInstrument = "") = 0; + virtual std::string initInstrumentList(const std::string &selectedInstrument = "") = 0; virtual void notifyPauseReductionRequested() = 0; virtual void notifyResumeReductionRequested() = 0; diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp index 828a91cc9af9..17a06bb9eed3 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp @@ -120,16 +120,7 @@ void MainWindowPresenter::notifyAnyBatchReductionPaused() { // Top level function to handle when user has requested to change the // instrument void MainWindowPresenter::notifyChangeInstrumentRequested(std::string const &newInstrumentName) { - // Cache changed state before calling updateInstrument - auto const hasChanged = (newInstrumentName != instrumentName()); - // Re-load instrument regardless of whether it has changed, e.g. if we are - // creating a new batch the instrument may not have changed but we still want - // the most up to date settings - updateInstrument(newInstrumentName); - // However, only perform updates if the instrument has changed, otherwise we - // may trigger overriding of user-specified settings - if (hasChanged) - onInstrumentChanged(); + processInstrumentSelection(newInstrumentName); } void MainWindowPresenter::notifyCloseEvent() { @@ -259,8 +250,8 @@ void MainWindowPresenter::optionsChanged() 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) + // Remember the instrument name, if we have one, so that 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); @@ -269,9 +260,10 @@ void MainWindowPresenter::addNewBatch(IBatchView *batchView) { void MainWindowPresenter::initNewBatch(IBatchPresenter *batchPresenter, std::string const &instrument, std::optional precision) { + // For the very first batch, the selected instrument will be the default from the instrument list + auto const selectedInstrument = batchPresenter->initInstrumentList(instrument); + processInstrumentSelection(selectedInstrument, batchPresenter); - batchPresenter->initInstrumentList(instrument); - batchPresenter->notifyInstrumentChanged(instrument); if (precision.has_value()) batchPresenter->notifySetRoundPrecision(precision.value()); @@ -383,4 +375,23 @@ void MainWindowPresenter::onInstrumentChanged() { m_slitCalculator->setCurrentInstrumentName(instrumentName()); m_slitCalculator->processInstrumentHasBeenChanged(); } + +void MainWindowPresenter::processInstrumentSelection(std::string const &selectedInstrument, + IBatchPresenter *batchPresenter) { + // Cache changed state before calling updateInstrument + auto const hasChanged = (selectedInstrument != instrumentName()); + // Re-load instrument regardless of whether it has changed, e.g. if we are + // creating a new batch the instrument may not have changed but we still want + // the most up to date settings + updateInstrument(selectedInstrument); + + if (hasChanged) { + // Perform updates for all batches. Only do this if the instrument has changed to avoid + // overriding any user-specified settings + onInstrumentChanged(); + } else if (batchPresenter) { + // Perform updates on the specified batch + batchPresenter->notifyInstrumentChanged(selectedInstrument); + } +} } // namespace MantidQt::CustomInterfaces::ISISReflectometry diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h index db50443e61dc..b7f9f76547c3 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h @@ -112,6 +112,7 @@ class MANTIDQT_ISISREFLECTOMETRY_DLL MainWindowPresenter : public MainWindowSubs void updateInstrument(const std::string &instrumentName); void setDefaultInstrument(const std::string &newInstrument); void onInstrumentChanged(); + void processInstrumentSelection(std::string const &selectedInstrument, IBatchPresenter *batchPresenter = nullptr); void disableSaveAndLoadBatch(); void enableSaveAndLoadBatch(); diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/IRunsPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/IRunsPresenter.h index 307e710e3dbe..bb0528256d90 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/IRunsPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/IRunsPresenter.h @@ -24,7 +24,7 @@ class IRunsPresenter { public: virtual ~IRunsPresenter() = default; virtual void acceptMainPresenter(IBatchPresenter *mainPresenter) = 0; - virtual void initInstrumentList(const std::string &selectedInstrument = "") = 0; + virtual std::string initInstrumentList(const std::string &selectedInstrument = "") = 0; virtual RunsTable const &runsTable() const = 0; virtual RunsTable &mutableRunsTable() = 0; diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/QtRunsView.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/QtRunsView.cpp index 75ef45d8b129..690d3a6545e2 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/QtRunsView.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/QtRunsView.cpp @@ -13,6 +13,7 @@ #include "MantidQtWidgets/Common/QtAlgorithmRunner.h" #include #include +#include namespace MantidQt::CustomInterfaces::ISISReflectometry { using namespace Mantid::API; @@ -168,14 +169,12 @@ void QtRunsView::setInstrumentList(const std::vector &instruments, // We block signals while populating the list and setting the selected instrument because adding the first item // will trigger a currentIndexChanged signal. This causes existing batch settings to be overwritten when we're // initialising a new batch for an instrument that isn't the first in the list. - m_ui.comboSearchInstrument->blockSignals(true); + const QSignalBlocker blocker(m_ui.comboSearchInstrument); + m_ui.comboSearchInstrument->clear(); for (auto &&instrument : instruments) m_ui.comboSearchInstrument->addItem(QString::fromStdString(instrument)); setSearchInstrument(selectedInstrument); - m_ui.comboSearchInstrument->blockSignals(false); - // Manually emit the signal once we've finished setting up the dropdown. - emit m_ui.comboSearchInstrument->currentIndexChanged(m_ui.comboSearchInstrument->currentIndex()); } /** diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.cpp index 82dbccaf2ff7..d48230665442 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.cpp @@ -72,8 +72,13 @@ RunsPresenter::~RunsPresenter() { */ void RunsPresenter::acceptMainPresenter(IBatchPresenter *mainPresenter) { m_mainPresenter = mainPresenter; } -void RunsPresenter::initInstrumentList(const std::string &selectedInstrument) { +/** Initialise the list of available instruments. + * @param selectedInstrument : Optional name of an instrument to try and select from the list. + * @returns The name of the instrument that is selected. + */ +std::string RunsPresenter::initInstrumentList(const std::string &selectedInstrument) { m_view->setInstrumentList(m_instruments, selectedInstrument); + return m_view->getSearchInstrument(); } RunsTable const &RunsPresenter::runsTable() const { return tablePresenter()->runsTable(); } @@ -542,7 +547,7 @@ IAlgorithm_sptr RunsPresenter::setupLiveDataMonitorAlgorithm() { auto errorMap = alg->validateInputs(); if (!errorMap.empty()) { std::string errorString; - for (auto &kvp : errorMap) + for (auto const &kvp : errorMap) errorString.append(kvp.first + ":" + kvp.second); handleError(errorString); return nullptr; diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.h index 84c1d6ad15c7..156cb24fc34f 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/RunsPresenter.h @@ -67,7 +67,7 @@ class MANTIDQT_ISISREFLECTOMETRY_DLL RunsPresenter : public IRunsPresenter, // IRunsPresenter overrides void acceptMainPresenter(IBatchPresenter *mainPresenter) override; - void initInstrumentList(const std::string &selectedInstrument = "") override; + std::string initInstrumentList(const std::string &selectedInstrument = "") override; RunsTable const &runsTable() const override; RunsTable &mutableRunsTable() override; bool isProcessing() const override; diff --git a/qt/scientific_interfaces/ISISReflectometry/test/Batch/BatchPresenterTest.h b/qt/scientific_interfaces/ISISReflectometry/test/Batch/BatchPresenterTest.h index dc437715a062..24b220f627e7 100644 --- a/qt/scientific_interfaces/ISISReflectometry/test/Batch/BatchPresenterTest.h +++ b/qt/scientific_interfaces/ISISReflectometry/test/Batch/BatchPresenterTest.h @@ -64,8 +64,9 @@ class BatchPresenterTest : public CxxTest::TestSuite { void testInitInstrumentListUpdatesRunsPresenter() { auto presenter = makePresenter(makeModel()); - EXPECT_CALL(*m_runsPresenter, initInstrumentList(_)).Times(1); - presenter->initInstrumentList(); + std::string const selectedInstrument = "INTER"; + EXPECT_CALL(*m_runsPresenter, initInstrumentList(selectedInstrument)).Times(1).WillOnce(Return(selectedInstrument)); + TS_ASSERT_EQUALS(presenter->initInstrumentList(selectedInstrument), selectedInstrument); } void testMainPresenterUpdatedWhenChangeInstrumentRequested() { diff --git a/qt/scientific_interfaces/ISISReflectometry/test/MainWindow/MainWindowPresenterTest.h b/qt/scientific_interfaces/ISISReflectometry/test/MainWindow/MainWindowPresenterTest.h index 668f69251e9b..57071b59d4d2 100644 --- a/qt/scientific_interfaces/ISISReflectometry/test/MainWindow/MainWindowPresenterTest.h +++ b/qt/scientific_interfaces/ISISReflectometry/test/MainWindow/MainWindowPresenterTest.h @@ -34,6 +34,10 @@ using testing::Return; using testing::ReturnRef; using testing::Throw; +namespace { +static const std::string DEFAULT_INSTRUMENT = "INTER"; +} // unnamed namespace + class MainWindowPresenterTest : public CxxTest::TestSuite { public: // This pair of boilerplate methods prevent the suite being created statically @@ -78,10 +82,15 @@ class MainWindowPresenterTest : public CxxTest::TestSuite { void testConstructorAddsBatchPresenterForAllBatchViews() { EXPECT_CALL(m_view, batches()).Times(1); - for (auto batchPresenter : m_batchPresenters) - expectBatchAdded(batchPresenter); - - auto presenter = makePresenter(); + auto optionsPresenter = makeOptionsPresenter(); + auto slitCalculator = makeSlitCalculator(); + auto makeBatchPresenter = makeBatchPresenterFactory(); + expectSlitCalculatorInstrumentUpdated(DEFAULT_INSTRUMENT); + for (size_t i = 0; i < m_batchPresenters.size(); ++i) { + expectBatchAdded(m_batchPresenters[i], DEFAULT_INSTRUMENT); + } + auto presenter = + makePresenter(std::move(optionsPresenter), std::move(slitCalculator), std::move(makeBatchPresenter)); TS_ASSERT_EQUALS(presenter.m_batchPresenters.size(), m_batchViews.size()); } @@ -91,7 +100,8 @@ class MainWindowPresenterTest : public CxxTest::TestSuite { EXPECT_CALL(m_view, newBatch()).Times(1).WillOnce(Return(dynamic_cast(batchView))); auto batchPresenter = new NiceMock(); EXPECT_CALL(*m_makeBatchPresenter, makeProxy(batchView)).Times(1).WillOnce(Return(batchPresenter)); - expectBatchAdded(batchPresenter); + expectBatchAdded(batchPresenter, DEFAULT_INSTRUMENT); + expectSlitCalculatorInstrumentNotUpdated(); presenter.notifyNewBatchRequested(); } @@ -211,8 +221,7 @@ class MainWindowPresenterTest : public CxxTest::TestSuite { void testShowSlitCalculatorSetsInstrument() { auto presenter = makePresenter(); - auto const instrument = setupInstrument(presenter, "TEST_INSTRUMENT"); - expectSlitCalculatorInstrumentUpdated(instrument); + expectSlitCalculatorInstrumentUpdated(DEFAULT_INSTRUMENT); presenter.notifyShowSlitCalculatorRequested(); } @@ -277,7 +286,6 @@ class MainWindowPresenterTest : public CxxTest::TestSuite { void testChangeInstrumentRequestedUpdatesInstrumentInChildPresenters() { auto presenter = makePresenter(); - setupInstrument(presenter, "INTER"); auto const instrument = std::string("POLREF"); EXPECT_CALL(*m_batchPresenters[0], notifyInstrumentChanged(instrument)).Times(1); EXPECT_CALL(*m_batchPresenters[1], notifyInstrumentChanged(instrument)).Times(1); @@ -286,15 +294,13 @@ class MainWindowPresenterTest : public CxxTest::TestSuite { void testChangeInstrumentRequestedDoesNotUpdateInstrumentIfNotChanged() { auto presenter = makePresenter(); - auto const instrument = setupInstrument(presenter, "POLREF"); - EXPECT_CALL(*m_batchPresenters[0], notifyInstrumentChanged(instrument)).Times(0); - EXPECT_CALL(*m_batchPresenters[1], notifyInstrumentChanged(instrument)).Times(0); - presenter.notifyChangeInstrumentRequested(instrument); + EXPECT_CALL(*m_batchPresenters[0], notifyInstrumentChanged(DEFAULT_INSTRUMENT)).Times(0); + EXPECT_CALL(*m_batchPresenters[1], notifyInstrumentChanged(DEFAULT_INSTRUMENT)).Times(0); + presenter.notifyChangeInstrumentRequested(DEFAULT_INSTRUMENT); } void testChangeInstrumentUpdatesInstrumentInSlitCalculator() { auto presenter = makePresenter(); - setupInstrument(presenter, "INTER"); auto const instrument = std::string("POLREF"); expectSlitCalculatorInstrumentUpdated(instrument); presenter.notifyChangeInstrumentRequested(instrument); @@ -302,41 +308,37 @@ class MainWindowPresenterTest : public CxxTest::TestSuite { void testChangeInstrumentDoesNotUpdateInstrumentInSlitCalculatorIfNotChanged() { auto presenter = makePresenter(); - auto const instrument = setupInstrument(presenter, "POLREF"); expectSlitCalculatorInstrumentNotUpdated(); - presenter.notifyChangeInstrumentRequested(instrument); + presenter.notifyChangeInstrumentRequested(DEFAULT_INSTRUMENT); } void testUpdateInstrumentDoesNotUpdateInstrumentInSlitCalculator() { auto presenter = makePresenter(); - auto const instrument = setupInstrument(presenter, "POLREF"); expectSlitCalculatorInstrumentNotUpdated(); presenter.notifyUpdateInstrumentRequested(); } void testUpdateInstrumentDoesNotUpdateInstrumentInChildPresenters() { auto presenter = makePresenter(); - auto const instrument = setupInstrument(presenter, "POLREF"); - EXPECT_CALL(*m_batchPresenters[0], notifyInstrumentChanged(instrument)).Times(0); - EXPECT_CALL(*m_batchPresenters[1], notifyInstrumentChanged(instrument)).Times(0); + EXPECT_CALL(*m_batchPresenters[0], notifyInstrumentChanged(DEFAULT_INSTRUMENT)).Times(0); + EXPECT_CALL(*m_batchPresenters[1], notifyInstrumentChanged(DEFAULT_INSTRUMENT)).Times(0); presenter.notifyUpdateInstrumentRequested(); } void testUpdateInstrumentDoesNotChangeInstrumentName() { auto presenter = makePresenter(); - auto const instrument = setupInstrument(presenter, "POLREF"); presenter.notifyUpdateInstrumentRequested(); - TS_ASSERT_EQUALS(presenter.instrumentName(), instrument); + TS_ASSERT_EQUALS(presenter.instrumentName(), DEFAULT_INSTRUMENT); } void testUpdateInstrumentThrowsIfInstrumentNotSet() { auto presenter = makePresenter(); + presenter.m_instrument = nullptr; TS_ASSERT_THROWS_ANYTHING(presenter.notifyUpdateInstrumentRequested()); } void testUpdateInstrumentSetsFacilityInConfig() { auto presenter = makePresenter(); - auto const instrument = setupInstrument(presenter, "POLREF"); auto &config = Mantid::Kernel::ConfigService::Instance(); config.setString("default.facility", "OLD_FACILITY"); presenter.notifyUpdateInstrumentRequested(); @@ -345,11 +347,10 @@ class MainWindowPresenterTest : public CxxTest::TestSuite { void testUpdateInstrumentSetsInstrumentInConfig() { auto presenter = makePresenter(); - auto const instrument = setupInstrument(presenter, "POLREF"); auto &config = Mantid::Kernel::ConfigService::Instance(); config.setString("default.instrument", "OLD_INSTRUMENT"); presenter.notifyUpdateInstrumentRequested(); - TS_ASSERT_EQUALS(config.getString("default.instrument"), instrument); + TS_ASSERT_EQUALS(config.getString("default.instrument"), DEFAULT_INSTRUMENT); } void testCloseEventChecksIfPrevented() { @@ -505,24 +506,47 @@ class MainWindowPresenterTest : public CxxTest::TestSuite { return optionsPresenter; } - MainWindowPresenterFriend makePresenter(std::unique_ptr> optionsPresenter = - std::make_unique>()) { - m_optionsPresenter = optionsPresenter.get(); - auto encoder = std::make_unique>(); - m_encoder = encoder.get(); - auto decoder = std::make_unique>(); - m_decoder = decoder.get(); + std::unique_ptr> makeSlitCalculator() { auto slitCalculator = std::make_unique>(); m_slitCalculator = slitCalculator.get(); + return slitCalculator; + } + + std::unique_ptr> makeBatchPresenterFactory() { auto makeBatchPresenter = std::make_unique>(); m_makeBatchPresenter = makeBatchPresenter.get(); // Set up a mock batch presenter for each view to be returned from the // factory for (auto batchView : m_batchViews) { auto batchPresenter = new NiceMock(); + ON_CALL(*batchPresenter, initInstrumentList(_)).WillByDefault(Return(DEFAULT_INSTRUMENT)); m_batchPresenters.emplace_back(batchPresenter); ON_CALL(*m_makeBatchPresenter, makeProxy(batchView)).WillByDefault(Return(batchPresenter)); } + return makeBatchPresenter; + } + + MainWindowPresenterFriend + makePresenter(std::unique_ptr> optionsPresenter = nullptr, + std::unique_ptr> slitCalculator = nullptr, + std::unique_ptr> makeBatchPresenter = nullptr) { + if (!optionsPresenter) { + optionsPresenter = makeOptionsPresenter(); + } + + auto encoder = std::make_unique>(); + m_encoder = encoder.get(); + auto decoder = std::make_unique>(); + m_decoder = decoder.get(); + + if (!slitCalculator) { + slitCalculator = makeSlitCalculator(); + } + + if (!makeBatchPresenter) { + makeBatchPresenter = makeBatchPresenterFactory(); + } + // Make the presenter auto presenter = MainWindowPresenterFriend(&m_view, &m_messageHandler, &m_fileHandler, std::move(encoder), std::move(decoder), std::move(slitCalculator), @@ -543,15 +567,10 @@ class MainWindowPresenterTest : public CxxTest::TestSuite { m_batchPresenters.clear(); } - std::string setupInstrument(MainWindowPresenterFriend &presenter, std::string const &instrumentName) { - presenter.m_instrument = std::make_shared(instrumentName); - return presenter.instrumentName(); - } - - void expectBatchAdded(MockBatchPresenter *batchPresenter) { + void expectBatchAdded(MockBatchPresenter *batchPresenter, std::string const &instrumentName) { EXPECT_CALL(*batchPresenter, acceptMainPresenter(_)).Times(1); - EXPECT_CALL(*batchPresenter, initInstrumentList(_)).Times(1); - EXPECT_CALL(*batchPresenter, notifyInstrumentChanged(_)).Times(1); + EXPECT_CALL(*batchPresenter, initInstrumentList(_)).Times(1).WillOnce(Return(instrumentName)); + EXPECT_CALL(*batchPresenter, notifyInstrumentChanged(instrumentName)).Times(1); EXPECT_CALL(*batchPresenter, notifyReductionPaused()).Times(1); EXPECT_CALL(*batchPresenter, notifyAnyBatchAutoreductionPaused()).Times(1); } diff --git a/qt/scientific_interfaces/ISISReflectometry/test/ReflMockObjects.h b/qt/scientific_interfaces/ISISReflectometry/test/ReflMockObjects.h index 27b146a38329..3c81ce7d048e 100644 --- a/qt/scientific_interfaces/ISISReflectometry/test/ReflMockObjects.h +++ b/qt/scientific_interfaces/ISISReflectometry/test/ReflMockObjects.h @@ -64,7 +64,7 @@ class MockBatchPresenterFactory : public IBatchPresenterFactory { class MockBatchPresenter : public IBatchPresenter { public: MOCK_METHOD1(acceptMainPresenter, void(IMainWindowPresenter *)); - MOCK_METHOD1(initInstrumentList, void(const std::string &)); + MOCK_METHOD1(initInstrumentList, std::string(const std::string &)); MOCK_METHOD0(notifyResumeReductionRequested, void()); MOCK_METHOD0(notifyPauseReductionRequested, void()); MOCK_METHOD0(notifyResumeAutoreductionRequested, void()); @@ -111,7 +111,7 @@ class MockBatchPresenter : public IBatchPresenter { class MockRunsPresenter : public IRunsPresenter { public: MOCK_METHOD1(acceptMainPresenter, void(IBatchPresenter *)); - MOCK_METHOD1(initInstrumentList, void(const std::string &)); + MOCK_METHOD1(initInstrumentList, std::string(const std::string &)); MOCK_CONST_METHOD0(runsTable, RunsTable const &()); MOCK_METHOD0(mutableRunsTable, RunsTable &()); MOCK_METHOD1(notifyChangeInstrumentRequested, bool(std::string const &)); diff --git a/qt/scientific_interfaces/ISISReflectometry/test/Runs/RunsPresenterTest.h b/qt/scientific_interfaces/ISISReflectometry/test/Runs/RunsPresenterTest.h index d516c10b5daf..6e3190057fea 100644 --- a/qt/scientific_interfaces/ISISReflectometry/test/Runs/RunsPresenterTest.h +++ b/qt/scientific_interfaces/ISISReflectometry/test/Runs/RunsPresenterTest.h @@ -84,10 +84,17 @@ class RunsPresenterTest : public CxxTest::TestSuite { void testInitInstrumentListUpdatesView() { auto presenter = makePresenter(); - EXPECT_CALL(m_view, setInstrumentList(m_instruments, _)).Times(1); + expectInstrumentListUpdated(); presenter.initInstrumentList(); } + void testInitInstrumentListUpdatesViewWithSelectedValue() { + auto presenter = makePresenter(); + std::string const &selectedInstrument = m_instruments[2]; + expectInstrumentListUpdated(selectedInstrument); + TS_ASSERT_EQUALS(presenter.initInstrumentList(selectedInstrument), selectedInstrument); + } + void testCreatePresenterUpdatesView() { expectUpdateViewWhenMonitorStopped(); auto presenter = makePresenter(); @@ -885,6 +892,12 @@ class RunsPresenterTest : public CxxTest::TestSuite { return props; } + void expectInstrumentListUpdated(std::string const &requestedInstrument = "") { + EXPECT_CALL(m_view, setInstrumentList(m_instruments, requestedInstrument)).Times(1); + std::string const &selectedInstrument = requestedInstrument.empty() ? m_instruments[0] : requestedInstrument; + EXPECT_CALL(m_view, getSearchInstrument()).Times(1).WillOnce(Return(selectedInstrument)); + } + void expectRunsTableWithContent(RunsTable &runsTable) { EXPECT_CALL(*m_runsTablePresenter, runsTable()).Times(1).WillOnce(ReturnRef(runsTable)); }