This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/unit/lib/keyboard-shortcuts-test.js
Martin Brennan b01e4738ab
DEV: Add more keyboard shortcut acceptance tests (#13280)
This adds acceptance tests for keyboard shortcuts to
dismiss new and unread topics.

Also, I cleaned out a few old specs for the unit test for
keyboard-shortcuts. Some were introduced way back in
5100c2bbd2
but then supplanted by
9548876c2d
and never cleaned up, so they were doing nothing.

Follow up to https://review.discourse.org/t/fix-dismiss-topics-keyboard-shortcut-not-working-pr-13260/22157/4?u=martin
2021-06-04 14:04:20 +10:00

49 lines
1.5 KiB
JavaScript

import { module, test } from "qunit";
import DiscourseURL from "discourse/lib/url";
import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
import sinon from "sinon";
module("Unit | Utility | keyboard-shortcuts", function (hooks) {
hooks.beforeEach(function () {
sinon.stub(DiscourseURL, "routeTo");
});
test("selectDown calls _moveSelection with 1", function (assert) {
let stub = sinon.stub(KeyboardShortcuts, "_moveSelection");
KeyboardShortcuts.selectDown();
assert.ok(stub.calledWith(1), "_moveSelection is called with 1");
});
test("selectUp calls _moveSelection with -1", function (assert) {
let stub = sinon.stub(KeyboardShortcuts, "_moveSelection");
KeyboardShortcuts.selectUp();
assert.ok(stub.calledWith(-1), "_moveSelection is called with -1");
});
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");
});
});