on xenial help sign in
First snap decision should always be expanded, unless user decides otherwise Fixes: #1575045, #1580090

Approved by: Michael Terry

commit81124b8e7719032e86ca6e23f08ae1044bc8cd39 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateFri 27 May 2016, 13:53 (10 years ago) parent760bfdf20065f8
5 files changed+110−11
qml/Notifications/Notification.qml+5−1 qml/Notifications/Notifications.qml+1−1 tests/mocks/QtMultimedia/audio.cpp+3−3 tests/mocks/QtMultimedia/audio.h+12−6 tests/qmltests/Notifications/tst_Notifications.qml+89
qml/Notifications/Notification.qml+5−1
@@ -99,6 +99,10 @@ StyledItem {
9999 }
100100
101101 function closeNotification() {
102+ if (index === ListView.view.currentIndex) { // reset to get the 1st snap decision expanded
103+ ListView.view.currentIndex = -1;
104+ }
105+
102106 if (notification.actions.count > 1) { // perform the "reject" action
103107 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId));
104108 }
@@ -382,7 +386,7 @@ StyledItem {
382386 objectName: "dialogListView"
383387 spacing: notification.margins
384388
385− visible: count > 0
389+ visible: count > 0 && notification.expanded
386390
387391 anchors {
388392 left: parent.left
qml/Notifications/Notifications.qml+1−1
@@ -52,7 +52,7 @@ ListView {
5252 type: model.type
5353 hints: model.hints
5454 iconSource: model.icon
55− secondaryIconSource: model.secondaryIcon
55+ secondaryIconSource: model.secondaryIcon ? model.secondaryIcon : ""
5656 summary: model.summary
5757 body: model.body
5858 value: model.value ? model.value : -1
tests/mocks/QtMultimedia/audio.cpp+3−3
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013, 2015 Canonical, Ltd.
2+ * Copyright (C) 2013-2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@
2121Audio::Audio(QObject* parent):
2222 QObject(parent),
2323 m_playbackState(StoppedState),
24− m_playlist(0)
24+ m_playlist(nullptr)
2525{
2626 qsrand(time(nullptr));
2727 m_timer.setInterval(1000);
@@ -109,7 +109,7 @@ void Audio::timerEvent()
109109
110110Audio::AudioRole Audio::audioRole() const
111111{
112− return Audio::multimedia;
112+ return Audio::MusicRole;
113113}
114114
115115void Audio::setAudioRole(Audio::AudioRole audioRole)
tests/mocks/QtMultimedia/audio.h+12−6
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2012, 2013, 2015 Canonical, Ltd.
2+ * Copyright (C) 2012-2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -44,13 +44,19 @@ public:
4444 };
4545
4646 enum AudioRole {
47− alarm,
48− alert,
49− multimedia,
50− phone
47+ UnknownRole,
48+ MusicRole,
49+ VideoRole,
50+ VoiceCommunicationRole,
51+ AlarmRole,
52+ NotificationRole,
53+ RingtoneRole,
54+ AccessibilityRole,
55+ SonificationRole,
56+ GameRole
5157 };
5258
53− explicit Audio(QObject *parent = 0);
59+ explicit Audio(QObject *parent = nullptr);
5460
5561 QUrl source() const;
5662 void setSource(const QUrl &source);
tests/qmltests/Notifications/tst_Notifications.qml+89
@@ -725,6 +725,95 @@ Item {
725725 tryCompare(mockModel, "count", before - 1)
726726 }
727727
728+ function expansionLogic_data() {
729+ return [{
730+ tag: "Snap Decision without secondary icon and no button-tint",
731+ n: nlist[3],
732+ summaryVisible: true,
733+ bodyVisible: true,
734+ iconVisible: true,
735+ centeredIconVisible: false,
736+ shaped: true,
737+ secondaryIconVisible: false,
738+ buttonRowVisible: true,
739+ buttonTinted: false,
740+ hasSound: true,
741+ valueVisible: false,
742+ valueLabelVisible: false,
743+ valueTinted: false
744+ },
745+ {
746+ tag: "2-over-1 Snap Decision with button-tint",
747+ n: nlist[8],
748+ summaryVisible: true,
749+ bodyVisible: true,
750+ iconVisible: false,
751+ centeredIconVisible: false,
752+ shaped: false,
753+ secondaryIconVisible: false,
754+ buttonRowVisible: false,
755+ buttonTinted: true,
756+ hasSound: false,
757+ valueVisible: false,
758+ valueLabelVisible: false,
759+ valueTinted: false
760+ },
761+ {
762+ tag: "Snap Decision without secondary icon and no button-tint",
763+ n: nlist[3],
764+ summaryVisible: true,
765+ bodyVisible: true,
766+ iconVisible: true,
767+ centeredIconVisible: false,
768+ shaped: true,
769+ secondaryIconVisible: false,
770+ buttonRowVisible: true,
771+ buttonTinted: false,
772+ hasSound: true,
773+ valueVisible: false,
774+ valueLabelVisible: false,
775+ valueTinted: false
776+ }
777+ ]
778+ }
779+
780+ function test_expansionLogic() {
781+ var data = expansionLogic_data();
782+
783+ // fill the model
784+ data.forEach(function(notification) {
785+ mockModel.append(notification.n);
786+ notification.n.completed.connect(mockModel.onCompleted)
787+ })
788+
789+ // make sure the view is properly updated before going on
790+ notifications.forceLayout();
791+ waitForRendering(notifications);
792+
793+ // first one should be expanded by default
794+ var notification1 = findChild(notifications, "notification1") // 0 is placeholder...
795+ verify(!!notification1, "notification wasn't found");
796+ waitForRendering(notification1);
797+ verify(notification1.expanded);
798+
799+ // click the 2nd one, verify it's now expanded
800+ var notification2 = findChild(notifications, "notification2") // 0 is placeholder...
801+ verify(!!notification2, "notification wasn't found");
802+ waitForRendering(notification2);
803+ mouseClick(notification2);
804+ verify(notification2.expanded);
805+ verify(!notification1.expanded);
806+
807+ // now close the 2nd one, verify 1st is again expanded, 2nd is gone
808+ var dragStart = notification2.width * 0.25;
809+ var dragEnd = notification2.width;
810+ var dragY = notification2.height / 2;
811+ touchFlick(notification2, dragStart, dragY, dragEnd, dragY);
812+ waitForRendering(notifications);
813+ tryCompareFunction(function() { return notification1.expanded; }, true);
814+ tryCompareFunction(function() { return notification2.expanded; }, undefined);
815+ }
816+
728817 function cleanupTestCase() {
729818 notifications.hasMouse = false;
730819 }