Files
discourse/app/assets/javascripts/discourse/tests/unit/lib/keyboard-shortcuts-test.js
Sam 9e5e5d4078 FEATURE: shift+j and shift+k will scroll entire posts (#25684)
* FEATURE: shift+j and shift+k will scroll entire posts

When scrolling through topics with very long posts we would like to use
`shift+j` and `shift+k` to quickly move between posts.

This allows users to bypass the scroll within post behavior when zooming
through topics with keyboard shortcuts

This overloads the behavior of shift+k and j which can be used to scroll
through sections (new/latest/etc...)

* remove useless tests

These tests are testing nothing, no point carrying them around
2024-02-16 08:50:29 +11:00

38 lines
1.1 KiB
JavaScript

import { setupTest } from "ember-qunit";
import { module, test } from "qunit";
import sinon from "sinon";
import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
import DiscourseURL from "discourse/lib/url";
module("Unit | Utility | keyboard-shortcuts", function (hooks) {
setupTest(hooks);
hooks.beforeEach(function () {
sinon.stub(DiscourseURL, "routeTo");
});
test("goBack calls history.back", function (assert) {
let called = false;
sinon.stub(history, "back").callsFake(function () {
called = true;
});
KeyboardShortcuts.goBack();
assert.ok(called, "history.back is called");
});
test("nextSection calls _changeSection with 1", function (assert) {
let spy = sinon.spy(KeyboardShortcuts, "_changeSection");
KeyboardShortcuts.nextSection();
assert.ok(spy.calledWith(1), "_changeSection is called with 1");
});
test("prevSection calls _changeSection with -1", function (assert) {
let spy = sinon.spy(KeyboardShortcuts, "_changeSection");
KeyboardShortcuts.prevSection();
assert.ok(spy.calledWith(-1), "_changeSection is called with -1");
});
});