aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/InputLineSpec.cpp136
-rw-r--r--spec/InputMediatorSpec.cpp158
2 files changed, 0 insertions, 294 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"
diff --git a/spec/InputMediatorSpec.cpp b/spec/InputMediatorSpec.cpp
index abc2232..b48b008 100644
--- a/spec/InputMediatorSpec.cpp
+++ b/spec/InputMediatorSpec.cpp
@@ -1,170 +1,12 @@
#include "InputMediator.hpp"
#include "LuaRuntime.hpp"
#include "testUtils.h"
-#include "widgets/InputLine.hpp"
#include "widgets/WebViewStack.hpp"
class InputMediatorSpec : public QObject {
Q_OBJECT
private slots:
- void testInputTypes() {
- context("when showCommandInput is called");
- it("shows url input with default command") {
- InputLine inputLine;
- Configuration configuration;
- WebViewStack webViewStack(&configuration);
- auto luaRuntime = LuaRuntime::instance();
- InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
- QCOMPARE(inputLine.isHidden(), true);
-
- inputMediator.showCommandInput("open");
-
- QCOMPARE(inputLine.isHidden(), false);
- QCOMPARE(inputLine.prompt(), "[exec]");
- QCOMPARE(inputLine.getInputText(), "open");
- }
-
- context("when showURLInput is called");
- it("shows url input with default url") {
- InputLine inputLine;
- Configuration configuration;
- WebViewStack webViewStack(&configuration);
- auto luaRuntime = LuaRuntime::instance();
- InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
- QCOMPARE(inputLine.isHidden(), true);
-
- inputMediator.showURLInput("http://a.com");
-
- QCOMPARE(inputLine.isHidden(), false);
- QCOMPARE(inputLine.prompt(), "[url]");
- QCOMPARE(inputLine.getInputText(), "http://a.com");
- }
- }
-
- void testCommandEvaluationOpen() {
- context("when command open is executed");
- context("- without args");
- it("opens url input") {
- InputLine inputLine;
- Configuration configuration;
- WebViewStack webViewStack(&configuration);
- auto luaRuntime = LuaRuntime::instance();
- InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
-
- inputMediator.showCommandInput();
- emit inputLine.submitted("open");
-
- QCOMPARE(inputLine.prompt(), "[url]");
- }
-
- context("when command open is executed");
- context("- with url as an arg");
- it("opens url in current tab") {
- InputLine inputLine;
- Configuration configuration;
- WebViewStack webViewStack(&configuration);
- auto luaRuntime = LuaRuntime::instance();
- InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
-
- inputMediator.showCommandInput();
- emit inputLine.submitted("open http://a.com");
-
- std::vector<QUrl> urls = {QUrl("http://a.com")};
- QCOMPARE(webViewStack.urls(), urls);
- QCOMPARE(webViewStack.currentWebViewIndex(), 0);
- }
- }
-
- void testCommandEvaluationTabOpen() {
- context("when command tabopen is run");
- context("- without args");
- it("opens url in a new tab") {
- InputLine inputLine;
- Configuration configuration;
- WebViewStack webViewStack(&configuration);
- auto luaRuntime = LuaRuntime::instance();
- InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
-
- inputMediator.showCommandInput();
- emit inputLine.submitted("tabopen");
-
- QCOMPARE(inputLine.prompt(), "[url]");
- }
-
- context("when command tabopen is executed");
- context("- with url as an arg");
- it("opens url in a new tab") {
- InputLine inputLine;
- Configuration configuration;
- WebViewStack webViewStack(&configuration);
- auto luaRuntime = LuaRuntime::instance();
- InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
-
- inputMediator.showCommandInput();
- emit inputLine.submitted("tabopen http://a.com");
-
- std::vector<QUrl> urls = {QUrl(configuration.newTabUrl),
- QUrl("http://a.com")};
- QCOMPARE(webViewStack.urls(), urls);
- QCOMPARE(webViewStack.currentWebViewIndex(), 1);
- }
- }
-
- void testCommandEvaluationTabNextPrev() {
- context("when command tabnext is executed");
- it("jumps to next tab") {
- InputLine inputLine;
- Configuration configuration;
- WebViewStack webViewStack(&configuration);
- auto luaRuntime = LuaRuntime::instance();
- InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
- webViewStack.openUrl(QUrl("https://a1.com"), OpenType::OpenUrl);
- webViewStack.openUrl(QUrl("https://a2.com"), OpenType::OpenUrlInTab);
- webViewStack.openUrl(QUrl("https://a2.com"), OpenType::OpenUrlInBgTab);
- QCOMPARE(webViewStack.currentWebViewIndex(), 1);
-
- inputMediator.showCommandInput();
- emit inputLine.submitted("tabnext");
-
- QCOMPARE(webViewStack.currentWebViewIndex(), 2);
- }
-
- context("when command tabprev is executed");
- it("jumps to previous tab") {
- InputLine inputLine;
- Configuration configuration;
- WebViewStack webViewStack(&configuration);
- auto luaRuntime = LuaRuntime::instance();
- InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
- webViewStack.openUrl(QUrl("https://a1.com"), OpenType::OpenUrl);
- webViewStack.openUrl(QUrl("https://a2.com"), OpenType::OpenUrlInTab);
- webViewStack.openUrl(QUrl("https://a2.com"), OpenType::OpenUrlInBgTab);
- QCOMPARE(webViewStack.currentWebViewIndex(), 1);
-
- inputMediator.showCommandInput();
- emit inputLine.submitted("tabprev");
-
- QCOMPARE(webViewStack.currentWebViewIndex(), 0);
- }
- }
-
- void testHideInputLine() {
- context("when hideInputLine is called");
- it("hides input") {
- InputLine inputLine;
- Configuration configuration;
- WebViewStack webViewStack(&configuration);
- auto luaRuntime = LuaRuntime::instance();
- InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
- inputMediator.showURLInput();
- QCOMPARE(inputLine.isHidden(), false);
-
- inputMediator.hideInputLine();
-
- QCOMPARE(inputLine.isHidden(), true);
- }
- }
};
QTEST_REGISTER(InputMediatorSpec)