Warning, /frameworks/kirigami/autotests/tst_avatar.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.12
0002 import QtQuick.Controls 2.12 as QQC2
0003 import org.kde.kirigami 2.14 as Kirigami
0004 import QtTest 1.0
0005 
0006 Item {
0007     id: root
0008 
0009     width: 110
0010     height: 110 * 3
0011 
0012     TestCase {
0013         name: "AvatarTests"
0014         function test_latin_name() {
0015             compare(Kirigami.NameUtils.isStringUnsuitableForInitials("Nate Martin"), false)
0016             compare(Kirigami.NameUtils.initialsFromString("Nate Martin"), "NM")
0017 
0018             compare(Kirigami.NameUtils.isStringUnsuitableForInitials("Kalanoka"), false)
0019             compare(Kirigami.NameUtils.initialsFromString("Kalanoka"), "K")
0020 
0021             compare(Kirigami.NameUtils.isStringUnsuitableForInitials("Why would anyone use such a long not name in the field of the Name"), false)
0022             compare(Kirigami.NameUtils.initialsFromString("Why would anyone use such a long not name in the field of the Name"), "WN")
0023 
0024             compare(Kirigami.NameUtils.isStringUnsuitableForInitials("Live-CD User"), false)
0025             compare(Kirigami.NameUtils.initialsFromString("Live-CD User"), "LU")
0026         }
0027         // these are just randomly sampled names from internet pages in the
0028         // source languages of the name
0029         function test_jp_name() {
0030             compare(Kirigami.NameUtils.isStringUnsuitableForInitials("北里 柴三郎"), false)
0031             compare(Kirigami.NameUtils.initialsFromString("北里 柴三郎"), "北")
0032 
0033             compare(Kirigami.NameUtils.isStringUnsuitableForInitials("小野田 寛郎"), false)
0034             compare(Kirigami.NameUtils.initialsFromString("小野田 寛郎"), "小")
0035         }
0036         function test_cn_name() {
0037             compare(Kirigami.NameUtils.isStringUnsuitableForInitials("蔣經國"), false)
0038             compare(Kirigami.NameUtils.initialsFromString("蔣經國"), "蔣")
0039         }
0040         function test_cyrillic_name() {
0041             compare(Kirigami.NameUtils.isStringUnsuitableForInitials("Нейт Мартин"), false)
0042             compare(Kirigami.NameUtils.initialsFromString("Нейт Мартин"), "НМ")
0043 
0044             compare(Kirigami.NameUtils.isStringUnsuitableForInitials("Каланока"), false)
0045             compare(Kirigami.NameUtils.initialsFromString("Каланока"), "К")
0046 
0047             compare(Kirigami.NameUtils.isStringUnsuitableForInitials("Зачем кому-то использовать такое длинное не имя в поле Имя"), false)
0048             compare(Kirigami.NameUtils.initialsFromString("Зачем кому-то использовать такое длинное не имя в поле Имя"), "ЗИ")
0049 
0050             compare(Kirigami.NameUtils.isStringUnsuitableForInitials("Пользователь Лайв-СИДИ"), false)
0051             compare(Kirigami.NameUtils.initialsFromString("Лайв-СИДИ Пользователь"), "ЛП")
0052         }
0053         function test_bad_names() {
0054             compare(Kirigami.NameUtils.isStringUnsuitableForInitials("151231023"), true)
0055         }
0056     }
0057     TestCase {
0058         name: "AvatarActions"
0059 
0060         width: 110
0061         height: 110 * 3
0062         visible: true
0063         when: windowShown
0064 
0065         Kirigami.Avatar {
0066             id: avatarWithNullAction
0067 
0068             x: 5
0069             y: 5
0070             width: 100
0071             height: 100
0072 
0073             actions.main: null
0074             activeFocusOnTab: true
0075         }
0076 
0077         Kirigami.Avatar {
0078             id: avatarWithKirigamiAction
0079 
0080             x: 5
0081             y: 110 + 5
0082             width: 100
0083             height: 100
0084 
0085             actions.main: Kirigami.Action {
0086                 onTriggered: {
0087                     signalProxyForKirigamiAction.triggered();
0088                 }
0089             }
0090 
0091             QtObject {
0092                 id: signalProxyForKirigamiAction
0093                 signal triggered()
0094             }
0095 
0096             SignalSpy {
0097                 id: spyKirigamiAction
0098                 target: signalProxyForKirigamiAction
0099                 signalName: "triggered"
0100             }
0101         }
0102 
0103         Kirigami.Avatar {
0104             id: avatarWithImpostorAction
0105 
0106             x: 5
0107             y: 110 * 2 + 5
0108             width: 100
0109             height: 100
0110 
0111             // Ideally, custom objects should not be assignable here
0112             actions.main: QtObject {
0113                 function trigger() {
0114                     signalProxyForImpostorAction.triggered();
0115                     return true;
0116                 }
0117             }
0118 
0119             QtObject {
0120                 id: signalProxyForImpostorAction
0121                 signal triggered()
0122             }
0123 
0124             SignalSpy {
0125                 id: spyImpostorAction
0126                 target: signalProxyForImpostorAction
0127                 signalName: "triggered"
0128             }
0129         }
0130 
0131         function test_null_action() {
0132             mouseClick(avatarWithNullAction);
0133             avatarWithNullAction.forceActiveFocus(Qt.TabFocusReason);
0134             compare(avatarWithNullAction.activeFocus, true);
0135             keyClick(Qt.Key_Space);
0136             keyClick(Qt.Key_Return);
0137             keyClick(Qt.Key_Enter);
0138             // Should not print any TypeError warnings, but there's no way to
0139             // test it, except that it should not abort execution of this
0140             // test script.
0141             // TODO KF6: Use failOnWarning available from Qt 6.3
0142         }
0143 
0144         function test_kirigami_action() {
0145             spyKirigamiAction.clear();
0146             mouseClick(avatarWithKirigamiAction);
0147             compare(spyKirigamiAction.count, 1);
0148             avatarWithKirigamiAction.forceActiveFocus(Qt.TabFocusReason);
0149             keyClick(Qt.Key_Space);
0150             compare(spyKirigamiAction.count, 2);
0151             keyClick(Qt.Key_Return);
0152             compare(spyKirigamiAction.count, 3);
0153             keyClick(Qt.Key_Enter);
0154             compare(spyKirigamiAction.count, 4);
0155         }
0156 
0157         function test_impostor_action() {
0158             spyImpostorAction.clear();
0159             mouseClick(avatarWithImpostorAction);
0160             compare(spyImpostorAction.count, 1);
0161             avatarWithImpostorAction.forceActiveFocus(Qt.TabFocusReason);
0162             keyClick(Qt.Key_Space);
0163             compare(spyImpostorAction.count, 2);
0164             keyClick(Qt.Key_Return);
0165             compare(spyImpostorAction.count, 3);
0166             keyClick(Qt.Key_Enter);
0167             compare(spyImpostorAction.count, 4);
0168         }
0169     }
0170 }