From 387cf24e389854ecc97f6236fdd6acbc2486dd52 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 15 Mar 2025 19:17:03 +0530 Subject: Replaced QCompleter with custom implementation --- spec/InputLineSpec.cpp | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'spec/InputLineSpec.cpp') diff --git a/spec/InputLineSpec.cpp b/spec/InputLineSpec.cpp index 9a3115a..db6890c 100644 --- a/spec/InputLineSpec.cpp +++ b/spec/InputLineSpec.cpp @@ -1,16 +1,38 @@ +#include "completion/Adapter.hpp" +#include "completion/Completer.hpp" #include "testUtils.h" #include "widgets/InputLine.hpp" +#include +#include +#include +#include +#include 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(), QString("Initial content")); + QCOMPARE(inputWidget.getInputText(), "Initial content"); } } @@ -22,7 +44,7 @@ private slots: auto input = inputWidget.findChild(); QTest::keyClicks(input, " updated"); - QCOMPARE(inputWidget.getInputText(), QString("Initial content updated")); + QCOMPARE(inputWidget.getInputText(), "Initial content updated"); } context("when setInputText is called"); @@ -31,7 +53,7 @@ private slots: inputWidget.setInputText("New content"); - QCOMPARE(inputWidget.getInputText(), QString("New content")); + QCOMPARE(inputWidget.getInputText(), "New content"); } } @@ -96,6 +118,18 @@ private slots: 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) -- cgit v1.3.1