Warning, /frameworks/kirigami/autotests/tst_placeholdermessage.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
0003 *
0004 * SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006
0007 import QtQuick
0008 import QtQuick.Controls as QQC2
0009 import org.kde.kirigami as Kirigami
0010 import QtTest
0011
0012 TestCase {
0013 id: root
0014
0015 name: "PlaceholderMessageTest"
0016 visible: true
0017 when: windowShown
0018
0019 width: 300
0020 height: 300
0021
0022 Component {
0023 id: placeholderMessageComponent
0024 Kirigami.PlaceholderMessage {
0025 id: message
0026
0027 anchors.centerIn: parent
0028 width: parent.width - (Kirigami.Units.largeSpacing * 4)
0029
0030 readonly property SignalSpy linkHoveredSpy: SignalSpy {
0031 target: message
0032 signalName: "linkHovered"
0033 }
0034 readonly property SignalSpy linkActivatedSpy: SignalSpy {
0035 target: message
0036 signalName: "linkActivated"
0037 }
0038 }
0039 }
0040
0041 Component {
0042 id: helpfulMessageComponent
0043 Kirigami.PlaceholderMessage {
0044 id: message
0045
0046 property int count: 0
0047
0048 anchors.centerIn: parent
0049 width: parent.width - (Kirigami.Units.largeSpacing * 4)
0050
0051 helpfulAction: QQC2.Action {
0052 onTriggered: {
0053 message.count += 1
0054 }
0055 }
0056 }
0057 }
0058
0059 function hoverAll(item: Item, /*predicate: (x, y) => bool*/ until) {
0060 for (let x = 0; x < item.width; x += 10) {
0061 for (let y = 0; y < item.height; y += 10) {
0062 mouseMove(item, x, y);
0063 if (until(x, y)) {
0064 return Qt.point(x, y);
0065 }
0066 }
0067 }
0068 return null;
0069 }
0070
0071 function test_link() {
0072 skip("finding links by sweeping with the mouse cursor all over the place seems very unreliable, especially on FreeBSD and Windows TODO: find a better way to find links")
0073 const href = "some";
0074 const message = createTemporaryObject(placeholderMessageComponent, this, {
0075 text: "Attention!",
0076 explanation: `<a href="${href}">link</a>`,
0077 });
0078 verify(message);
0079 verify(message.linkHoveredSpy.valid);
0080 verify(message.linkActivatedSpy.valid);
0081
0082 const point = hoverAll(message, (x, y) => message.hoveredLink === href);
0083 verify(point !== null);
0084 compare(message.linkHoveredSpy.count, 1);
0085 const hoveredLink = message.linkHoveredSpy.signalArguments[0][0];
0086 compare(hoveredLink, href);
0087
0088 mouseClick(message, point.x, point.y);
0089 compare(message.linkActivatedSpy.count, 1);
0090 const activatedLink = message.linkActivatedSpy.signalArguments[0][0];
0091 compare(activatedLink, href);
0092 }
0093
0094 function test_action() {
0095 const message = createTemporaryObject(helpfulMessageComponent, this, {
0096 text: "Attention!",
0097 });
0098 const point = hoverAll(message, (x, y) => {
0099 mouseClick(message, x, y);
0100 return message.count > 0;
0101 });
0102 verify(point !== null);
0103 compare(message.count, 1);
0104 }
0105
0106 function test_disabled_action() {
0107 const message = createTemporaryObject(helpfulMessageComponent, this, {
0108 text: "Attention!",
0109 });
0110 message.helpfulAction.enabled = false;
0111 const point = hoverAll(message, (x, y) => {
0112 mouseClick(message, x, y);
0113 return message.count > 0;
0114 });
0115 verify(point === null);
0116 compare(message.count, 0);
0117 }
0118
0119 function test_null_action() {
0120 const message = createTemporaryObject(helpfulMessageComponent, this, {
0121 text: "Attention!",
0122 helpfulAction: null,
0123 });
0124 const point = hoverAll(message, (x, y) => {
0125 mouseClick(message, x, y);
0126 return message.count > 0;
0127 });
0128 verify(point === null);
0129 compare(message.count, 0);
0130 }
0131 }