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/integration/components/bookmark-test.js
Jarek Radosz f0b2e77abb
FIX: Isolate modal and global key-binds (#12477)
This change makes is so that when a time-picking modal (e.g.  "Add bookmark" modal) is visible, **all** global key bindings are paused.

1. Fixes an issue where opening and closing a time-picking modal would break global single-key keybinds, so for example, <kbd>L</kbd> would no longer like posts, but <kbd>L</kbd> <kbd>L</kbd> would
2. Fixes a related issue, where doing the above would also override custom keybinds provided by plugins (e.g. <kbd>L</kbd> shortcut that discourse-reactions uses)

Included:

* DEV: Reset Mousetraps instead of unbinding
* FIX: Make unbind use unbind
* DEV: Don't check for keyTrapper twice
* DEV: Use an instance of Mousetrap
* DEV: Remove an invalid `for` attribute (`set_reminder` doesn't exist)
* DEV: Add ability to pause all KeyboardShortcuts
* FIX: Pause all keybinds when in a time-picking modal
* DEV: Move bookmark keybind resets to willDestroyElement
* DEV: Fix shortcuts-related tests
2021-03-29 13:58:03 +02:00

158 lines
3.7 KiB
JavaScript

import componentTest, {
setupRenderingTest,
} from "discourse/tests/helpers/component-test";
import {
discourseModule,
fakeTime,
query,
} from "discourse/tests/helpers/qunit-helpers";
import sinon from "sinon";
let clock = null;
function mockMomentTz(dateString, timezone) {
clock = fakeTime(dateString, timezone, true);
}
discourseModule("Integration | Component | bookmark", function (hooks) {
setupRenderingTest(hooks);
let template =
'{{bookmark model=model afterSave=afterSave afterDelete=afterDelete onCloseWithoutSaving=onCloseWithoutSaving registerOnCloseHandler=(action "registerOnCloseHandler") closeModal=(action "closeModal")}}';
hooks.beforeEach(function () {
this.actions.registerOnCloseHandler = () => {};
this.actions.closeModal = () => {};
this.setProperties({
model: {},
afterSave: () => {},
afterDelete: () => {},
onCloseWithoutSaving: () => {},
});
});
hooks.afterEach(function () {
if (clock) {
clock.restore();
}
sinon.restore();
});
componentTest("show later this week option if today is < Thursday", {
template,
skip: true,
beforeEach() {
mockMomentTz("2019-12-10T08:00:00", this.currentUser._timezone);
},
test(assert) {
assert.ok(exists("#tap_tile_later_this_week"), "it has later this week");
},
});
componentTest(
"does not show later this week option if today is >= Thursday",
{
template,
skip: true,
beforeEach() {
mockMomentTz("2019-12-13T08:00:00", this.currentUser._timezone);
},
test(assert) {
assert.notOk(
exists("#tap_tile_later_this_week"),
"it does not have later this week"
);
},
}
);
componentTest("later today does not show if later today is tomorrow", {
template,
skip: true,
beforeEach() {
mockMomentTz("2019-12-11T22:00:00", this.currentUser._timezone);
},
test(assert) {
assert.notOk(
exists("#tap_tile_later_today"),
"it does not have later today"
);
},
});
componentTest("later today shows if it is after 5pm but before 6pm", {
template,
skip: true,
beforeEach() {
mockMomentTz("2019-12-11T14:30:00", this.currentUser._timezone);
},
test(assert) {
assert.ok(exists("#tap_tile_later_today"), "it does have later today");
},
});
componentTest("later today does not show if it is after 5pm", {
template,
skip: true,
beforeEach() {
mockMomentTz("2019-12-11T17:00:00", this.currentUser._timezone);
},
test(assert) {
assert.notOk(
exists("#tap_tile_later_today"),
"it does not have later today"
);
},
});
componentTest("later today does show if it is before the end of the day", {
template,
skip: true,
beforeEach() {
mockMomentTz("2019-12-11T13:00:00", this.currentUser._timezone);
},
test(assert) {
assert.ok(exists("#tap_tile_later_today"), "it does have later today");
},
});
componentTest("prefills the custom reminder type date and time", {
template,
skip: true,
beforeEach() {
let name = "test";
let reminderAt = "2020-05-15T09:45:00";
this.model = { id: 1, name, reminderAt };
},
test(assert) {
assert.equal(query("#bookmark-name").value, "test");
assert.equal(query("#custom-date > .date-picker").value, "2020-05-15");
assert.equal(query("#custom-time").value, "09:45");
},
});
componentTest("defaults to 08:00 for custom time", {
template,
skip: true,
async test(assert) {
await click("#tap_tile_custom");
assert.equal(query("#custom-time").value, "08:00");
},
});
});