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

0001 /*
0002  *  SPDX-FileCopyrightText: 2020 Janet Blackquill <uhhadd@gmail.com>
0003  *  SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
0004  *
0005  *  SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 
0008 import QtQuick
0009 import QtQuick.Controls as QQC2
0010 import QtQuick.Templates as T
0011 import QtTest
0012 
0013 import org.kde.kirigami as Kirigami
0014 import org.kde.kirigamiaddons.components as KirigamiComponents
0015 
0016 Item {
0017     id: root
0018 
0019     width: 110
0020     height: 110 * 3
0021 
0022     TestCase {
0023         name: "AvatarTests"
0024         function test_latin_name() {
0025             compare(KirigamiComponents.NameUtils.isStringUnsuitableForInitials("Nate Martin"), false)
0026             compare(KirigamiComponents.NameUtils.initialsFromString("Nate Martin"), "NM")
0027 
0028             compare(KirigamiComponents.NameUtils.isStringUnsuitableForInitials("Kalanoka"), false)
0029             compare(KirigamiComponents.NameUtils.initialsFromString("Kalanoka"), "K")
0030 
0031             compare(KirigamiComponents.NameUtils.isStringUnsuitableForInitials("Why would anyone use such a long not name in the field of the Name"), false)
0032             compare(KirigamiComponents.NameUtils.initialsFromString("Why would anyone use such a long not name in the field of the Name"), "WN")
0033 
0034             compare(KirigamiComponents.NameUtils.isStringUnsuitableForInitials("Live-CD User"), false)
0035             compare(KirigamiComponents.NameUtils.initialsFromString("Live-CD User"), "LU")
0036         }
0037         // these are just randomly sampled names from internet pages in the
0038         // source languages of the name
0039         function test_jp_name() {
0040             compare(KirigamiComponents.NameUtils.isStringUnsuitableForInitials("北里 柴三郎"), false)
0041             compare(KirigamiComponents.NameUtils.initialsFromString("北里 柴三郎"), "北")
0042 
0043             compare(KirigamiComponents.NameUtils.isStringUnsuitableForInitials("小野田 寛郎"), false)
0044             compare(KirigamiComponents.NameUtils.initialsFromString("小野田 寛郎"), "小")
0045         }
0046         function test_cn_name() {
0047             compare(KirigamiComponents.NameUtils.isStringUnsuitableForInitials("蔣經國"), false)
0048             compare(KirigamiComponents.NameUtils.initialsFromString("蔣經國"), "蔣")
0049         }
0050         function test_cyrillic_name() {
0051             compare(KirigamiComponents.NameUtils.isStringUnsuitableForInitials("Нейт Мартин"), false)
0052             compare(KirigamiComponents.NameUtils.initialsFromString("Нейт Мартин"), "НМ")
0053 
0054             compare(KirigamiComponents.NameUtils.isStringUnsuitableForInitials("Каланока"), false)
0055             compare(KirigamiComponents.NameUtils.initialsFromString("Каланока"), "К")
0056 
0057             compare(KirigamiComponents.NameUtils.isStringUnsuitableForInitials("Зачем кому-то использовать такое длинное не имя в поле Имя"), false)
0058             compare(KirigamiComponents.NameUtils.initialsFromString("Зачем кому-то использовать такое длинное не имя в поле Имя"), "ЗИ")
0059 
0060             compare(KirigamiComponents.NameUtils.isStringUnsuitableForInitials("Пользователь Лайв-СИДИ"), false)
0061             compare(KirigamiComponents.NameUtils.initialsFromString("Лайв-СИДИ Пользователь"), "ЛП")
0062         }
0063         function test_bad_names() {
0064             compare(KirigamiComponents.NameUtils.isStringUnsuitableForInitials("151231023"), true)
0065         }
0066     }
0067 
0068     TestCase {
0069         name: "AvatarActions"
0070 
0071         width: 110
0072         height: 110 * 1
0073         visible: true
0074         when: windowShown
0075 
0076         KirigamiComponents.AvatarButton {
0077             id: avatarButton
0078 
0079             x: 5
0080             y: 5
0081             width: 100
0082             height: 100
0083 
0084             activeFocusOnTab: true
0085         }
0086 
0087         function test_avatar_type() {
0088             // Implies that it is clickable, keyboard-interactible, and supports actions.
0089             verify(avatarButton instanceof T.AbstractButton)
0090         }
0091     }
0092 
0093     TestCase {
0094         name: "AvatarColors"
0095         y: 110 * 1
0096         width: 110
0097         height: 110 * 2
0098         visible: true
0099         when: windowShown
0100 
0101         KirigamiComponents.Avatar {
0102             id: avatarWithDefaultInitialsColor
0103 
0104             x: 5
0105             y: 5
0106             width: 100
0107             height: 100
0108         }
0109 
0110         KirigamiComponents.Avatar {
0111             id: avatarWithNonWritableColors
0112 
0113             x: 5
0114             y: 110 + 5
0115             width: 100
0116             height: 100
0117         }
0118 
0119         function checkInitialsColorIsDefault(avatar) {
0120             compare(avatar.initialsColor, avatar.defaultInitialsColor);
0121         }
0122 
0123         function test_initialsColors() {
0124             checkInitialsColorIsDefault(avatarWithDefaultInitialsColor);
0125             avatarWithDefaultInitialsColor.initialsColor = "red";
0126             verify(Qt.colorEqual(avatarWithDefaultInitialsColor.initialsColor, "red"));
0127             // Test reset
0128             avatarWithDefaultInitialsColor.initialsColor = Qt.binding(() => avatarWithDefaultInitialsColor.defaultInitialsColor);
0129             checkInitialsColorIsDefault(avatarWithDefaultInitialsColor);
0130         }
0131 
0132         function test_defaultColorIsNotWritable() {
0133             let failed = false;
0134             try {
0135                 avatarWithNonWritableColors.defaultInitialsColor = "red";
0136             } catch (ex) {
0137                 failed = true;
0138             }
0139             verify(failed);
0140             checkInitialsColorIsDefault(avatarWithNonWritableColors);
0141         }
0142     }
0143 }