Skip to content

Commit

Permalink
Add tests for SpectrumViewerWindowPresenter.handle_roi_clicked()
Browse files Browse the repository at this point in the history
Co-authored-by: JackEAllen <jack.allen@stfc.ac.uk>
Co-authored-by: Mike Sullivan <michael.sullivan@stfc.ac.uk>
  • Loading branch information
3 people committed Jun 6, 2024
1 parent c4ce799 commit d0f137a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion mantidimaging/gui/windows/spectrum_viewer/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
if TYPE_CHECKING:
from mantidimaging.gui.windows.spectrum_viewer.view import SpectrumViewerWindowView # pragma: no cover
from mantidimaging.gui.windows.main.view import MainWindowView # pragma: no cover
from mantidimaging.gui.windows.spectrum_viewer.spectrum_widget import SpectrumROI
from mantidimaging.core.data import ImageStack
from uuid import UUID

Expand Down Expand Up @@ -191,7 +192,7 @@ def handle_roi_moved(self, force_new_spectrums: bool = False) -> None:
self.model.set_roi(name, roi)
self.view.set_spectrum(name, self.model.get_spectrum(name, self.spectrum_mode))

def handle_roi_clicked(self, roi) -> None:
def handle_roi_clicked(self, roi: SpectrumROI) -> None:
if not roi.name == ROI_RITS:
self.view.current_roi = roi.name
self.view.last_clicked_roi = roi.name
Expand Down
20 changes: 18 additions & 2 deletions mantidimaging/gui/windows/spectrum_viewer/test/presenter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
from parameterized import parameterized

from mantidimaging.core.data.dataset import StrictDataset, MixedDataset
from mantidimaging.core.utility.sensible_roi import SensibleROI
from mantidimaging.gui.windows.main import MainWindowView
from mantidimaging.gui.windows.spectrum_viewer import SpectrumViewerWindowView, SpectrumViewerWindowPresenter
from mantidimaging.gui.windows.spectrum_viewer.model import ErrorMode, ToFUnitMode
from mantidimaging.gui.windows.spectrum_viewer.spectrum_widget import SpectrumWidget, SpectrumPlotWidget
from mantidimaging.gui.windows.spectrum_viewer.model import ErrorMode, ToFUnitMode, ROI_RITS
from mantidimaging.gui.windows.spectrum_viewer.spectrum_widget import SpectrumWidget, SpectrumPlotWidget, SpectrumROI
from mantidimaging.test_helpers import mock_versions, start_qapplication
from mantidimaging.test_helpers.unit_test_helper import generate_images

Expand Down Expand Up @@ -240,6 +241,21 @@ def test_WHEN_do_remove_roi_called_THEN_roi_removed(self):
self.presenter.do_remove_roi("roi_1")
self.assertEqual(["all", "roi"], self.presenter.model.get_list_of_roi_names())

def test_WHEN_roi_clicked_THEN_roi_updated(self):
roi = SpectrumROI("themightyroi", SensibleROI())
self.presenter.handle_roi_clicked(roi)
self.assertEqual(self.view.current_roi, "themightyroi")
self.assertEqual(self.view.last_clicked_roi, "themightyroi")
self.view.set_roi_properties.assert_called_once()

def test_WHEN_rits_roi_clicked_THEN_rois_not_updated(self):
self.view.current_roi = self.view.last_clicked_roi = "NOT_RITS_ROI"
roi = SpectrumROI(ROI_RITS, SensibleROI())
self.presenter.handle_roi_clicked(roi)
self.assertEqual(self.view.current_roi, "NOT_RITS_ROI")
self.assertEqual(self.view.last_clicked_roi, "NOT_RITS_ROI")
self.view.set_roi_properties.assert_not_called()

def test_WHEN_ROI_renamed_THEN_roi_renamed(self):
self.presenter.model.set_stack(generate_images())
self.presenter.do_add_roi()
Expand Down

0 comments on commit d0f137a

Please sign in to comment.