Skip to content

Commit

Permalink
Merge pull request #199 from ba-st/198-extract-LoadingNotificationCom…
Browse files Browse the repository at this point in the history
…mand

198 extract loading notification command
  • Loading branch information
mtabacman authored Mar 15, 2021
2 parents 5e5f22e + 9562070 commit 7808af3
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,9 @@ CombinedWebInteractionInterpreterTest >> testRender [
{ #category : #'tests - Configuring - DOM' }
CombinedWebInteractionInterpreterTest >> testRenderAll [

| interpreter html id |
| interpreter html |

interpreter := self combinedInterpreter.
id := '15'.

html := self
renderUsing: [ :canvas |
Expand Down
4 changes: 2 additions & 2 deletions source/Willow-Core-Tests/ServerResponseCommandTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ ServerResponseCommandTest >> testOnRespond [
{ #category : #'tests-accessing' }
ServerResponseCommandTest >> testParameter [

| parameterObtained command html |
| parameterObtained command |

command := ServerResponseCommand
withBehaviorDeterminedBy: [ :request | parameterObtained := request parameter ]
conditionedBy: Optional unused
requiring: ( Optional containing: 'test complete' ).

html := self
self
renderUsing: [ :canvas |
command priorityActions do: [ :action | action value: self value: 'canvas' ].
command modelLoadingInstructions appendTo: 'script' on: canvas
Expand Down
54 changes: 44 additions & 10 deletions source/Willow-Core-Tests/WebInteractionInstructionsTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ A WebInteractionInstructionsTest is a test class for testing the behavior of Web
"
Class {
#name : #WebInteractionInstructionsTest,
#superclass : #TestCase,
#superclass : #BWRenderingTest,
#category : #'Willow-Core-Tests-WebInteraction'
}

Expand Down Expand Up @@ -76,23 +76,52 @@ WebInteractionInstructionsTest >> testDirectingTo [

| instructions |

instructions := WebInteractionInstructions directingTo: [ :canvas | canvas asString ].
instructions := WebInteractionInstructions directingTo: [ :canvas | 'this will be returned' ].
self
deny: instructions isEmpty;
assert: instructions notEmpty.

self assertCollection: ( instructions statementsOn: 8 ) equals: ( Array with: '8' )
self
renderUsing: [ :canvas |
self
assertCollection: ( instructions statementsOn: canvas )
equals: ( Array with: 'this will be returned' )
]
]

{ #category : #tests }
WebInteractionInstructionsTest >> testDirectingToOrderedAt [

| instructions otherInstructions combinedInstructions |

instructions := WebInteractionInstructions directingTo: [ :canvas | 'then this one' ] orderedAt: 30.
otherInstructions := WebInteractionInstructions
directingTo: [ :canvas | 'first thins one' ]
orderedAt: 10.
combinedInstructions := instructions combinedWith: otherInstructions.
self
deny: combinedInstructions isEmpty;
assert: combinedInstructions notEmpty.

self
renderUsing: [ :canvas |
self
assertCollection: ( combinedInstructions statementsOn: canvas )
equals: ( Array with: 'first thins one' with: 'then this one' )
]
]

{ #category : #tests }
WebInteractionInstructionsTest >> testEmpty [
|instructions|
instructions := WebInteractionInstructions empty.
self assert: instructions isEmpty;
deny: instructions notEmpty.

self assert: (instructions statementsOn: self ) isEmpty
| instructions |

instructions := WebInteractionInstructions empty.
self
assert: instructions isEmpty;
deny: instructions notEmpty.

self renderUsing: [ :canvas | self assert: ( instructions statementsOn: canvas ) isEmpty ]
]

{ #category : #tests }
Expand All @@ -118,6 +147,11 @@ WebInteractionInstructionsTest >> testStatementsOn [

| instructions |

instructions := WebInteractionInstructions directingTo: [ :canvas | canvas asString ].
self assertCollection: ( instructions statementsOn: 8 ) equals: ( Array with: '8' )
instructions := WebInteractionInstructions directingTo: [ :canvas | 'this will be returned' ].
self
renderUsing: [ :canvas |
self
assertCollection: ( instructions statementsOn: canvas )
equals: ( Array with: 'this will be returned' )
]
]
56 changes: 52 additions & 4 deletions source/Willow-Core-Tests/WebInteractionInterpreterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ WebInteractionInterpreterTest >> testAddCssClassToComponentsMatching [
'<input id="input-id1" type="text"/><script type="text/javascript">$("#input-id1").click(function(event){$(".aComponentByStyleName").addClass("willow")});</script>'
]

{ #category : #'tests - Configuring' }
WebInteractionInterpreterTest >> testAjaxCallsEvaluateTheBlock [

| interpreter evaluated |

interpreter := self clickInterpreter.
evaluated := false.
interpreter serverDo: [ evaluated := true ].
self
renderUsing: [ :canvas |
| component |

component := canvas textInput.
interpreter applyTo: component on: canvas.
self executeAjaxCallbacksOn: canvas
].
self assert: evaluated
]

{ #category : #'tests - evaluating' }
WebInteractionInterpreterTest >> testApplyToOn [

Expand Down Expand Up @@ -405,7 +424,7 @@ WebInteractionInterpreterTest >> testRender [
textInput := canvas textInput.
textInput id: id.
container := ContainerWebView
wrapping: [ :containerCanvas | textInput value ]
wrapping: [ :containerCanvas | containerCanvas render: id ]
intoElementBuiltUsing: [ :theCanvas | theCanvas div ]
applying: [ ].
interpreter render: container.
Expand All @@ -416,7 +435,7 @@ WebInteractionInterpreterTest >> testRender [
self
assert: html
equals:
'<input id="15" type="text"/><div id="container-id1"></div><script type="text/javascript">$("#15").change(function(event){Willow.callServer({"type":"POST","url":"/","data":["2",$(this).serialize()].join("&")})});</script>'
'<input id="15" type="text"/><div id="container-id1">15</div><script type="text/javascript">$("#15").change(function(event){Willow.callServer({"type":"POST","url":"/","data":["2",$(this).serialize()].join("&")})});</script>'
]

{ #category : #'tests - Configuring - DOM' }
Expand All @@ -434,7 +453,7 @@ WebInteractionInterpreterTest >> testRenderAll [
textInput := canvas textInput.
textInput id: id.
container := ContainerWebView
wrapping: [ :containerCanvas | textInput value ]
wrapping: [ :containerCanvas | containerCanvas render: id ]
intoElementBuiltUsing: [ :theCanvas | theCanvas div ]
applying: [ ].
anotherContainer := ContainerWebView
Expand All @@ -451,7 +470,36 @@ WebInteractionInterpreterTest >> testRenderAll [
self
assert: html
equals:
'<input id="15" type="text"/><div id="container-id1"></div><div id="container-id2"></div><script type="text/javascript">$("#15").change(function(event){Willow.callServer({"type":"POST","url":"/","data":["3",$(this).serialize()].join("&")})});</script>'
'<input id="15" type="text"/><div id="container-id1">15</div><div id="container-id2"></div><script type="text/javascript">$("#15").change(function(event){Willow.callServer({"type":"POST","url":"/","data":["3",$(this).serialize()].join("&")})});</script>'
]

{ #category : #'tests - Configuring - DOM' }
WebInteractionInterpreterTest >> testRenderIsAddedLast [

| interpreter id |

interpreter := self changeInterpreter.
id := '15'.

self
renderUsing: [ :canvas |
| textInput container |

textInput := canvas textInput.
textInput id: id.
container := ContainerWebView
wrapping: [ :containerCanvas | containerCanvas render: id ]
intoElementBuiltUsing: [ :theCanvas | theCanvas div ]
applying: [ ].
interpreter
render: container;
serverDo: [ id := 27 ].
canvas render: container.
interpreter applyTo: textInput on: canvas.
self executeAjaxCallbacksOn: canvas
].

self assert: self requestContext response contents equals: '$("#container-id1").html("27")'
]

{ #category : #'tests - Configuring - DOM' }
Expand Down
14 changes: 6 additions & 8 deletions source/Willow-Core/CombinedWebInteractionInterpreter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,14 @@ CombinedWebInteractionInterpreter >> serializeWithHiddenInputs [
{ #category : #Configuring }
CombinedWebInteractionInterpreter >> serverDo: aCallbackBlock [

self interpretersDo: [:interpreter | interpreter serverDo: aCallbackBlock]
self interpretersDo: [ :interpreter | interpreter serverDo: aCallbackBlock ]
]

{ #category : #'Configuring - DOM' }
CombinedWebInteractionInterpreter >> setValueTo: aValueProvider thenTriggerChangeOf: anIdentifiedView [

self
interpretersDo:
[ :interpreter | interpreter setValueTo: aValueProvider thenTriggerChangeOf: anIdentifiedView ]
interpretersDo: [ :interpreter | interpreter setValueTo: aValueProvider thenTriggerChangeOf: anIdentifiedView ]
]

{ #category : #'Configuring - DOM' }
Expand All @@ -169,7 +168,7 @@ CombinedWebInteractionInterpreter >> setValueTo: aValueProvider withoutTriggerin
{ #category : #Configuring }
CombinedWebInteractionInterpreter >> showLoadingNotificationStyledAsAll: classes [

self interpretersDo: [:interpreter | interpreter showLoadingNotificationStyledAsAll: classes]
self interpretersDo: [ :interpreter | interpreter showLoadingNotificationStyledAsAll: classes ]
]

{ #category : #'Configuring - Serialization' }
Expand All @@ -181,7 +180,7 @@ CombinedWebInteractionInterpreter >> submitForm: anIdentifiedForm [
{ #category : #Configuring }
CombinedWebInteractionInterpreter >> submitFormStyledAs: aCssStyle [

self interpretersDo: [:interpreter | interpreter submitFormStyledAs: aCssStyle]
self interpretersDo: [ :interpreter | interpreter submitFormStyledAs: aCssStyle ]
]

{ #category : #'Configuring - DOM' }
Expand Down Expand Up @@ -209,15 +208,14 @@ CombinedWebInteractionInterpreter >> updateCssClasses: aCssClassConfigurationBlo
{ #category : #Configuring }
CombinedWebInteractionInterpreter >> userAgentDo: aServerIndependentAction [

self interpretersDo: [:interpreter | interpreter userAgentDo: aServerIndependentAction]
self interpretersDo: [ :interpreter | interpreter userAgentDo: aServerIndependentAction ]
]

{ #category : #Configuring }
CombinedWebInteractionInterpreter >> with: aParameter onlyWhen: aStringCondition serverDo: aCallbackBlock [

self
interpretersDo:
[ :interpreter | interpreter with: aParameter onlyWhen: aStringCondition serverDo: aCallbackBlock ]
interpretersDo: [ :interpreter | interpreter with: aParameter onlyWhen: aStringCondition serverDo: aCallbackBlock ]
]

{ #category : #Configuring }
Expand Down
7 changes: 4 additions & 3 deletions source/Willow-Core/ComponentFocusingCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Class {
{ #category : #'instance creation' }
ComponentFocusingCommand class >> findingComponentUsing: aComponentProvider [

^self new initializeFindingComponentUsing: aComponentProvider
^ self new initializeFindingComponentUsing: aComponentProvider
]

{ #category : #'instance creation' }
Expand All @@ -22,7 +22,7 @@ ComponentFocusingCommand class >> for: anIdentifiedView [
^ self findingComponentUsing: [ :aCanvas | aCanvas locate: anIdentifiedView ]
]

{ #category : #'initialize-release' }
{ #category : #initialization }
ComponentFocusingCommand >> initializeFindingComponentUsing: aComponentProvider [

componentProvider := aComponentProvider
Expand All @@ -33,6 +33,7 @@ ComponentFocusingCommand >> modelLoadingInstructions [

^ WebInteractionInstructions
directingTo: [ :aCanvas | ( componentProvider value: aCanvas ) triggerFocus ]
orderedAt: 20
]

{ #category : #accessing }
Expand All @@ -44,7 +45,7 @@ ComponentFocusingCommand >> priorityActions [
{ #category : #testing }
ComponentFocusingCommand >> requiresSerialization [

^false
^ false
]

{ #category : #accessing }
Expand Down
4 changes: 3 additions & 1 deletion source/Willow-Core/ComponentRemovingCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ ComponentRemovingCommand >> initializeFor: anIdentifiedView [
{ #category : #accessing }
ComponentRemovingCommand >> modelLoadingInstructions [

^ WebInteractionInstructions directingTo: [ :aCanvas | ( aCanvas locate: identifiedView ) remove ]
^ WebInteractionInstructions
directingTo: [ :aCanvas | ( aCanvas locate: identifiedView ) remove ]
orderedAt: 20
]

{ #category : #accessing }
Expand Down
1 change: 1 addition & 0 deletions source/Willow-Core/ComponentValueSettingCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ ComponentValueSettingCommand >> modelLoadingInstructions [
jQueryInstance value: valueProvider value.
triggeringAction cull: jQueryInstance
]
orderedAt: 20
]

{ #category : #accessing }
Expand Down
1 change: 1 addition & 0 deletions source/Willow-Core/DialogClosingCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ DialogClosingCommand >> modelLoadingInstructions [
matching: dialogSupplier
on: aCanvas
]
orderedAt: 10
]

{ #category : #accessing }
Expand Down
1 change: 1 addition & 0 deletions source/Willow-Core/DialogOpeningCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ DialogOpeningCommand >> modelLoadingInstructions [

^ WebInteractionInstructions
directingTo: [ :aCanvas | DialogOpener new open: dialogView on: aCanvas ]
orderedAt: 10
]

{ #category : #accessing }
Expand Down
1 change: 0 additions & 1 deletion source/Willow-Core/EventInterpreterDispatcher.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ Class {
#name : #EventInterpreterDispatcher,
#superclass : #EventInterpreterDispatcherBehavior,
#instVars : [
'interactionsByEvent',
'interpretersByEvent',
'defaultInterpreter'
],
Expand Down
1 change: 1 addition & 0 deletions source/Willow-Core/FormSubmitCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ FormSubmitCommand >> modelLoadingInstructions [

^ WebInteractionInstructions
directingTo: [ :aCanvas | ( componentProvider value: aCanvas ) call: 'submit' ]
orderedAt: 10
]

{ #category : #accessing }
Expand Down
Loading

0 comments on commit 7808af3

Please sign in to comment.