Skip to content

Commit

Permalink
Add test for typeahead
Browse files Browse the repository at this point in the history
  • Loading branch information
tatut committed Jan 12, 2024
1 parent 20b7434 commit eed9545
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/LiveWeb-Examples-Tests/LWExamplesTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,13 @@ LWExamplesTest >> testMultiCounter [
locate: #( 'div.counter' 'nth=5' ) assert: [ :d | d hasText: '42' ]

]

{ #category : #tests }
LWExamplesTest >> testTypeahead [
self
go: 'http://localhost:8080/examples/typeahead';
locate: 'input#selected' do: [ :i | i pressSequentially: 'LWExamples' ];
locate: 'div.formCandidates div' assert: [ :c | c hasCount: 3 ];
locate: '[data-typeahead-id=LWExamples]' do: #click;
locate: 'div.selectedClass' assert: [ :s | s hasText: 'You have chosen: LWExamples' ]
]
25 changes: 21 additions & 4 deletions src/LiveWeb-Examples/LWTypeAheadExample.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ Class {
#name : #LWTypeAheadExample,
#superclass : #LWComponent,
#instVars : [
'typeahead'
'typeahead',
'selected'
],
#category : #'LiveWeb-Examples'
}
Expand All @@ -25,15 +26,31 @@ LWTypeAheadExample >> initialize [
span: [ h templateSlot: [ :c | c subclasses size asString ] ]]];
fetchCandidates: [ :v |
Smalltalk globals allClasses select: [ :c | (v,'*') match: c name ]];
accessor: #first;
form: (LWEditForm new entity: OrderedCollection new) .
accessor: #selected;
form: (LWEditForm new entity: self) .

]

{ #category : #rendering }
LWTypeAheadExample >> renderOn: h [
h div: [
h h3: 'Type ahead from Smalltalk image classes:'.
typeahead render: h ]
typeahead render: h.
selected ifNotNil: [
h div: { #class -> 'selectedClass' } with: 'You have chosen: ', selected asString
]
]

]

{ #category : #accessing }
LWTypeAheadExample >> selected [

^ selected
]

{ #category : #accessing }
LWTypeAheadExample >> selected: anObject [
selected := anObject.
self changed
]

0 comments on commit eed9545

Please sign in to comment.