File: testfolder.cpp

package info (click to toggle)
nextcloud-desktop 4.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 40,404 kB
  • sloc: cpp: 118,401; objc: 752; python: 606; sh: 395; ansic: 391; ruby: 174; makefile: 44; javascript: 32; xml: 6
file content (89 lines) | stat: -rw-r--r-- 3,388 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: CC0-1.0
 *
 * This software is in the public domain, furnished "as is", without technical
 * support, and with no warranty, express or implied, as to its usefulness for
 * any purpose.
 */

#include <QtTest>
#include <QTemporaryDir>

#include "accountstate.h"
#include "common/vfs.h"
#include "folder.h"

#include "account.h"
#include "accountmanager.h"
#include "logger.h"
#include "theme.h"

using namespace Qt::StringLiterals;

using namespace OCC;

class TestFolder: public QObject
{
    Q_OBJECT

private slots:
    void initTestCase()
    {
        OCC::Logger::instance()->setLogFlush(true);
        OCC::Logger::instance()->setLogDebug(true);

        QStandardPaths::setTestModeEnabled(true);
    }

    void test_sidebarDisplayName()
    {
        const auto createAccount = [](const QString &url, const QString &displayName) -> AccountState * {
            auto account = Account::create();
            account->setUrl(QUrl(url));
            account->setDavDisplayName(displayName);
            return AccountManager::instance()->addAccount(account);
        };

        const auto createFolder = [](AccountState * const accountState, const QString &targetPath, const QString &alias) -> Folder {
            FolderDefinition definition;
            definition.localPath = QTemporaryDir().path(); // for these tests the local folder path doesn't matter
            definition.targetPath = targetPath; // also known as the remote path
            definition.alias = alias;

            return Folder(definition, accountState, createVfsFromPlugin(Vfs::Off));
        };

        const auto appName = Theme::instance()->appNameGUI();

        // at this stage only one account is created
        const auto account1 = createAccount("http://admin:admin@nextcloud.local"_L1, "Admin"_L1);
        QVERIFY(account1);

        // when syncing the root folder it should return the (branded) app name
        auto folder1 = createFolder(account1, "/"_L1, "1"_L1);
        QCOMPARE(folder1.sidebarDisplayName(), appName);

        // when syncing subfolders it should return the remote folder path without the leading slash
        auto folder2 = createFolder(account1, "/Documents"_L1, "2"_L1);
        QCOMPARE(folder2.sidebarDisplayName(), "Documents"_L1);
        auto folder3 = createFolder(account1, "/Photos/to_sort"_L1, "3"_L1);
        QCOMPARE(folder3.sidebarDisplayName(), "Photos/to_sort"_L1);

        // so far we only had one account, let's add another one!
        const auto account2 = createAccount("http://testuser:testuser@stable31.local"_L1, "Test user"_L1);
        const auto folder4 = createFolder(account2, "/"_L1, "1"_L1);

        const auto expectedSuffixAccount1 = " - nextcloud.local - Admin"_L1;
        const auto expectedSuffixAccount2 = " - stable31.local - Test user"_L1;

        // now the account-specific suffixes should be added
        QCOMPARE(folder1.sidebarDisplayName(), appName + expectedSuffixAccount1);
        QCOMPARE(folder2.sidebarDisplayName(), "Documents"_L1 + expectedSuffixAccount1);
        QCOMPARE(folder3.sidebarDisplayName(), "Photos/to_sort"_L1 + expectedSuffixAccount1);
        QCOMPARE(folder4.sidebarDisplayName(), appName + expectedSuffixAccount2);
    }
};

QTEST_GUILESS_MAIN(TestFolder)
#include "testfolder.moc"