Changeset View
Changeset View
Standalone View
Standalone View
src/tests/kitemlistkeyboardsearchmanagertest.cpp
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
46 | 46 | | |||
47 | void KItemListKeyboardSearchManagerTest::testBasicKeyboardSearch() | 47 | void KItemListKeyboardSearchManagerTest::testBasicKeyboardSearch() | ||
48 | { | 48 | { | ||
49 | QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem); | 49 | QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem); | ||
50 | QVERIFY(spy.isValid()); | 50 | QVERIFY(spy.isValid()); | ||
51 | 51 | | |||
52 | m_keyboardSearchManager.addKeys("f"); | 52 | m_keyboardSearchManager.addKeys("f"); | ||
53 | QCOMPARE(spy.count(), 1); | 53 | QCOMPARE(spy.count(), 1); | ||
54 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "f" << true); | 54 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "f" << false); | ||
55 | 55 | | |||
56 | m_keyboardSearchManager.addKeys("i"); | 56 | m_keyboardSearchManager.addKeys("i"); | ||
57 | QCOMPARE(spy.count(), 1); | 57 | QCOMPARE(spy.count(), 1); | ||
58 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "fi" << false); | 58 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "fi" << false); | ||
59 | 59 | | |||
60 | m_keyboardSearchManager.addKeys("l"); | 60 | m_keyboardSearchManager.addKeys("l"); | ||
61 | QCOMPARE(spy.count(), 1); | 61 | QCOMPARE(spy.count(), 1); | ||
62 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "fil" << false); | 62 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "fil" << false); | ||
Show All 9 Lines | 70 | { | |||
72 | // to save time when running this test. | 72 | // to save time when running this test. | ||
73 | m_keyboardSearchManager.setTimeout(100); | 73 | m_keyboardSearchManager.setTimeout(100); | ||
74 | 74 | | |||
75 | QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem); | 75 | QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem); | ||
76 | QVERIFY(spy.isValid()); | 76 | QVERIFY(spy.isValid()); | ||
77 | 77 | | |||
78 | m_keyboardSearchManager.addKeys("f"); | 78 | m_keyboardSearchManager.addKeys("f"); | ||
79 | QCOMPARE(spy.count(), 1); | 79 | QCOMPARE(spy.count(), 1); | ||
80 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "f" << true); | 80 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "f" << false); | ||
81 | 81 | | |||
82 | m_keyboardSearchManager.addKeys("i"); | 82 | m_keyboardSearchManager.addKeys("i"); | ||
83 | QCOMPARE(spy.count(), 1); | 83 | QCOMPARE(spy.count(), 1); | ||
84 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "fi" << false); | 84 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "fi" << false); | ||
85 | 85 | | |||
86 | // If the delay between two key presses is larger than the chosen timeout, | 86 | // If the delay between two key presses is larger than the chosen timeout, | ||
87 | // a new search is started. We add a small safety margin to avoid race conditions. | 87 | // a new search is started. We add a small safety margin to avoid race conditions. | ||
88 | QTest::qWait(m_keyboardSearchManager.timeout() + 10); | 88 | QTest::qWait(m_keyboardSearchManager.timeout() + 10); | ||
89 | 89 | | |||
90 | m_keyboardSearchManager.addKeys("l"); | 90 | m_keyboardSearchManager.addKeys("l"); | ||
91 | QCOMPARE(spy.count(), 1); | 91 | QCOMPARE(spy.count(), 1); | ||
92 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "l" << true); | 92 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "l" << true); | ||
93 | 93 | | |||
94 | m_keyboardSearchManager.addKeys("e"); | 94 | m_keyboardSearchManager.addKeys("e"); | ||
95 | QCOMPARE(spy.count(), 1); | 95 | QCOMPARE(spy.count(), 1); | ||
96 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "le" << false); | 96 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "le" << false); | ||
97 | | ||||
98 | // the selection was deselected, for instance with Esc or a click outside the selection | ||||
99 | m_keyboardSearchManager.slotSelectionChanged(KItemSet(), KItemSet() << 1); | ||||
100 | | ||||
101 | m_keyboardSearchManager.addKeys("a"); | ||||
102 | QCOMPARE(spy.count(), 1); | ||||
103 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "a" << false); | ||||
97 | } | 104 | } | ||
98 | 105 | | |||
99 | void KItemListKeyboardSearchManagerTest::testRepeatedKeyPress() | 106 | void KItemListKeyboardSearchManagerTest::testRepeatedKeyPress() | ||
100 | { | 107 | { | ||
101 | // If the same key is pressed repeatedly, the next matching item should be highlighted after | 108 | // If the same key is pressed repeatedly, the next matching item should be highlighted after | ||
102 | // each key press. To achieve, that, the manager emits the changeCurrentItem(QString,bool) | 109 | // each key press. To achieve, that, the manager emits the changeCurrentItem(QString,bool) | ||
103 | // signal, where | 110 | // signal, where | ||
104 | // 1. the string contains the repeated key only once, and | 111 | // 1. the string contains the repeated key only once, and | ||
105 | // 2. the bool searchFromNextItem is true. | 112 | // 2. the bool searchFromNextItem is true. | ||
106 | 113 | | |||
107 | QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem); | 114 | QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem); | ||
108 | QVERIFY(spy.isValid()); | 115 | QVERIFY(spy.isValid()); | ||
109 | 116 | | |||
110 | m_keyboardSearchManager.addKeys("p"); | 117 | m_keyboardSearchManager.addKeys("p"); | ||
111 | QCOMPARE(spy.count(), 1); | 118 | QCOMPARE(spy.count(), 1); | ||
112 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "p" << true); | 119 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "p" << false); | ||
113 | 120 | | |||
114 | m_keyboardSearchManager.addKeys("p"); | 121 | m_keyboardSearchManager.addKeys("p"); | ||
115 | QCOMPARE(spy.count(), 1); | 122 | QCOMPARE(spy.count(), 1); | ||
116 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "p" << true); | 123 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "p" << true); | ||
117 | 124 | | |||
118 | m_keyboardSearchManager.addKeys("p"); | 125 | m_keyboardSearchManager.addKeys("p"); | ||
119 | QCOMPARE(spy.count(), 1); | 126 | QCOMPARE(spy.count(), 1); | ||
120 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "p" << true); | 127 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "p" << true); | ||
Show All 12 Lines | 136 | { | |||
133 | // https://bugs.kde.org/show_bug.cgi?id=321286 | 140 | // https://bugs.kde.org/show_bug.cgi?id=321286 | ||
134 | 141 | | |||
135 | QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem); | 142 | QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem); | ||
136 | QVERIFY(spy.isValid()); | 143 | QVERIFY(spy.isValid()); | ||
137 | 144 | | |||
138 | // Simulate that the user enters "a_b". | 145 | // Simulate that the user enters "a_b". | ||
139 | m_keyboardSearchManager.addKeys("a"); | 146 | m_keyboardSearchManager.addKeys("a"); | ||
140 | QCOMPARE(spy.count(), 1); | 147 | QCOMPARE(spy.count(), 1); | ||
141 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "a" << true); | 148 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "a" << false); | ||
142 | 149 | | |||
143 | m_keyboardSearchManager.addKeys(""); | 150 | m_keyboardSearchManager.addKeys(""); | ||
144 | QCOMPARE(spy.count(), 0); | 151 | QCOMPARE(spy.count(), 0); | ||
145 | 152 | | |||
146 | m_keyboardSearchManager.addKeys("_"); | 153 | m_keyboardSearchManager.addKeys("_"); | ||
147 | QCOMPARE(spy.count(), 1); | 154 | QCOMPARE(spy.count(), 1); | ||
148 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "a_" << false); | 155 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "a_" << false); | ||
149 | 156 | | |||
150 | m_keyboardSearchManager.addKeys("b"); | 157 | m_keyboardSearchManager.addKeys("b"); | ||
151 | QCOMPARE(spy.count(), 1); | 158 | QCOMPARE(spy.count(), 1); | ||
152 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "a_b" << false); | 159 | QCOMPARE(spy.takeFirst(), QList<QVariant>() << "a_b" << false); | ||
153 | } | 160 | } | ||
154 | 161 | | |||
155 | QTEST_GUILESS_MAIN(KItemListKeyboardSearchManagerTest) | 162 | QTEST_GUILESS_MAIN(KItemListKeyboardSearchManagerTest) | ||
156 | 163 | | |||
157 | #include "kitemlistkeyboardsearchmanagertest.moc" | 164 | #include "kitemlistkeyboardsearchmanagertest.moc" |