diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-08 20:28:10 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-08 20:29:03 +0530 |
| commit | 6d3ee55638164df6521a60b6392a26f855d5f924 (patch) | |
| tree | 18448793cbb971e76cbaeb7b9d2159ee2ab5d3b6 /spec/CommandInputSpec.cpp | |
| parent | b7ac4dc7a20c624a343c946c5decd1b84eab2b82 (diff) | |
| download | null-browser-6d3ee55638164df6521a60b6392a26f855d5f924.tar.gz null-browser-6d3ee55638164df6521a60b6392a26f855d5f924.zip | |
Add test setup + spec for command input
Diffstat (limited to '')
| -rw-r--r-- | spec/CommandInputSpec.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/CommandInputSpec.cpp b/spec/CommandInputSpec.cpp new file mode 100644 index 0000000..7d15f25 --- /dev/null +++ b/spec/CommandInputSpec.cpp @@ -0,0 +1,71 @@ +#include "TestUtils.h" + +#include "CommandInput.hpp" + +class CommandInputSpec : public QObject { + Q_OBJECT + +private slots: + void testWithInitialInput() { + context("when initialized with some text"); + it("sets the initial input text") { + CommandInput inputWidget("Initial content", new QWidget()); + + QCOMPARE(inputWidget.getInputCommand(), QString("Initial content")); + } + } + + void testInputUpdate() { + context("when user types in input"); + it("updates input command") { + CommandInput inputWidget("Initial content", new QWidget()); + + auto input = inputWidget.findChild<QLineEdit *>(); + QTest::keyClicks(input, " updated"); + + QCOMPARE(inputWidget.getInputCommand(), + QString("Initial content updated")); + } + } + + void testSubmitSignalOnReturnKey() { + context("when user hits return key"); + it("emits the submitted signal with the input command") { + CommandInput inputWidget("Initial content", new QWidget()); + QSignalSpy spy(&inputWidget, &CommandInput::submitted); + + auto input = inputWidget.findChild<QLineEdit *>(); + QTest::keyClicks(input, " updated"); + QTest::keyClick(&inputWidget, Qt::Key_Return); + + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().at(0).toString(), + QString("Initial content updated")); + } + } + + void testSetFocus() { + context("when setInputFocus is called with true"); + xit("focusses input field") { + CommandInput inputWidget("Initial content", new QWidget()); + + inputWidget.setInputFocus(true); + QApplication::processEvents(); + + QVERIFY(inputWidget.isInputFocussed()); + } + + context("when setInputFocus is called with false"); + xit("unfocusses input field") { + CommandInput inputWidget("Initial content", new QWidget()); + + inputWidget.setInputFocus(false); + QApplication::processEvents(); + + QVERIFY(!inputWidget.isInputFocussed()); + } + } +}; + +QTEST_MAIN(CommandInputSpec) +#include "CommandInputSpec.moc" |
