Skip to content

Commit

Permalink
Fix notebook page closing tests + add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tinchodias committed Aug 4, 2023
1 parent 614193b commit 573bdc3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 10 deletions.
23 changes: 14 additions & 9 deletions src/Toplo-Incubator/ToNotebook.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ ToNotebook >> refreshOnPageIsCloseableChange: aPage [
| but |
but := ToButton new.
but icon: (ToImage new innerImage: (Smalltalk ui icons iconNamed: #windowClose)).
but whenClickedDo: [ self removePage: aPage ].
but whenClickedDo: [ :evt |
evt consumed: true.
self removePage: aPage ].
aPage titleElement addChild: but as: #closeButton ]
ifFalse: [
aPage titleElement removeChildNamed: #closeButton ]
Expand Down Expand Up @@ -157,17 +159,20 @@ ToNotebook >> removeBodyElement [
{ #category : #api }
ToNotebook >> removePage: aPage [

aPage isSelected ifTrue: [
aPage isSelected: false ].

| pageIndex |
aPage isSelected ifTrue: [
pageIndex := pages indexOf: aPage ].
header removeChild: aPage titleElement.

self flag: #todo. "Unsubscribe from aPage"

aPage isSelected: false.
pages remove: aPage.
self flag: #todo. "Unsubscribe from aPage"

pageIndex ifNil: [ ^self ].
pages ifEmpty: [ ^self ].

(selectedPage isNil and: [ pages isNotEmpty ])
ifTrue: [ pages last isSelected: true ]
((pages size < pageIndex)
ifTrue: [ pages last ]
ifFalse: [ pages at: pageIndex ]) isSelected: true
]

{ #category : #api }
Expand Down
53 changes: 52 additions & 1 deletion src/Toplo-Incubator/ToNotebookTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,28 @@ ToNotebookTest >> testBodyFactoryIsValuedOnSelect [
]

{ #category : #tests }
ToNotebookTest >> testClosePage [
ToNotebookTest >> testCloseLastPage [

| redPage |
redPage := notebook
addPageTitle: 'Red'
body: (BlElement new
background: Color red;
yourself).
redPage isCloseable: true.

self waitTestingSpaces.
self assert: (notebook pages includes: redPage).
self assert: redPage isSelected.

BlSpace simulateClickOn: redPage closeButton.
self waitTestingSpaces.
self assert: notebook pages isEmpty.

]

{ #category : #tests }
ToNotebookTest >> testCloseSelectedPage [

| redPage greenPage |
redPage := notebook
Expand All @@ -74,6 +95,7 @@ ToNotebookTest >> testClosePage [

self waitTestingSpaces.
self assert: (notebook pages includes: redPage).
self assert: redPage isSelected.

BlSpace simulateClickOn: redPage closeButton.
self waitTestingSpaces.
Expand All @@ -82,6 +104,35 @@ ToNotebookTest >> testClosePage [

]

{ #category : #tests }
ToNotebookTest >> testCloseUnselectedPage [

| redPage greenPage |
redPage := notebook
addPageTitle: 'Red'
body: (BlElement new
background: Color red;
yourself).
redPage isCloseable: true.

greenPage := notebook
addPageTitle: 'Green'
body: (BlElement new
background: Color green;
yourself).
greenPage isCloseable: true.

self waitTestingSpaces.
self assert: (notebook pages includes: redPage).
self assert: redPage isSelected.

BlSpace simulateClickOn: greenPage closeButton.
self waitTestingSpaces.
self deny: (notebook pages includes: greenPage).
self assert: redPage isSelected.

]

{ #category : #tests }
ToNotebookTest >> testDefaultBodyIsTransparent [

Expand Down

0 comments on commit 573bdc3

Please sign in to comment.