-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests.
- Loading branch information
Hernán Morales Durand
committed
Dec 9, 2023
1 parent
fdeba46
commit 1f85cea
Showing
3 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
" | ||
Spec presenter example entry point which contains a component list: | ||
- A left-side component list acts as a ""selector"" (class `SpComponentListSelectorExample`) and it can hold Spec presenters as items in its list. | ||
- A right-side list acts as a ""destination"" which is a normal list, configured in `#connectPresenters` to be updated when the selected item changes | ||
" | ||
Class { | ||
#name : 'SpComponentListSelectionExample', | ||
#superclass : 'SpPresenter', | ||
#instVars : [ | ||
'selectorPresenter', | ||
'destinationPresenter' | ||
], | ||
#category : 'Spec2-Tests-Utils', | ||
#package : 'Spec2-Tests', | ||
#tag : 'Utils' | ||
} | ||
|
||
{ #category : 'instance creation' } | ||
SpComponentListSelectionExample class >> open [ | ||
<example> | ||
^ self new open | ||
] | ||
|
||
{ #category : 'initialization' } | ||
SpComponentListSelectionExample >> connectPresenters [ | ||
|
||
selectorPresenter | ||
transmitTo: destinationPresenter | ||
transform: [ : item | { item label asNumber . (item label asNumber * 2) } ] | ||
] | ||
|
||
{ #category : 'layout' } | ||
SpComponentListSelectionExample >> defaultLayout [ | ||
|
||
^ SpBoxLayout newLeftToRight | ||
add: selectorPresenter; | ||
add: destinationPresenter; | ||
yourself | ||
] | ||
|
||
{ #category : 'accessing' } | ||
SpComponentListSelectionExample >> destinationPresenter [ | ||
|
||
^ destinationPresenter | ||
] | ||
|
||
{ #category : 'initialization' } | ||
SpComponentListSelectionExample >> initializePresenters [ | ||
|
||
selectorPresenter := self instantiate: SpComponentListSelectorExample on: self. | ||
destinationPresenter := self newList. | ||
] | ||
|
||
{ #category : 'accessing' } | ||
SpComponentListSelectionExample >> selectorPresenter [ | ||
|
||
^ selectorPresenter | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
" | ||
This example acts as a selector of presenter items, this is, each of the items is a Spec component obtained through `#asPresenter`. | ||
" | ||
Class { | ||
#name : 'SpComponentListSelectorExample', | ||
#superclass : 'SpPresenter', | ||
#instVars : [ | ||
'componentListPresenter' | ||
], | ||
#category : 'Spec2-Tests-Utils', | ||
#package : 'Spec2-Tests', | ||
#tag : 'Utils' | ||
} | ||
|
||
{ #category : 'layout' } | ||
SpComponentListSelectorExample >> defaultLayout [ | ||
|
||
^ SpBoxLayout newTopToBottom | ||
add: componentListPresenter expand: true; | ||
yourself. | ||
] | ||
|
||
{ #category : 'ports' } | ||
SpComponentListSelectorExample >> defaultOutputPort [ | ||
|
||
^ componentListPresenter defaultOutputPort | ||
] | ||
|
||
{ #category : 'initialization' } | ||
SpComponentListSelectorExample >> initializePresenters [ | ||
|
||
componentListPresenter := self newComponentList | ||
items: ((10 to: 20) asArray collect: #asPresenter); | ||
yourself. | ||
] | ||
|
||
{ #category : 'api' } | ||
SpComponentListSelectorExample >> selectIndex: anIndex [ | ||
|
||
componentListPresenter selectIndex: anIndex | ||
] |
43 changes: 43 additions & 0 deletions
43
src/Spec2-Tests/SpTransmissionWithComponentListTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Class { | ||
#name : 'SpTransmissionWithComponentListTest', | ||
#superclass : 'SpSmokeTest', | ||
#category : 'Spec2-Tests-Examples', | ||
#package : 'Spec2-Tests', | ||
#tag : 'Examples' | ||
} | ||
|
||
{ #category : 'accessing' } | ||
SpTransmissionWithComponentListTest >> classToTest [ | ||
|
||
^ SpComponentListSelectionExample | ||
] | ||
|
||
{ #category : 'running' } | ||
SpTransmissionWithComponentListTest >> setUp [ | ||
|
||
super setUp. | ||
presenter := SpComponentListSelectionExample new. | ||
|
||
] | ||
|
||
{ #category : 'running' } | ||
SpTransmissionWithComponentListTest >> tearDown [ | ||
|
||
presenter delete. | ||
super tearDown. | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpTransmissionWithComponentListTest >> testOpen [ | ||
|
||
self shouldnt: [ presenter open ] raise: MessageNotUnderstood. | ||
] | ||
|
||
{ #category : 'tests' } | ||
SpTransmissionWithComponentListTest >> testSelection [ | ||
|
||
presenter selectorPresenter selectIndex: 1. | ||
self | ||
assertCollection: presenter destinationPresenter items | ||
hasSameElements: #(10 20) | ||
] |