| 1 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 2 |
|
| 3 |
#include "itemtagstests.h" |
| 4 |
|
| 5 |
#include "tests/test_utils.h" |
| 6 |
|
| 7 |
namespace { |
| 8 |
|
| 9 |
QString testTag(int i) |
| 10 |
{ |
| 11 |
return "TAG_&" + QString::number(i); |
| 12 |
} |
| 13 |
|
| 14 |
} // namespace |
| 15 |
|
| 16 |
ItemTagsTests::ItemTagsTests(const TestInterfacePtr &test, QObject *parent) |
| 17 |
: QObject(parent) |
| 18 |
, m_test(test) |
| 19 |
{ |
| 20 |
setProperty("CopyQ_test_id", QStringLiteral("itemtags")); |
| 21 |
const QVariantMap settings{ |
| 22 |
{QStringLiteral("tags"), ItemTagsTests::testTags()} |
| 23 |
}; |
| 24 |
setProperty("CopyQ_test_settings", settings); |
| 25 |
} |
| 26 |
|
| 27 |
QStringList ItemTagsTests::testTags() |
| 28 |
{ |
| 29 |
return QStringList() |
| 30 |
<< testTag(1) |
| 31 |
<< testTag(2) |
| 32 |
<< testTag(3) |
| 33 |
<< testTag(4) |
| 34 |
<< testTag(5); |
| 35 |
} |
| 36 |
|
| 37 |
void ItemTagsTests::initTestCase() |
| 38 |
{ |
| 39 |
TEST(m_test->initTestCase()); |
| 40 |
} |
| 41 |
|
| 42 |
void ItemTagsTests::cleanupTestCase() |
| 43 |
{ |
| 44 |
TEST(m_test->cleanupTestCase()); |
| 45 |
} |
| 46 |
|
| 47 |
void ItemTagsTests::init() |
| 48 |
{ |
| 49 |
TEST(m_test->init()); |
| 50 |
} |
| 51 |
|
| 52 |
void ItemTagsTests::cleanup() |
| 53 |
{ |
| 54 |
TEST( m_test->cleanup() ); |
| 55 |
} |
| 56 |
|
| 57 |
void ItemTagsTests::userTags() |
| 58 |
{ |
| 59 |
RUN("-e" << "plugins.itemtags.userTags", |
| 60 |
QString(testTags().join("\n") + "\n").toUtf8()); |
| 61 |
} |
| 62 |
|
| 63 |
void ItemTagsTests::tag() |
| 64 |
{ |
| 65 |
const QString tab1 = testTab(1); |
| 66 |
const Args args = Args() << "tab" << tab1; |
| 67 |
RUN(args << "-e" << "plugins.itemtags.tags(0)", ""); |
| 68 |
RUN(args << "add" << "A" << "B" << "C", ""); |
| 69 |
RUN(args << "-e" << "plugins.itemtags.tags(0)", ""); |
| 70 |
RUN(args << "-e" << "plugins.itemtags.tags(1)", ""); |
| 71 |
RUN(args << "-e" << "plugins.itemtags.tags(2)", ""); |
| 72 |
RUN(args << "-e" << "plugins.itemtags.tags(3)", ""); |
| 73 |
RUN(args << "size", "3\n"); |
| 74 |
|
| 75 |
RUN(args << "-e" << "plugins.itemtags.tag('x', 0)", ""); |
| 76 |
RUN(args << "-e" << "plugins.itemtags.tags(0)", "x\n"); |
| 77 |
RUN(args << "-e" << "plugins.itemtags.hasTag('x', 0)", "true\n"); |
| 78 |
RUN(args << "-e" << "plugins.itemtags.hasTag('y', 0)", "false\n"); |
| 79 |
RUN(args << "-e" << "plugins.itemtags.tags(1)", ""); |
| 80 |
RUN(args << "-e" << "plugins.itemtags.hasTag('x', 1)", "false\n"); |
| 81 |
RUN(args << "-e" << "plugins.itemtags.hasTag('y', 1)", "false\n"); |
| 82 |
RUN(args << "-e" << "plugins.itemtags.tags(2)", ""); |
| 83 |
RUN(args << "-e" << "plugins.itemtags.hasTag('x', 2)", "false\n"); |
| 84 |
RUN(args << "-e" << "plugins.itemtags.hasTag('y', 2)", "false\n"); |
| 85 |
RUN(args << "-e" << "plugins.itemtags.tags(3)", ""); |
| 86 |
RUN(args << "-e" << "plugins.itemtags.hasTag('x', 3)", "false\n"); |
| 87 |
RUN(args << "-e" << "plugins.itemtags.hasTag('y', 3)", "false\n"); |
| 88 |
RUN(args << "size", "3\n"); |
| 89 |
|
| 90 |
RUN(args << "-e" << "plugins.itemtags.tag('y', 0, 1)", ""); |
| 91 |
RUN(args << "-e" << "plugins.itemtags.tags(0)", "x\ny\n"); |
| 92 |
RUN(args << "-e" << "plugins.itemtags.hasTag('x', 0)", "true\n"); |
| 93 |
RUN(args << "-e" << "plugins.itemtags.hasTag('y', 0)", "true\n"); |
| 94 |
RUN(args << "-e" << "plugins.itemtags.tags(1)", "y\n"); |
| 95 |
RUN(args << "-e" << "plugins.itemtags.hasTag('x', 1)", "false\n"); |
| 96 |
RUN(args << "-e" << "plugins.itemtags.hasTag('y', 1)", "true\n"); |
| 97 |
RUN(args << "-e" << "plugins.itemtags.tags(2)", ""); |
| 98 |
RUN(args << "-e" << "plugins.itemtags.hasTag('x', 2)", "false\n"); |
| 99 |
RUN(args << "-e" << "plugins.itemtags.hasTag('y', 2)", "false\n"); |
| 100 |
RUN(args << "-e" << "plugins.itemtags.tags(3)", ""); |
| 101 |
RUN(args << "-e" << "plugins.itemtags.hasTag('x', 3)", "false\n"); |
| 102 |
RUN(args << "-e" << "plugins.itemtags.hasTag('y', 3)", "false\n"); |
| 103 |
RUN(args << "size", "3\n"); |
| 104 |
|
| 105 |
RUN(args << "-e" << "plugins.itemtags.tag('z', 2, 3, 4)", ""); |
| 106 |
RUN(args << "-e" << "plugins.itemtags.tags(0)", "x\ny\n"); |
| 107 |
RUN(args << "-e" << "plugins.itemtags.hasTag('x', 0)", "true\n"); |
| 108 |
RUN(args << "-e" << "plugins.itemtags.hasTag('y', 0)", "true\n"); |
| 109 |
RUN(args << "-e" << "plugins.itemtags.hasTag('z', 0)", "false\n"); |
| 110 |
RUN(args << "-e" << "plugins.itemtags.tags(1)", "y\n"); |
| 111 |
RUN(args << "-e" << "plugins.itemtags.hasTag('x', 1)", "false\n"); |
| 112 |
RUN(args << "-e" << "plugins.itemtags.hasTag('y', 1)", "true\n"); |
| 113 |
RUN(args << "-e" << "plugins.itemtags.hasTag('z', 1)", "false\n"); |
| 114 |
RUN(args << "-e" << "plugins.itemtags.tags(2)", "z\n"); |
| 115 |
RUN(args << "-e" << "plugins.itemtags.hasTag('x', 2)", "false\n"); |
| 116 |
RUN(args << "-e" << "plugins.itemtags.hasTag('y', 2)", "false\n"); |
| 117 |
RUN(args << "-e" << "plugins.itemtags.hasTag('z', 2)", "true\n"); |
| 118 |
RUN(args << "-e" << "plugins.itemtags.tags(3)", ""); |
| 119 |
RUN(args << "-e" << "plugins.itemtags.hasTag('x', 3)", "false\n"); |
| 120 |
RUN(args << "-e" << "plugins.itemtags.hasTag('y', 3)", "false\n"); |
| 121 |
RUN(args << "-e" << "plugins.itemtags.hasTag('z', 3)", "false\n"); |
| 122 |
RUN(args << "size", "3\n"); |
| 123 |
} |
| 124 |
|
| 125 |
void ItemTagsTests::untag() |
| 126 |
{ |
| 127 |
const QString tab1 = testTab(1); |
| 128 |
const Args args = Args() << "tab" << tab1; |
| 129 |
RUN(args << "-e" << "plugins.itemtags.tags(0)", ""); |
| 130 |
RUN(args << "add" << "A" << "B" << "C", ""); |
| 131 |
RUN(args << "-e" << "plugins.itemtags.tag('x', 0, 1)", ""); |
| 132 |
RUN(args << "-e" << "plugins.itemtags.tag('y', 1, 2)", ""); |
| 133 |
RUN(args << "-e" << "plugins.itemtags.tags(0)", "x\n"); |
| 134 |
RUN(args << "-e" << "plugins.itemtags.tags(1)", "x\ny\n"); |
| 135 |
RUN(args << "-e" << "plugins.itemtags.tags(2)", "y\n"); |
| 136 |
|
| 137 |
RUN(args << "-e" << "plugins.itemtags.untag('x', 1)", ""); |
| 138 |
RUN(args << "-e" << "plugins.itemtags.tags(0)", "x\n"); |
| 139 |
RUN(args << "-e" << "plugins.itemtags.tags(1)", "y\n"); |
| 140 |
RUN(args << "-e" << "plugins.itemtags.tags(2)", "y\n"); |
| 141 |
|
| 142 |
RUN(args << "-e" << "plugins.itemtags.untag('y', 1, 2)", ""); |
| 143 |
RUN(args << "-e" << "plugins.itemtags.tags(0)", "x\n"); |
| 144 |
RUN(args << "-e" << "plugins.itemtags.tags(1)", ""); |
| 145 |
RUN(args << "-e" << "plugins.itemtags.tags(2)", ""); |
| 146 |
} |
| 147 |
|
| 148 |
void ItemTagsTests::clearTags() |
| 149 |
{ |
| 150 |
const QString tab1 = testTab(1); |
| 151 |
const Args args = Args() << "tab" << tab1; |
| 152 |
RUN(args << "-e" << "plugins.itemtags.tags(0)", ""); |
| 153 |
RUN(args << "add" << "A" << "B" << "C", ""); |
| 154 |
RUN(args << "-e" << "plugins.itemtags.tag('x', 0, 1)", ""); |
| 155 |
RUN(args << "-e" << "plugins.itemtags.tag('y', 1, 2)", ""); |
| 156 |
RUN(args << "-e" << "plugins.itemtags.tags(0)", "x\n"); |
| 157 |
RUN(args << "-e" << "plugins.itemtags.tags(1)", "x\ny\n"); |
| 158 |
RUN(args << "-e" << "plugins.itemtags.tags(2)", "y\n"); |
| 159 |
|
| 160 |
RUN(args << "-e" << "plugins.itemtags.clearTags(1)", ""); |
| 161 |
RUN(args << "-e" << "plugins.itemtags.tags(0)", "x\n"); |
| 162 |
RUN(args << "-e" << "plugins.itemtags.tags(1)", ""); |
| 163 |
RUN(args << "-e" << "plugins.itemtags.tags(2)", "y\n"); |
| 164 |
|
| 165 |
RUN(args << "-e" << "plugins.itemtags.tag('a', 1, 2)", ""); |
| 166 |
RUN(args << "-e" << "plugins.itemtags.tags(0)", "x\n"); |
| 167 |
RUN(args << "-e" << "plugins.itemtags.tags(1)", "a\n"); |
| 168 |
RUN(args << "-e" << "plugins.itemtags.tags(2)", "a\ny\n"); |
| 169 |
|
| 170 |
RUN(args << "-e" << "plugins.itemtags.clearTags(0, 2)", ""); |
| 171 |
RUN(args << "-e" << "plugins.itemtags.tags(0)", ""); |
| 172 |
RUN(args << "-e" << "plugins.itemtags.tags(1)", "a\n"); |
| 173 |
RUN(args << "-e" << "plugins.itemtags.tags(2)", ""); |
| 174 |
} |
| 175 |
|
| 176 |
void ItemTagsTests::searchTags() |
| 177 |
{ |
| 178 |
const QString tab1 = testTab(1); |
| 179 |
const Args args = Args() << "tab" << tab1; |
| 180 |
RUN(args << "-e" << "plugins.itemtags.tags(0)", ""); |
| 181 |
RUN(args << "add" << "A" << "B" << "C", ""); |
| 182 |
RUN(args << "-e" << "plugins.itemtags.tag('tag1', 0, 1)", ""); |
| 183 |
RUN(args << "-e" << "plugins.itemtags.tag('tag2', 1, 2)", ""); |
| 184 |
RUN(args << "-e" << "plugins.itemtags.tag('tag3', 2)", ""); |
| 185 |
RUN(args << "-e" << "plugins.itemtags.tags(0)", "tag1\n"); |
| 186 |
RUN(args << "-e" << "plugins.itemtags.tags(1)", "tag1\ntag2\n"); |
| 187 |
RUN(args << "-e" << "plugins.itemtags.tags(2)", "tag2\ntag3\n"); |
| 188 |
|
| 189 |
KEYS("RIGHT"); |
| 190 |
KEYS("t" << "a" << "g" << "1"); |
| 191 |
KEYS("TAB" << "CTRL+A"); |
| 192 |
TEST_SELECTED(tab1 + " 0 0 1\n"); |
| 193 |
|
| 194 |
KEYS("ESCAPE"); |
| 195 |
KEYS("t" << "a" << "g" << "2"); |
| 196 |
KEYS("TAB" << "CTRL+A"); |
| 197 |
TEST_SELECTED(tab1 + " 1 1 2\n"); |
| 198 |
|
| 199 |
KEYS("ESCAPE"); |
| 200 |
KEYS("t" << "a" << "g" << "3"); |
| 201 |
KEYS("TAB" << "CTRL+A"); |
| 202 |
TEST_SELECTED(tab1 + " 2 2\n"); |
| 203 |
} |
| 204 |
|
| 205 |
void ItemTagsTests::tagSelected() |
| 206 |
{ |
| 207 |
const auto script = R"( |
| 208 |
setCommands([{ |
| 209 |
name: 'Add Tag x', |
| 210 |
inMenu: true, |
| 211 |
shortcuts: ['Ctrl+F1'], |
| 212 |
cmd: 'copyq: plugins.itemtags.tag("x")' |
| 213 |
}, |
| 214 |
{ |
| 215 |
name: 'Add Tag y', |
| 216 |
inMenu: true, |
| 217 |
shortcuts: ['Ctrl+F2'], |
| 218 |
cmd: 'copyq: plugins.itemtags.tag("y")' |
| 219 |
}]) |
| 220 |
)"; |
| 221 |
RUN(script, ""); |
| 222 |
|
| 223 |
RUN("add" << "A" << "B" << "C", ""); |
| 224 |
KEYS("CTRL+F1"); |
| 225 |
WAIT_ON_OUTPUT("plugins.itemtags.tags(0)", "x\n"); |
| 226 |
RUN("plugins.itemtags.tags(1)", ""); |
| 227 |
RUN("plugins.itemtags.tags(2)", ""); |
| 228 |
|
| 229 |
RUN("selectItems(0,1)", "true\n"); |
| 230 |
KEYS("CTRL+F2"); |
| 231 |
WAIT_ON_OUTPUT("plugins.itemtags.tags(0)", "x\ny\n"); |
| 232 |
RUN("plugins.itemtags.tags(1)", "y\n"); |
| 233 |
RUN("plugins.itemtags.tags(2)", ""); |
| 234 |
} |
| 235 |
|
| 236 |
void ItemTagsTests::untagSelected() |
| 237 |
{ |
| 238 |
const auto script = R"( |
| 239 |
setCommands([{ |
| 240 |
name: 'Remove Tag x', |
| 241 |
inMenu: true, |
| 242 |
shortcuts: ['Ctrl+F1'], |
| 243 |
cmd: 'copyq: plugins.itemtags.untag("x")' |
| 244 |
}]) |
| 245 |
)"; |
| 246 |
RUN(script, ""); |
| 247 |
|
| 248 |
RUN("add" << "A" << "B" << "C", ""); |
| 249 |
RUN("plugins.itemtags.tag('x', 0, 2)", ""); |
| 250 |
RUN("plugins.itemtags.tag('y', 1, 2)", ""); |
| 251 |
RUN("plugins.itemtags.tags(0)", "x\n"); |
| 252 |
|
| 253 |
RUN("selectItems(0,1,2)", "true\n"); |
| 254 |
KEYS("CTRL+F1"); |
| 255 |
WAIT_ON_OUTPUT("plugins.itemtags.tags(0)", ""); |
| 256 |
RUN("plugins.itemtags.tags(1)", "y\n"); |
| 257 |
RUN("plugins.itemtags.tags(2)", "y\n"); |
| 258 |
} |