File indexing completed on 2024-06-02 05:26:27
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "richtextcomposeractionstest.h" 0008 #include "../richtextcomposer.h" 0009 #include "../richtextcomposeractions.h" 0010 #include "../richtextcomposercontroler.h" 0011 #include <KActionCollection> 0012 #include <QAction> 0013 #include <QStandardPaths> 0014 #include <QTest> 0015 0016 RichTextComposerActionsTest::RichTextComposerActionsTest(QObject *parent) 0017 : QObject(parent) 0018 { 0019 QStandardPaths::setTestModeEnabled(true); 0020 } 0021 0022 RichTextComposerActionsTest::~RichTextComposerActionsTest() = default; 0023 0024 void RichTextComposerActionsTest::shouldHaveDefaultValue() 0025 { 0026 KPIMTextEdit::RichTextComposer composer; 0027 KPIMTextEdit::RichTextComposerControler controller(&composer); 0028 KPIMTextEdit::RichTextComposerActions composerActions(&controller); 0029 0030 auto actionCollection = new KActionCollection(&composerActions); 0031 QVERIFY(actionCollection->actions().isEmpty()); 0032 0033 composerActions.createActions(actionCollection); 0034 0035 QVERIFY(!actionCollection->actions().isEmpty()); 0036 QCOMPARE(composerActions.numberOfActions(), actionCollection->actions().count() - 5); 0037 } 0038 0039 void RichTextComposerActionsTest::shouldHaveActions() 0040 { 0041 KPIMTextEdit::RichTextComposer composer; 0042 KPIMTextEdit::RichTextComposerControler controller(&composer); 0043 KPIMTextEdit::RichTextComposerActions composerActions(&controller); 0044 0045 auto actionCollection = new KActionCollection(&composerActions); 0046 composerActions.createActions(actionCollection); 0047 0048 QStringList lst; 0049 lst << QStringLiteral("format_align_left") << QStringLiteral("format_align_center") << QStringLiteral("format_align_right") 0050 << QStringLiteral("format_align_justify") << QStringLiteral("direction_ltr") << QStringLiteral("direction_rtl") 0051 << QStringLiteral("format_text_subscript") << QStringLiteral("format_text_superscript") << QStringLiteral("format_text_bold") 0052 << QStringLiteral("format_text_italic") << QStringLiteral("format_text_underline") << QStringLiteral("format_text_strikeout") 0053 << QStringLiteral("format_font_family") << QStringLiteral("format_font_size") << QStringLiteral("insert_horizontal_rule") 0054 << QStringLiteral("format_text_foreground_color") << QStringLiteral("format_text_background_color") << QStringLiteral("manage_link") 0055 << QStringLiteral("format_list_indent_less") << QStringLiteral("format_list_indent_more") << QStringLiteral("format_list_style") 0056 << QStringLiteral("add_image") << QStringLiteral("insert_html") << QStringLiteral("insert_table") << QStringLiteral("delete_line") 0057 << QStringLiteral("format_reset") << QStringLiteral("format_painter") << QStringLiteral("format_heading_level") 0058 << QStringLiteral("format_list_checkbox"); 0059 0060 QStringList actionNoRichText; 0061 actionNoRichText << QStringLiteral("paste_quoted") << QStringLiteral("tools_quote") << QStringLiteral("tools_unquote") << QStringLiteral("add_emoticon") 0062 << QStringLiteral("paste_without_formatting"); 0063 0064 // QCOMPARE(lst.count(), composerActions.numberOfActions()); 0065 for (QAction *act : actionCollection->actions()) { 0066 const QString actionName = act->objectName(); 0067 if (!actionNoRichText.contains(actionName)) { 0068 const bool hasActionName = lst.contains(actionName); 0069 if (!hasActionName) { 0070 qDebug() << " actionName " << actionName; 0071 } 0072 QVERIFY(hasActionName); 0073 } 0074 } 0075 } 0076 0077 void RichTextComposerActionsTest::shouldChangeEnableState() 0078 { 0079 KPIMTextEdit::RichTextComposer composer; 0080 KPIMTextEdit::RichTextComposerControler controller(&composer); 0081 KPIMTextEdit::RichTextComposerActions composerActions(&controller); 0082 0083 auto actionCollection = new KActionCollection(&composerActions); 0084 composerActions.createActions(actionCollection); 0085 0086 QStringList actionNoRichText; 0087 actionNoRichText << QStringLiteral("paste_quoted") << QStringLiteral("tools_quote") << QStringLiteral("tools_unquote") << QStringLiteral("add_emoticon") 0088 << QStringLiteral("paste_without_formatting"); 0089 0090 composerActions.setActionsEnabled(false); 0091 for (QAction *act : actionCollection->actions()) { 0092 if (!actionNoRichText.contains(act->objectName())) { 0093 QVERIFY(!act->isEnabled()); 0094 } 0095 } 0096 composerActions.setActionsEnabled(true); 0097 for (QAction *act : actionCollection->actions()) { 0098 if (!actionNoRichText.contains(act->objectName())) { 0099 QVERIFY(act->isEnabled()); 0100 } 0101 } 0102 } 0103 0104 QTEST_MAIN(RichTextComposerActionsTest) 0105 0106 #include "moc_richtextcomposeractionstest.cpp"