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 /* TODO FIXME
0137 function test_itemRightClick() {
0138 var testAlbum = createTemporaryObject(album, root);
0139 testAlbum.open();
0140
0141 // Make sure the item delegate is ready.
0142 tryCompare(testAlbum.content.currentItem.children[0], "status", Image.Ready)
0143 wait(100) // Let the image resize animation happen.
0144 mouseClick(root, 400, 300, Qt.RightButton)
0145 compare(testAlbum.signalSpyItemRightClick.count, 1)
0146
0147 testAlbum.destroy();
0148 }
0149 */
0150
0151 function test_saveItem() {
0152 var testAlbum = createTemporaryObject(album, root);
0153 testAlbum.open();
0154
0155 // Make sure the item delegate is ready.
0156 tryCompare(testAlbum.content.currentItem.children[0], "status", Image.Ready)
0157 wait(200) // Let the image resize animation happen.
0158 mouseClick(root, 738, 18, Qt.LeftButton)
0159 compare(testAlbum.signalSpySaveItem.count, 1)
0160
0161 testAlbum.destroy();
0162 }
0163
0164 function test_userCaption() {
0165 var testAlbum = createTemporaryObject(album, root);
0166 testAlbum.open();
0167
0168 // Check that caption will be visible for the first item with
0169 // showCaption = true.
0170 testAlbum.showCaption = true
0171 testAlbum.content.currentIndex = 0;
0172
0173 // Make sure the item delegate is ready.
0174 tryCompare(testAlbum.content.currentItem.children[0], "status", Image.Ready)
0175 wait(200) // Let the image resize animation happen.
0176
0177 mouseClick(root, 702, 18, Qt.LeftButton)
0178 compare(testAlbum.footer.visible, false)
0179 mouseClick(root, 702, 18, Qt.LeftButton)
0180 compare(testAlbum.footer.visible, true)
0181
0182 testAlbum.destroy();
0183 }
0184
0185 Component {
0186 id: album
0187 AlbumMaximizeComponent {
0188 id: albumComponent
0189 property alias signalSpyItemRightClick: spyItemRightClick
0190 property alias signalSpySaveItem: spySaveItem
0191
0192 parent: root
0193 initialIndex: 0
0194 model: root.model
0195
0196 SignalSpy {
0197 id: spyItemRightClick
0198 target: albumComponent
0199 signalName: "itemRightClicked"
0200 }
0201 SignalSpy {
0202 id: spySaveItem
0203 target: albumComponent
0204 signalName: "saveItem"
0205 }
0206 }
0207 }
0208 }