Warning, /pim/kube/views/conversation/tests/tst_conversationview.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *   Copyright 2017 Christian Mollekopf <mollekopf@kolabsys.com>
0003  *
0004  *   This program is free software; you can redistribute it and/or modify
0005  *   it under the terms of the GNU Library General Public License as
0006  *   published by the Free Software Foundation; either version 2, or
0007  *   (at your option) any later version.
0008  *
0009  *   This program is distributed in the hope that it will be useful,
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *   GNU Library General Public License for more details
0013  *
0014  *   You should have received a copy of the GNU Library General Public
0015  *   License along with this program; if not, write to the
0016  *   Free Software Foundation, Inc.,
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018  */
0019 
0020 import QtQuick 2.7
0021 import QtTest 1.0
0022 import "../qml"
0023 import org.kube.framework 1.0 as Kube
0024 import org.kube.test 1.0
0025 
0026 ViewTestCase {
0027     id: testCase
0028     name: "MailView"
0029 
0030     Component {
0031         id: mailViewComponent
0032         View {
0033             focus: true
0034         }
0035     }
0036 
0037     function test_1start() {
0038         var mailView = createTemporaryObject(mailViewComponent, testCase, {})
0039         verify(mailView)
0040     }
0041 
0042     function test_2verifyInitialFocus() {
0043         var mailView = createTemporaryObject(mailViewComponent, testCase, {})
0044         var newMailButton = findChild(mailView, "newMailButton");
0045         verify(newMailButton)
0046         // verify(newMailButton.activeFocus)
0047     }
0048 
0049     function test_3selectMessage() {
0050         var initialState = {
0051             accounts: [{
0052                     id: "account1",
0053                     name: "Test Account"
0054                 }],
0055             identities: [{
0056                     account: "account1",
0057                     name: "Test Identity",
0058                     address: "identity@example.org"
0059                 }],
0060             resources: [{
0061                     id: "resource1",
0062                     account: "account1",
0063                     type: "dummy"
0064                 },
0065                 {
0066                     id: "resource2",
0067                     account: "account1",
0068                     type: "mailtransport"
0069                 }],
0070             folders: [{
0071                     id: "folder1",
0072                     resource: "resource1",
0073                     name: "Folder 1",
0074                     specialpurpose: ["inbox"],
0075                     mails: [{
0076                             resource: "resource1",
0077                             subject: "subject1",
0078                             body: "body",
0079                             to: ["to@example.org"],
0080                             cc: ["cc@example.org"],
0081                             bcc: ["bcc@example.org"],
0082                             draft: true
0083                         },
0084                         {
0085                             resource: "resource1",
0086                             subject: "subject2",
0087                             body: "body",
0088                             to: ["to@example.org"],
0089                             cc: ["cc@example.org"],
0090                             bcc: ["bcc@example.org"],
0091                             draft: true
0092                         }
0093                     ],
0094                 }],
0095         }
0096         TestStore.setup(initialState)
0097         Kube.Context.currentAccountId = "account1"
0098         var mailView = createTemporaryObject(mailViewComponent, testCase, {})
0099         var folderListView = findChild(mailView, "folderListView");
0100         verify(folderListView)
0101 
0102         var folder = TestStore.load("folder", {resource: "resource1"})
0103         verify(folder)
0104 
0105         Kube.Fabric.postMessage(Kube.Messages.folderSelection, {"folder": folder, "trash": false});
0106 
0107         var mailListView = findChild(mailView, "mailListView");
0108         verify(mailListView)
0109         var listView = findChild(mailListView, "listView");
0110         verify(listView)
0111         tryCompare(listView, "count", 2)
0112 
0113         var conversationView = findChild(mailView, "mailView");
0114         verify(conversationView)
0115         var listView = findChild(conversationView, "listView");
0116         verify(listView)
0117     }
0118 
0119     function test_4moveToTrash() {
0120         var initialState = {
0121             accounts: [{
0122                     id: "account1",
0123                     name: "Test Account"
0124                 }],
0125             identities: [{
0126                     account: "account1",
0127                     name: "Test Identity",
0128                     address: "identity@example.org"
0129                 }],
0130             resources: [{
0131                     id: "resource3",
0132                     account: "account1",
0133                     type: "dummy"
0134                 }],
0135             folders: [{
0136                     id: "folder1",
0137                     resource: "resource3",
0138                     name: "Folder 1",
0139                     specialpurpose: ["inbox"],
0140                     mails: [{
0141                             resource: "resource3",
0142                             subject: "subject1",
0143                             body: "body",
0144                             to: ["to@example.org"],
0145                             cc: ["cc@example.org"],
0146                             bcc: ["bcc@example.org"]
0147                         }
0148                     ],
0149                 }],
0150         }
0151         TestStore.setup(initialState)
0152         var mailView = createTemporaryObject(mailViewComponent, testCase, {})
0153         var folderListView = findChild(mailView, "folderListView");
0154         verify(folderListView)
0155 
0156         var folder = TestStore.load("folder", {resource: "resource3"})
0157         verify(folder)
0158 
0159         Kube.Fabric.postMessage(Kube.Messages.folderSelection, {"folder": folder, "trash": false});
0160 
0161         var mailListView = findChild(mailView, "mailListView");
0162         verify(mailListView)
0163         var listView = findChild(mailListView, "listView");
0164         verify(listView)
0165         tryCompare(listView, "count", 1)
0166 
0167         listView.currentIndex = 0
0168         var currentItem = listView.currentItem
0169         verify(currentItem)
0170         //Pretend we're hovering over the delegate so the button becomes visible
0171         currentItem.buttonsVisible = true
0172 
0173         var deleteButton = findChild(currentItem, "deleteButton");
0174         verify(deleteButton)
0175         deleteButton.clicked()
0176 
0177         tryCompare(listView, "count", 0)
0178     }
0179 
0180     function test_5selectFolder() {
0181         var initialState = {
0182             accounts: [{
0183                     id: "account1",
0184                     name: "Test Account1"
0185                 }, {
0186                     id: "account2",
0187                     name: "Test Account2"
0188                 }],
0189             identities: [{
0190                     account: "account1",
0191                     name: "Test Identity",
0192                     address: "identity@example.org"
0193                 }],
0194             resources: [{
0195                     id: "resource1",
0196                     account: "account1",
0197                     type: "dummy"
0198                 },
0199                 {
0200                     id: "resource2",
0201                     account: "account1",
0202                     type: "mailtransport"
0203                 },
0204                 {
0205                     id: "resource3",
0206                     account: "account2",
0207                     type: "dummy"
0208                 }
0209             ],
0210             folders: [{
0211                     id: "folder1",
0212                     resource: "resource1",
0213                     name: "Folder 1",
0214                     specialpurpose: ["inbox"],
0215                     mails: [{
0216                             resource: "resource1",
0217                             subject: "subject1",
0218                             body: "body",
0219                             to: ["to@example.org"],
0220                             cc: ["cc@example.org"],
0221                             bcc: ["bcc@example.org"],
0222                             draft: true
0223                         }
0224                     ],
0225                 },
0226                 {
0227                     id: "folder2",
0228                     resource: "resource3",
0229                     name: "Folder 2",
0230                     specialpurpose: ["inbox"],
0231                     mails: [{
0232                             resource: "resource3",
0233                             subject: "subject2",
0234                             body: "body",
0235                             to: ["to@example.org"],
0236                             cc: ["cc@example.org"],
0237                             bcc: ["bcc@example.org"],
0238                             draft: true
0239                         }
0240                     ],
0241                 }
0242             ],
0243         }
0244         TestStore.setup(initialState)
0245         var mailView = createTemporaryObject(mailViewComponent, testCase, {})
0246         var folderListView = findChild(mailView, "folderListView")
0247         verify(folderListView)
0248 
0249         var mailListView = findChild(mailView, "mailListView");
0250         verify(mailListView)
0251 
0252         var folder = TestStore.load("folder", {resource: "resource1"})
0253         verify(folder)
0254         tryCompare(mailListView, "parentFolder", folder)
0255 
0256         var listView = findChild(mailListView, "listView");
0257         verify(listView)
0258         tryCompare(listView, "count", 1)
0259 
0260         //Switch to second account
0261         Kube.Context.currentAccountId = "account2"
0262 
0263         var folder2 = TestStore.load("folder", {resource: "resource3"})
0264         verify(folder2)
0265         tryCompare(mailListView, "parentFolder", folder2)
0266         tryCompare(listView, "count", 1)
0267     }
0268 }