on xenial help sign in
Fixed previewCommentInput and added test
15365b4Andrea Cimitan
qml/Dash/Previews/PreviewCommentInput.qml+2
@@ -17,6 +17,7 @@
17import QtQuick 2.4
17import QtQuick 2.4
18import Ubuntu.Components 1.3
18import Ubuntu.Components 1.3
19import "../../Components"
19import "../../Components"
20+import "PreviewSingleton"
20
21
21/*! \brief Preview widget for commenting.
22/*! \brief Preview widget for commenting.
22
23
@@ -45,6 +46,7 @@ PreviewWidget {
45 }
46 }
46
47
47 function restoreCommentState() {
48 function restoreCommentState() {
49+ if (!PreviewSingleton.widgetExtraData[widgetId]) return;
48 if (PreviewSingleton.widgetExtraData[widgetId] != "") commentText = PreviewSingleton.widgetExtraData[widgetId];
50 if (PreviewSingleton.widgetExtraData[widgetId] != "") commentText = PreviewSingleton.widgetExtraData[widgetId];
49 }
51 }
50
52
tests/qmltests/Dash/Previews/tst_PreviewCommentInput.qml+29
@@ -39,6 +39,22 @@ Rectangle {
39 widgetId: "previewCommentInput"
39 widgetId: "previewCommentInput"
40 }
40 }
41
41
42+ Loader {
43+ id: previewCommentInputLoader
44+ anchors {
45+ left: parent.left
46+ right: parent.right
47+ top: previewCommentInput.bottom
48+ topMargin: units.gu(2)
49+ }
50+
51+ sourceComponent: PreviewCommentInput {
52+ widgetData: widgetDataNewLabels
53+ widgetId: "previewCommentInputLoader"
54+ }
55+ }
56+
57+
42 SignalSpy {
58 SignalSpy {
43 id: spy
59 id: spy
44 signalName: "triggered"
60 signalName: "triggered"
@@ -81,5 +97,18 @@ Rectangle {
81 compare(args[2]["comment"], data.inputText);
97 compare(args[2]["comment"], data.inputText);
82 }
98 }
83 }
99 }
100+
101+ function test_singleton() {
102+ var commentTextAreaLoader = findChild(previewCommentInputLoader, "commentTextArea")
103+
104+ commentTextAreaLoader.text = "singleton test text";
105+
106+ // Simulate widget being destroyed and recreated
107+ previewCommentInputLoader.active = false;
108+ previewCommentInputLoader.active = true;
109+
110+ commentTextAreaLoader = findChild(previewCommentInputLoader, "commentTextArea")
111+ tryCompare(commentTextAreaLoader, "text", "singleton test text");
112+ }
84 }
113 }
85}
114}