diff options
Diffstat (limited to '')
| -rw-r--r-- | spec/InputLineSpec.cpp | 14 | ||||
| -rw-r--r-- | spec/InputMediatorSpec.cpp | 162 |
2 files changed, 168 insertions, 8 deletions
diff --git a/spec/InputLineSpec.cpp b/spec/InputLineSpec.cpp index e4eb9a5..9a3115a 100644 --- a/spec/InputLineSpec.cpp +++ b/spec/InputLineSpec.cpp @@ -1,5 +1,4 @@ #include "testUtils.h" - #include "widgets/InputLine.hpp" class InputLineSpec : public QObject { @@ -11,35 +10,34 @@ private slots: it("sets the initial input text") { InputLine inputWidget("Initial content", new QWidget()); - QCOMPARE(inputWidget.getInputCommand(), QString("Initial content")); + QCOMPARE(inputWidget.getInputText(), QString("Initial content")); } } void testInputUpdate() { context("when user types in input"); - it("updates input command") { + it("updates input text") { InputLine inputWidget("Initial content", new QWidget()); auto input = inputWidget.findChild<QLineEdit *>(); QTest::keyClicks(input, " updated"); - QCOMPARE(inputWidget.getInputCommand(), - QString("Initial content updated")); + QCOMPARE(inputWidget.getInputText(), QString("Initial content updated")); } context("when setInputText is called"); - it("sets input command") { + it("sets input text") { InputLine inputWidget("Initial content", new QWidget()); inputWidget.setInputText("New content"); - QCOMPARE(inputWidget.getInputCommand(), QString("New content")); + QCOMPARE(inputWidget.getInputText(), QString("New content")); } } void testSubmitSignalOnReturnKey() { context("when user hits return key"); - it("emits the submitted signal with the input command") { + it("emits the submitted signal with the input text") { InputLine inputWidget("Initial content", new QWidget()); QSignalSpy submitSignal(&inputWidget, &InputLine::submitted); diff --git a/spec/InputMediatorSpec.cpp b/spec/InputMediatorSpec.cpp new file mode 100644 index 0000000..464e156 --- /dev/null +++ b/spec/InputMediatorSpec.cpp @@ -0,0 +1,162 @@ +#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") { + auto inputLine = InputLine(); + auto webViewStack = WebViewStack(); + 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") { + auto inputLine = InputLine(); + auto webViewStack = WebViewStack(); + 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") { + auto inputLine = InputLine(); + auto webViewStack = WebViewStack(); + 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") { + auto inputLine = InputLine(); + auto webViewStack = WebViewStack(); + 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") { + auto inputLine = InputLine(); + auto webViewStack = WebViewStack(); + 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") { + auto inputLine = InputLine(); + auto webViewStack = WebViewStack(); + auto luaRuntime = LuaRuntime::instance(); + InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime); + + inputMediator.showCommandInput(); + emit inputLine.submitted("tabopen http://a.com"); + + std::vector<QUrl> urls = {QUrl(WebViewStack::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") { + auto inputLine = InputLine(); + auto webViewStack = WebViewStack(); + 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") { + auto inputLine = InputLine(); + auto webViewStack = WebViewStack(); + 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") { + auto inputLine = InputLine(); + auto webViewStack = WebViewStack(); + auto luaRuntime = LuaRuntime::instance(); + InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime); + inputMediator.showURLInput(); + QCOMPARE(inputLine.isHidden(), false); + + inputMediator.hideInputLine(); + + QCOMPARE(inputLine.isHidden(), true); + } + } +}; + +QTEST_REGISTER(InputMediatorSpec) +#include "InputMediatorSpec.moc" |
