Skip to content

Commit

Permalink
test refactoring + transparent global color
Browse files Browse the repository at this point in the history
  • Loading branch information
simonimmelmann committed Jul 12, 2024
1 parent 6e6201d commit 27d8e3a
Show file tree
Hide file tree
Showing 8 changed files with 337 additions and 226 deletions.
10 changes: 7 additions & 3 deletions src/SqueakWhiteboard-Core/WBElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -897,15 +897,19 @@ WBElement >> right [

{
#category : #layout,
#'squeak_changestamp' : 'si 7/11/2024 14:48'
#'squeak_changestamp' : 'si 7/12/2024 11:38'
}
WBElement >> setLayout [

self
extent: self class defaultSize;
borderWidth: 3;
color: self canvas globalColor;
borderColor: self canvas globalColor
borderColor: self canvas globalColor.
self canvas globalColor = Color transparent
ifTrue:
[self color: self canvas globalColor.
self borderColor: Color black]
ifFalse: [self color: self canvas globalColor]
]

{
Expand Down
42 changes: 34 additions & 8 deletions src/SqueakWhiteboard-Core/WBToolbar.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ WBToolbar >> buttonFunctionalityForTextbox [
^ [:aButton | self canvas spawnAnElement: (WBTextbox newWithCanvas: self canvas) At: aButton currentMouseEvent]
]

{
#category : #'button functionalities',
#'squeak_changestamp' : 'si 7/12/2024 11:35'
}
WBToolbar >> buttonFunctionalityForTransparentColor [

^ [:aButton | self canvas globalColor: Color transparent]
]

{
#category : #appearance,
#'squeak_changestamp' : 'si 7/11/2024 15:38'
Expand Down Expand Up @@ -212,20 +221,23 @@ WBToolbar >> canvas: aCanvas [

{
#category : #'button creation',
#'squeak_changestamp' : 'si 7/11/2024 15:32'
#'squeak_changestamp' : 'si 7/12/2024 11:34'
}
WBToolbar >> createColorButtons [

^ OrderedCollection new
add: (self getColorButtonWithColor: Color yellow);
add: (self getColorButtonWithColor: Color orange);
add: (self getColorButtonWithColor: Color black);
add: (self getColorButtonWithColor: Color gray);
add: (self getTransparentColorButton);
add: (self getColorButtonWithColor: Color red);
add: (self getColorButtonWithColor: Color magenta);
add: (self getColorButtonWithColor: Color blue);
add: (self getColorButtonWithColor: Color cyan);
add: (self getColorButtonWithColor: Color orange);
add: (self getColorButtonWithColor: Color yellow);
add: (self getColorButtonWithColor: Color green);
add: (self getColorButtonWithColor: Color gray);
add: (self getColorButtonWithColor: Color black);
add: (self getColorButtonWithColor: Color cyan);
add: (self getColorButtonWithColor: Color blue);
add: (self getColorButtonWithColor: Color ocean);
add: (self getColorButtonWithColor: Color magenta);
add: (self getColorButtonWithColor: Color magenta muchDarker);
yourself
]

Expand Down Expand Up @@ -469,6 +481,20 @@ WBToolbar >> getTextboxButton [

]

{
#category : #'get buttons',
#'squeak_changestamp' : 'si 7/12/2024 11:34'
}
WBToolbar >> getTransparentColorButton [

^ WBButton new
color: Color white;
backgroundColor: Color white;
clickedColor: Color white muchDarker;
block: self buttonFunctionalityForTransparentColor;
yourself
]

{
#category : #appearance,
#'squeak_changestamp' : 'is 6/23/2024 02:09'
Expand Down
60 changes: 37 additions & 23 deletions src/SqueakWhiteboard-Tests/WBButtonTests.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ Class {
#category : #'SqueakWhiteboard-Tests'
}

{
#category : #'mouse click',
#'squeak_changestamp' : 'si 7/12/2024 10:57'
}
WBButtonTests >> artificialMouseClick [
| mouseEvent |

mouseEvent := MouseButtonEvent new.
mouseEvent setType: #mouseDown position: self canvas position + (100 @ 100) which: 4 buttons: mouseEvent class redButton hand: HandMorph new stamp: 0.
^ mouseEvent
]

{
#category : #accessing,
#'squeak_changestamp' : 'is 6/15/2024 13:00'
Expand All @@ -25,6 +37,15 @@ WBButtonTests >> canvas: aCanvas [
canvas := aCanvas
]

{
#category : #'getting button',
#'squeak_changestamp' : 'si 7/12/2024 10:56'
}
WBButtonTests >> getButtonWithFunctionality: aBlock from: aCollection [

aCollection do: [:b | b block asString = aBlock asString ifTrue: [^ b]]
]

{
#category : #setUp,
#'squeak_changestamp' : 'is 6/15/2024 13:02'
Expand All @@ -48,20 +69,18 @@ WBButtonTests >> tearDown [

{
#category : #testing,
#'squeak_changestamp' : 'is 6/21/2024 18:52'
#'squeak_changestamp' : 'si 7/12/2024 10:58'
}
WBButtonTests >> testButtonClickColor [
| aButton aMouseEvent |
| aButton |

aButton := WBButton new block: [:b | nil].
self assert: aButton color = aButton backgroundColor.

aMouseEvent := MouseButtonEvent new.
aMouseEvent setType: #mouseDown position: aButton position which: 4 buttons: aMouseEvent class redButton hand: HandMorph new stamp: 1.
aButton mouseDown: aMouseEvent.
aButton mouseDown: self artificialMouseClick.
self assert: aButton color = aButton clickedColor.

aButton mouseUp: aMouseEvent.
aButton mouseUp: self artificialMouseClick.
self assert: aButton color = aButton backgroundColor


Expand All @@ -73,20 +92,18 @@ WBButtonTests >> testButtonClickColor [

{
#category : #testing,
#'squeak_changestamp' : 'is 6/21/2024 18:52'
#'squeak_changestamp' : 'si 7/12/2024 10:59'
}
WBButtonTests >> testButtonHoverColor [
| aButton aMouseEvent |
| aButton |

aButton := WBButton new.
self assert: aButton color = aButton backgroundColor.

aMouseEvent := MouseEvent new position: aButton position.
aButton mouseEnter: aMouseEvent.
aButton mouseEnter: self artificialMouseClick.
self assert: aButton color = aButton hoverColor.

aMouseEvent position: aMouseEvent position + aButton extent + 1000.
aButton mouseLeave: aMouseEvent.
aButton mouseLeave: self artificialMouseClick.
self assert: aButton color = aButton backgroundColor


Expand All @@ -98,28 +115,25 @@ WBButtonTests >> testButtonHoverColor [

{
#category : #testing,
#'squeak_changestamp' : 'si 7/10/2024 13:24'
#'squeak_changestamp' : 'si 7/12/2024 11:01'
}
WBButtonTests >> testMouseDown [
| aButton aMouseEvent |
| aButton |

aButton := self canvas toolbar buttons at: 1.
aMouseEvent := MouseButtonEvent new.
aMouseEvent setType: #mouseDown position: (aButton position + aButton extent + (1 @ 1)) which: 4 buttons: aMouseEvent class redButton hand: HandMorph new stamp: 0.
self assert: (aButton handlesMouseOver: aMouseEvent) = true.
self assert: (aButton handlesMouseDown: aMouseEvent) = true.
self assert: (aButton handlesMouseOver: self artificialMouseClick) = true.
self assert: (aButton handlesMouseDown: self artificialMouseClick) = true.

"Test whether button actives on mouseUp"
aButton mouseDown: aMouseEvent.
aButton mouseDown: self artificialMouseClick.
self assert: aButton currentMouseEvent = nil.

"Test whether button activates only if position of mouse is still above button. Currently the mouse isn't"
aButton mouseUp: aMouseEvent.
aButton mouseUp: self artificialMouseClick.
self assert: aButton currentMouseEvent = nil.

aMouseEvent position: aButton position.
aButton mouseUp: aMouseEvent.
self assert: aButton currentMouseEvent = aMouseEvent
aButton mouseUp: (self artificialMouseClick position: aButton center).
self assert: aButton currentMouseEvent = (self artificialMouseClick position: aButton center)



Expand Down
100 changes: 60 additions & 40 deletions src/SqueakWhiteboard-Tests/WBDeletePopUpTests.class.st
Original file line number Diff line number Diff line change
@@ -1,28 +1,58 @@
Class {
#name : #WBDeletePopUpTests,
#superclass : #WBToolbarButtonTests,
#instVars : [
'buttonForDelete'
],
#category : #'SqueakWhiteboard-Tests'
}

{
#category : #asserting,
#'squeak_changestamp' : 'si 7/12/2024 11:12'
}
WBDeletePopUpTests >> buttonForDelete [

^ buttonForDelete
]

{
#category : #asserting,
#'squeak_changestamp' : 'si 7/12/2024 11:12'
}
WBDeletePopUpTests >> buttonForDelete: aButton [

buttonForDelete := aButton
]

{
#category : #setUp,
#'squeak_changestamp' : 'si 7/12/2024 11:13'
}
WBDeletePopUpTests >> setUp [

super setUp.
self buttonForDelete: (self getButtonWithFunctionality: self canvas toolbar buttonFunctionalityForDeleteAll from: self canvas toolbar submorphs)
]

{
#category : #tests,
#'squeak_changestamp' : 'si 7/11/2024 14:13'
#'squeak_changestamp' : 'si 7/12/2024 11:18'
}
WBDeletePopUpTests >> testButtonFunctionalityForCancel [
| button buttonForCancel mouseEvent |
| buttonForConfirm |

self buttonForDelete clickFunctionality: self artificialMouseClick.

mouseEvent := MouseButtonEvent new.
mouseEvent setType: #mouseDown position: self canvas position + (100 @ 100) which: 4 buttons: mouseEvent class redButton hand: HandMorph new stamp: 0.
button := self canvas toolbar buttons at: 6.
button clickFunctionality: (MouseButtonEvent new position: self canvas position + (100 @ 100)).
self canvas spawnAnElement: (WBRectangularElement newWithCanvas: self canvas) At: self artificialMouseClick.
self canvas dropElement: self artificialMouseClick.
self canvas spawnAnElement: (WBRectangularElement newWithCanvas: self canvas) At: self artificialMouseClick.
self canvas dropElement: self artificialMouseClick.

self canvas spawnAnElement: (WBRectangularElement newWithCanvas: self canvas) At: (MouseButtonEvent new position: self canvas position + (100 @ 100)).
self canvas dropElement: mouseEvent.
self canvas spawnAnElement: (WBRectangularElement newWithCanvas: self canvas) At: (MouseButtonEvent new position: self canvas position + (200 @ 200)).
self canvas dropElement: mouseEvent.
self assert: self canvas elements size = 2.

buttonForCancel := self canvas toolbar popUp submorphs at: 1.
buttonForCancel clickFunctionality: (MouseButtonEvent new position: self canvas position + (100 @ 100)).
buttonForConfirm := self getButtonWithFunctionality: self canvas toolbar buttonFunctionalityForDeleteCancel from: canvas toolbar popUp submorphs.
buttonForConfirm clickFunctionality: self artificialMouseClick.

self assert: self canvas elements size = 2.
self assert: self canvas toolbar popUp = nil.
Expand All @@ -31,24 +61,22 @@ WBDeletePopUpTests >> testButtonFunctionalityForCancel [

{
#category : #tests,
#'squeak_changestamp' : 'si 7/11/2024 14:13'
#'squeak_changestamp' : 'si 7/12/2024 11:18'
}
WBDeletePopUpTests >> testButtonFunctionalityForConfirm [
| button buttonForConfirm mouseEvent |
| buttonForConfirm |

mouseEvent := MouseButtonEvent new.
mouseEvent setType: #mouseDown position: self canvas position + (100 @ 100) which: 4 buttons: mouseEvent class redButton hand: HandMorph new stamp: 0.
self buttonForDelete clickFunctionality: self artificialMouseClick.

button := self canvas toolbar buttons at: 6.
button clickFunctionality: (MouseButtonEvent new position: self canvas position + (100 @ 100)).
self canvas spawnAnElement: (WBRectangularElement newWithCanvas: self canvas) At: self artificialMouseClick.
self canvas dropElement: self artificialMouseClick.
self canvas spawnAnElement: (WBRectangularElement newWithCanvas: self canvas) At: self artificialMouseClick.
self canvas dropElement: self artificialMouseClick.

self canvas spawnAnElement: (WBRectangularElement newWithCanvas: self canvas) At: (MouseButtonEvent new position: self canvas position + (100 @ 100)).
self canvas dropElement: mouseEvent.
self canvas spawnAnElement: (WBRectangularElement newWithCanvas: self canvas) At: (MouseButtonEvent new position: self canvas position + (200 @ 200)).
self canvas dropElement: mouseEvent.
self assert: self canvas elements size = 2.

buttonForConfirm := self canvas toolbar popUp submorphs at: 2.
buttonForConfirm clickFunctionality: (MouseButtonEvent new position: self canvas position + (100 @ 100)).
buttonForConfirm := self getButtonWithFunctionality: self canvas toolbar buttonFunctionalityForDeleteConfirm from: canvas toolbar popUp submorphs.
buttonForConfirm clickFunctionality: self artificialMouseClick.

self assert: self canvas elements size = 0.
self assert: self canvas toolbar popUp = nil.
Expand All @@ -57,54 +85,46 @@ WBDeletePopUpTests >> testButtonFunctionalityForConfirm [

{
#category : #tests,
#'squeak_changestamp' : 'ACL 7/7/2024 18:21'
#'squeak_changestamp' : 'si 7/12/2024 11:15'
}
WBDeletePopUpTests >> testButtonsOfPopUp [
| button |

button := self canvas toolbar buttons at: 6.
button clickFunctionality: (MouseButtonEvent new position: self canvas position + (100 @ 100)).
self buttonForDelete clickFunctionality: self artificialMouseClick.

self assert: self canvas toolbar popUp submorphs size = 2
]

{
#category : #tests,
#'squeak_changestamp' : 'ACL 7/7/2024 18:21'
#'squeak_changestamp' : 'si 7/12/2024 11:14'
}
WBDeletePopUpTests >> testExistenceOfPopUp [
| button|

button := self canvas toolbar buttons at: 6.
button clickFunctionality: (MouseButtonEvent new position: self canvas position + (100 @ 100)).
self buttonForDelete clickFunctionality: self artificialMouseClick.

self assert: self canvas toolbar popUp notNil.
self assert: self canvas text contents = WBToolbar textForDeleteAll
]

{
#category : #tests,
#'squeak_changestamp' : 'ACL 7/7/2024 18:21'
#'squeak_changestamp' : 'si 7/12/2024 11:15'
}
WBDeletePopUpTests >> testPopUpPlacementInX [
| button |

button := self canvas toolbar buttons at: 6.
button clickFunctionality: (MouseButtonEvent new position: self canvas position + (100 @ 100)).
self buttonForDelete clickFunctionality: self artificialMouseClick.

self assert: (self canvas center x - 100) <= self canvas toolbar popUp left.
self assert: self canvas toolbar popUp right <= (self canvas center x + 100)
]

{
#category : #tests,
#'squeak_changestamp' : 'ACL 7/7/2024 18:21'
#'squeak_changestamp' : 'si 7/12/2024 11:15'
}
WBDeletePopUpTests >> testPopUpPlacementInY [
| button |

button := self canvas toolbar buttons at: 6.
button clickFunctionality: (MouseButtonEvent new position: self canvas position + (100 @ 100)).
self buttonForDelete clickFunctionality: self artificialMouseClick.

self assert: self canvas center y <= self canvas toolbar popUp top.
self assert: self canvas toolbar popUp bottom <= (self canvas bottom)
Expand Down
Loading

0 comments on commit 27d8e3a

Please sign in to comment.