From 266b8eaa1e85e9e864d2772090f9e313061d2dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Blizni=C4=8Denko?= Date: Fri, 10 May 2024 10:33:30 +0200 Subject: [PATCH] Fixed ntb page selection change announcement if built without pages --- .../SpMorphicNotebookAdapter.class.st | 29 +++++++++++++------ .../SpNotebookAdapterTest.class.st | 18 ++++++++++++ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/Spec2-Adapters-Morphic/SpMorphicNotebookAdapter.class.st b/src/Spec2-Adapters-Morphic/SpMorphicNotebookAdapter.class.st index 7f239b80..f4b516c4 100644 --- a/src/Spec2-Adapters-Morphic/SpMorphicNotebookAdapter.class.st +++ b/src/Spec2-Adapters-Morphic/SpMorphicNotebookAdapter.class.st @@ -27,20 +27,31 @@ SpMorphicNotebookAdapter >> addFocusRotationKeyBindings [ toAction: [ self focusPrevious ] ] -{ #category : 'factory' } -SpMorphicNotebookAdapter >> addModelTo: aNotebook [ - +{ #category : 'private' } +SpMorphicNotebookAdapter >> addInitialPagesTo: aNotebook [ + self presenter pages ifEmpty: [ ^ self ]. + self presenter pages do: [ :each | "Since I do not have the page added, I need to take it from the list. - But I know this will be the last added :)" + But I know this will be the last added :)" self addPage: each to: aNotebook ]. + "force first page to be drawn" - self presenter selectedPage ifNil: [ self presenter selectPageIndex: 1 ]. - aNotebook selectedPageIndex: self presenter selectedPageIndex. - aNotebook announcer - when: SpNotebookPageChanged - send: #pageChanged: + self presenter selectedPage ifNil: [ + self presenter selectPageIndex: 1 ]. + + aNotebook selectedPageIndex: self presenter selectedPageIndex +] + +{ #category : 'factory' } +SpMorphicNotebookAdapter >> addModelTo: aNotebook [ + + self addInitialPagesTo: aNotebook. + + aNotebook announcer + when: SpNotebookPageChanged + send: #pageChanged: to: self ] diff --git a/src/Spec2-Backend-Tests/SpNotebookAdapterTest.class.st b/src/Spec2-Backend-Tests/SpNotebookAdapterTest.class.st index 25c7e90b..d7080d9b 100644 --- a/src/Spec2-Backend-Tests/SpNotebookAdapterTest.class.st +++ b/src/Spec2-Backend-Tests/SpNotebookAdapterTest.class.st @@ -104,3 +104,21 @@ SpNotebookAdapterTest >> testSelectingPageShouldAnnounceChangeEvent [ self assert: change oldPage model title equals: 'Mock'. self assert: change page model title equals: 'Mock2' ] + +{ #category : 'tests' } +SpNotebookAdapterTest >> testSelectingPageShouldAnnounceChangeEventWithNoInitialPages [ + + | changed | + "start with no pages" + presenter removeAll. + presenter whenSelectedPageChangedDo: [ changed := true ]. + "build without any pages" + self widget. + "add pages after build" + self initializeTestedInstance. + presenter selectPageIndex: 1. + changed := false. + "this should trigger the page change" + self widget updatePageIndex: 2 oldIndex: 1. + self assert: changed +]