From 027a10c04b1589329e859d4c0d85a912070788a6 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 24 Nov 2015 21:32:45 +0100 Subject: [PATCH] bdd: Add some tests for :navigate. --- qutebrowser/browser/commands.py | 2 +- tests/integration/data/navigate/1.txt | 1 + tests/integration/data/navigate/2.txt | 1 + tests/integration/data/navigate/3.txt | 1 + tests/integration/data/navigate/4.txt | 1 + tests/integration/data/navigate/index.html | 12 ++++ tests/integration/data/navigate/next.html | 10 +++ tests/integration/data/navigate/prev.html | 10 +++ .../integration/data/navigate/sub/index.html | 10 +++ tests/integration/features/navigate.feature | 67 +++++++++++++++++++ tests/integration/features/test_navigate.py | 21 ++++++ 11 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 tests/integration/data/navigate/1.txt create mode 100644 tests/integration/data/navigate/2.txt create mode 100644 tests/integration/data/navigate/3.txt create mode 100644 tests/integration/data/navigate/4.txt create mode 100644 tests/integration/data/navigate/index.html create mode 100644 tests/integration/data/navigate/next.html create mode 100644 tests/integration/data/navigate/prev.html create mode 100644 tests/integration/data/navigate/sub/index.html create mode 100644 tests/integration/features/navigate.feature create mode 100644 tests/integration/features/test_navigate.py diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 312d20048..e5c5bc2df 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -516,7 +516,7 @@ class CommandDispatcher: self._navigate_up(url, tab, bg, window) elif where in ('decrement', 'increment'): self._navigate_incdec(url, where, tab, bg, window) - else: + else: # pragma: no cover raise ValueError("Got called with invalid value {} for " "`where'.".format(where)) diff --git a/tests/integration/data/navigate/1.txt b/tests/integration/data/navigate/1.txt new file mode 100644 index 000000000..5626abf0f --- /dev/null +++ b/tests/integration/data/navigate/1.txt @@ -0,0 +1 @@ +one diff --git a/tests/integration/data/navigate/2.txt b/tests/integration/data/navigate/2.txt new file mode 100644 index 000000000..f719efd43 --- /dev/null +++ b/tests/integration/data/navigate/2.txt @@ -0,0 +1 @@ +two diff --git a/tests/integration/data/navigate/3.txt b/tests/integration/data/navigate/3.txt new file mode 100644 index 000000000..2bdf67abb --- /dev/null +++ b/tests/integration/data/navigate/3.txt @@ -0,0 +1 @@ +three diff --git a/tests/integration/data/navigate/4.txt b/tests/integration/data/navigate/4.txt new file mode 100644 index 000000000..851066514 --- /dev/null +++ b/tests/integration/data/navigate/4.txt @@ -0,0 +1 @@ +four diff --git a/tests/integration/data/navigate/index.html b/tests/integration/data/navigate/index.html new file mode 100644 index 000000000..ac867afb2 --- /dev/null +++ b/tests/integration/data/navigate/index.html @@ -0,0 +1,12 @@ + + + + + Navigate + + +

Index page

+ previous + next + + diff --git a/tests/integration/data/navigate/next.html b/tests/integration/data/navigate/next.html new file mode 100644 index 000000000..2568d55ca --- /dev/null +++ b/tests/integration/data/navigate/next.html @@ -0,0 +1,10 @@ + + + + + Navigate + + +

next

+ + diff --git a/tests/integration/data/navigate/prev.html b/tests/integration/data/navigate/prev.html new file mode 100644 index 000000000..92eae94e3 --- /dev/null +++ b/tests/integration/data/navigate/prev.html @@ -0,0 +1,10 @@ + + + + + Navigate + + +

prev

+ + diff --git a/tests/integration/data/navigate/sub/index.html b/tests/integration/data/navigate/sub/index.html new file mode 100644 index 000000000..c116a5bfc --- /dev/null +++ b/tests/integration/data/navigate/sub/index.html @@ -0,0 +1,10 @@ + + + + + Navigate + + +

Sub page

+ + diff --git a/tests/integration/features/navigate.feature b/tests/integration/features/navigate.feature new file mode 100644 index 000000000..e6c2e8db4 --- /dev/null +++ b/tests/integration/features/navigate.feature @@ -0,0 +1,67 @@ +Feature: Using :navigate + + Scenario: :navigate with invalid argument + When I run :navigate foo + Then the error "Invalid value foo." should be shown. + + # up + + Scenario: Navigating up + When I open data/navigate/sub + And I run :navigate up + Then data/navigate should be loaded + + Scenario: Navigating up with root directory + When I open / + And I run :navigate up + Then the error "Can't go up!" should be shown. + + # prev/next + + Scenario: Navigating to previous page + When I open data/navigate + And I run :navigate prev + Then data/navigate/prev.html should be loaded + + Scenario: Navigating to next page + When I open data/navigate + And I run :navigate next + Then data/navigate/next.html should be loaded + + Scenario: Navigating to previous page without links + When I open data/navigate/1.txt + And I run :navigate prev + Then the error "No prev links found!" should be shown. + + Scenario: Navigating to next page without links + When I open data/navigate/1.txt + And I run :navigate next + Then the error "No forward links found!" should be shown. + + # increment/decrement + + Scenario: Incrementing number in URL + When I open data/navigate/1.txt + And I run :navigate increment + Then data/navigate/2.txt should be loaded + + Scenario: Decrementing number in URL + When I open data/navigate/4.txt + And I run :navigate decrement + Then data/navigate/3.txt should be loaded + + Scenario: Decrementing with no number in URL + When I open data/navigate + And I run :navigate decrement + Then the error "No number found in URL!" should be shown. + + Scenario: Incrementing with no number in URL + When I open data/navigate + And I run :navigate increment + Then the error "No number found in URL!" should be shown. + + Scenario: Setting url-incdec-segments + When I set general -> url-incdec-segments to anchor + And I open data/navigate/1.txt + And I run :navigate increment + Then the error "No number found in URL!" should be shown. diff --git a/tests/integration/features/test_navigate.py b/tests/integration/features/test_navigate.py new file mode 100644 index 000000000..91a44344f --- /dev/null +++ b/tests/integration/features/test_navigate.py @@ -0,0 +1,21 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2015 Florian Bruhin (The Compiler) +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +import pytest_bdd as bdd +bdd.scenarios('navigate.feature')