Skip to content

Commit

Permalink
Keep filter if result not empty, moved sorting to FilteringListPres
Browse files Browse the repository at this point in the history
  • Loading branch information
JanBliznicenko committed Dec 16, 2023
1 parent 8463fc4 commit 1743dcf
Show file tree
Hide file tree
Showing 3 changed files with 322 additions and 44 deletions.
279 changes: 278 additions & 1 deletion src/Spec2-CommonWidgets-Tests/SpChooserPresenterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,47 @@ SpChooserPresenterTest >> testAddAll [
self assert: chooserPresenter targetList unfilteredItems isNotEmpty
]

{ #category : 'tests' }
SpChooserPresenterTest >> testAddAllOfFiltered [

| sourceItemsToAdd sourceItems targetItems allItems presenter |
sourceItemsToAdd := #( ToAdd1 ToAdd2 ).
sourceItems := { 'S1' } , sourceItemsToAdd.
targetItems := { 'T1'. 'T2' }.
allItems := sourceItems , targetItems.

presenter := SpChooserPresenter
sourceItems: sourceItems copy
chosenItems: targetItems copy.

presenter sourceList filterInputPresenter text: 'ToAdd'.

self
assertCollection: presenter sourceList items
hasSameElements: sourceItemsToAdd.
self
assertCollection: presenter sourceList unfilteredItems
hasSameElements: sourceItems.
self
assertCollection: presenter targetList items
hasSameElements: targetItems.
self
assertCollection: presenter targetList unfilteredItems
hasSameElements: targetItems.

presenter addAll.

self
assert: presenter sourceList filterInputPresenter text
equals: ''.
self
assertCollection: presenter sourceList items
hasSameElements: sourceItems \ sourceItemsToAdd.
self
assertCollection: presenter sourceList unfilteredItems
hasSameElements: sourceItems \ sourceItemsToAdd
]

{ #category : 'tests' }
SpChooserPresenterTest >> testAddItemUsingFilter [

Expand Down Expand Up @@ -74,6 +115,93 @@ SpChooserPresenterTest >> testAddSelected [
equals: self items size - 1
]

{ #category : 'tests' }
SpChooserPresenterTest >> testAddSelectedAllOfFiltered [

| sourceItemsToAdd sourceItems targetItems allItems presenter |
sourceItemsToAdd := #( ToAdd1 ToAdd2 ).
sourceItems := { 'S1' } , sourceItemsToAdd.
targetItems := { 'T1'. 'T2' }.
allItems := sourceItems , targetItems.

presenter := SpChooserPresenter
sourceItems: sourceItems copy
chosenItems: targetItems copy.

presenter sourceList filterInputPresenter text: 'ToAdd'.

self
assertCollection: presenter sourceList items
hasSameElements: sourceItemsToAdd.
self
assertCollection: presenter sourceList unfilteredItems
hasSameElements: sourceItems.
self
assertCollection: presenter targetList items
hasSameElements: targetItems.
self
assertCollection: presenter targetList unfilteredItems
hasSameElements: targetItems.

presenter sourceList selectItems: sourceItemsToAdd.
presenter addSelected.

self
assert: presenter sourceList filterInputPresenter text
equals: ''.
self
assertCollection: presenter sourceList items
hasSameElements: sourceItems \ sourceItemsToAdd.
self
assertCollection: presenter sourceList unfilteredItems
hasSameElements: sourceItems \ sourceItemsToAdd
]

{ #category : 'tests' }
SpChooserPresenterTest >> testAddSelectedPartOfFiltered [

| sourceItemToAdd sourceItems targetItems allItems presenter |
sourceItemToAdd := 'ToAdd'.
sourceItems := {
'S1'.
'ToNotAdd'.
sourceItemToAdd }.
targetItems := { 'T1'. 'T2' }.
allItems := sourceItems , targetItems.

presenter := SpChooserPresenter
sourceItems: sourceItems copy
chosenItems: targetItems copy.

presenter sourceList filterInputPresenter text: 'To'.

self
assertCollection: presenter sourceList items
hasSameElements: #( ToAdd ToNotAdd ).
self
assertCollection: presenter sourceList unfilteredItems
hasSameElements: sourceItems.
self
assertCollection: presenter targetList items
hasSameElements: targetItems.
self
assertCollection: presenter targetList unfilteredItems
hasSameElements: targetItems.

presenter sourceList selectItem: sourceItemToAdd.
presenter addSelected.

self
assert: presenter sourceList filterInputPresenter text
equals: 'To'.
self
assertCollection: presenter sourceList items
hasSameElements: { 'ToNotAdd' }.
self
assertCollection: presenter sourceList unfilteredItems
hasSameElements: (sourceItems copyWithout: sourceItemToAdd)
]

{ #category : 'tests' }
SpChooserPresenterTest >> testAllRemoveThenAdd [

Expand Down Expand Up @@ -151,11 +279,32 @@ SpChooserPresenterTest >> testFilterBothThenRemove [

presenter sourceList filterInputPresenter text: 'ToAdd'.
presenter targetList filterInputPresenter text: 'ToRemove'.


self
assertCollection: presenter sourceList items
hasSameElements: { sourceItemToAdd }.
self
assertCollection: presenter sourceList unfilteredItems
hasSameElements: sourceItems.
self
assertCollection: presenter targetList items
hasSameElements: { targetItemToRemove }.
self
assertCollection: presenter targetList unfilteredItems
hasSameElements: targetItems.

presenter removeAll.

self
assert: presenter sourceList filterInputPresenter text
equals: 'ToAdd'.
self
assert: presenter targetList filterInputPresenter text
equals: ''.
self
assertCollection: presenter sourceList items
hasSameElements: sourceItems , { targetItemToRemove }.
hasSameElements: { sourceItemToAdd }.
self
assertCollection: presenter sourceList unfilteredItems
hasSameElements: sourceItems , { targetItemToRemove }.
Expand Down Expand Up @@ -225,6 +374,47 @@ SpChooserPresenterTest >> testRemoveAll [
self assert: chooserPresenter targetList unfilteredItems isEmpty
]

{ #category : 'tests' }
SpChooserPresenterTest >> testRemoveAllOfFiltered [

| targetItemsToRemove sourceItems targetItems allItems presenter |
targetItemsToRemove := #( ToRemove1 ToRemove2 ).
sourceItems := { 'S1'. 'S2' }.
targetItems := { 'T1' } , targetItemsToRemove.
allItems := sourceItems , targetItems.

presenter := SpChooserPresenter
sourceItems: sourceItems copy
chosenItems: targetItems copy.

presenter targetList filterInputPresenter text: 'ToRemove'.

self
assertCollection: presenter sourceList items
hasSameElements: sourceItems.
self
assertCollection: presenter sourceList unfilteredItems
hasSameElements: sourceItems.
self
assertCollection: presenter targetList items
hasSameElements: targetItemsToRemove.
self
assertCollection: presenter targetList unfilteredItems
hasSameElements: targetItems.

presenter removeAll.

self
assert: presenter targetList filterInputPresenter text
equals: ''.
self
assertCollection: presenter targetList items
hasSameElements: targetItems \ targetItemsToRemove.
self
assertCollection: presenter targetList unfilteredItems
hasSameElements: targetItems \ targetItemsToRemove
]

{ #category : 'tests' }
SpChooserPresenterTest >> testRemoveItemUsingFilter [

Expand Down Expand Up @@ -257,6 +447,93 @@ SpChooserPresenterTest >> testRemoveSelected [
equals: self items size - 1
]

{ #category : 'tests' }
SpChooserPresenterTest >> testRemoveSelectedAllOfFiltered [

| targetItemsToRemove sourceItems targetItems allItems presenter |
targetItemsToRemove := #( ToRemove1 ToRemove2 ).
sourceItems := { 'S1'. 'S2' }.
targetItems := { 'T1' } , targetItemsToRemove.
allItems := sourceItems , targetItems.

presenter := SpChooserPresenter
sourceItems: sourceItems copy
chosenItems: targetItems copy.

presenter targetList filterInputPresenter text: 'ToRemove'.

self
assertCollection: presenter sourceList items
hasSameElements: sourceItems.
self
assertCollection: presenter sourceList unfilteredItems
hasSameElements: sourceItems.
self
assertCollection: presenter targetList items
hasSameElements: targetItemsToRemove.
self
assertCollection: presenter targetList unfilteredItems
hasSameElements: targetItems.

presenter targetList selectItems: targetItemsToRemove.
presenter removeSelected.

self
assert: presenter targetList filterInputPresenter text
equals: ''.
self
assertCollection: presenter targetList items
hasSameElements: targetItems \ targetItemsToRemove.
self
assertCollection: presenter targetList unfilteredItems
hasSameElements: targetItems \ targetItemsToRemove
]

{ #category : 'tests' }
SpChooserPresenterTest >> testRemoveSelectedPartOfFiltered [

| targetItemToRemove sourceItems targetItems allItems presenter |
targetItemToRemove := 'ToRemove'.
sourceItems := { 'S1'. 'S2' }.
targetItems := {
'T1'.
'ToNotRemove'.
targetItemToRemove }.
allItems := sourceItems , targetItems.

presenter := SpChooserPresenter
sourceItems: sourceItems copy
chosenItems: targetItems copy.

presenter targetList filterInputPresenter text: 'To'.

self
assertCollection: presenter sourceList items
hasSameElements: sourceItems.
self
assertCollection: presenter sourceList unfilteredItems
hasSameElements: sourceItems.
self
assertCollection: presenter targetList items
hasSameElements: #( ToNotRemove ToRemove ).
self
assertCollection: presenter targetList unfilteredItems
hasSameElements: targetItems.

presenter targetList selectItem: targetItemToRemove.
presenter removeSelected.

self
assert: presenter targetList filterInputPresenter text
equals: 'To'.
self
assertCollection: presenter targetList items
hasSameElements: #( ToNotRemove ).
self
assertCollection: presenter targetList unfilteredItems
hasSameElements: (targetItems copyWithout: targetItemToRemove)
]

{ #category : 'tests' }
SpChooserPresenterTest >> testSelectedAddThenRemove [

Expand Down
Loading

0 comments on commit 1743dcf

Please sign in to comment.