diff --git a/discover/autotests/DiscoverTest.qml b/discover/autotests/DiscoverTest.qml index 64589c3e..56bd16ea 100644 --- a/discover/autotests/DiscoverTest.qml +++ b/discover/autotests/DiscoverTest.qml @@ -1,114 +1,115 @@ import QtQuick 2.1 import QtTest 1.1 import org.kde.discover.app 1.0 Item { id: testRoot signal reset() property QtObject appRoot function verify(condition, msg) { if (!condition) { console.trace(); var e = new Error(condition + (msg ? (": " + msg) : "")) e.object = testRoot; throw e; } } function compare(valA, valB, msg) { if (valA !== valB) { console.trace(); var e = new Error(valA + " !== " + valB + (msg ? (": " + msg) : "")) e.object = testRoot; throw e; } } function typeName(obj) { var name = obj.toString(); var idx = name.indexOf("_QMLTYPE_"); return name.substring(0, idx); } function isType(obj, typename) { return obj && obj.toString().indexOf(typename+"_QMLTYPE_") === 0 } function chooseChild(obj, validator) { + verify(obj, "can't find a null's child") if (validator(obj)) return true; var children = obj.data ? obj.data : obj.contentData for(var v in children) { var stop = chooseChild(children[v], validator) if (stop) return true } return false } function findChild(obj, typename) { var ret = null; chooseChild(obj, function(o) { var found = isType(o, typename); if (found) { ret = o; } return found }) return ret; } SignalSpy { id: spy } function waitForSignal(object, name, timeout) { if (!timeout) timeout = 5000; spy.clear(); spy.signalName = "" spy.target = object; spy.signalName = name; verify(spy); verify(spy.valid); verify(spy.count == 0); try { spy.wait(timeout); } catch (e) { console.warn("wait for signal '"+name+"' failed") return false; } return spy.count>0; } function waitForRendering() { return waitForSignal(appRoot, "frameSwapped") } property string currentTest: "" onCurrentTestChanged: console.log("changed to test", currentTest) Connections { target: ResourcesModel property bool done: false onIsFetchingChanged: { if (ResourcesModel.isFetching || done) return; done = true; for(var v in testRoot) { if (v.indexOf("test_") === 0) { testRoot.currentTest = v; testRoot.reset(); testRoot[v](); } } console.log("done") appRoot.close() } } } diff --git a/discover/autotests/toplevels.qml b/discover/autotests/toplevels.qml index e18c7095..b259dcc4 100644 --- a/discover/autotests/toplevels.qml +++ b/discover/autotests/toplevels.qml @@ -1,127 +1,124 @@ import QtQuick 2.0 import org.kde.discover.app 1.0 import QtTest 1.1 DiscoverTest { onReset: { appRoot.currentTopLevel = appRoot.topBrowsingComp } function test_openCategory() { var categoryName = "dummy 3"; app.openCategory(categoryName); verify(appRoot.stack.currentItem, "has a page"); compare(appRoot.stack.currentItem.title, categoryName, "same title"); verify(waitForRendering()) categoryName = "dummy 4"; app.openCategory(categoryName); verify(appRoot.stack.currentItem, "has a page"); compare(appRoot.stack.currentItem.title, categoryName, "same title"); verify(waitForRendering()) } function test_openHome() { var drawer = appRoot.globalDrawer; var firstitem; chooseChild(drawer, function(object) { if (object.hasOwnProperty("label") && object.label.indexOf("ummy")>0) { firstitem = object; return true } return false; }); var categoryName = "dummy 3"; firstitem.clicked() drawer.bannerClicked() compare(appRoot.stack.currentItem.title, "Featured", "same title"); compare(drawer.currentSubMenu, null) } function test_navigateThenUpdate() { var drawer = appRoot.globalDrawer; var firstitem; chooseChild(drawer, function(object) { if (object.hasOwnProperty("label") && object.label.indexOf("ummy")>0) { firstitem = object; return true } return false; }); var updateButton; chooseChild(drawer, function(object) { if (object.objectName === "updateButton") { updateButton = object; return true } return false; }); firstitem.clicked() verify(updateButton.enabled) updateButton.clicked() compare(appRoot.currentTopLevel, appRoot.topUpdateComp, "correct component, updates"); } function test_update() { app.openMode("Update"); var updatePage = appRoot.stack.currentItem; compare(typeName(updatePage), "UpdatesPage") compare(updatePage.state, "has-updates", "to update") var action = updatePage.actions.main verify(action); action.triggered(updatePage); compare(updatePage.state, "progressing", "updating") //make sure the window doesn't close while updating verify(appRoot.visible); verify(waitForRendering()) appRoot.close() verify(appRoot.visible); while(updatePage.state !== "now-uptodate") waitForSignal(updatePage, "stateChanged") compare(ResourcesModel.updatesCount, 0, "should be up to date") } function test_search() { app.openMode("Browsing"); - var searchField = findChild(appRoot.globalDrawer.topContent[0], "SearchField"); - verify(searchField); - searchField.text = "cocacola" - searchField.accepted() + app.openSearch("cocacola") while(!isType(appRoot.stack.currentItem, "ApplicationsListPage")) verify(waitForSignal(appRoot.stack, "currentItemChanged")) var listPage = appRoot.stack.currentItem while(listPage.count>0) verify(waitForSignal(listPage, "countChanged")) compare(listPage.count, 0) compare(listPage.search, "cocacola") - searchField.text = "dummy" - searchField.accepted() - compare(listPage.search, searchField.text) + app.openSearch("dummy") + listPage = appRoot.stack.currentItem + compare(listPage.search, "dummy") // compare(listPage.count, ResourcesModel.rowCount()/2) } function test_modes() { app.openMode("Browsing"); compare(appRoot.currentTopLevel, appRoot.topBrowsingComp, "correct component, browsing"); verify(waitForRendering()) app.openMode("Installed"); compare(appRoot.currentTopLevel, appRoot.topInstalledComp, "correct component, installed"); verify(waitForRendering()) app.openMode("Update"); compare(appRoot.currentTopLevel, appRoot.topUpdateComp, "correct component, updates"); verify(waitForRendering()) app.openMode("Sources"); compare(appRoot.currentTopLevel, appRoot.topSourcesComp, "correct component, sources"); verify(waitForRendering()) } }