From 895cb4b491daae91be6a6ae0caaea376c14c21d0 Mon Sep 17 00:00:00 2001 From: Martin Dias Date: Wed, 13 Nov 2024 13:48:00 -0300 Subject: [PATCH] Add tests in SpSliderAdapterTest that were removed by mistake in e035028 --- .../SpSliderAdapterTest.class.st | 164 +++++++++++++++++- 1 file changed, 163 insertions(+), 1 deletion(-) diff --git a/src/Spec2-Backend-Tests/SpSliderAdapterTest.class.st b/src/Spec2-Backend-Tests/SpSliderAdapterTest.class.st index 37915e3a..a3ca0484 100644 --- a/src/Spec2-Backend-Tests/SpSliderAdapterTest.class.st +++ b/src/Spec2-Backend-Tests/SpSliderAdapterTest.class.st @@ -8,6 +8,168 @@ Class { { #category : 'accessing' } SpSliderAdapterTest >> classToTest [ + ^ SpSliderPresenter +] + +{ #category : 'tests' } +SpSliderAdapterTest >> testChangeInLabelUpdatesWidget [ + + self + assert: self adapter widgetLabel + closeTo: ''. + + presenter label: 'test'. + + self + assert: self adapter widgetLabel + equals: 'test' +] + +{ #category : 'tests' } +SpSliderAdapterTest >> testChangeInMaxUpdatesWidget [ + + presenter value: 80. + + "Default max is 100" + self + assert: self adapter widgetAbsoluteValue + closeTo: 0.8. + self + assert: self adapter widgetValue + equals: 80. + + "Changing max updates the slider value" + presenter max: 1000. + self + assert: self adapter widgetAbsoluteValue + closeTo: 0.8. + self + assert: self adapter widgetValue + equals: 800 +] + +{ #category : 'tests' } +SpSliderAdapterTest >> testChangeInMinUpdatesWidget [ + + presenter value: 80. + + "Default min is 0" + self + assert: self adapter widgetAbsoluteValue + closeTo: 0.8. + self + assert: self adapter widgetValue + equals: 80. + + "Changing min updates the slider value" + presenter min: 50. + self + assert: self adapter widgetAbsoluteValue + closeTo: 0.8. + self + assert: self adapter widgetValue + equals: 90 +] + +{ #category : 'tests' } +SpSliderAdapterTest >> testChangeInQuantumUpdatesWidget [ + + presenter + min: -50; + max: 150. + + "By default, quantum is 1, which means round Floats to Integer" + presenter value: 49.1. + self assert: self adapter widgetValue closeTo: 49. + + presenter value: -49.1. + self assert: self adapter widgetValue closeTo: -49. + + "Quantum is disabled when nil is set" + presenter quantum: nil. + + presenter value: 49.1. + self assert: self adapter widgetValue closeTo: 49.1. + + presenter value: -49.1. + self assert: self adapter widgetValue closeTo: -49.1. + + "Set 50 as quantum" + presenter quantum: 10. + + "Current value is automatically rounded acording to the new quamtum" + self assert: self adapter widgetValue equals: -50. + + "It also works with new values" + presenter value: 49. + self assert: self adapter widgetValue equals: 50 +] + +{ #category : 'tests' } +SpSliderAdapterTest >> testChangeInValueUpdatesWidget [ + + presenter + min: -50; + max: 150. + + presenter value: 50. + self assert: self adapter widgetValue equals: 50. + + presenter value: -50. + self assert: self adapter widgetValue equals: -50 +] + +{ #category : 'tests' } +SpSliderAdapterTest >> testPresenterUpdatesWidget [ + + presenter + min: -50; + max: 150. + + presenter value: 50. + self assert: self adapter widgetValue equals: 50. + + presenter value: -50. + self assert: self adapter widgetValue equals: -50. + + "By default, quantum is 1, which means round Floats to Integer" + presenter value: 49.1. + self assert: self adapter widgetValue closeTo: 49. + + presenter value: -49.1. + self assert: self adapter widgetValue closeTo: -49. + + "Quantum is disabled when nil is set" + presenter quantum: nil. + + presenter value: 49.1. + self assert: self adapter widgetValue closeTo: 49.1. + + presenter value: -49.1. + self assert: self adapter widgetValue closeTo: -49.1. + + "Set 50 as quantum" + presenter quantum: 10. + + "Current value is automatically rounded acording to the new quamtum" + self assert: self adapter widgetValue equals: -50. + + "It also works with new values" + presenter value: 49. + self assert: self adapter widgetValue equals: 50 +] + +{ #category : 'tests' } +SpSliderAdapterTest >> testWidgetUpdatesPresenter [ + + presenter + min: -50; + max: 150; + quantum: 10. + + "Emulate a change on the widget" + self adapter widgetValue: 54. - ^ SpSliderPresenter + self assert: presenter value equals: 50. + self assert: presenter absoluteValue equals: 0.5 ]