1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/*
* Copyright 2015 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.4
import Lomiri.Test 1.0
import Lomiri.Components 1.3
// NOTE: Other parts of the page head API are tested with autopilot in
// lomiriuitoolkit.tests.components.test_header
Item {
width: units.gu(50)
height: units.gu(80)
MainView {
id: mainView
anchors.fill: parent
PageStack {
id: pageStack
Page {
id: page1
title: "First page"
Button {
anchors.centerIn: parent
onClicked: pageStack.push(page2)
text: "Push page 2"
}
head {
actions: [
Action {
iconName: "settings"
text: "first"
onTriggered: print("Trigger first action")
},
Action {
iconName: "info"
text: "second"
onTriggered: print("Trigger second action")
},
Action {
iconName: "toolkit_input-search"
text: "third"
onTriggered: print("Trigger third action")
},
Action {
iconName: "appointment"
text: "fourth"
onTriggered: print("Trigger fourth action")
}
]
}
}
Page {
id: page2
visible: false
title: "Second page"
Action {
id: customBackAction
iconName: "close"
text: "Close"
onTriggered: print("Triggered custom back action.")
}
Action {
id: invisibleAction
visible: false
}
head {
backAction: customBackActionSwitch.checked ?
customBackAction : null
}
Row {
anchors.centerIn: parent
spacing: units.gu(1)
Label {
text: "standard"
}
Switch {
id: customBackActionSwitch
}
Label {
text: "custom back action"
}
}
}
}
Component.onCompleted: {
pageStack.push(page1);
}
}
LomiriTestCase {
name: "HeaderBackButton"
when: windowShown
id: testCase
property var back_button
property var custom_back_button
function initTestCase() {
var app_header = findChild(mainView, "MainView_Header");
testCase.back_button = findChild(app_header, "backButton");
testCase.custom_back_button = findChild(app_header, "customBackButton");
waitForHeaderAnimation(mainView);
compare(page2.head.backAction, null, "Back action set by default.");
compare(back_button.visible, false, "Back button visible with only 1 page on the stack.");
compare(custom_back_button.visible, false, "Custom back button visible without custom back action.")
}
function test_default_back_button() {
pageStack.push(page2);
waitForHeaderAnimation(mainView);
compare(back_button.visible, true, "Back button not visible with 2 pages on stack.");
compare(custom_back_button.visible, false, "Showing custom back button without custom back action.");
pageStack.pop();
waitForHeaderAnimation(mainView);
}
function test_custom_back_button() {
page2.head.backAction = customBackAction;
pageStack.push(page2);
waitForHeaderAnimation(mainView);
compare(back_button.visible, false, "Default back button visible with custom back action.");
compare(custom_back_button.visible, true, "Custom back button invisible with back action.");
pageStack.pop();
waitForHeaderAnimation(mainView);
page2.head.backAction = null;
}
function test_no_back_button() {
page2.head.backAction = invisibleAction;
pageStack.push(page2);
waitForHeaderAnimation(mainView);
compare(back_button.visible, false, "Default back button visible with invisible custom back action.");
compare(custom_back_button.visible, false, "Custom back button visible with invisible custom back action.");
pageStack.pop();
waitForHeaderAnimation(mainView);
page2.head.backAction = null;
}
}
}
|