Warning, /libraries/kirigami-addons/autotests/BaseAlbumMaximizeComponentTestCase.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com> 0002 // SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0003 0004 import QtQuick 2.15 0005 import QtTest 1.2 0006 0007 import org.kde.kirigami 2.15 as Kirigami 0008 import org.kde.kirigamiaddons.labs.components 1.0 0009 0010 TestCase { 0011 id: root 0012 0013 property var model 0014 0015 readonly property string testImage: dataDir + "/kmail.png" 0016 readonly property string testVideo: dataDir + "/discover_hl_720p.webm" 0017 0018 when: windowShown 0019 0020 width: 800 0021 height: 600 0022 0023 // Check that the AlbumMaximizeComponent fills the window. 0024 function test_maximize() { 0025 var testAlbum = createTemporaryObject(album, root); 0026 testAlbum.open(); 0027 0028 compare(testAlbum.width, root.width); 0029 compare(testAlbum.height, root.height); 0030 0031 testAlbum.destroy(); 0032 } 0033 0034 function test_hasItems() { 0035 var testAlbum = createTemporaryObject(album, root); 0036 testAlbum.open(); 0037 0038 compare(testAlbum.content.count == 3, true); 0039 0040 testAlbum.destroy(); 0041 } 0042 0043 // Select the image item and check that the current delegate has the correct properties. 0044 function test_imageParams() { 0045 var testAlbum = createTemporaryObject(album, root); 0046 testAlbum.open(); 0047 0048 testAlbum.content.currentIndex = 0; 0049 compare(testAlbum.content.currentItem.type, AlbumModelItem.Image); 0050 compare(testAlbum.content.currentItem.source, Qt.resolvedUrl(root.testImage)); 0051 compare(testAlbum.content.currentItem.tempSource, Qt.resolvedUrl(root.testImage)); 0052 compare(testAlbum.content.currentItem.caption, "A test image"); 0053 0054 testAlbum.destroy(); 0055 } 0056 0057 // Select the video item and check that the current delegate has the correct properties. 0058 function test_videoParams() { 0059 var testAlbum = createTemporaryObject(album, root); 0060 testAlbum.open(); 0061 0062 testAlbum.content.currentIndex = 1; 0063 compare(testAlbum.content.currentItem.type, AlbumModelItem.Video); 0064 compare(testAlbum.content.currentItem.source, Qt.resolvedUrl(root.testVideo)); 0065 compare(testAlbum.content.currentItem.tempSource, Qt.resolvedUrl(root.testImage)); 0066 compare(testAlbum.content.currentItem.caption, "A test video"); 0067 0068 testAlbum.destroy(); 0069 } 0070 0071 // Select the image item and check that the image only actions are visible. 0072 function test_imageActions() { 0073 var testAlbum = createTemporaryObject(album, root); 0074 testAlbum.open(); 0075 0076 testAlbum.content.currentIndex = 0; 0077 compare(testAlbum.actions[2].visible, true); 0078 compare(testAlbum.actions[3].visible, true); 0079 0080 testAlbum.destroy(); 0081 } 0082 0083 // Select the video item and check that the image only actions are not visible. 0084 function test_videoActions() { 0085 var testAlbum = createTemporaryObject(album, root); 0086 testAlbum.open(); 0087 0088 testAlbum.content.currentIndex = 1; 0089 compare(testAlbum.actions[2].visible, false); 0090 compare(testAlbum.actions[3].visible, false); 0091 0092 testAlbum.destroy(); 0093 } 0094 0095 // Test that the caption is only visible if showCaption is true and a 0096 // captions string exists. 0097 function test_captionVisibility() { 0098 var testAlbum = createTemporaryObject(album, root); 0099 testAlbum.open(); 0100 0101 // Check that caption will be visible for the first item with 0102 // showCaption = true. 0103 testAlbum.showCaption = true 0104 testAlbum.content.currentIndex = 0; 0105 compare(testAlbum.footer.visible, true); 0106 0107 // Check that caption will be visible for the second item with 0108 // showCaption = true. 0109 testAlbum.content.currentIndex = 1; 0110 compare(testAlbum.footer.visible, true); 0111 0112 // Check that caption will not be visible for the third item with 0113 // showCaption = true. 0114 testAlbum.content.currentIndex = 2; 0115 compare(testAlbum.footer.visible, false); 0116 0117 // Check that caption will not be visible for the first item with 0118 // showCaption = false. 0119 testAlbum.showCaption = false 0120 testAlbum.content.currentIndex = 0; 0121 compare(testAlbum.footer.visible, false); 0122 0123 // Check that caption will not be visible for the second item with 0124 // showCaption = false. 0125 testAlbum.content.currentIndex = 1; 0126 compare(testAlbum.footer.visible, false); 0127 0128 // Check that caption will not be visible for the third item with 0129 // showCaption = false. 0130 testAlbum.content.currentIndex = 2; 0131 compare(testAlbum.footer.visible, false); 0132 0133 testAlbum.destroy(); 0134 } 0135 0136 function test_itemRightClick() { 0137 var testAlbum = createTemporaryObject(album, root); 0138 testAlbum.open(); 0139 0140 // Make sure the item delegate is ready. 0141 tryCompare(testAlbum.content.currentItem.children[0], "status", Image.Ready) 0142 wait(100) // Let the image resize animation happen. 0143 mouseClick(root, 400, 300, Qt.RightButton) 0144 compare(testAlbum.signalSpyItemRightClick.count, 1) 0145 0146 testAlbum.destroy(); 0147 } 0148 0149 function test_saveItem() { 0150 var testAlbum = createTemporaryObject(album, root); 0151 testAlbum.open(); 0152 0153 // Make sure the item delegate is ready. 0154 tryCompare(testAlbum.content.currentItem.children[0], "status", Image.Ready) 0155 wait(200) // Let the image resize animation happen. 0156 mouseClick(root, 738, 18, Qt.LeftButton) 0157 compare(testAlbum.signalSpySaveItem.count, 1) 0158 0159 testAlbum.destroy(); 0160 } 0161 0162 function test_userCaption() { 0163 var testAlbum = createTemporaryObject(album, root); 0164 testAlbum.open(); 0165 0166 // Check that caption will be visible for the first item with 0167 // showCaption = true. 0168 testAlbum.showCaption = true 0169 testAlbum.content.currentIndex = 0; 0170 0171 // Make sure the item delegate is ready. 0172 tryCompare(testAlbum.content.currentItem.children[0], "status", Image.Ready) 0173 wait(200) // Let the image resize animation happen. 0174 0175 mouseClick(root, 702, 18, Qt.LeftButton) 0176 compare(testAlbum.footer.visible, false) 0177 mouseClick(root, 702, 18, Qt.LeftButton) 0178 compare(testAlbum.footer.visible, true) 0179 0180 testAlbum.destroy(); 0181 } 0182 0183 Component { 0184 id: album 0185 AlbumMaximizeComponent { 0186 id: albumComponent 0187 property alias signalSpyItemRightClick: spyItemRightClick 0188 property alias signalSpySaveItem: spySaveItem 0189 0190 parent: root 0191 initialIndex: 0 0192 model: root.model 0193 0194 SignalSpy { 0195 id: spyItemRightClick 0196 target: albumComponent 0197 signalName: "itemRightClicked" 0198 } 0199 SignalSpy { 0200 id: spySaveItem 0201 target: albumComponent 0202 signalName: "saveItem" 0203 } 0204 } 0205 } 0206 }