From 4ac5d9fb4ee8e46110d7934b04ec952bc7741d15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phaneDucasse?= Date: Tue, 21 Nov 2023 11:10:55 +0100 Subject: [PATCH] Cleaning more and adding better tests --- .../BaselineOfSpecCore.class.st | 5 ++- src/Spec2-Dialogs-Tests/SpDialogTest.class.st | 44 +++++++++++++++++++ src/Spec2-Dialogs-Tests/package.st | 1 + src/Spec2-Dialogs/SpInformUserDialog.class.st | 13 ++++-- src/Spec2-Dialogs/SpProgressDialog.class.st | 22 ++-------- 5 files changed, 60 insertions(+), 25 deletions(-) create mode 100644 src/Spec2-Dialogs-Tests/SpDialogTest.class.st create mode 100644 src/Spec2-Dialogs-Tests/package.st diff --git a/src/BaselineOfSpecCore/BaselineOfSpecCore.class.st b/src/BaselineOfSpecCore/BaselineOfSpecCore.class.st index 8f43df40..40435acd 100644 --- a/src/BaselineOfSpecCore/BaselineOfSpecCore.class.st +++ b/src/BaselineOfSpecCore/BaselineOfSpecCore.class.st @@ -16,7 +16,8 @@ BaselineOfSpecCore >> baseline: spec [ "Core" package: 'Spec2-Layout'; package: 'Spec2-Core' with: [ spec requires: #('Spec2-Layout') ]; - package: 'Spec2-Dialogs' with: [ spec requires: #('Spec2-Core') ]; + package: 'Spec2-Dialogs' with: [ spec requires: #('Spec2-Dialogs') ]; + package: 'Spec2-Dialogs-Tests' with: [ spec requires: #('Spec2-Core') ]; package: 'Spec2-CommandLine' with: [ spec requires: #('Spec2-Core') ]; package: 'Spec2-Commands'; package: 'Spec2-Transmission' with: [ spec requires: #('Spec2-Core') ]; @@ -32,7 +33,7 @@ BaselineOfSpecCore >> baseline: spec [ "Tests" package: 'Spec2-Adapters-Stub' with: [ spec requires: #('Spec2-Core') ]; package: 'Spec2-Commander2-Tests' with: [ spec requires: #('Spec2-Commander2') ]; - package: 'Spec2-Tests' with: [ spec requires: #('Spec2-Core' 'Spec2-Examples') ]; + package: 'Spec2-Tests' with: [ spec requires: #('Spec2-Core' 'Spec2-Examples' 'Spec2-Dialogs-Tests') ]; package: 'Spec2-Code-Tests' with: [ spec requires: #('Spec2-Tests' 'Spec2-Code') ]; package: 'Spec2-Code-Diff-Tests' with: [ spec requires: #('Spec2-Tests' 'Spec2-Code-Diff') ]; "Examples" diff --git a/src/Spec2-Dialogs-Tests/SpDialogTest.class.st b/src/Spec2-Dialogs-Tests/SpDialogTest.class.st new file mode 100644 index 00000000..46c9d955 --- /dev/null +++ b/src/Spec2-Dialogs-Tests/SpDialogTest.class.st @@ -0,0 +1,44 @@ +Class { + #name : 'SpDialogTest', + #superclass : 'TestCase', + #category : 'Spec2-Dialogs-Tests', + #package : 'Spec2-Dialogs-Tests' +} + +{ #category : 'tests - informUserDuring' } +SpDialogTest >> testInformUserDuring [ + + self shouldnt: [ SpInformUserDialog new informUser: 'hello' during: [ (Delay forMilliseconds: 100) wait] ] raise: Error +] + +{ #category : 'tests - progress bar' } +SpDialogTest >> testInformUserDuringExecutesItsBlock [ + + | executed | + executed := false. + SpInformUserDialog new informUser: 'hello' during: [ executed := true ]. + self assert: executed. +] + +{ #category : 'tests - informUserDuring' } +SpDialogTest >> testInformUserDuringViaApplication [ + + self shouldnt: [ SpPresenter new application informUser: 'hello' during: [ (Delay forMilliseconds: 100) wait] ] raise: Error. + +] + +{ #category : 'tests - informUserDuring' } +SpDialogTest >> testInformUserDuringViaPresenter [ + + self shouldnt: [ SpPresenter new informUser: 'hello' during: [ (Delay forMilliseconds: 100) wait] ] raise: Error. + self shouldnt: [ SpPresenter new informUser: 'hello' during: [ (Delay forMilliseconds: 100) wait] ] raise: Error +] + +{ #category : 'tests - progress bar' } +SpDialogTest >> testProgressInformUserDuringExecutesItsBlock [ + + | executed | + executed := false. + SpProgressDialog new informUser: 'hello' during: [ executed := true. ]. + self assert: executed. +] diff --git a/src/Spec2-Dialogs-Tests/package.st b/src/Spec2-Dialogs-Tests/package.st new file mode 100644 index 00000000..0b97e418 --- /dev/null +++ b/src/Spec2-Dialogs-Tests/package.st @@ -0,0 +1 @@ +Package { #name : 'Spec2-Dialogs-Tests' } diff --git a/src/Spec2-Dialogs/SpInformUserDialog.class.st b/src/Spec2-Dialogs/SpInformUserDialog.class.st index 38ccae7e..bd5d5b27 100644 --- a/src/Spec2-Dialogs/SpInformUserDialog.class.st +++ b/src/Spec2-Dialogs/SpInformUserDialog.class.st @@ -62,15 +62,20 @@ SpInformUserDialog >> afterOpenAction [ { #category : 'api' } SpInformUserDialog >> informUser: aString during: aBlock [ - - self informUserDuring: [ :bar | - bar label: aString. + "Pay attention that the aBlock argument does not expect an argument representing the bar. + Check class side example." + + title := aString. + self informUserDuring: [ aBlock value ] ] { #category : 'api' } SpInformUserDialog >> informUserDuring: aBlock [ - + "Inform the user with a title during an execution. + Pay attention in this method the block is expecting no argument while in the subclass + it expects the progress bar. + Check examples on the class side" openAction := aBlock. self openModal. parentWindow ifNotNil: [ diff --git a/src/Spec2-Dialogs/SpProgressDialog.class.st b/src/Spec2-Dialogs/SpProgressDialog.class.st index 299d26ef..5997d79e 100644 --- a/src/Spec2-Dialogs/SpProgressDialog.class.st +++ b/src/Spec2-Dialogs/SpProgressDialog.class.st @@ -65,32 +65,16 @@ SpProgressDialog >> afterOpenAction [ ] fork ] -{ #category : 'examples' } -SpProgressDialog >> exampleModal [ - - self new - title: 'Example Progress'; - label: 'You are seeing a progress dialog!'; - openModal -] - { #category : 'api' } SpProgressDialog >> informUser: aString during: aBlock [ - + "Pay attention that the aBlock argument does not expect an argument representing the bar. + Check class side example." + self informUserDuring: [ :bar | bar label: aString. aBlock value ] ] -{ #category : 'api' } -SpProgressDialog >> informUserDuring: aBlock [ - - openAction := aBlock. - self openModal. - parentWindow ifNotNil: [ - parentWindow takeKeyboardFocus ] -] - { #category : 'initialization' } SpProgressDialog >> initialize [