Skip to content

Commit

Permalink
[sociald] Improve unit test coverage. Contributes to JB#13730
Browse files Browse the repository at this point in the history
  • Loading branch information
antseppa authored and Antti Seppälä committed Jan 2, 2014
1 parent cedfa92 commit 2f55580
Show file tree
Hide file tree
Showing 35 changed files with 1,174 additions and 19 deletions.
3 changes: 3 additions & 0 deletions rpm/sociald.spec
Expand Up @@ -88,6 +88,9 @@ Translation source for sociald
Summary: Automatable tests for sociald
License: TBD
Group: System/Applications
BuildRequires: pkgconfig(Qt5Test)
Requires: qt5-qtdeclarative-devel-tools
Requires: qt5-qtdeclarative-import-qttest

%description tests
Automatable tests for sociald
Expand Down
1 change: 1 addition & 0 deletions sociald.pro
@@ -1,5 +1,6 @@
TEMPLATE = subdirs
SUBDIRS = src tests

tests.depends = src

OTHER_FILES += rpm/sociald.spec
1 change: 0 additions & 1 deletion src/eventfeed/SocialAvatar.qml
Expand Up @@ -19,4 +19,3 @@ SocialImage {
visible: image.status !== Image.Ready
}
}

1 change: 1 addition & 0 deletions src/eventfeed/SocialBody.qml
Expand Up @@ -5,6 +5,7 @@ import Sailfish.TextLinking 1.0
Column {
property alias text: body.plainText
property alias time: time.text

anchors {
left: parent.left
right: parent.right
Expand Down
7 changes: 5 additions & 2 deletions src/eventfeed/SocialContent.qml
Expand Up @@ -40,7 +40,10 @@ Item {
}

Column {
id: column

property int _depth: parentPage && parentPage._depth ? parentPage._depth + 1 : 0

visible: subSource != ""
anchors {
verticalCenter: parent.verticalCenter
Expand All @@ -50,7 +53,7 @@ Item {
spacing: -Theme.paddingSmall

Label {
width: Math.min(implicitWidth, header.width - Theme.pageStackIndicatorWidth * _depth
width: Math.min(implicitWidth, header.width - Theme.pageStackIndicatorWidth * column._depth
- 2 * Theme.paddingLarge)
truncationMode: TruncationMode.Fade
color: Theme.highlightColor
Expand All @@ -66,7 +69,7 @@ Item {
}

Label {
width: Math.min(implicitWidth, header.width - Theme.pageStackIndicatorWidth * _depth
width: Math.min(implicitWidth, header.width - Theme.pageStackIndicatorWidth * column._depth
- 2 * Theme.paddingLarge)
truncationMode: TruncationMode.Fade
color: Theme.highlightColor
Expand Down
4 changes: 1 addition & 3 deletions src/eventfeed/SocialImage.qml
Expand Up @@ -11,8 +11,6 @@ Item {
property alias fillMode: image.fillMode
property alias sourceSize: image.sourceSize

// ---------------------

onConnectedToNetworkChanged: _setImageSource()
onSourceChanged: _setImageSource()
Component.onCompleted: _setImageSource()
Expand Down Expand Up @@ -41,4 +39,4 @@ Item {
width: container.width
height: container.height
}
}
}
4 changes: 2 additions & 2 deletions src/eventfeed/SocialInfoLabel.qml
Expand Up @@ -8,8 +8,8 @@ Item {
right: parent.right
}

height: label.text != "" ? (label.height + 2 * Theme.paddingLarge) : Theme.paddingLarge
opacity: label.text != "" ? 1 : 0
height: label.text !== "" ? (label.height + 2 * Theme.paddingLarge) : Theme.paddingLarge
opacity: label.text !== "" ? 1 : 0

Label {
id: label
Expand Down
2 changes: 0 additions & 2 deletions src/eventfeed/SocialMediaAccountDelegate.qml
Expand Up @@ -12,8 +12,6 @@ BackgroundItem {
property alias iconSource: icon.source
property int unseenPostCount: feedPage ? feedPage.unseenPostCount : 0

// -------------------------

onClicked: {
pageStack.push(feedPage)
feedPage.positionViewAtBeginning()
Expand Down
4 changes: 1 addition & 3 deletions src/eventfeed/SocialMediaFeedPage.qml
Expand Up @@ -21,11 +21,9 @@ Page {
property bool connectedToNetwork // ALL other connectedToNetwork properties in other pages
// are bound to this property, directly or indirectly.
property int refreshTimeCount: 1 // Increment this to trigger feed items to refresh times.

// -------------------------

property bool _needToSync
allowedOrientations: Lipstick.compositor.eventsWindowOrientation

onConnectedToNetworkChanged: {
if (page.connectedToNetwork && page._needToSync) {
page._needToSync = false
Expand Down
2 changes: 0 additions & 2 deletions src/eventfeed/SocialMediaPreviewRow.qml
Expand Up @@ -7,8 +7,6 @@ Item {

property var imageList
property string mediaName
property string mediaCaption
property string mediaDescription
property real imageSize: width / 3
property int imageCount: imageList ? imageList.length : 0
property bool connectedToNetwork
Expand Down
2 changes: 0 additions & 2 deletions src/facebook/eventfeed/FacebookFeedItem.qml
Expand Up @@ -21,8 +21,6 @@ SocialMediaFeedItem {
id: mediaRow
imageList: item.imageList
mediaName: model.attachmentName
mediaCaption: model.attachmentCaption
mediaDescription: model.attachmentDescription
connectedToNetwork: item.connectedToNetwork
}

Expand Down
4 changes: 2 additions & 2 deletions src/twitter/eventfeed/TwitterPostPage.qml
Expand Up @@ -400,8 +400,8 @@ Page {
accountString: qsTrId("lipstick-jolla-home-la-account-name")

// We should not set the identifier of account when we are syncing or signin in
switchEnabled: account.status != Account.SigningIn
&& account.status != Account.SyncInProgress
switchEnabled: account.status !== Account.SigningIn
&& account.status !== Account.SyncInProgress
serviceName: "twitter"
}
}
Expand Down
16 changes: 16 additions & 0 deletions tests/auto/auto.pro
@@ -0,0 +1,16 @@
TEMPLATE = aux

OTHER_FILES += \
../*.xml \
*.qml

unittest.files = *.qml
unittest.path = /opt/tests/sociald/auto

shared.files = ../../src/eventfeed/*.qml
shared.path = /opt/tests/sociald/auto/eventfeed/shared

twitter.files = ../../src/twitter/eventfeed/*.qml
twitter.path = /opt/tests/sociald/auto/eventfeed

INSTALLS += unittest shared twitter
57 changes: 57 additions & 0 deletions tests/auto/tst_socialaccountpage.qml
@@ -0,0 +1,57 @@
/****************************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Contact: Antti Seppälä <antti.seppala@jollamobile.com>
** All rights reserved.
**
** This file is part of sociald package.
**
****************************************************************************************/

import QtTest 1.0
import QtQuick 2.0
import Sailfish.Silica 1.0
import "eventfeed/shared"

ApplicationWindow {
id: window
deviceOrientation: Orientation.Portrait
initialPage: accountPage

SocialAccountPage {
id: accountPage
accounts: createAccounts()

function createAccounts() {
var accArray = new Array
for (var i = 0; i < 100; i++) {
accArray.push({"name": "Account" + i})
}
return accArray
}
}

SignalSpy {
id: clickedSpy
target: accountPage
signalName: "indexSelected"
}
TestEvent { id: testEvent }

TestCase {
name: "SocialAccountPage"
when: windowShown

function test_accountPage() {
verify(accountPage === pageStack.currentPage)
compare(accountPage.currentIndex, 0)
verify(accountPage.accounts !== null)
compare(accountPage.headerText, "")

clickedSpy.clear()
testEvent.mouseClick(accountPage, accountPage.width / 2, accountPage.height / 2, Qt.LeftButton, 0, 0)
compare(clickedSpy.count, 1)
verify(accountPage.currentIndex > 0)
}
}
}
74 changes: 74 additions & 0 deletions tests/auto/tst_socialaccountpulldownmenu.qml
@@ -0,0 +1,74 @@
/****************************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Contact: Antti Seppälä <antti.seppala@jollamobile.com>
** All rights reserved.
**
** This file is part of sociald package.
**
****************************************************************************************/

import QtTest 1.0
import QtQuick 2.0
import Sailfish.Silica 1.0
import "eventfeed/shared"

ApplicationWindow {
id: window
deviceOrientation: Orientation.Portrait

Page {
id: page

SilicaListView {
id: listView
anchors.fill: parent
model: ListModel {}

Item {
id: subviewModel

function accountList(idString) {
var result = new Array
result.push({"identifier": 2, "displayName": "Test account"})
return result
}
}

SocialAccountPullDownMenu {
id: pullDownMenu
pageContainer: page
accountString: "Account %1"

property QtObject model: QtObject {
property QtObject accounts: QtObject {
function indexOf(what) {
if (what === 2) {
return 0
}
return -1
}
}
}
}
}
}

initialPage: page

TestCase {
name: "SocialAccountPullDownMenu"
when: windowShown

function test_pullDownMenu() {
compare(pullDownMenu.currentAccount, 2)
compare(pullDownMenu.currentAccountIndex, 0)
compare(pullDownMenu.selectAccountString, "")
compare(pullDownMenu.changeToAccountString, "")
compare(pullDownMenu.accountString, "Account %1")
compare(pullDownMenu.pageContainer, page)
compare(pullDownMenu.serviceName, "")
compare(pullDownMenu.switchEnabled, false)
}
}
}
36 changes: 36 additions & 0 deletions tests/auto/tst_socialavatar.qml
@@ -0,0 +1,36 @@
/****************************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Contact: Antti Seppälä <antti.seppala@jollamobile.com>
** All rights reserved.
**
** This file is part of sociald package.
**
****************************************************************************************/

import QtTest 1.0
import QtQuick 2.0
import Sailfish.Silica 1.0
import "eventfeed/shared"

Item {
id: item
width: 100; height: 100

SocialAvatar {
id: avatar
}

TestCase {
name: "SocialAvatar"
when: windowShown

function test_avatar() {
compare(avatar.width, Theme.itemSizeExtraLarge)
compare(avatar.height, Theme.itemSizeExtraLarge)
compare(avatar.fillMode, Image.PreserveAspectCrop)
compare(avatar.sourceSize.width, avatar.width)
compare(avatar.sourceSize.height, avatar.height)
}
}
}
33 changes: 33 additions & 0 deletions tests/auto/tst_socialbody.qml
@@ -0,0 +1,33 @@
/****************************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Contact: Antti Seppälä <antti.seppala@jollamobile.com>
** All rights reserved.
**
** This file is part of sociald package.
**
****************************************************************************************/

import QtTest 1.0
import QtQuick 2.0
import Sailfish.Silica 1.0
import "eventfeed/shared"

Item {
width: 100; height: 100

SocialBody {
id: body
width: parent.width
}

TestCase {
name: "SocialBody"
when: windowShown

function test_body() {
compare(body.text, "")
compare(body.time, "")
}
}
}

0 comments on commit 2f55580

Please sign in to comment.