Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Options presenter for text search input fields #1607

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adapt select block logic to radio button update.
Add accessors.
Add tests in SpSearchInputFieldOptionsPresenterTest.
Hernán Morales Durand committed Sep 20, 2024
commit 47f67f2aa219c6dfb9d6928d770cb0ca4bbf3ac7
38 changes: 26 additions & 12 deletions src/Spec2-Core/SpSearchInputFieldOptionsPresenter.class.st
Original file line number Diff line number Diff line change
@@ -31,6 +31,12 @@ SpSearchInputFieldOptionsPresenter class >> open [
^ self new open
]

{ #category : 'accessing' }
SpSearchInputFieldOptionsPresenter >> caseCheckBox [

^ caseCheckBox
]

{ #category : 'layout' }
SpSearchInputFieldOptionsPresenter >> defaultLayout [

@@ -43,6 +49,12 @@ SpSearchInputFieldOptionsPresenter >> defaultLayout [
yourself
]

{ #category : 'accessing' }
SpSearchInputFieldOptionsPresenter >> exactOptionButton [

^ exactOptionButton
]

{ #category : 'initialization' }
SpSearchInputFieldOptionsPresenter >> initializePresenters [

@@ -79,29 +91,31 @@ SpSearchInputFieldOptionsPresenter >> initializeSearchTypePresenters [
yourself.
]

{ #category : 'accessing' }
SpSearchInputFieldOptionsPresenter >> regexpOptionButton [

^ regexpOptionButton
]

{ #category : 'updating' }
SpSearchInputFieldOptionsPresenter >> selectBlock [
"Answer a <BlockClosure> with the matching strategy depending of the active searching options in the receiver"

(regexpOptionButton isActive and: [ caseCheckBox isActive ])
ifTrue: [ ^ [ : item : regex | regex asRegex search: item ] ].
(regexpOptionButton isActive and: [ caseCheckBox isActive not ])
ifTrue: [ ^ [ : item : regex | regex asRegexIgnoringCase search: item ] ].

(regexpOptionButton isActive and: [ caseCheckBox isActive ])
ifTrue: [ ^ [ : item : regex | regex search: item ] ].

(exactOptionButton isActive and: [ caseCheckBox isActive and: [ regexpOptionButton isActive not ]])
ifTrue: [ ^ [ : item : pattern | item = pattern ] ].

(exactOptionButton isActive and: [ caseCheckBox isActive not and: [ regexpOptionButton isActive not ] ])
ifTrue: [ ^ [ : item : pattern | item asLowercase = pattern asLowercase ] ].
(exactOptionButton isActive and: [ caseCheckBox isActive])
ifTrue: [ ^ [ : item : pattern | item = pattern ] ].
(exactOptionButton isActive and: [ caseCheckBox isActive not ])
ifTrue: [ ^ [ : item : pattern | item asLowercase = pattern asLowercase ] ].

(exactOptionButton isActive not and: [ caseCheckBox isActive and: [ regexpOptionButton isActive not ] ])
(substringOptionButton isActive and: [ caseCheckBox isActive ])
ifTrue: [ ^ [ : item : pattern | item includesSubstring: pattern caseSensitive: true ] ].

(exactOptionButton isActive not and: [ caseCheckBox isActive not and: [ regexpOptionButton isActive not ] ])
(substringOptionButton isActive and: [ caseCheckBox isActive not ])
ifTrue: [ ^ [ : item : pattern | item includesSubstring: pattern caseSensitive: false ] ].


]

{ #category : 'accessing' }
94 changes: 94 additions & 0 deletions src/Spec2-Tests/SpSearchInputFieldOptionsPresenterTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Class {
#name : 'SpSearchInputFieldOptionsPresenterTest',
#superclass : 'SpBasePresenterTest',
#category : 'Spec2-Tests-Common-Widgets',
#package : 'Spec2-Tests',
#tag : 'Common-Widgets'
}

{ #category : 'accessing' }
SpSearchInputFieldOptionsPresenterTest >> classToTest [

^ SpSearchInputFieldOptionsPresenter
]

{ #category : 'tests' }
SpSearchInputFieldOptionsPresenterTest >> testSelectBlockExactCaseInsensitive [

presenter exactOptionButton click.
self
assert: (presenter selectBlock value: 'ABC' value: 'abc')
description: 'It checks that exact and case-insensitive returns true for same letters with different case'
]

{ #category : 'tests' }
SpSearchInputFieldOptionsPresenterTest >> testSelectBlockExactCaseSensitive [

presenter exactOptionButton click.
presenter caseCheckBox click.
self
deny: (presenter selectBlock value: 'ABC' value: 'abc')
description: 'It checks that exact and case-insensitive returns false for same letters with different case'.

self
assert: (presenter selectBlock value: 'ABC' value: 'ABC')
description: 'It checks that exact and case-insensitive returns false for same letters with equal case'.
]

{ #category : 'tests' }
SpSearchInputFieldOptionsPresenterTest >> testSelectBlockRegexCaseInsensitive [

presenter regexpOptionButton click.

self
assert: (presenter selectBlock value: 'ABC' value: 'ABC')
description: 'It checks that exact and case-insensitive returns false for same letters with equal case'.

self
assert: (presenter selectBlock value: 'AbCD' value: '^AB(.*)$')
description: 'It checks that exact and case-insensitive returns false for same letters with equal case'.
]

{ #category : 'tests' }
SpSearchInputFieldOptionsPresenterTest >> testSelectBlockRegexCaseSensitive [

presenter regexpOptionButton click.
presenter caseCheckBox click.

self
deny: (presenter selectBlock value: 'AbCD' value: '^AB(.*)$')
description: 'It checks that regular expression and case-insensitive returns false for same letters with different case'.

self
assert: (presenter selectBlock value: 'ABC' value: '^AB(.*)$')
description: 'It checks that regular expression and case-insensitive returns true for matching pattern with equal case'.
]

{ #category : 'tests' }
SpSearchInputFieldOptionsPresenterTest >> testSelectBlockSubstringCaseInsensitive [

presenter substringBox click.

self
deny: (presenter selectBlock value: 'AbCDef' value: 'pspsp')
description: 'It checks that substring and case-insensitive returns false for different substring'.

self
assert: (presenter selectBlock value: 'ABCdef' value: 'cde')
description: 'It checks that substring and case-insensitive returns true for existing substring pattern'.
]

{ #category : 'tests' }
SpSearchInputFieldOptionsPresenterTest >> testSelectBlockSubstringCaseSensitive [

presenter substringBox click.
presenter caseCheckBox click.

self
deny: (presenter selectBlock value: 'AbCDef' value: 'cdE')
description: 'It checks that substring and case-sensitive returns false for same substring with different case'.

self
assert: (presenter selectBlock value: 'ABCdef' value: 'Cde')
description: 'It checks that substring and case-sensitive returns true for existing substring pattern with same case'.
]