aboutsummaryrefslogtreecommitdiff
path: root/spec/InputMediatorSpec.cpp
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-03-12 20:47:57 +0530
committerAkshay Nair <phenax5@gmail.com>2025-03-12 21:06:52 +0530
commit05ae8976a8e1ab5411058de244c4e2fcc87ec369 (patch)
treecb3661ed66b9aeb6b78818228d4ec4785dbf27e1 /spec/InputMediatorSpec.cpp
parentd46cf6e12452261c6aaf498dddf8e1176d349d6e (diff)
downloadnull-browser-05ae8976a8e1ab5411058de244c4e2fcc87ec369.tar.gz
null-browser-05ae8976a8e1ab5411058de244c4e2fcc87ec369.zip
Refactor MainWindow into InputMediator
Diffstat (limited to '')
-rw-r--r--spec/InputMediatorSpec.cpp162
1 files changed, 162 insertions, 0 deletions
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"