richtextcomposeractionstest.cpp 5.42 KB
Newer Older
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
   Copyright (C) 2015-2020 Laurent Montel <montel@kde.org>
3

Laurent Montel's avatar
Laurent Montel committed
4
5
6
7
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
8

Laurent Montel's avatar
Laurent Montel committed
9
10
11
12
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
13

Laurent Montel's avatar
Laurent Montel committed
14
15
16
17
   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
18
19
20
21
22
23
24
25
*/

#include "richtextcomposeractionstest.h"
#include "../richtextcomposercontroler.h"
#include "../richtextcomposeractions.h"
#include "../richtextcomposer.h"
#include <KActionCollection>
#include <QAction>
Laurent Montel's avatar
Laurent Montel committed
26
#include <QTest>
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

RichTextComposerActionsTest::RichTextComposerActionsTest(QObject *parent)
    : QObject(parent)
{
}

RichTextComposerActionsTest::~RichTextComposerActionsTest()
{
}

void RichTextComposerActionsTest::shouldHaveDefaultValue()
{
    KPIMTextEdit::RichTextComposer composer;
    KPIMTextEdit::RichTextComposerControler controler(&composer);
    KPIMTextEdit::RichTextComposerActions composerActions(&controler);

    KActionCollection *actionCollection = new KActionCollection(&composerActions);
    QVERIFY(actionCollection->actions().isEmpty());

    composerActions.createActions(actionCollection);

    QVERIFY(!actionCollection->actions().isEmpty());
Laurent Montel's avatar
Laurent Montel committed
49
    QCOMPARE(composerActions.numberOfActions(), actionCollection->actions().count() - 5);
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
}

void RichTextComposerActionsTest::shouldHaveActions()
{
    KPIMTextEdit::RichTextComposer composer;
    KPIMTextEdit::RichTextComposerControler controler(&composer);
    KPIMTextEdit::RichTextComposerActions composerActions(&controler);

    KActionCollection *actionCollection = new KActionCollection(&composerActions);
    composerActions.createActions(actionCollection);

    QStringList lst;
    lst << QStringLiteral("format_align_left")
        << QStringLiteral("format_align_center")
        << QStringLiteral("format_align_right")
        << QStringLiteral("format_align_justify")
        << QStringLiteral("direction_ltr")
        << QStringLiteral("direction_rtl")
        << QStringLiteral("format_text_subscript")
        << QStringLiteral("format_text_superscript")
        << QStringLiteral("format_text_bold")
        << QStringLiteral("format_text_italic")
        << QStringLiteral("format_text_underline")
        << QStringLiteral("format_text_strikeout")
        << QStringLiteral("format_font_family")
        << QStringLiteral("format_font_size")
        << QStringLiteral("insert_horizontal_rule")
        << QStringLiteral("format_text_foreground_color")
        << QStringLiteral("format_text_background_color")
        << QStringLiteral("manage_link")
        << QStringLiteral("format_list_indent_less")
        << QStringLiteral("format_list_indent_more")
        << QStringLiteral("format_list_style")
        << QStringLiteral("add_image")
        << QStringLiteral("insert_html")
        << QStringLiteral("insert_table")
        << QStringLiteral("delete_line")
        << QStringLiteral("format_reset")
88
        << QStringLiteral("format_painter")
Laurent Montel's avatar
Laurent Montel committed
89
90
        << QStringLiteral("format_heading_level")
        << QStringLiteral("format_list_checkbox");
91
92
93
94
95

    QStringList actionNoRichText;
    actionNoRichText << QStringLiteral("paste_quoted")
                     << QStringLiteral("tools_quote")
                     << QStringLiteral("tools_unquote")
Laurent Montel's avatar
Laurent Montel committed
96
                     << QStringLiteral("add_emoticon")
97
98
                     << QStringLiteral("paste_without_formatting");

Laurent Montel's avatar
Laurent Montel committed
99
    //QCOMPARE(lst.count(), composerActions.numberOfActions());
Laurent Montel's avatar
Laurent Montel committed
100
    for (QAction *act : actionCollection->actions()) {
101
102
        const QString actionName = act->objectName();
        if (!actionNoRichText.contains(actionName)) {
Laurent Montel's avatar
Laurent Montel committed
103
104
105
106
107
            const bool hasActionName = lst.contains(actionName);
            if (!hasActionName) {
                qDebug() << " actionName " << actionName;
            }
            QVERIFY(hasActionName);
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
        }
    }
}

void RichTextComposerActionsTest::shouldChangeEnableState()
{
    KPIMTextEdit::RichTextComposer composer;
    KPIMTextEdit::RichTextComposerControler controler(&composer);
    KPIMTextEdit::RichTextComposerActions composerActions(&controler);

    KActionCollection *actionCollection = new KActionCollection(&composerActions);
    composerActions.createActions(actionCollection);

    QStringList actionNoRichText;
    actionNoRichText << QStringLiteral("paste_quoted")
                     << QStringLiteral("tools_quote")
                     << QStringLiteral("tools_unquote")
Laurent Montel's avatar
Laurent Montel committed
125
                     << QStringLiteral("add_emoticon")
126
127
128
                     << QStringLiteral("paste_without_formatting");

    composerActions.setActionsEnabled(false);
Laurent Montel's avatar
Laurent Montel committed
129
    for (QAction *act : actionCollection->actions()) {
130
131
132
133
134
        if (!actionNoRichText.contains(act->objectName())) {
            QVERIFY(!act->isEnabled());
        }
    }
    composerActions.setActionsEnabled(true);
Laurent Montel's avatar
Laurent Montel committed
135
    for (QAction *act : actionCollection->actions()) {
136
137
138
139
140
141
142
        if (!actionNoRichText.contains(act->objectName())) {
            QVERIFY(act->isEnabled());
        }
    }
}

QTEST_MAIN(RichTextComposerActionsTest)