on xenial help sign in
Changed checks for passed action-id string. Also had to remove a waitForRendering() as it was causing a segfault... wtf
2559bddMirco Müller
tests/mocks/Unity/Notifications/MockActionModel.cpp+5
@@ -68,3 +68,8 @@ void ActionModel::insertAction(const QString &id, const QString &label) {
68 p->ids.push_back(id);
68 p->ids.push_back(id);
69 p->labels.push_back(label);
69 p->labels.push_back(label);
70}
70}
71+
72+int ActionModel::getCount() const {
73+ return p->labels.size();
74+}
75+
tests/mocks/Unity/Notifications/MockActionModel.h+2
@@ -26,6 +26,7 @@ struct ActionModelPrivate;
26
26
27class ActionModel : public QStringListModel {
27class ActionModel : public QStringListModel {
28 Q_OBJECT
28 Q_OBJECT
29+ Q_PROPERTY(int count READ getCount)
29
30
30public:
31public:
31 ActionModel(QObject *parent=nullptr);
32 ActionModel(QObject *parent=nullptr);
@@ -43,6 +44,7 @@ public:
43 Q_INVOKABLE QVariant data(int row, int role) const;
44 Q_INVOKABLE QVariant data(int row, int role) const;
44
45
45 void insertAction(const QString &id, const QString &label);
46 void insertAction(const QString &id, const QString &label);
47+ int getCount() const;
46
48
47private:
49private:
48 QScopedPointer<ActionModelPrivate> p;
50 QScopedPointer<ActionModelPrivate> p;
tests/qmltests/Notifications/tst_Notifications.qml+13−12
@@ -546,10 +546,12 @@ Item {
546 }
546 }
547
547
548 function test_NotificationRenderer(data) {
548 function test_NotificationRenderer(data) {
549− // hook up notification's completed-signal with model's onCompleted-slot, so that remove happens on close()
549+ // make sure the clicks on mocked notifications can be checked against by "actionSpy" (mimicking the NotificationServer component)
550− data.n.completed.connect(mockModel.onCompleted)
551 data.n.actionInvoked.connect(mockModel.actionInvoked)
550 data.n.actionInvoked.connect(mockModel.actionInvoked)
552
551
552+ // hook up notification's completed-signal with model's onCompleted-slot, so that remove() (model) happens on close() (notification)
553+ data.n.completed.connect(mockModel.onCompleted)
554+
553 // populate model with some mock notifications
555 // populate model with some mock notifications
554 mockModel.append(data.n)
556 mockModel.append(data.n)
555
557
@@ -591,7 +593,7 @@ Item {
591 mouseClick(notification)
593 mouseClick(notification)
592 if(data.n.type === Notification.Interactive) {
594 if(data.n.type === Notification.Interactive) {
593 actionSpy.wait()
595 actionSpy.wait()
594− compare(actionSpy.signalArguments[0][0], data.n.rawActions[0], "got wrong id for interactive action")
596+ compare(actionSpy.signalArguments[0][0], data.n.actions.data(0, ActionModel.RoleActionId), "got wrong id for interactive action")
595 }
597 }
596 compare(clickThroughSpy.count, 0, "click on notification fell through")
598 compare(clickThroughSpy.count, 0, "click on notification fell through")
597
599
@@ -608,9 +610,9 @@ Item {
608 var buttonAccept = findChild(buttonRow, "notify_button0")
610 var buttonAccept = findChild(buttonRow, "notify_button0")
609
611
610 // only test the left/cancel-button if two actions have been passed in
612 // only test the left/cancel-button if two actions have been passed in
611− if (data.n.rawActions.length === 4) {
613+ if (data.n.actions.count === 2) {
612 tryCompareFunction(function() { mouseClick(buttonCancel); return actionSpy.signalArguments.length > 0; }, true);
614 tryCompareFunction(function() { mouseClick(buttonCancel); return actionSpy.signalArguments.length > 0; }, true);
613− compare(actionSpy.signalArguments[0][0], data.n.rawActions[2], "got wrong id for negative action")
615+ compare(actionSpy.signalArguments[0][0], data.n.actions.data(1, ActionModel.RoleActionId), "got wrong id for negative action")
614 actionSpy.clear()
616 actionSpy.clear()
615 }
617 }
616
618
@@ -619,12 +621,11 @@ Item {
619
621
620 // click the positive/right button
622 // click the positive/right button
621 tryCompareFunction(function() { mouseClick(buttonAccept); return actionSpy.signalArguments.length > 0; }, true);
623 tryCompareFunction(function() { mouseClick(buttonAccept); return actionSpy.signalArguments.length > 0; }, true);
622− compare(actionSpy.signalArguments[0][0], data.n.rawActions[0], "got wrong id positive action")
624+ compare(actionSpy.signalArguments[0][0], data.n.actions.data(0, ActionModel.RoleActionId), "got wrong id positive action")
623 actionSpy.clear()
625 actionSpy.clear()
624− waitForRendering (notification)
625
626
626 // check if there's a ComboButton created due to more actions being passed
627 // check if there's a ComboButton created due to more actions being passed
627− if (data.n.actions.length > 2) {
628+ if (data.n.actions.count > 3) {
628 var comboButton = findChild(notification, "notify_button2")
629 var comboButton = findChild(notification, "notify_button2")
629 tryCompareFunction(function() { return comboButton.expanded === false; }, true);
630 tryCompareFunction(function() { return comboButton.expanded === false; }, true);
630
631
@@ -634,19 +635,19 @@ Item {
634 // try clicking on choices in expanded comboList
635 // try clicking on choices in expanded comboList
635 var choiceButton1 = findChild(notification, "notify_button3")
636 var choiceButton1 = findChild(notification, "notify_button3")
636 tryCompareFunction(function() { mouseClick(choiceButton1); return actionSpy.signalArguments.length > 0; }, true);
637 tryCompareFunction(function() { mouseClick(choiceButton1); return actionSpy.signalArguments.length > 0; }, true);
637− compare(actionSpy.signalArguments[0][0], data.n.rawActions[6], "got wrong id choice action 1")
638+ compare(actionSpy.signalArguments[0][0], data.n.actions.data(3, ActionModel.RoleActionId), "got wrong id choice action 1")
638 actionSpy.clear()
639 actionSpy.clear()
639
640
640 var choiceButton2 = findChild(notification, "notify_button4")
641 var choiceButton2 = findChild(notification, "notify_button4")
641 tryCompareFunction(function() { mouseClick(choiceButton2); return actionSpy.signalArguments.length > 0; }, true);
642 tryCompareFunction(function() { mouseClick(choiceButton2); return actionSpy.signalArguments.length > 0; }, true);
642− compare(actionSpy.signalArguments[0][0], data.n.rawActions[8], "got wrong id choice action 2")
643+ compare(actionSpy.signalArguments[0][0], data.n.actions.data(4, ActionModel.RoleActionId), "got wrong id choice action 2")
643 actionSpy.clear()
644 actionSpy.clear()
644
645
645 // click to collapse
646 // click to collapse
646− //tryCompareFunction(function() { mouseClick(comboButton, comboButton.width - comboButton.__styleInstance.dropDownWidth / 2, comboButton.height / 2); return comboButton.expanded == false; }, true);
647+ tryCompareFunction(function() { mouseClick(comboButton, comboButton.width / 2, comboButton.height / 2); return comboButton.expanded == false; }, true);
647 } else {
648 } else {
648 mouseClick(buttonCancel)
649 mouseClick(buttonCancel)
649− compare(actionSpy.signalArguments[0][0], data.n.rawActions[2], "got wrong id for negative action")
650+ compare(actionSpy.signalArguments[0][0], data.n.actions.data(1, ActionModel.RoleActionId), "got wrong id for negative action")
650 }
651 }
651 }
652 }
652
653