Skip to content
Permalink
Browse files

Merge pull request #672 from CafeKrem/667-PolyWidget-SpChooseMethod-i…

…mprovement

667-PolyWidget-SpChooseMethod-improvement
  • Loading branch information...
jecisc committed Aug 5, 2019
2 parents 9cda46c + b5697ad commit fe964f9027f2d84fe79cee6701e6e2148bde7405
@@ -87,6 +87,8 @@ BaselineOfSpec2 >> baseline: spec [
do: [ spec
package: 'Spec2-Tools'
with: [ spec requires: #('Spec2-PolyWidgets') ];
package: 'Spec2-Tools-Tests'
with: [ spec requires: #('Spec2-Tests' 'Spec2-Tools') ];
package: 'Spec2-Examples'
with: [ spec requires: #('Spec2-Tools') ];
package: 'Spec2-Deprecated-Tools'
@@ -7,7 +7,7 @@ Class {
#instVars : [
'biChooseMethod'
],
#category : #'Spec2-PolyWidgets-Tests-Tests'
#category : #'Spec2-Tools-Tests-Tests'
}

{ #category : #running }
@@ -19,7 +19,7 @@ SpChooseMethodUITest >> setUp [
{ #category : #tests }
SpChooseMethodUITest >> testClassSideRadioButtonState [
biChooseMethod radioButtonClassSide click.
self deny: biChooseMethod isInstanceButtonSelected
self deny: biChooseMethod isInstanceSideSelected
]

{ #category : #tests }
@@ -37,7 +37,7 @@ SpChooseMethodUITest >> testInitializeClassListShouldBeSelectTheFistItem [

{ #category : #tests }
SpChooseMethodUITest >> testInitializeIsInstanceButtonSelectedShouldBetrue [
self assert: biChooseMethod isInstanceButtonSelected
self assert: biChooseMethod isInstanceSideSelected
]

{ #category : #tests }
@@ -50,12 +50,17 @@ SpChooseMethodUITest >> testInitializePackageListShouldBeSelectTheFistItem [
self assert: biChooseMethod packageList selection selectedIndex equals: 1
]

{ #category : #tests }
SpChooseMethodUITest >> testInitializeProtocolListShouldSelectedItemSetToAll [
self assert: biChooseMethod selectedProtocol name equals: '-- all --'
]

{ #category : #tests }
SpChooseMethodUITest >> testInstanceSideRadioButtonClickIsInstanceButtonShouldbeTrue [
biChooseMethod radioButtonClassSide click.
self deny: biChooseMethod isInstanceButtonSelected.
self deny: biChooseMethod isInstanceSideSelected.
biChooseMethod radioButtonInstanceSide click.
self assert: biChooseMethod isInstanceButtonSelected
self assert: biChooseMethod isInstanceSideSelected
]

{ #category : #tests }
@@ -80,12 +85,35 @@ SpChooseMethodUITest >> testMethodListContentWhenInstanceSideIsSelected [
self assertCollection: SpMethodChooserMockClass methods hasSameElements: biChooseMethod methodList items
]

{ #category : #tests }
SpChooseMethodUITest >> testSelectAClassShouldDisplayHisProtcolInProtocolList [
biChooseMethod packageList selectItem: self class package.
biChooseMethod classList selectItem: SpMethodChooserMockClass.
self assertCollection: (biChooseMethod protocolList items collect: #name) hasSameElements: #(#'-- all --' #accessing)
]

{ #category : #tests }
SpChooseMethodUITest >> testTransmissionFromPackageToClassList [
| package |
package := RPackage named: 'MigratePrettyPrinterUI-Tests-environementEmpty' asSymbol.
package := RPackage named: 'TestPackageForSpecTests' asSymbol.
biChooseMethod packageList items: {package}.
biChooseMethod packageList selectItem: package.
self assertEmpty: biChooseMethod classList items.
self assert: biChooseMethod classList selection selectedItem isNil
self assert: biChooseMethod selectedClass isNil
]

{ #category : #tests }
SpChooseMethodUITest >> testWhenClassSideRadioClickShouldChangeProtocolList [
biChooseMethod packageList selectItem: self class package.
biChooseMethod classList selectItem: SpMethodChooserMockClass.
biChooseMethod radioButtonClassSide click.
self assertCollection: (biChooseMethod protocolList items collect: #name) hasSameElements: SpMethodChooserMockClass class protocols
]

{ #category : #tests }
SpChooseMethodUITest >> testWhenSelectAProtocolShouldMethodListOnlyContainsMethodWithSelectedProtocol [
biChooseMethod packageList selectItem: self class package.
biChooseMethod classList selectItem: self class.
biChooseMethod protocolList selectIndex: ((biChooseMethod protocolList items collect: #name) indexOf: 'running').
self assert: (biChooseMethod methodList items allSatisfy: [ :method | method category = 'running' ])
]
@@ -4,10 +4,10 @@ I am a mock class for Method Chooser tests.
Class {
#name : #SpMethodChooserMockClass,
#superclass : #Object,
#category : #'Spec2-PolyWidgets-Tests-Mocks'
#category : #'Spec2-Tools-Tests-Mocks'
}

{ #category : #accessing }
{ #category : #accessingClassSide }
SpMethodChooserMockClass class >> classMethod [
]

@@ -0,0 +1 @@
Package { #name : #'Spec2-Tools-Tests' }
@@ -1,9 +1,9 @@
"
I am an UI used to select a method of the system.
I'll display the list of packages of the system, the classes of the selected package and the methods of the selected class.
I am an UI used to select a method of the system.
I'll display the list of packages of the system, the classes of the selected package and the methods of the selected class , the protocols of selectedClass.
The user can configure me with an action to execute when the user does the selection. The action will take my instance as parameter to get the package/class/method selected.
The user can configure me with an action to execute when the user does the selection. The action will take my instance as parameter to get the package/class/method/protocols selected.
Public API and Key Messages
--------------------
@@ -24,6 +24,7 @@ Internal Representation and Key Implementation Points.
packageList: <aListPresenter> A list of the packages of the system.
classList: <aListPresenter> A list of the classes in the selected package.
methodList: <aListPresenter> A list of the methods in the selected class.
protocolList: <aListPresenter> A list of the protocols in the selected class.
radioButtonClassSide: <aRadioButton> A radio button to select the class side.
radioButtonInstanceSide: <aRadioButton> A radio button to select the instance side.
@@ -36,40 +37,55 @@ Class {
'classList',
'methodList',
'radioButtonInstanceSide',
'radioButtonClassSide'
'radioButtonClassSide',
'protocolList'
],
#category : #'Spec2-PolyWidgets-Widgets'
#category : #'Spec2-Tools-ChooseMethod'
}

{ #category : #specs }
SpChooseMethodUI class >> defaultSpec [
^ SpPanedLayout newHorizontal
position: 33 percent;
position: 25 percent;
add: #packageList;
add:
(SpPanedLayout newHorizontal
position: 50 percent;
position: 25 percent;
add: #classList;
add:
(SpBoxLayout newVertical
add: #methodList;
(SpPanedLayout newHorizontal
position: 40 percent;
add: #protocolList;
add:
(SpBoxLayout newHorizontal
add: #radioButtonInstanceSide;
add: #radioButtonClassSide;
yourself)
withConstraints: [ :contraint | contraint height: 20 ];
(SpBoxLayout newVertical
add: #methodList;
add:
(SpBoxLayout newHorizontal
add: #radioButtonInstanceSide;
add: #radioButtonClassSide;
yourself)
withConstraints: [ :contraint | contraint height: 20 ];
yourself);
yourself);
yourself);
yourself
]

{ #category : #examples }
SpChooseMethodUI class >> example [
SpChooseMethodUI class >> exampleMethodChooser [
<example>
(self openOnAccept: [ :chooseMethodPresenter | chooseMethodPresenter selectedMethod browse ]) withWindowDo: [ :w | w title: 'Select a method example' ]
]

{ #category : #examples }
SpChooseMethodUI class >> exampleNavigationSystem [
<example>
| presenter |
presenter := self new.
presenter openWithSpec extent: 900 @ 400.
^ presenter
]

{ #category : #'instance creation' }
SpChooseMethodUI class >> openOnAccept: aBlock [
| instance |
@@ -84,9 +100,35 @@ SpChooseMethodUI >> classList [
^ classList
]

{ #category : #utilities }
SpChooseMethodUI >> classMethodsOf: aClass [
^ aClass class methods
{ #category : #'initialization - actions' }
SpChooseMethodUI >> classListAction [
classList
transmitTo: methodList
transform: [ :selectedClass |
selectedClass
ifNotNil: [ self methodsFromClass: selectedClass ]
ifNil: [ #() ] ]
postTransmission: [ :destination | destination selectIndex: 1 ].

classList
transmitTo: protocolList
transform: [ :selectedClass |
selectedClass
ifNotNil: [ self isInstanceSideSelected
ifTrue:
[ selectedClass organization allProtocols as: OrderedCollection ]
ifFalse:
[ selectedClass class organization allProtocols as: OrderedCollection ] ]
ifNil: [ #()]]
postTransmission: [ :protcolList |
protocolList
selectIndex: ((protcolList items collect: #name) indexOf: '-- all --') ]
]

{ #category : #'initialization - actions' }
SpChooseMethodUI >> fillWith: aClass [
methodList items: aClass methods.
^ protocolList items: (aClass protocols collect: [ :eachSymbol | aClass organization protocolOrganizer protocolNamed: eachSymbol ])
]

{ #category : #initialization }
@@ -100,20 +142,10 @@ SpChooseMethodUI >> initializeDialogWindow: aDialog [

{ #category : #initialization }
SpChooseMethodUI >> initializePresenter [
packageList
transmitTo: classList
transform: [ :selectedPacakge | selectedPacakge classes asOrderedCollection ]
postTransmission: [ classList selectIndex: 1 ].

classList
transmitTo: methodList
transform: [ :selectedClass | selectedClass ifNotNil: [ self methodsToDisplayOf: selectedClass ] ifNil: [ #() ] ]
postTransmission: [ :destination | destination selectIndex: 1 ].

radioButtonClassSide whenActivatedDo: [ methodList items: (self classMethodsOf: self selectedClass) ].

radioButtonInstanceSide whenActivatedDo: [ methodList items: (self instanceMethodsOf: self selectedClass) ].

self packageListAction.
self classListAction.
self protocolListAction.
self radioButtonsAction.
packageList selectIndex: 1
]

@@ -124,6 +156,7 @@ SpChooseMethodUI >> initializeWidgets [
methodList := self newList.
radioButtonClassSide := self newRadioButton.
radioButtonInstanceSide := self newRadioButton.
protocolList := self newList.

packageList
items: RPackageOrganizer default packages;
@@ -135,8 +168,12 @@ SpChooseMethodUI >> initializeWidgets [
sortingBlock: #name ascending;
icons: [ :item | self iconNamed: item systemIconName ].

protocolList
displayBlock: #name;
sortingBlock: #name ascending.

methodList
sortingBlock: #selector ascending;
sortingBlock: #name ascending;
displayBlock: #selector.

radioButtonClassSide label: 'class side'.
@@ -152,13 +189,8 @@ SpChooseMethodUI >> initializeWidgets [
add: methodList
]

{ #category : #utilities }
SpChooseMethodUI >> instanceMethodsOf: aClass [
^ aClass methods
]

{ #category : #testing }
SpChooseMethodUI >> isInstanceButtonSelected [
SpChooseMethodUI >> isInstanceSideSelected [
^ radioButtonInstanceSide state
]

@@ -168,15 +200,46 @@ SpChooseMethodUI >> methodList [
]

{ #category : #utilities }
SpChooseMethodUI >> methodsToDisplayOf: aClass [
^ (self isInstanceButtonSelected ifTrue: [ self instanceMethodsOf: aClass ] ifFalse: [ self classMethodsOf: aClass ]) asOrderedCollection
SpChooseMethodUI >> methodNamed: methodSelector [
^ (self isInstanceSideSelected ifTrue: [ self selectedClass ] ifFalse: [ self selectedClass class ]) methodNamed: methodSelector
]

{ #category : #utilities }
SpChooseMethodUI >> methodsFromClass: aClass [
^ (self isInstanceSideSelected ifTrue: [ aClass ] ifFalse: [ aClass class ]) methods asOrderedCollection
]

{ #category : #accessing }
SpChooseMethodUI >> packageList [
^ packageList
]

{ #category : #'initialization - actions' }
SpChooseMethodUI >> packageListAction [
packageList
transmitTo: classList
transform: [ :selectedPacakge |
selectedPacakge
ifNotNil: [ selectedPacakge classes asOrderedCollection ] ]
postTransmission: [ classList selectIndex: 1 ]
]

{ #category : #accessing }
SpChooseMethodUI >> protocolList [
^ protocolList
]

{ #category : #'initialization - actions' }
SpChooseMethodUI >> protocolListAction [
protocolList
transmitTo: methodList
transform:
[ :selectedProtocol | selectedProtocol
ifNotNil: [ (selectedProtocol methods collect: [ :methodSelector | self methodNamed: methodSelector ]) asOrderedCollection ]
ifNil: [ #() ] ]
postTransmission: [ :methodPresenter | methodPresenter selectIndex: 1 ]
]

{ #category : #accessing }
SpChooseMethodUI >> radioButtonClassSide [
^ radioButtonClassSide
@@ -187,6 +250,12 @@ SpChooseMethodUI >> radioButtonInstanceSide [
^ radioButtonInstanceSide
]

{ #category : #'initialization - actions' }
SpChooseMethodUI >> radioButtonsAction [
radioButtonClassSide whenActivatedDo: [ self fillWith: self selectedClass class ].
radioButtonInstanceSide whenActivatedDo: [ self fillWith: self selectedClass ]
]

{ #category : #accessing }
SpChooseMethodUI >> selectedClass [
^ classList selection selectedItem
@@ -201,3 +270,8 @@ SpChooseMethodUI >> selectedMethod [
SpChooseMethodUI >> selectedPackage [
^ packageList selectedItem
]

{ #category : #accessing }
SpChooseMethodUI >> selectedProtocol [
^ protocolList selection selectedItem
]

0 comments on commit fe964f9

Please sign in to comment.
You can’t perform that action at this time.