Skip to content

Commit

Permalink
Merge bd6893d into 9a385ef
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanecek committed Nov 5, 2018
2 parents 9a385ef + bd6893d commit a3a387c
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 38 deletions.
129 changes: 103 additions & 26 deletions source/Willow-Tests/LoadingNotificationCommandTest.class.st
Expand Up @@ -4,40 +4,80 @@ A LoadingNotificationCommandTest is a test class for testing the behavior of Loa
Class {
#name : #LoadingNotificationCommandTest,
#superclass : #WARenderingTest,
#instVars : [
'command'
],
#category : #'Willow-Tests-WebInteraction'
}

{ #category : #initialization }
LoadingNotificationCommandTest >> setUp [
{ #category : #'tests-accessing' }
LoadingNotificationCommandTest >> renderedContentUsingModelLoadingActionsOf: aCommand [

^ self
renderUsing: [ :canvas |
| script anchor |

script := canvas javascript.
anchor := canvas anchor.
canvas ensureIdFor: anchor.

super setUp.
command := LoadingNotificationCommand onPageTopWithClasses: #()
aCommand modelLoadingActions do: [ :action | action value: script value: canvas ].
anchor script: (canvas jQuery this onClick: script) ]
]

{ #category : #'tests-accessing' }
LoadingNotificationCommandTest >> renderedContentUsingServerIndependentActionOf: aCommand [

^ self
renderUsing: [ :canvas |
| script anchor |

script := canvas javascript.
aCommand serverIndependentActions do: [ :action | action value: script value: canvas ].
anchor := canvas anchor.
canvas ensureIdFor: anchor.
anchor script: (canvas jQuery this onClick: script) ].
]

{ #category : #'tests-accessing' }
LoadingNotificationCommandTest >> testClientIndependentActions [

| command |

command := LoadingNotificationCommand onPageTopWithClasses: #().

self assert: command clientIndependentActions isEmpty
]

{ #category : #'tests-accessing' }
LoadingNotificationCommandTest >> testClientIndependentActionsWithCustomView [

| command |

command := LoadingNotificationCommand displaying: [ :canvas | canvas span with: 'Processing...' ] applying: [ :div | div addClass loading ].

self assert: command clientIndependentActions isEmpty
]

{ #category : #'tests-accessing' }
LoadingNotificationCommandTest >> testModelLoadingActions [

| html |
| html command |

command := LoadingNotificationCommand onPageTopWithClasses: #().

html := self
renderUsing: [ :canvas |
| script anchor |
html := self renderedContentUsingModelLoadingActionsOf: command.

script := canvas javascript.
anchor := canvas anchor.
canvas ensureIdFor: anchor.
self
assert: html
equals: '<a id="a-id1"></a><script type="text/javascript">$("#a-id1").click(function(){$("#willow-notification-section").html("")});</script>'
]

command modelLoadingActions do: [ :action | action value: script value: canvas ].
anchor script: (canvas jQuery this onClick: script) ].
{ #category : #'tests-accessing' }
LoadingNotificationCommandTest >> testModelLoadingActionsWithCustomView [

| html command |

command := LoadingNotificationCommand displaying: [ :canvas | canvas span with: 'Processing...' ] applying: [ :div | div addClass loading ].

html := self renderedContentUsingModelLoadingActionsOf: command.

self
assert: html
Expand All @@ -47,32 +87,69 @@ LoadingNotificationCommandTest >> testModelLoadingActions [
{ #category : #'tests-accessing' }
LoadingNotificationCommandTest >> testPriorityActions [

| command |

command := LoadingNotificationCommand onPageTopWithClasses: #().

self assert: command priorityActions isEmpty
]

{ #category : #'tests-accessing' }
LoadingNotificationCommandTest >> testPriorityActionsWithCustomView [

| command |

command := LoadingNotificationCommand displaying: [ :canvas | canvas span with: 'Processing...' ] applying: [ :div | div addClass loading ].

self assert: command priorityActions isEmpty
]

{ #category : #'tests-testing' }
LoadingNotificationCommandTest >> testRequiresSerialization [

| command |

command := LoadingNotificationCommand onPageTopWithClasses: #().

self deny: command requiresSerialization
]

{ #category : #'tests-testing' }
LoadingNotificationCommandTest >> testRequiresSerializationWithCustomView [

| command |

command := LoadingNotificationCommand displaying: [ :canvas | canvas span with: 'Processing...' ] applying: [ :div | div addClass loading ].

self deny: command requiresSerialization
]

{ #category : #'tests-accessing' }
LoadingNotificationCommandTest >> testServerIndependentActions [

| html |
| html command |

command := LoadingNotificationCommand onPageTopWithClasses: #('loading').

html := self
renderUsing: [ :canvas |
| script anchor |
html := self renderedContentUsingServerIndependentActionOf: command.

script := canvas javascript.
command serverIndependentActions do: [ :action | action value: script value: canvas ].
anchor := canvas anchor.
canvas ensureIdFor: anchor.
anchor script: (canvas jQuery this onClick: script) ].
self
assert: html
equals:
'<a id="a-id1"></a><script type="text/javascript">$("#a-id1").click(function(){$("#willow-notification-section").html("<div class=\"loading\">Loading...</div>")});</script>'
]

{ #category : #'tests-accessing' }
LoadingNotificationCommandTest >> testServerIndependentActionsWithCustomVIew [

| html command |

command := LoadingNotificationCommand displaying: [ :canvas | canvas span with: 'Processing...' ] applying: [ :div | div addClass loading ].

html := self renderedContentUsingServerIndependentActionOf: command.

self
assert: html
equals:
'<a id="a-id1"></a><script type="text/javascript">$("#a-id1").click(function(){$("#willow-notification-section").html("<div>Loading...</div>")});</script>'
'<a id="a-id1"></a><script type="text/javascript">$("#a-id1").click(function(){$("#willow-notification-section").html("<div class=\"willow-loading\"><span>Processing...</span></div>")});</script>'
]
8 changes: 7 additions & 1 deletion source/Willow/IdentifiedWebView.class.st
Expand Up @@ -88,7 +88,13 @@ IdentifiedWebView class >> forRowNamed: aName containing: aView [
{ #category : #'instance creation' }
IdentifiedWebView class >> forSpanNamed: aName containing: aView [

^ self forComponentBuiltUsing: [ :canvas | canvas span ] named: aName containing: aView
^ self forSpanNamed: aName containing: aView applying: [ ]
]

{ #category : #'instance creation' }
IdentifiedWebView class >> forSpanNamed: aName containing: aView applying: aComponentCommand [

^ self forComponentBuiltUsing: [ :canvas | canvas span ] named: aName containing: aView applying: aComponentCommand
]

{ #category : #private }
Expand Down
29 changes: 18 additions & 11 deletions source/Willow/LoadingNotificationCommand.class.st
Expand Up @@ -11,32 +11,39 @@ Class {
#category : #'Willow-WebInteraction'
}

{ #category : #'instance creation - private' }
LoadingNotificationCommand class >> executing: aServerIndependentActionCollection then: aModelLoadingActionCollection [

^self new initializeExecuting: aServerIndependentActionCollection
then: aModelLoadingActionCollection
]

{ #category : #'instance creation' }
LoadingNotificationCommand class >> onPageTopWithClasses: aCssClassCollection [
LoadingNotificationCommand class >> displaying: aWebView applying: aComponentCommand [

^ self
executing:
(Array
with: [ :aScript :aCanvas |
aScript << (aCanvas jQuery id: Constants >> #willow >> #notificationSectionName)
html: [ :aSubCanvas |
aSubCanvas div
classes: aCssClassCollection;
with: 'Loading...' ] ])
aSubCanvas render:
(GenericContainerWebView wrapping: aWebView applying: aComponentCommand) ] ])
then:
(Array
with: [ :aScript :aCanvas |
aScript << (aCanvas jQuery id: Constants >> #willow >> #notificationSectionName)
html: [ :aSubCanvas | ] ])
]

{ #category : #'instance creation - private' }
LoadingNotificationCommand class >> executing: aServerIndependentActionCollection then: aModelLoadingActionCollection [

^self new initializeExecuting: aServerIndependentActionCollection
then: aModelLoadingActionCollection
]

{ #category : #'instance creation' }
LoadingNotificationCommand class >> onPageTopWithClasses: aCssClassCollection [

^ self
displaying: 'Loading...'
applying: (ComponentClassificationCommand toStyleWithAll: aCssClassCollection)
]

{ #category : #accessing }
LoadingNotificationCommand >> clientIndependentActions [

Expand Down
7 changes: 7 additions & 0 deletions source/Willow/WebInteractionInterpreter.class.st
Expand Up @@ -281,6 +281,13 @@ WebInteractionInterpreter >> setValueTo: aValueProvider withoutTriggeringChangeO
valueFrom: aValueProvider)
]

{ #category : #Configuring }
WebInteractionInterpreter >> showLoadingNotificationDisplaying: aWebView applying: aComponentCommand [

interaction onTriggerExecute:
(LoadingNotificationCommand displaying: aWebView applying: aComponentCommand)
]

{ #category : #Configuring }
WebInteractionInterpreter >> showLoadingNotificationStyledAsAll: classes [

Expand Down

0 comments on commit a3a387c

Please sign in to comment.