Commit 328c1aaf authored by Heqro Iglens's avatar Heqro Iglens Committed by Nate Graham
Browse files

Add simple tests for VolumeSlider

VolumeSlider is a Slider that features a MouseArea inside it. This is a combination that I myself have broken
from time to time. Hence, I add three simple test cases for reacting to clicks, for reacting to dragging while
the mouse is pressed and for reacting to the user's wheel input.

The test case for the wheel input requires to expose the 'wheelEffect' property, which is the hack we use
in MouseArea to avoid getting tickmarks. Its value is 5, because that's the value it had without the property.
Exposing this property makes sure that the test case won't fail if, say, the number 5 was exchanged for
the number 6.
parent 53e23eae
Pipeline #219787 passed with stage
in 15 minutes and 59 seconds
import QtQuick 2.3
import QtTest 1.0
import "../../src/qml"
Item {
VolumeSlider {
id: slider
readonly property int middleValue: (slider.to - slider.from) / 2
}
TestCase {
name: "Clicking, dragging, wheel test"
when: windowShown
function init() {
mouseClick(slider, 0, 0) // set slider to leftmost part
}
function test_click() {
mouseClick(slider)
verify(slider.value == slider.middleValue, "Clicking in the middle of the slider should set its value to the middle");
}
function test_click_drag() {
mouseDrag(slider, 0, 0, slider.width, 0) // drag from leftmost side to rightmost side
verify(slider.value == 100, "Should have slided to the maximum")
mouseDrag(slider,slider.width,0,-slider.width,0) // drag from rightmost side to leftmost side
verify(slider.value == 0, "Should have slided to the minimum")
}
function test_wheel() { // checking that wheel works
mouseWheel(slider, 0,0,0, 120) // wheel up one notch
verify(slider.value == slider.wheelEffect, "The current value of the slider should be equal to the wheel effect")
mouseWheel(slider, 0,0,0, -120) // wheel down one notch
verify(slider.value == 0, "The current value of the slider should be back to zero")
}
}
}
......@@ -20,6 +20,8 @@ Slider {
enabled: !muted
readonly property int wheelEffect: 5
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.NoButton
......@@ -30,11 +32,11 @@ Slider {
// the slider because if we do, it gets gets tickmarks which look ugly.
if (wheel.angleDelta.y > 0) {
// Increase volume
volumeSlider.value = Math.min(volumeSlider.to, volumeSlider.value + 5);
volumeSlider.value = Math.min(volumeSlider.to, volumeSlider.value + wheelEffect);
} else {
// Decrease volume
volumeSlider.value = Math.max(volumeSlider.from, volumeSlider.value - 5);
volumeSlider.value = Math.max(volumeSlider.from, volumeSlider.value - wheelEffect);
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment