diff --git a/qutebrowser/mainwindow/statusbar/bar.py b/qutebrowser/mainwindow/statusbar/bar.py index 63fd144a3..e7c6016f8 100644 --- a/qutebrowser/mainwindow/statusbar/bar.py +++ b/qutebrowser/mainwindow/statusbar/bar.py @@ -252,7 +252,7 @@ class StatusBar(QWidget): if segment == 'scroll_raw': widget.set_raw() - elif segment in ('history', 'progress'): + elif segment in ('history', 'progress', 'zoom'): widget.enabled = True if tab: widget.on_tab_changed(tab) diff --git a/qutebrowser/mainwindow/statusbar/zoom.py b/qutebrowser/mainwindow/statusbar/zoom.py index 32749c9b4..f24c4d60d 100644 --- a/qutebrowser/mainwindow/statusbar/zoom.py +++ b/qutebrowser/mainwindow/statusbar/zoom.py @@ -18,9 +18,10 @@ class Zoom(textbase.TextBase): def on_zoom_changed(self, factor: float) -> None: """Update percentage when factor changed.""" if factor == 1 and config.val.statusbar.zoom.show == 'non-default': - self.setText("") + self.hide() return - percentage = int(100 * factor) + self.show() + percentage = round(100 * factor) self.setText(f"[{percentage}%]") def on_tab_changed(self, tab: browsertab.AbstractTab) -> None: diff --git a/tests/unit/mainwindow/statusbar/test_zoom.py b/tests/unit/mainwindow/statusbar/test_zoom.py index 0355f1d52..d7f3eb80f 100644 --- a/tests/unit/mainwindow/statusbar/test_zoom.py +++ b/tests/unit/mainwindow/statusbar/test_zoom.py @@ -15,18 +15,17 @@ def zoom(qtbot: pytestqt.qtbot.QtBot, config_stub: Any) -> Zoom: return widget -@pytest.mark.parametrize('factor, show, expected', [ - (1, 'always', '[100%]'), - (1.5, 'always', '[150%]'), - (2, 'always', '[200%]'), - (0.5, 'always', '[50%]'), - (0.25, 'always', '[25%]'), - (1, 'non-default', ''), - (1.5, 'non-default', '[150%]'), - (2, 'non-default', '[200%]'), - (0.5, 'non-default', '[50%]'), - (0.25, 'non-default', '[25%]'), +@pytest.mark.parametrize('factor, expected', [ + (0.25, '[25%]'), + (0.5, '[50%]'), + (0.75, '[75%]'), + (1.5, '[150%]'), + (2, '[200%]'), + (3, '[300%]'), + (4, '[400%]'), + (5, '[500%]'), ]) +@pytest.mark.parametrize("show", ["non-default", "always"]) def test_percentage_texts(zoom: Zoom, factor: float, show: str, expected: str, config_stub: Any) -> None: """Test text displayed by the widget based on the zoom factor of a tab and a config value. @@ -41,6 +40,23 @@ def test_percentage_texts(zoom: Zoom, factor: float, show: str, expected: str, assert zoom.text() == expected +@pytest.mark.parametrize('show, expected', [ + ("always", '[100%]'), + ("non-default", ''), +]) +def test_default_percentage_text(zoom: Zoom, show: str, expected: str, + config_stub: Any) -> None: + """Test default percentage text based on a config value. + + Args: + show: config value for `statusbar.zoom.show`. + expected: expected text given show config value. + """ + config_stub.val.statusbar.zoom.show = show + zoom.on_zoom_changed(factor=1) + assert zoom.text() == expected + + def test_tab_change(zoom: Zoom, fake_web_tab: Any) -> None: """Test zoom factor change when switching tabs.""" zoom.on_zoom_changed(factor=2)