aboutsummaryrefslogtreecommitdiff
path: root/spec/InputLineSpec.cpp
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-03-18 21:19:28 +0530
committerAkshay Nair <phenax5@gmail.com>2025-03-18 21:19:47 +0530
commit4c762b2516bc664293c2aec072074f1e34dda8c3 (patch)
treeebe441f7af8c1f4c49f04630538312d55f18f63b /spec/InputLineSpec.cpp
parent056b0b16947ac19a0c425aa9d2ff8f589378d3bc (diff)
downloadnull-browser-4c762b2516bc664293c2aec072074f1e34dda8c3.tar.gz
null-browser-4c762b2516bc664293c2aec072074f1e34dda8c3.zip
Remove all the ui bits because screw it, lets unix a bit more
Diffstat (limited to '')
-rw-r--r--spec/InputLineSpec.cpp136
1 files changed, 0 insertions, 136 deletions
diff --git a/spec/InputLineSpec.cpp b/spec/InputLineSpec.cpp
deleted file mode 100644
index db6890c..0000000
--- a/spec/InputLineSpec.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-#include "completion/Adapter.hpp"
-#include "completion/Completer.hpp"
-#include "testUtils.h"
-#include "widgets/InputLine.hpp"
-#include <QAbstractItemView>
-#include <QtCore/qsharedpointer.h>
-#include <QtCore/qstringlistmodel.h>
-#include <QtCore>
-#include <QtTest/qtestkeyboard.h>
-
-class InputLineSpec : public QObject {
- Q_OBJECT
-
- class FakeInputAdapter : public Adapter {
- public:
- FakeInputAdapter() : Adapter() {
- completerInstance = new Completer;
- QStringList list = {"one", "two", "three"};
- QStringListModel model(list);
- completerInstance->setSourceModel(&model);
- }
- Completer *completer() { return completerInstance; }
- QString prompt() { return "fake prompt"; }
-
- private:
- Completer *completerInstance;
- };
-
-private slots:
- void testWithInitialInput() {
- context("when initialized with some text");
- it("sets the initial input text") {
- InputLine inputWidget("Initial content", new QWidget());
-
- QCOMPARE(inputWidget.getInputText(), "Initial content");
- }
- }
-
- void testInputUpdate() {
- context("when user types in input");
- it("updates input text") {
- InputLine inputWidget("Initial content", new QWidget());
-
- auto input = inputWidget.findChild<QLineEdit *>();
- QTest::keyClicks(input, " updated");
-
- QCOMPARE(inputWidget.getInputText(), "Initial content updated");
- }
-
- context("when setInputText is called");
- it("sets input text") {
- InputLine inputWidget("Initial content", new QWidget());
-
- inputWidget.setInputText("New content");
-
- QCOMPARE(inputWidget.getInputText(), "New content");
- }
- }
-
- void testSubmitSignalOnReturnKey() {
- context("when user hits return key");
- it("emits the submitted signal with the input text") {
- InputLine inputWidget("Initial content", new QWidget());
- QSignalSpy submitSignal(&inputWidget, &InputLine::submitted);
-
- auto input = inputWidget.findChild<QLineEdit *>();
- QTest::keyClicks(input, " updated");
- QTest::keyClick(&inputWidget, Qt::Key_Return);
-
- QCOMPARE(submitSignal.count(), 1);
- QCOMPARE(submitSignal.takeFirst().at(0).toString(),
- QString("Initial content updated"));
- }
- }
-
- void testCancelSignalOnEscapeKey() {
- context("when user hits escape key");
- it("emits 'cancelled' signal") {
- InputLine inputWidget("Initial content", new QWidget());
- QSignalSpy cancelSignal(&inputWidget, &InputLine::cancelled);
-
- auto input = inputWidget.findChild<QLineEdit *>();
- QTest::keyClick(&inputWidget, Qt::Key_Escape);
-
- QCOMPARE(cancelSignal.count(), 1);
- }
-
- context("when user hits ctrl+l key");
- it("emits 'cancelled' signal") {
- InputLine inputWidget("Initial content", new QWidget());
- QSignalSpy cancelSignal(&inputWidget, &InputLine::cancelled);
-
- auto input = inputWidget.findChild<QLineEdit *>();
- QTest::keyClick(&inputWidget, Qt::Key_L, Qt::ControlModifier);
-
- QCOMPARE(cancelSignal.count(), 1);
- }
- }
-
- void testSetFocus() {
- context("when setInputFocus is called with true");
- xit("focusses input field") {
- InputLine inputWidget("Initial content", new QWidget());
-
- inputWidget.setInputFocus(true);
- QApplication::processEvents();
-
- QVERIFY(inputWidget.isInputFocussed());
- }
-
- context("when setInputFocus is called with false");
- xit("unfocusses input field") {
- InputLine inputWidget("Initial content", new QWidget());
-
- inputWidget.setInputFocus(false);
- QApplication::processEvents();
-
- QVERIFY(!inputWidget.isInputFocussed());
- }
- }
-
- void testInputPrompt() {
- it("sets the prompt text using the adapter") {
- InputLine inputWidget("Initial content", new QWidget());
- FakeInputAdapter inputAdapter;
- inputWidget.setAdapter(&inputAdapter);
-
- QCOMPARE(inputWidget.prompt(), "fake prompt");
- }
- }
-
- // TODO: completions test
-};
-
-QTEST_REGISTER(InputLineSpec)
-#include "InputLineSpec.moc"