-
-
Notifications
You must be signed in to change notification settings - Fork 353
/
SpAbstractListPresenterTest.class.st
180 lines (141 loc) · 4.27 KB
/
SpAbstractListPresenterTest.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
"
testing ListComposablePresenter
"
Class {
#name : #SpAbstractListPresenterTest,
#superclass : #SpTestCase,
#category : #'Spec2-Tests-Core-Widgets'
}
{ #category : #testing }
SpAbstractListPresenterTest class >> isAbstract [
^ self == SpAbstractListPresenterTest
]
{ #category : #running }
SpAbstractListPresenterTest >> setUp [
super setUp.
presenter items: #(10 20 30).
]
{ #category : #'tests-activation' }
SpAbstractListPresenterTest >> testActivationOnDoubleClickShouldActivateOnDoubleClick [
| activatedItem |
activatedItem := nil.
presenter
activateOnDoubleClick;
whenActivatedDo: [ :selection | activatedItem := selection selectedItem ].
presenter doubleClickAtIndex: 1.
self assert: activatedItem equals: 10.
]
{ #category : #'tests-activation' }
SpAbstractListPresenterTest >> testActivationOnDoubleClickShouldNotActivateOnClick [
| activatedItem |
activatedItem := nil.
presenter
activateOnDoubleClick;
whenActivatedDo: [ :selection | activatedItem := selection selectionItem ].
presenter clickAtIndex: 1.
self assert: activatedItem equals: nil.
]
{ #category : #'tests-activation' }
SpAbstractListPresenterTest >> testActivationOnSingleClickShouldActivateOnClick [
| activatedItem |
activatedItem := nil.
presenter
activateOnSingleClick;
whenActivatedDo: [ :selection | activatedItem := selection selectedItem ].
presenter clickAtIndex: 1.
self assert: activatedItem equals: 10.
]
{ #category : #'tests-activation' }
SpAbstractListPresenterTest >> testActivationOnSingleClickShouldNotActivateOnClickOutside [
| activatedItem |
activatedItem := nil.
presenter
activateOnSingleClick;
whenActivatedDo: [ :selection | activatedItem := selection selectedIndex ].
presenter clickAtIndex: 100.
self assert: activatedItem equals: nil
]
{ #category : #'tests-activation' }
SpAbstractListPresenterTest >> testActivationWithoutActivationBlockDoesNothing [
| activatedItem |
activatedItem := nil.
presenter activateOnSingleClick.
presenter clickAtIndex: 1.
self assert: activatedItem equals: nil
]
{ #category : #tests }
SpAbstractListPresenterTest >> testContextMenu [
| menu changed |
self assert: presenter contextMenu isNil.
menu := SpMenuPresenter new.
changed := false.
presenter whenMenuChangedDo: [
changed := true. ].
presenter contextMenu: menu.
self assert: presenter contextMenu equals: menu.
self assert: changed
]
{ #category : #tests }
SpAbstractListPresenterTest >> testReplaceItemList [
| changed |
changed := false.
presenter whenModelChangedDo: [ changed := true ].
presenter items: #(a b c).
self
assert: presenter model collection
equals: #(a b c).
self assert: changed
]
{ #category : #tests }
SpAbstractListPresenterTest >> testSelectAll [
presenter beSingleSelection.
presenter selectAll.
"in single mode selectAll has no effect"
self assertEmpty: presenter selection selectedItems.
presenter beMultipleSelection.
presenter selectAll.
"but in multiple mode selectAll works"
self
assert: presenter selection selectedItems asArray
equals: #(10 20 30)
]
{ #category : #'tests-smoke' }
SpAbstractListPresenterTest >> testSetSortingBlockBeforeItems [
| count |
count := 0.
presenter whenSortingBlockChangedDo: [ :sortFunction | count := count + 1 ].
presenter sortingBlock: #yourself ascending.
presenter items: #(3 8 1 0).
self assert: count equals: 1.
self assert: (presenter model at: 1) equals: 0
]
{ #category : #'tests-smoke' }
SpAbstractListPresenterTest >> testSmokeOpenEmptyPresenter [
window := presenter openWithSpec
]
{ #category : #'tests-smoke' }
SpAbstractListPresenterTest >> testSmokeOpenPresenterWithItems [
window := presenter
items: #(1 2 3);
openWithSpec.
]
{ #category : #'tests-smoke' }
SpAbstractListPresenterTest >> testSortingBlock [
| count |
count := 0.
presenter whenSortingBlockChangedDo: [ :sortFunction | count := count + 1 ].
presenter items: #(3 8 1 0).
presenter sortingBlock: #yourself ascending.
self assert: count equals: 1.
self assert: (presenter model at: 1) equals: 0
]
{ #category : #tests }
SpAbstractListPresenterTest >> testUnselectAll [
presenter beMultipleSelection.
presenter selectAll.
self
assert: presenter selection selectedItems asArray
equals: #(10 20 30).
presenter unselectAll.
self assertEmpty: presenter selection selectedItems
]