Warning, /frameworks/kirigami/autotests/pagepool/tst_pagepool.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Mason McParlane <mtmcp@outlook.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 0008 import QtQuick.Controls 0009 import QtQuick.Window 0010 import org.kde.kirigami as Kirigami 0011 import QtTest 0012 0013 TestCase { 0014 id: testCase 0015 width: 400 0016 height: 400 0017 name: "PagePool" 0018 0019 function initTestCase() { 0020 mainWindow.show() 0021 } 0022 0023 function cleanupTestCase() { 0024 mainWindow.close() 0025 } 0026 0027 function applicationWindow() { return mainWindow; } 0028 0029 Kirigami.ApplicationWindow { 0030 id: mainWindow 0031 width: 480 0032 height: 360 0033 } 0034 0035 Kirigami.PagePool { 0036 id: pool 0037 } 0038 0039 function init() { 0040 mainWindow.pageStack.clear() 0041 pool.clear() 0042 } 0043 0044 // Queries added to page URLs ensure the PagePool can 0045 // have multiple instances of TestPage.qml 0046 0047 Kirigami.PagePoolAction { 0048 id: loadPageAction 0049 pagePool: pool 0050 pageStack: mainWindow.pageStack 0051 page: "TestPage.qml?action=loadPageAction" 0052 } 0053 0054 function test_loadPage () { 0055 var expectedUrl = "TestPage.qml?action=loadPageAction" 0056 compare(mainWindow.pageStack.depth, 0) 0057 loadPageAction.trigger() 0058 compare(mainWindow.pageStack.depth, 1) 0059 verify(pool.lastLoadedUrl.toString().endsWith(expectedUrl)) 0060 compare(mainWindow.pageStack.currentItem.title, "INITIAL TITLE") 0061 } 0062 0063 Kirigami.PagePoolAction { 0064 id: loadPageActionWithProps 0065 pagePool: pool 0066 pageStack: mainWindow.pageStack 0067 page: "TestPage.qml?action=loadPageActionWithProps" 0068 initialProperties: { 0069 return {title: "NEW TITLE" } 0070 } 0071 } 0072 0073 function test_loadPageInitialPropertyOverride () { 0074 var expectedUrl = "TestPage.qml?action=loadPageActionWithProps" 0075 compare(mainWindow.pageStack.depth, 0) 0076 loadPageActionWithProps.trigger() 0077 compare(mainWindow.pageStack.depth, 1) 0078 verify(pool.lastLoadedUrl.toString().endsWith(expectedUrl)) 0079 compare(mainWindow.pageStack.currentItem.title, "NEW TITLE") 0080 compare(pool.lastLoadedItem.title, "NEW TITLE") 0081 } 0082 0083 Kirigami.PagePoolAction { 0084 id: loadPageActionPropsNotObject 0085 pagePool: pool 0086 pageStack: mainWindow.pageStack 0087 page: "TestPage.qml?action=loadPageActionPropsNotObject" 0088 initialProperties: "This is a string not an object..." 0089 } 0090 0091 function test_loadPageInitialPropertiesWrongType () { 0092 ignoreWarning("initialProperties must be of type object") 0093 var expectedUrl = "TestPage.qml?action=loadPageAction" 0094 compare(mainWindow.pageStack.depth, 0) 0095 loadPageAction.trigger() 0096 loadPageActionPropsNotObject.trigger() 0097 compare(mainWindow.pageStack.depth, 1) 0098 verify(pool.lastLoadedUrl.toString().endsWith(expectedUrl)) 0099 } 0100 0101 Kirigami.PagePoolAction { 0102 id: loadPageActionPropDoesNotExist 0103 pagePool: pool 0104 pageStack: mainWindow.pageStack 0105 page: "TestPage.qml?action=loadPageActionPropDoesNotExist" 0106 initialProperties: { 0107 return { propDoesNotExist: "PROP-NON-EXISTENT" } 0108 } 0109 } 0110 0111 function test_loadPageInitialPropertyNotExistFails () { 0112 ignoreWarning(/.*Setting initial properties failed: TestPage does not have a property called propDoesNotExist/) 0113 var expectedUrl = "TestPage.qml?action=loadPageActionPropDoesNotExist" 0114 loadPageActionPropDoesNotExist.trigger() 0115 verify(pool.lastLoadedUrl.toString().endsWith(expectedUrl)) 0116 } 0117 0118 function test_contains () { 0119 const page = "TestPage.qml?action=contains" 0120 let item = pool.loadPage(page) 0121 verify(item !== null, "valid item returned from loadPage") 0122 verify(pool.contains(page), "pool contains page") 0123 verify(pool.contains(item), "pool contains item") 0124 } 0125 0126 function test_deletePageByUrl () { 0127 const urlPage = "TestPage.qml?action=deletePageByUrl" 0128 pool.loadPage(urlPage) 0129 verify(pool.contains(urlPage), "pool contains page before deletion") 0130 pool.deletePage(urlPage) 0131 verify(!pool.contains(urlPage), "pool does not contain page after deletion") 0132 } 0133 0134 function test_deletePageByItem () { 0135 const itemPage = "TestPage.qml?action=deletePageByItem" 0136 let item = pool.loadPage(itemPage) 0137 verify(pool.contains(item), "pool contains item before deletion") 0138 pool.deletePage(item) 0139 verify(!pool.contains(itemPage), "pool does not contain page after deletion") 0140 } 0141 0142 function test_iterateAndDeleteByItem () { 0143 const pages = [] 0144 for (let i = 1; i <= 5; ++i) { 0145 const page = "TestPage.qml?page=" + i 0146 pool.loadPage(page) 0147 verify(pool.contains(page), "pool contains page " + page) 0148 pages.push(page) 0149 } 0150 verify(pool.items.length == 5, "pool contains 5 items") 0151 for (const item of pool.items) { 0152 const url = pool.urlForPage(item) 0153 const found = pages.find(page => url.toString().endsWith(page)) 0154 verify(found, "pool.items contains page " + found) 0155 pool.deletePage(item) 0156 } 0157 verify(pool.items.length == 0, "all items have been deleted") 0158 } 0159 0160 function test_iterateAndDeleteByUrl () { 0161 const pages = [] 0162 for (let i = 1; i <= 5; ++i) { 0163 const page = "TestPage.qml?page=" + i 0164 pool.loadPage(page) 0165 verify(pool.contains(page), "pool contains page " + page) 0166 pages.push(page) 0167 } 0168 verify(pool.urls.length == 5, "pool contains 5 urls") 0169 for (const url of pool.urls) { 0170 const found = pages.find(page => url.toString().endsWith(page)) 0171 verify(found, "pool.urls contains page " + found) 0172 } 0173 for (const page of pages) { 0174 pool.deletePage(page) 0175 } 0176 verify(pool.urls.length == 0, "all urls have been deleted") 0177 } 0178 }