Remove more global variables from tests.
* Use `sinon` instead of `sandbox` and require an import. * You need to import `currentURL` to use it.
This commit is contained in:
parent
5ce006aea1
commit
1e4c0d1857
|
@ -9,5 +9,6 @@
|
||||||
"testStart": "off",
|
"testStart": "off",
|
||||||
"testDone": "off",
|
"testDone": "off",
|
||||||
"sinon": "off",
|
"sinon": "off",
|
||||||
|
"currentURL": "off",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { visit } from "@ember/test-helpers";
|
import { visit, currentURL } from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import siteSettingFixture from "discourse/tests/fixtures/site-settings";
|
import siteSettingFixture from "discourse/tests/fixtures/site-settings";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { visit } from "@ember/test-helpers";
|
import { visit, currentURL } from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { visit } from "@ember/test-helpers";
|
import { visit, currentURL } from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||||
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { visit } from "@ember/test-helpers";
|
import { visit, currentURL } from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { _clearSnapshots } from "select-kit/components/composer-actions";
|
||||||
import { toggleCheckDraftPopup } from "discourse/controllers/composer";
|
import { toggleCheckDraftPopup } from "discourse/controllers/composer";
|
||||||
import Draft from "discourse/models/draft";
|
import Draft from "discourse/models/draft";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
|
import sinon from "sinon";
|
||||||
|
|
||||||
acceptance("Composer Actions", function (needs) {
|
acceptance("Composer Actions", function (needs) {
|
||||||
needs.user();
|
needs.user();
|
||||||
|
@ -110,7 +111,7 @@ acceptance("Composer Actions", function (needs) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("replying to post - reply_as_new_topic", async (assert) => {
|
test("replying to post - reply_as_new_topic", async (assert) => {
|
||||||
sandbox
|
sinon
|
||||||
.stub(Draft, "get")
|
.stub(Draft, "get")
|
||||||
.returns(Promise.resolve({ draft: "", draft_sequence: 0 }));
|
.returns(Promise.resolve({ draft: "", draft_sequence: 0 }));
|
||||||
const composerActions = selectKit(".composer-actions");
|
const composerActions = selectKit(".composer-actions");
|
||||||
|
@ -137,7 +138,7 @@ acceptance("Composer Actions", function (needs) {
|
||||||
I18n.t("topic.create_long")
|
I18n.t("topic.create_long")
|
||||||
);
|
);
|
||||||
assert.ok(find(".d-editor-input").val().includes(quote));
|
assert.ok(find(".d-editor-input").val().includes(quote));
|
||||||
sandbox.restore();
|
sinon.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("reply_as_new_topic without a new_topic draft", async (assert) => {
|
test("reply_as_new_topic without a new_topic draft", async (assert) => {
|
||||||
|
@ -359,7 +360,7 @@ acceptance("Composer Actions", function (needs) {
|
||||||
});
|
});
|
||||||
|
|
||||||
function stubDraftResponse() {
|
function stubDraftResponse() {
|
||||||
sandbox.stub(Draft, "get").returns(
|
sinon.stub(Draft, "get").returns(
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
draft:
|
draft:
|
||||||
'{"reply":"dum de dum da ba.","action":"createTopic","title":"dum da ba dum dum","categoryId":null,"archetypeId":"regular","metaData":null,"composerTime":540879,"typingTime":3400}',
|
'{"reply":"dum de dum da ba.","action":"createTopic","title":"dum da ba dum dum","categoryId":null,"archetypeId":"regular","metaData":null,"composerTime":540879,"typingTime":3400}',
|
||||||
|
@ -418,7 +419,7 @@ acceptance("Composer Actions With New Topic Draft", function (needs) {
|
||||||
} finally {
|
} finally {
|
||||||
toggleCheckDraftPopup(false);
|
toggleCheckDraftPopup(false);
|
||||||
}
|
}
|
||||||
sandbox.restore();
|
sinon.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("reply_as_new_topic with new_topic draft", async (assert) => {
|
test("reply_as_new_topic with new_topic draft", async (assert) => {
|
||||||
|
@ -433,6 +434,6 @@ acceptance("Composer Actions With New Topic Draft", function (needs) {
|
||||||
I18n.t("composer.composer_actions.reply_as_new_topic.confirm")
|
I18n.t("composer.composer_actions.reply_as_new_topic.confirm")
|
||||||
);
|
);
|
||||||
await click(".modal-footer .btn.btn-default");
|
await click(".modal-footer .btn.btn-default");
|
||||||
sandbox.restore();
|
sinon.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { visit } from "@ember/test-helpers";
|
import { visit, currentURL } from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import Category from "discourse/models/category";
|
import Category from "discourse/models/category";
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { visit } from "@ember/test-helpers";
|
import { visit, currentURL } from "@ember/test-helpers";
|
||||||
import { skip } from "qunit";
|
import { skip } from "qunit";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
|
@ -8,6 +8,7 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import { toggleCheckDraftPopup } from "discourse/controllers/composer";
|
import { toggleCheckDraftPopup } from "discourse/controllers/composer";
|
||||||
import Draft from "discourse/models/draft";
|
import Draft from "discourse/models/draft";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
|
import sinon from "sinon";
|
||||||
|
|
||||||
acceptance("Composer", function (needs) {
|
acceptance("Composer", function (needs) {
|
||||||
needs.user();
|
needs.user();
|
||||||
|
@ -633,7 +634,7 @@ acceptance("Composer", function (needs) {
|
||||||
|
|
||||||
const longText = "a".repeat(256);
|
const longText = "a".repeat(256);
|
||||||
|
|
||||||
sandbox.stub(Draft, "get").returns(
|
sinon.stub(Draft, "get").returns(
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
draft: null,
|
draft: null,
|
||||||
draft_sequence: 0,
|
draft_sequence: 0,
|
||||||
|
@ -672,14 +673,14 @@ acceptance("Composer", function (needs) {
|
||||||
} finally {
|
} finally {
|
||||||
toggleCheckDraftPopup(false);
|
toggleCheckDraftPopup(false);
|
||||||
}
|
}
|
||||||
sandbox.restore();
|
sinon.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Loading draft also replaces the recipients", async (assert) => {
|
test("Loading draft also replaces the recipients", async (assert) => {
|
||||||
try {
|
try {
|
||||||
toggleCheckDraftPopup(true);
|
toggleCheckDraftPopup(true);
|
||||||
|
|
||||||
sandbox.stub(Draft, "get").returns(
|
sinon.stub(Draft, "get").returns(
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
draft:
|
draft:
|
||||||
'{"reply":"hello","action":"privateMessage","title":"hello","categoryId":null,"archetypeId":"private_message","metaData":null,"recipients":"codinghorror","composerTime":9159,"typingTime":2500}',
|
'{"reply":"hello","action":"privateMessage","title":"hello","categoryId":null,"archetypeId":"private_message","metaData":null,"recipients":"codinghorror","composerTime":9159,"typingTime":2500}',
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { visit } from "@ember/test-helpers";
|
import { visit, currentURL } from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { visit } from "@ember/test-helpers";
|
import { visit, currentURL } from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||||
import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
|
import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
|
||||||
import KeyboardShortcutInitializer from "discourse/initializers/keyboard-shortcuts";
|
import KeyboardShortcutInitializer from "discourse/initializers/keyboard-shortcuts";
|
||||||
|
import sinon from "sinon";
|
||||||
|
|
||||||
acceptance("Plugin Keyboard Shortcuts - Logged In", function (needs) {
|
acceptance("Plugin Keyboard Shortcuts - Logged In", function (needs) {
|
||||||
needs.user();
|
needs.user();
|
||||||
|
@ -34,7 +35,7 @@ acceptance("Plugin Keyboard Shortcuts - Anonymous", function (needs) {
|
||||||
KeyboardShortcutInitializer.initialize(this.container);
|
KeyboardShortcutInitializer.initialize(this.container);
|
||||||
});
|
});
|
||||||
test("a plugin can add a keyboard shortcut with an option", async (assert) => {
|
test("a plugin can add a keyboard shortcut with an option", async (assert) => {
|
||||||
let spy = sandbox.spy(KeyboardShortcuts, "_bindToPath");
|
let spy = sinon.spy(KeyboardShortcuts, "_bindToPath");
|
||||||
withPluginApi("0.8.38", (api) => {
|
withPluginApi("0.8.38", (api) => {
|
||||||
api.addKeyboardShortcut("]", () => {}, {
|
api.addKeyboardShortcut("]", () => {}, {
|
||||||
anonymous: true,
|
anonymous: true,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { visit } from "@ember/test-helpers";
|
import { visit, currentURL } from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import DiscourseURL from "discourse/lib/url";
|
||||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||||
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import MessageBus from "message-bus-client";
|
import MessageBus from "message-bus-client";
|
||||||
|
import sinon from "sinon";
|
||||||
|
|
||||||
acceptance("Topic Discovery", function (needs) {
|
acceptance("Topic Discovery", function (needs) {
|
||||||
needs.settings({
|
needs.settings({
|
||||||
|
@ -114,7 +115,7 @@ acceptance("Topic Discovery", function (needs) {
|
||||||
test("Using period chooser when query params are present", async (assert) => {
|
test("Using period chooser when query params are present", async (assert) => {
|
||||||
await visit("/top?f=foo&d=bar");
|
await visit("/top?f=foo&d=bar");
|
||||||
|
|
||||||
sandbox.stub(DiscourseURL, "routeTo");
|
sinon.stub(DiscourseURL, "routeTo");
|
||||||
|
|
||||||
const periodChooser = selectKit(".period-chooser");
|
const periodChooser = selectKit(".period-chooser");
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { visit } from "@ember/test-helpers";
|
import { visit, currentURL } from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { visit } from "@ember/test-helpers";
|
import { visit, currentURL } from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ import Site from "discourse/models/site";
|
||||||
import createStore from "discourse/tests/helpers/create-store";
|
import createStore from "discourse/tests/helpers/create-store";
|
||||||
import { getApplication } from "@ember/test-helpers";
|
import { getApplication } from "@ember/test-helpers";
|
||||||
import deprecated from "discourse-common/lib/deprecated";
|
import deprecated from "discourse-common/lib/deprecated";
|
||||||
|
import sinon from "sinon";
|
||||||
|
|
||||||
export function currentUser() {
|
export function currentUser() {
|
||||||
return User.create(sessionFixtures["/session/current.json"].current_user);
|
return User.create(sessionFixtures["/session/current.json"].current_user);
|
||||||
|
@ -61,7 +62,7 @@ export function loggedInUser() {
|
||||||
|
|
||||||
export function fakeTime(timeString, timezone = null, advanceTime = false) {
|
export function fakeTime(timeString, timezone = null, advanceTime = false) {
|
||||||
let now = moment.tz(timeString, timezone);
|
let now = moment.tz(timeString, timezone);
|
||||||
return sandbox.useFakeTimers({
|
return sinon.useFakeTimers({
|
||||||
now: now.valueOf(),
|
now: now.valueOf(),
|
||||||
shouldAdvanceTime: advanceTime,
|
shouldAdvanceTime: advanceTime,
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
import { test, module } from "qunit";
|
import { test, module } from "qunit";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
|
import sinon from "sinon";
|
||||||
var testMouseTrap;
|
|
||||||
import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
|
import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
|
||||||
|
|
||||||
|
let testMouseTrap;
|
||||||
|
|
||||||
module("lib:keyboard-shortcuts", {
|
module("lib:keyboard-shortcuts", {
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
var _bindings = {};
|
let _bindings = {};
|
||||||
|
|
||||||
testMouseTrap = {
|
testMouseTrap = {
|
||||||
bind: function (bindings, callback) {
|
bind: function (bindings, callback) {
|
||||||
var registerBinding = function (binding) {
|
let registerBinding = function (binding) {
|
||||||
_bindings[binding] = callback;
|
_bindings[binding] = callback;
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
|
@ -26,7 +27,7 @@ module("lib:keyboard-shortcuts", {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
sandbox.stub(DiscourseURL, "routeTo");
|
sinon.stub(DiscourseURL, "routeTo");
|
||||||
|
|
||||||
$("#qunit-fixture").html(
|
$("#qunit-fixture").html(
|
||||||
[
|
[
|
||||||
|
@ -69,10 +70,10 @@ module("lib:keyboard-shortcuts", {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var pathBindings = KeyboardShortcuts.PATH_BINDINGS || {};
|
let pathBindings = KeyboardShortcuts.PATH_BINDINGS || {};
|
||||||
Object.keys(pathBindings).forEach((path) => {
|
Object.keys(pathBindings).forEach((path) => {
|
||||||
const binding = pathBindings[path];
|
const binding = pathBindings[path];
|
||||||
var testName = binding + " goes to " + path;
|
let testName = binding + " goes to " + path;
|
||||||
|
|
||||||
test(testName, function (assert) {
|
test(testName, function (assert) {
|
||||||
KeyboardShortcuts.bindEvents();
|
KeyboardShortcuts.bindEvents();
|
||||||
|
@ -82,12 +83,12 @@ Object.keys(pathBindings).forEach((path) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var clickBindings = KeyboardShortcuts.CLICK_BINDINGS || {};
|
let clickBindings = KeyboardShortcuts.CLICK_BINDINGS || {};
|
||||||
Object.keys(clickBindings).forEach((selector) => {
|
Object.keys(clickBindings).forEach((selector) => {
|
||||||
const binding = clickBindings[selector];
|
const binding = clickBindings[selector];
|
||||||
var bindings = binding.split(",");
|
let bindings = binding.split(",");
|
||||||
|
|
||||||
var testName = binding + " clicks on " + selector;
|
let testName = binding + " clicks on " + selector;
|
||||||
|
|
||||||
test(testName, function (assert) {
|
test(testName, function (assert) {
|
||||||
KeyboardShortcuts.bindEvents();
|
KeyboardShortcuts.bindEvents();
|
||||||
|
@ -101,13 +102,13 @@ Object.keys(clickBindings).forEach((selector) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var functionBindings = KeyboardShortcuts.FUNCTION_BINDINGS || {};
|
let functionBindings = KeyboardShortcuts.FUNCTION_BINDINGS || {};
|
||||||
Object.keys(functionBindings).forEach((func) => {
|
Object.keys(functionBindings).forEach((func) => {
|
||||||
const binding = functionBindings[func];
|
const binding = functionBindings[func];
|
||||||
var testName = binding + " calls " + func;
|
let testName = binding + " calls " + func;
|
||||||
|
|
||||||
test(testName, function (assert) {
|
test(testName, function (assert) {
|
||||||
sandbox.stub(KeyboardShortcuts, func, function () {
|
sinon.stub(KeyboardShortcuts, func, function () {
|
||||||
assert.ok(true, func + " is called when " + binding + " is triggered");
|
assert.ok(true, func + " is called when " + binding + " is triggered");
|
||||||
});
|
});
|
||||||
KeyboardShortcuts.bindEvents();
|
KeyboardShortcuts.bindEvents();
|
||||||
|
@ -117,22 +118,22 @@ Object.keys(functionBindings).forEach((func) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("selectDown calls _moveSelection with 1", (assert) => {
|
test("selectDown calls _moveSelection with 1", (assert) => {
|
||||||
var stub = sandbox.stub(KeyboardShortcuts, "_moveSelection");
|
let stub = sinon.stub(KeyboardShortcuts, "_moveSelection");
|
||||||
|
|
||||||
KeyboardShortcuts.selectDown();
|
KeyboardShortcuts.selectDown();
|
||||||
assert.ok(stub.calledWith(1), "_moveSelection is called with 1");
|
assert.ok(stub.calledWith(1), "_moveSelection is called with 1");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("selectUp calls _moveSelection with -1", (assert) => {
|
test("selectUp calls _moveSelection with -1", (assert) => {
|
||||||
var stub = sandbox.stub(KeyboardShortcuts, "_moveSelection");
|
let stub = sinon.stub(KeyboardShortcuts, "_moveSelection");
|
||||||
|
|
||||||
KeyboardShortcuts.selectUp();
|
KeyboardShortcuts.selectUp();
|
||||||
assert.ok(stub.calledWith(-1), "_moveSelection is called with -1");
|
assert.ok(stub.calledWith(-1), "_moveSelection is called with -1");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("goBack calls history.back", (assert) => {
|
test("goBack calls history.back", (assert) => {
|
||||||
var called = false;
|
let called = false;
|
||||||
sandbox.stub(history, "back").callsFake(function () {
|
sinon.stub(history, "back").callsFake(function () {
|
||||||
called = true;
|
called = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -141,14 +142,14 @@ test("goBack calls history.back", (assert) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("nextSection calls _changeSection with 1", (assert) => {
|
test("nextSection calls _changeSection with 1", (assert) => {
|
||||||
var spy = sandbox.spy(KeyboardShortcuts, "_changeSection");
|
let spy = sinon.spy(KeyboardShortcuts, "_changeSection");
|
||||||
|
|
||||||
KeyboardShortcuts.nextSection();
|
KeyboardShortcuts.nextSection();
|
||||||
assert.ok(spy.calledWith(1), "_changeSection is called with 1");
|
assert.ok(spy.calledWith(1), "_changeSection is called with 1");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("prevSection calls _changeSection with -1", (assert) => {
|
test("prevSection calls _changeSection with -1", (assert) => {
|
||||||
var spy = sandbox.spy(KeyboardShortcuts, "_changeSection");
|
let spy = sinon.spy(KeyboardShortcuts, "_changeSection");
|
||||||
|
|
||||||
KeyboardShortcuts.prevSection();
|
KeyboardShortcuts.prevSection();
|
||||||
assert.ok(spy.calledWith(-1), "_changeSection is called with -1");
|
assert.ok(spy.calledWith(-1), "_changeSection is called with -1");
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
ALL_CATEGORIES_ID,
|
ALL_CATEGORIES_ID,
|
||||||
} from "select-kit/components/category-drop";
|
} from "select-kit/components/category-drop";
|
||||||
import { set } from "@ember/object";
|
import { set } from "@ember/object";
|
||||||
|
import sinon from "sinon";
|
||||||
|
|
||||||
testSelectKitModule("category-drop");
|
testSelectKitModule("category-drop");
|
||||||
|
|
||||||
|
@ -332,7 +333,7 @@ componentTest("category url", {
|
||||||
|
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
initCategoriesWithParentCategory(this);
|
initCategoriesWithParentCategory(this);
|
||||||
sandbox.stub(DiscourseURL, "routeTo");
|
sinon.stub(DiscourseURL, "routeTo");
|
||||||
},
|
},
|
||||||
|
|
||||||
async test(assert) {
|
async test(assert) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sinon from "sinon";
|
||||||
import { moduleForComponent } from "ember-qunit";
|
import { moduleForComponent } from "ember-qunit";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import componentTest from "discourse/tests/helpers/component-test";
|
import componentTest from "discourse/tests/helpers/component-test";
|
||||||
|
@ -16,7 +17,7 @@ componentTest("support a placeholder", {
|
||||||
template: `{{text-field placeholderKey="placeholder.i18n.key"}}`,
|
template: `{{text-field placeholderKey="placeholder.i18n.key"}}`,
|
||||||
|
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
sandbox.stub(I18n, "t").returnsArg(0);
|
sinon.stub(I18n, "t").returnsArg(0);
|
||||||
},
|
},
|
||||||
|
|
||||||
test(assert) {
|
test(assert) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sinon from "sinon";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
import {
|
import {
|
||||||
|
@ -68,7 +69,7 @@ widgetTest("notifications", {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const routeToStub = sandbox.stub(DiscourseURL, "routeTo");
|
const routeToStub = sinon.stub(DiscourseURL, "routeTo");
|
||||||
await click(".user-notifications-link");
|
await click(".user-notifications-link");
|
||||||
assert.ok(
|
assert.ok(
|
||||||
routeToStub.calledWith(find(".user-notifications-link")[0].href),
|
routeToStub.calledWith(find(".user-notifications-link")[0].href),
|
||||||
|
@ -131,7 +132,7 @@ widgetTest("private messages - enabled", {
|
||||||
"should correctly render emoji in message title"
|
"should correctly render emoji in message title"
|
||||||
);
|
);
|
||||||
|
|
||||||
const routeToStub = sandbox.stub(DiscourseURL, "routeTo");
|
const routeToStub = sinon.stub(DiscourseURL, "routeTo");
|
||||||
await click(".user-pms-link");
|
await click(".user-pms-link");
|
||||||
assert.ok(
|
assert.ok(
|
||||||
routeToStub.calledWith(userPmsLink.href),
|
routeToStub.calledWith(userPmsLink.href),
|
||||||
|
@ -159,7 +160,7 @@ widgetTest("bookmarks", {
|
||||||
"should correctly render emoji in bookmark title"
|
"should correctly render emoji in bookmark title"
|
||||||
);
|
);
|
||||||
|
|
||||||
const routeToStub = sandbox.stub(DiscourseURL, "routeTo");
|
const routeToStub = sinon.stub(DiscourseURL, "routeTo");
|
||||||
await click(".user-bookmarks-link");
|
await click(".user-bookmarks-link");
|
||||||
assert.ok(
|
assert.ok(
|
||||||
routeToStub.calledWith(find(".user-bookmarks-link")[0].href),
|
routeToStub.calledWith(find(".user-bookmarks-link")[0].href),
|
||||||
|
|
|
@ -67,6 +67,18 @@ export default function setupTests(app, container) {
|
||||||
return server;
|
return server;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Object.defineProperty(window, "sandbox", {
|
||||||
|
get() {
|
||||||
|
deprecated(
|
||||||
|
"Accessing the global variable `sandbox` is deprecated. Import `sinon` instead",
|
||||||
|
{
|
||||||
|
since: "2.6.0.beta.4",
|
||||||
|
dropFrom: "2.6.0",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return window.sinon;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.testStart(function (ctx) {
|
QUnit.testStart(function (ctx) {
|
||||||
let settings = resetSettings();
|
let settings = resetSettings();
|
||||||
|
@ -125,17 +137,16 @@ export default function setupTests(app, container) {
|
||||||
|
|
||||||
PreloadStore.reset();
|
PreloadStore.reset();
|
||||||
|
|
||||||
window.sandbox = sinon;
|
window.sinon.stub(ScrollingDOMMethods, "screenNotFull");
|
||||||
window.sandbox.stub(ScrollingDOMMethods, "screenNotFull");
|
window.sinon.stub(ScrollingDOMMethods, "bindOnScroll");
|
||||||
window.sandbox.stub(ScrollingDOMMethods, "bindOnScroll");
|
window.sinon.stub(ScrollingDOMMethods, "unbindOnScroll");
|
||||||
window.sandbox.stub(ScrollingDOMMethods, "unbindOnScroll");
|
|
||||||
|
|
||||||
// Unless we ever need to test this, let's leave it off.
|
// Unless we ever need to test this, let's leave it off.
|
||||||
$.fn.autocomplete = function () {};
|
$.fn.autocomplete = function () {};
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.testDone(function () {
|
QUnit.testDone(function () {
|
||||||
window.sandbox.restore();
|
window.sinon.restore();
|
||||||
|
|
||||||
// Destroy any modals
|
// Destroy any modals
|
||||||
$(".modal-backdrop").remove();
|
$(".modal-backdrop").remove();
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sinon from "sinon";
|
||||||
import { moduleFor } from "ember-qunit";
|
import { moduleFor } from "ember-qunit";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import { logIn } from "discourse/tests/helpers/qunit-helpers";
|
import { logIn } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
@ -20,7 +21,7 @@ moduleFor("controller:bookmark", {
|
||||||
},
|
},
|
||||||
|
|
||||||
afterEach() {
|
afterEach() {
|
||||||
sandbox.restore();
|
sinon.restore();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -223,7 +224,7 @@ test("loadLastUsedCustomReminderDatetime does not fills the custom reminder date
|
||||||
|
|
||||||
test("user timezone updates when the modal is shown", function (assert) {
|
test("user timezone updates when the modal is shown", function (assert) {
|
||||||
User.current().changeTimezone(null);
|
User.current().changeTimezone(null);
|
||||||
let stub = sandbox.stub(moment.tz, "guess").returns("Europe/Moscow");
|
let stub = sinon.stub(moment.tz, "guess").returns("Europe/Moscow");
|
||||||
BookmarkController.onShow();
|
BookmarkController.onShow();
|
||||||
assert.equal(BookmarkController.userHasTimezoneSet, true);
|
assert.equal(BookmarkController.userHasTimezoneSet, true);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sinon from "sinon";
|
||||||
import { test, module } from "qunit";
|
import { test, module } from "qunit";
|
||||||
import { formattedReminderTime } from "discourse/lib/bookmark";
|
import { formattedReminderTime } from "discourse/lib/bookmark";
|
||||||
import { fakeTime } from "discourse/tests/helpers/qunit-helpers";
|
import { fakeTime } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
@ -8,7 +9,7 @@ module("lib:bookmark", {
|
||||||
},
|
},
|
||||||
|
|
||||||
afterEach() {
|
afterEach() {
|
||||||
sandbox.restore();
|
sinon.restore();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { test } from "qunit";
|
||||||
import createStore from "discourse/tests/helpers/create-store";
|
import createStore from "discourse/tests/helpers/create-store";
|
||||||
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import Site from "discourse/models/site";
|
import Site from "discourse/models/site";
|
||||||
|
import sinon from "sinon";
|
||||||
|
|
||||||
discourseModule("lib:category-link");
|
discourseModule("lib:category-link");
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ test("allowUncategorized", (assert) => {
|
||||||
id: 345,
|
id: 345,
|
||||||
});
|
});
|
||||||
|
|
||||||
sandbox
|
sinon
|
||||||
.stub(Site, "currentProp")
|
.stub(Site, "currentProp")
|
||||||
.withArgs("uncategorized_category_id")
|
.withArgs("uncategorized_category_id")
|
||||||
.returns(345);
|
.returns(345);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sinon from "sinon";
|
||||||
import { module, skip } from "qunit";
|
import { module, skip } from "qunit";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
import ClickTrack from "discourse/lib/click-track";
|
import ClickTrack from "discourse/lib/click-track";
|
||||||
|
@ -10,11 +11,11 @@ module("lib:click-track-edit-history", {
|
||||||
logIn();
|
logIn();
|
||||||
|
|
||||||
let win = { focus: function () {} };
|
let win = { focus: function () {} };
|
||||||
sandbox.stub(window, "open").returns(win);
|
sinon.stub(window, "open").returns(win);
|
||||||
sandbox.stub(win, "focus");
|
sinon.stub(win, "focus");
|
||||||
|
|
||||||
sandbox.stub(DiscourseURL, "routeTo");
|
sinon.stub(DiscourseURL, "routeTo");
|
||||||
sandbox.stub(DiscourseURL, "redirectTo");
|
sinon.stub(DiscourseURL, "redirectTo");
|
||||||
|
|
||||||
sessionStorage.clear();
|
sessionStorage.clear();
|
||||||
|
|
||||||
|
@ -61,7 +62,7 @@ function generateClickEventOn(selector) {
|
||||||
|
|
||||||
skip("tracks internal URLs", async (assert) => {
|
skip("tracks internal URLs", async (assert) => {
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
sinon.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||||
|
|
||||||
const done = assert.async();
|
const done = assert.async();
|
||||||
pretender.post("/clicks/track", (request) => {
|
pretender.post("/clicks/track", (request) => {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sinon from "sinon";
|
||||||
import { module, skip } from "qunit";
|
import { module, skip } from "qunit";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
import ClickTrack from "discourse/lib/click-track";
|
import ClickTrack from "discourse/lib/click-track";
|
||||||
|
@ -9,11 +10,11 @@ module("lib:click-track-profile-page", {
|
||||||
logIn();
|
logIn();
|
||||||
|
|
||||||
let win = { focus: function () {} };
|
let win = { focus: function () {} };
|
||||||
sandbox.stub(window, "open").returns(win);
|
sinon.stub(window, "open").returns(win);
|
||||||
sandbox.stub(win, "focus");
|
sinon.stub(win, "focus");
|
||||||
|
|
||||||
sandbox.stub(DiscourseURL, "routeTo");
|
sinon.stub(DiscourseURL, "routeTo");
|
||||||
sandbox.stub(DiscourseURL, "redirectTo");
|
sinon.stub(DiscourseURL, "redirectTo");
|
||||||
|
|
||||||
sessionStorage.clear();
|
sessionStorage.clear();
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ function generateClickEventOn(selector) {
|
||||||
|
|
||||||
skip("tracks internal URLs", async (assert) => {
|
skip("tracks internal URLs", async (assert) => {
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
sinon.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||||
|
|
||||||
const done = assert.async();
|
const done = assert.async();
|
||||||
pretender.post("/clicks/track", (request) => {
|
pretender.post("/clicks/track", (request) => {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sinon from "sinon";
|
||||||
import { skip } from "qunit";
|
import { skip } from "qunit";
|
||||||
import { test, module } from "qunit";
|
import { test, module } from "qunit";
|
||||||
import { later } from "@ember/runloop";
|
import { later } from "@ember/runloop";
|
||||||
|
@ -12,11 +13,11 @@ module("lib:click-track", {
|
||||||
logIn();
|
logIn();
|
||||||
|
|
||||||
let win = { focus: function () {} };
|
let win = { focus: function () {} };
|
||||||
sandbox.stub(window, "open").returns(win);
|
sinon.stub(window, "open").returns(win);
|
||||||
sandbox.stub(win, "focus");
|
sinon.stub(win, "focus");
|
||||||
|
|
||||||
sandbox.stub(DiscourseURL, "routeTo");
|
sinon.stub(DiscourseURL, "routeTo");
|
||||||
sandbox.stub(DiscourseURL, "redirectTo");
|
sinon.stub(DiscourseURL, "redirectTo");
|
||||||
|
|
||||||
sessionStorage.clear();
|
sessionStorage.clear();
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ function generateClickEventOn(selector) {
|
||||||
|
|
||||||
skip("tracks internal URLs", async (assert) => {
|
skip("tracks internal URLs", async (assert) => {
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
sinon.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||||
|
|
||||||
const done = assert.async();
|
const done = assert.async();
|
||||||
pretender.post("/clicks/track", (request) => {
|
pretender.post("/clicks/track", (request) => {
|
||||||
|
@ -74,7 +75,7 @@ test("does not track elements with no href", async (assert) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("does not track attachments", async (assert) => {
|
test("does not track attachments", async (assert) => {
|
||||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
sinon.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||||
|
|
||||||
pretender.post("/clicks/track", () => assert.ok(false));
|
pretender.post("/clicks/track", () => assert.ok(false));
|
||||||
|
|
||||||
|
@ -184,12 +185,12 @@ function badgeClickCount(assert, id, expected) {
|
||||||
}
|
}
|
||||||
|
|
||||||
test("does not update badge clicks on my own link", async (assert) => {
|
test("does not update badge clicks on my own link", async (assert) => {
|
||||||
sandbox.stub(User, "currentProp").withArgs("id").returns(314);
|
sinon.stub(User, "currentProp").withArgs("id").returns(314);
|
||||||
badgeClickCount(assert, "with-badge", 1);
|
badgeClickCount(assert, "with-badge", 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("does not update badge clicks in my own post", async (assert) => {
|
test("does not update badge clicks in my own post", async (assert) => {
|
||||||
sandbox.stub(User, "currentProp").withArgs("id").returns(3141);
|
sinon.stub(User, "currentProp").withArgs("id").returns(3141);
|
||||||
badgeClickCount(assert, "with-badge-but-not-mine", 1);
|
badgeClickCount(assert, "with-badge-but-not-mine", 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sinon from "sinon";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import EmberObject from "@ember/object";
|
import EmberObject from "@ember/object";
|
||||||
|
@ -15,7 +16,7 @@ import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
|
||||||
discourseModule("lib:computed", {
|
discourseModule("lib:computed", {
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
sandbox.stub(I18n, "t").callsFake(function (scope) {
|
sinon.stub(I18n, "t").callsFake(function (scope) {
|
||||||
return "%@ translated: " + scope;
|
return "%@ translated: " + scope;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sinon from "sinon";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import {
|
import {
|
||||||
|
@ -31,7 +32,7 @@ test("validateUploadedFiles", function (assert) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("uploading one file", function (assert) {
|
test("uploading one file", function (assert) {
|
||||||
sandbox.stub(bootbox, "alert");
|
sinon.stub(bootbox, "alert");
|
||||||
|
|
||||||
assert.not(
|
assert.not(
|
||||||
validateUploadedFiles([1, 2], { siteSettings: this.siteSettings })
|
validateUploadedFiles([1, 2], { siteSettings: this.siteSettings })
|
||||||
|
@ -41,7 +42,7 @@ test("uploading one file", function (assert) {
|
||||||
|
|
||||||
test("new user cannot upload images", function (assert) {
|
test("new user cannot upload images", function (assert) {
|
||||||
this.siteSettings.newuser_max_embedded_media = 0;
|
this.siteSettings.newuser_max_embedded_media = 0;
|
||||||
sandbox.stub(bootbox, "alert");
|
sinon.stub(bootbox, "alert");
|
||||||
|
|
||||||
assert.not(
|
assert.not(
|
||||||
validateUploadedFiles([{ name: "image.png" }], {
|
validateUploadedFiles([{ name: "image.png" }], {
|
||||||
|
@ -61,7 +62,7 @@ test("new user cannot upload images", function (assert) {
|
||||||
test("new user can upload images if allowed", function (assert) {
|
test("new user can upload images if allowed", function (assert) {
|
||||||
this.siteSettings.newuser_max_embedded_media = 1;
|
this.siteSettings.newuser_max_embedded_media = 1;
|
||||||
this.siteSettings.default_trust_level = 0;
|
this.siteSettings.default_trust_level = 0;
|
||||||
sandbox.stub(bootbox, "alert");
|
sinon.stub(bootbox, "alert");
|
||||||
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
validateUploadedFiles([{ name: "image.png" }], {
|
validateUploadedFiles([{ name: "image.png" }], {
|
||||||
|
@ -73,7 +74,7 @@ test("new user can upload images if allowed", function (assert) {
|
||||||
|
|
||||||
test("TL1 can upload images", function (assert) {
|
test("TL1 can upload images", function (assert) {
|
||||||
this.siteSettings.newuser_max_embedded_media = 0;
|
this.siteSettings.newuser_max_embedded_media = 0;
|
||||||
sandbox.stub(bootbox, "alert");
|
sinon.stub(bootbox, "alert");
|
||||||
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
validateUploadedFiles([{ name: "image.png" }], {
|
validateUploadedFiles([{ name: "image.png" }], {
|
||||||
|
@ -85,7 +86,7 @@ test("TL1 can upload images", function (assert) {
|
||||||
|
|
||||||
test("new user cannot upload attachments", function (assert) {
|
test("new user cannot upload attachments", function (assert) {
|
||||||
this.siteSettings.newuser_max_attachments = 0;
|
this.siteSettings.newuser_max_attachments = 0;
|
||||||
sandbox.stub(bootbox, "alert");
|
sinon.stub(bootbox, "alert");
|
||||||
|
|
||||||
assert.not(
|
assert.not(
|
||||||
validateUploadedFiles([{ name: "roman.txt" }], {
|
validateUploadedFiles([{ name: "roman.txt" }], {
|
||||||
|
@ -101,7 +102,7 @@ test("new user cannot upload attachments", function (assert) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("ensures an authorized upload", function (assert) {
|
test("ensures an authorized upload", function (assert) {
|
||||||
sandbox.stub(bootbox, "alert");
|
sinon.stub(bootbox, "alert");
|
||||||
assert.not(
|
assert.not(
|
||||||
validateUploadedFiles([{ name: "unauthorized.html" }], {
|
validateUploadedFiles([{ name: "unauthorized.html" }], {
|
||||||
siteSettings: this.siteSettings,
|
siteSettings: this.siteSettings,
|
||||||
|
@ -118,7 +119,7 @@ test("ensures an authorized upload", function (assert) {
|
||||||
|
|
||||||
test("skipping validation works", function (assert) {
|
test("skipping validation works", function (assert) {
|
||||||
const files = [{ name: "backup.tar.gz" }];
|
const files = [{ name: "backup.tar.gz" }];
|
||||||
sandbox.stub(bootbox, "alert");
|
sinon.stub(bootbox, "alert");
|
||||||
|
|
||||||
assert.not(
|
assert.not(
|
||||||
validateUploadedFiles(files, {
|
validateUploadedFiles(files, {
|
||||||
|
@ -137,7 +138,7 @@ test("skipping validation works", function (assert) {
|
||||||
test("staff can upload anything in PM", function (assert) {
|
test("staff can upload anything in PM", function (assert) {
|
||||||
const files = [{ name: "some.docx" }];
|
const files = [{ name: "some.docx" }];
|
||||||
this.siteSettings.authorized_extensions = "jpeg";
|
this.siteSettings.authorized_extensions = "jpeg";
|
||||||
sandbox.stub(bootbox, "alert");
|
sinon.stub(bootbox, "alert");
|
||||||
|
|
||||||
let user = User.create({ moderator: true });
|
let user = User.create({ moderator: true });
|
||||||
assert.not(
|
assert.not(
|
||||||
|
@ -171,7 +172,7 @@ const dummyBlob = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
test("allows valid uploads to go through", function (assert) {
|
test("allows valid uploads to go through", function (assert) {
|
||||||
sandbox.stub(bootbox, "alert");
|
sinon.stub(bootbox, "alert");
|
||||||
|
|
||||||
let user = User.create({ trust_level: 1 });
|
let user = User.create({ trust_level: 1 });
|
||||||
|
|
||||||
|
@ -303,7 +304,7 @@ test("getUploadMarkdown - replaces GUID in image alt text on iOS", (assert) => {
|
||||||
"![8F2B469B-6B2C-4213-BC68-57B4876365A0|100x200](/uploads/123/abcdef.ext)"
|
"![8F2B469B-6B2C-4213-BC68-57B4876365A0|100x200](/uploads/123/abcdef.ext)"
|
||||||
);
|
);
|
||||||
|
|
||||||
sandbox.stub(Utilities, "isAppleDevice").returns(true);
|
sinon.stub(Utilities, "isAppleDevice").returns(true);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
testUploadMarkdown("8F2B469B-6B2C-4213-BC68-57B4876365A0.jpeg"),
|
testUploadMarkdown("8F2B469B-6B2C-4213-BC68-57B4876365A0.jpeg"),
|
||||||
"![image|100x200](/uploads/123/abcdef.ext)"
|
"![image|100x200](/uploads/123/abcdef.ext)"
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sinon from "sinon";
|
||||||
import { test, module } from "qunit";
|
import { test, module } from "qunit";
|
||||||
import DiscourseURL, { userPath, prefixProtocol } from "discourse/lib/url";
|
import DiscourseURL, { userPath, prefixProtocol } from "discourse/lib/url";
|
||||||
import { setPrefix } from "discourse-common/lib/get-url";
|
import { setPrefix } from "discourse-common/lib/get-url";
|
||||||
|
@ -7,7 +8,7 @@ import User from "discourse/models/user";
|
||||||
module("lib:url");
|
module("lib:url");
|
||||||
|
|
||||||
test("isInternal with a HTTP url", (assert) => {
|
test("isInternal with a HTTP url", (assert) => {
|
||||||
sandbox.stub(DiscourseURL, "origin").returns("http://eviltrout.com");
|
sinon.stub(DiscourseURL, "origin").returns("http://eviltrout.com");
|
||||||
|
|
||||||
assert.not(DiscourseURL.isInternal(null), "a blank URL is not internal");
|
assert.not(DiscourseURL.isInternal(null), "a blank URL is not internal");
|
||||||
assert.ok(DiscourseURL.isInternal("/test"), "relative URLs are internal");
|
assert.ok(DiscourseURL.isInternal("/test"), "relative URLs are internal");
|
||||||
|
@ -34,7 +35,7 @@ test("isInternal with a HTTP url", (assert) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("isInternal with a HTTPS url", (assert) => {
|
test("isInternal with a HTTPS url", (assert) => {
|
||||||
sandbox.stub(DiscourseURL, "origin").returns("https://eviltrout.com");
|
sinon.stub(DiscourseURL, "origin").returns("https://eviltrout.com");
|
||||||
assert.ok(
|
assert.ok(
|
||||||
DiscourseURL.isInternal("http://eviltrout.com/monocle"),
|
DiscourseURL.isInternal("http://eviltrout.com/monocle"),
|
||||||
"HTTPS urls match HTTP urls"
|
"HTTPS urls match HTTP urls"
|
||||||
|
@ -42,7 +43,7 @@ test("isInternal with a HTTPS url", (assert) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("isInternal on subfolder install", (assert) => {
|
test("isInternal on subfolder install", (assert) => {
|
||||||
sandbox.stub(DiscourseURL, "origin").returns("http://eviltrout.com/forum");
|
sinon.stub(DiscourseURL, "origin").returns("http://eviltrout.com/forum");
|
||||||
assert.not(
|
assert.not(
|
||||||
DiscourseURL.isInternal("http://eviltrout.com"),
|
DiscourseURL.isInternal("http://eviltrout.com"),
|
||||||
"the host root is not internal"
|
"the host root is not internal"
|
||||||
|
@ -73,7 +74,7 @@ test("routeTo with prefix", async (assert) => {
|
||||||
logIn();
|
logIn();
|
||||||
const user = User.current();
|
const user = User.current();
|
||||||
|
|
||||||
sandbox.stub(DiscourseURL, "handleURL");
|
sinon.stub(DiscourseURL, "handleURL");
|
||||||
DiscourseURL.routeTo("/my/messages");
|
DiscourseURL.routeTo("/my/messages");
|
||||||
assert.ok(
|
assert.ok(
|
||||||
DiscourseURL.handleURL.calledWith(`/u/${user.username}/messages`),
|
DiscourseURL.handleURL.calledWith(`/u/${user.username}/messages`),
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sinon from "sinon";
|
||||||
import { test, module } from "qunit";
|
import { test, module } from "qunit";
|
||||||
import createStore from "discourse/tests/helpers/create-store";
|
import createStore from "discourse/tests/helpers/create-store";
|
||||||
import Category from "discourse/models/category";
|
import Category from "discourse/models/category";
|
||||||
|
@ -87,7 +88,7 @@ test("findBySlug", (assert) => {
|
||||||
}),
|
}),
|
||||||
categoryList = [darth, luke, hurricane, newsFeed, time, bah];
|
categoryList = [darth, luke, hurricane, newsFeed, time, bah];
|
||||||
|
|
||||||
sandbox.stub(Category, "list").returns(categoryList);
|
sinon.stub(Category, "list").returns(categoryList);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
Category.findBySlug("darth"),
|
Category.findBySlug("darth"),
|
||||||
|
@ -120,7 +121,7 @@ test("findBySlug", (assert) => {
|
||||||
"we can find a category with english slug whose parent slug is CJK"
|
"we can find a category with english slug whose parent slug is CJK"
|
||||||
);
|
);
|
||||||
|
|
||||||
sandbox.restore();
|
sinon.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("findSingleBySlug", (assert) => {
|
test("findSingleBySlug", (assert) => {
|
||||||
|
@ -151,7 +152,7 @@ test("findSingleBySlug", (assert) => {
|
||||||
}),
|
}),
|
||||||
categoryList = [darth, luke, hurricane, newsFeed, time, bah];
|
categoryList = [darth, luke, hurricane, newsFeed, time, bah];
|
||||||
|
|
||||||
sandbox.stub(Category, "list").returns(categoryList);
|
sinon.stub(Category, "list").returns(categoryList);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
Category.findSingleBySlug("darth"),
|
Category.findSingleBySlug("darth"),
|
||||||
|
@ -201,7 +202,7 @@ test("findBySlugPathWithID", (assert) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const categoryList = [foo, bar, baz];
|
const categoryList = [foo, bar, baz];
|
||||||
sandbox.stub(Category, "list").returns(categoryList);
|
sinon.stub(Category, "list").returns(categoryList);
|
||||||
|
|
||||||
assert.deepEqual(Category.findBySlugPathWithID("foo"), foo);
|
assert.deepEqual(Category.findBySlugPathWithID("foo"), foo);
|
||||||
assert.deepEqual(Category.findBySlugPathWithID("foo/bar"), bar);
|
assert.deepEqual(Category.findBySlugPathWithID("foo/bar"), bar);
|
||||||
|
@ -222,7 +223,7 @@ test("search with category name", (assert) => {
|
||||||
slug: "another-different-slug",
|
slug: "another-different-slug",
|
||||||
});
|
});
|
||||||
|
|
||||||
sandbox.stub(Category, "listByActivity").returns([category1, category2]);
|
sinon.stub(Category, "listByActivity").returns([category1, category2]);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
Category.search("term", { limit: 0 }),
|
Category.search("term", { limit: 0 }),
|
||||||
|
@ -254,7 +255,7 @@ test("search with category name", (assert) => {
|
||||||
"orders matching begin with and then contains"
|
"orders matching begin with and then contains"
|
||||||
);
|
);
|
||||||
|
|
||||||
sandbox.restore();
|
sinon.restore();
|
||||||
|
|
||||||
const child_category1 = store.createRecord("category", {
|
const child_category1 = store.createRecord("category", {
|
||||||
id: 3,
|
id: 3,
|
||||||
|
@ -267,7 +268,7 @@ test("search with category name", (assert) => {
|
||||||
read_restricted: true,
|
read_restricted: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
sandbox
|
sinon
|
||||||
.stub(Category, "listByActivity")
|
.stub(Category, "listByActivity")
|
||||||
.returns([read_restricted_category, category1, child_category1, category2]);
|
.returns([read_restricted_category, category1, child_category1, category2]);
|
||||||
|
|
||||||
|
@ -295,7 +296,7 @@ test("search with category name", (assert) => {
|
||||||
"prioritize non read_restricted with limit"
|
"prioritize non read_restricted with limit"
|
||||||
);
|
);
|
||||||
|
|
||||||
sandbox.restore();
|
sinon.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("search with category slug", (assert) => {
|
test("search with category slug", (assert) => {
|
||||||
|
@ -311,7 +312,7 @@ test("search with category slug", (assert) => {
|
||||||
slug: "another-different-slug",
|
slug: "another-different-slug",
|
||||||
});
|
});
|
||||||
|
|
||||||
sandbox.stub(Category, "listByActivity").returns([category1, category2]);
|
sinon.stub(Category, "listByActivity").returns([category1, category2]);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
Category.search("different-slug"),
|
Category.search("different-slug"),
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sinon from "sinon";
|
||||||
import { test, module } from "qunit";
|
import { test, module } from "qunit";
|
||||||
import ArrayProxy from "@ember/array/proxy";
|
import ArrayProxy from "@ember/array/proxy";
|
||||||
import Post from "discourse/models/post";
|
import Post from "discourse/models/post";
|
||||||
|
@ -212,7 +213,7 @@ test("removePosts", (assert) => {
|
||||||
test("cancelFilter", (assert) => {
|
test("cancelFilter", (assert) => {
|
||||||
const postStream = buildStream(1235);
|
const postStream = buildStream(1235);
|
||||||
|
|
||||||
sandbox.stub(postStream, "refresh").returns(Promise.resolve());
|
sinon.stub(postStream, "refresh").returns(Promise.resolve());
|
||||||
|
|
||||||
postStream.set("summary", true);
|
postStream.set("summary", true);
|
||||||
postStream.cancelFilter();
|
postStream.cancelFilter();
|
||||||
|
@ -250,7 +251,7 @@ test("findPostIdForPostNumber", (assert) => {
|
||||||
|
|
||||||
test("fillGapBefore", (assert) => {
|
test("fillGapBefore", (assert) => {
|
||||||
const postStream = buildStream(1234, [60]);
|
const postStream = buildStream(1234, [60]);
|
||||||
sandbox.stub(postStream, "findPostsByIds").returns(Promise.resolve([]));
|
sinon.stub(postStream, "findPostsByIds").returns(Promise.resolve([]));
|
||||||
let post = postStream.store.createRecord("post", { id: 60, post_number: 60 });
|
let post = postStream.store.createRecord("post", { id: 60, post_number: 60 });
|
||||||
postStream.set("gaps", {
|
postStream.set("gaps", {
|
||||||
before: { 60: [51, 52, 53, 54, 55, 56, 57, 58, 59] },
|
before: { 60: [51, 52, 53, 54, 55, 56, 57, 58, 59] },
|
||||||
|
@ -267,7 +268,7 @@ test("fillGapBefore", (assert) => {
|
||||||
|
|
||||||
test("toggleParticipant", (assert) => {
|
test("toggleParticipant", (assert) => {
|
||||||
const postStream = buildStream(1236);
|
const postStream = buildStream(1236);
|
||||||
sandbox.stub(postStream, "refresh").returns(Promise.resolve());
|
sinon.stub(postStream, "refresh").returns(Promise.resolve());
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
postStream.get("userFilters.length"),
|
postStream.get("userFilters.length"),
|
||||||
|
@ -290,7 +291,7 @@ test("toggleParticipant", (assert) => {
|
||||||
|
|
||||||
test("streamFilters", (assert) => {
|
test("streamFilters", (assert) => {
|
||||||
const postStream = buildStream(1237);
|
const postStream = buildStream(1237);
|
||||||
sandbox.stub(postStream, "refresh").returns(Promise.resolve());
|
sinon.stub(postStream, "refresh").returns(Promise.resolve());
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
postStream.get("streamFilters"),
|
postStream.get("streamFilters"),
|
||||||
|
@ -807,7 +808,7 @@ test("comitting and triggerNewPostsInStream race condition", (assert) => {
|
||||||
);
|
);
|
||||||
stagedPost.set("id", 123);
|
stagedPost.set("id", 123);
|
||||||
|
|
||||||
sandbox.stub(postStream, "appendMore");
|
sinon.stub(postStream, "appendMore");
|
||||||
postStream.triggerNewPostsInStream([123]);
|
postStream.triggerNewPostsInStream([123]);
|
||||||
assert.equal(postStream.get("filteredPostsCount"), 1, "it added the post");
|
assert.equal(postStream.get("filteredPostsCount"), 1, "it added the post");
|
||||||
|
|
||||||
|
@ -845,7 +846,7 @@ test("triggerNewPostInStream for ignored posts", async (assert) => {
|
||||||
username: "ignoreduser",
|
username: "ignoreduser",
|
||||||
});
|
});
|
||||||
|
|
||||||
var stub = sandbox
|
let stub = sinon
|
||||||
.stub(postStream, "findPostsByIds")
|
.stub(postStream, "findPostsByIds")
|
||||||
.returns(Promise.resolve([post2]));
|
.returns(Promise.resolve([post2]));
|
||||||
|
|
||||||
|
@ -862,7 +863,7 @@ test("triggerNewPostInStream for ignored posts", async (assert) => {
|
||||||
);
|
);
|
||||||
|
|
||||||
stub.restore();
|
stub.restore();
|
||||||
sandbox.stub(postStream, "findPostsByIds").returns(Promise.resolve([post3]));
|
sinon.stub(postStream, "findPostsByIds").returns(Promise.resolve([post3]));
|
||||||
|
|
||||||
await postStream.triggerNewPostsInStream([102]);
|
await postStream.triggerNewPostsInStream([102]);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sinon from "sinon";
|
||||||
import { test, module } from "qunit";
|
import { test, module } from "qunit";
|
||||||
module("rest-model");
|
module("rest-model");
|
||||||
|
|
||||||
|
@ -25,8 +26,8 @@ test("update", async (assert) => {
|
||||||
assert.equal(widget.get("name"), "Trout Lure");
|
assert.equal(widget.get("name"), "Trout Lure");
|
||||||
assert.ok(!widget.get("isSaving"), "it is not saving");
|
assert.ok(!widget.get("isSaving"), "it is not saving");
|
||||||
|
|
||||||
const spyBeforeUpdate = sandbox.spy(widget, "beforeUpdate");
|
const spyBeforeUpdate = sinon.spy(widget, "beforeUpdate");
|
||||||
const spyAfterUpdate = sandbox.spy(widget, "afterUpdate");
|
const spyAfterUpdate = sinon.spy(widget, "afterUpdate");
|
||||||
const promise = widget.update({ name: "new name" });
|
const promise = widget.update({ name: "new name" });
|
||||||
assert.ok(widget.get("isSaving"), "it is saving");
|
assert.ok(widget.get("isSaving"), "it is saving");
|
||||||
assert.ok(spyBeforeUpdate.calledOn(widget));
|
assert.ok(spyBeforeUpdate.calledOn(widget));
|
||||||
|
@ -66,8 +67,8 @@ test("save new", async (assert) => {
|
||||||
assert.ok(!widget.get("isCreated"), "it is not created");
|
assert.ok(!widget.get("isCreated"), "it is not created");
|
||||||
assert.ok(!widget.get("isSaving"), "it is not saving");
|
assert.ok(!widget.get("isSaving"), "it is not saving");
|
||||||
|
|
||||||
const spyBeforeCreate = sandbox.spy(widget, "beforeCreate");
|
const spyBeforeCreate = sinon.spy(widget, "beforeCreate");
|
||||||
const spyAfterCreate = sandbox.spy(widget, "afterCreate");
|
const spyAfterCreate = sinon.spy(widget, "afterCreate");
|
||||||
const promise = widget.save({ name: "Evil Widget" });
|
const promise = widget.save({ name: "Evil Widget" });
|
||||||
assert.ok(widget.get("isSaving"), "it is not saving");
|
assert.ok(widget.get("isSaving"), "it is not saving");
|
||||||
assert.ok(spyBeforeCreate.calledOn(widget));
|
assert.ok(spyBeforeCreate.calledOn(widget));
|
||||||
|
|
|
@ -175,7 +175,7 @@ test("subscribe to category", function (assert) {
|
||||||
}),
|
}),
|
||||||
categoryList = [darth, luke];
|
categoryList = [darth, luke];
|
||||||
|
|
||||||
sandbox.stub(Category, "list").returns(categoryList);
|
sinon.stub(Category, "list").returns(categoryList);
|
||||||
|
|
||||||
const state = TopicTrackingState.create();
|
const state = TopicTrackingState.create();
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ test("getSubCategoryIds", (assert) => {
|
||||||
slug: "baz",
|
slug: "baz",
|
||||||
parent_category_id: bar.id,
|
parent_category_id: bar.id,
|
||||||
});
|
});
|
||||||
sandbox.stub(Category, "list").returns([foo, bar, baz]);
|
sinon.stub(Category, "list").returns([foo, bar, baz]);
|
||||||
|
|
||||||
const state = TopicTrackingState.create();
|
const state = TopicTrackingState.create();
|
||||||
assert.deepEqual(Array.from(state.getSubCategoryIds(1)), [1, 2, 3]);
|
assert.deepEqual(Array.from(state.getSubCategoryIds(1)), [1, 2, 3]);
|
||||||
|
@ -270,7 +270,7 @@ test("countNew", (assert) => {
|
||||||
id: 4,
|
id: 4,
|
||||||
slug: "qux",
|
slug: "qux",
|
||||||
});
|
});
|
||||||
sandbox.stub(Category, "list").returns([foo, bar, baz, qux]);
|
sinon.stub(Category, "list").returns([foo, bar, baz, qux]);
|
||||||
|
|
||||||
let currentUser = User.create({
|
let currentUser = User.create({
|
||||||
username: "chuck",
|
username: "chuck",
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sinon from "sinon";
|
||||||
import { test, module } from "qunit";
|
import { test, module } from "qunit";
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
import Group from "discourse/models/group";
|
import Group from "discourse/models/group";
|
||||||
|
@ -74,13 +75,13 @@ test("canMangeGroup", (assert) => {
|
||||||
test("resolvedTimezone", (assert) => {
|
test("resolvedTimezone", (assert) => {
|
||||||
const tz = "Australia/Brisbane";
|
const tz = "Australia/Brisbane";
|
||||||
let user = User.create({ timezone: tz, username: "chuck", id: 111 });
|
let user = User.create({ timezone: tz, username: "chuck", id: 111 });
|
||||||
let stub = sandbox.stub(moment.tz, "guess").returns("America/Chicago");
|
let stub = sinon.stub(moment.tz, "guess").returns("America/Chicago");
|
||||||
|
|
||||||
pretender.put("/u/chuck.json", () => {
|
pretender.put("/u/chuck.json", () => {
|
||||||
return [200, { "Content-Type": "application/json" }, {}];
|
return [200, { "Content-Type": "application/json" }, {}];
|
||||||
});
|
});
|
||||||
|
|
||||||
let spy = sandbox.spy(ajaxlib, "ajax");
|
let spy = sinon.spy(ajaxlib, "ajax");
|
||||||
assert.equal(
|
assert.equal(
|
||||||
user.resolvedTimezone(user),
|
user.resolvedTimezone(user),
|
||||||
tz,
|
tz,
|
||||||
|
|
|
@ -30,6 +30,9 @@ define("@ember/test-helpers", () => {
|
||||||
visit() {
|
visit() {
|
||||||
return window.visit(...arguments);
|
return window.visit(...arguments);
|
||||||
},
|
},
|
||||||
|
currentURL() {
|
||||||
|
return window.currentURL(...arguments);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
define("pretender", () => {
|
define("pretender", () => {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
import sinon from "sinon";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import LocalDateBuilder from "./local-date-builder";
|
import LocalDateBuilder from "./local-date-builder";
|
||||||
import sinon from "sinon";
|
|
||||||
|
|
||||||
const UTC = "Etc/UTC";
|
const UTC = "Etc/UTC";
|
||||||
const SYDNEY = "Australia/Sydney";
|
const SYDNEY = "Australia/Sydney";
|
||||||
|
@ -11,16 +11,14 @@ const LONDON = "Europe/London";
|
||||||
|
|
||||||
module("lib:local-date-builder");
|
module("lib:local-date-builder");
|
||||||
|
|
||||||
const sandbox = sinon.createSandbox();
|
|
||||||
|
|
||||||
function freezeTime({ date, timezone }, cb) {
|
function freezeTime({ date, timezone }, cb) {
|
||||||
date = date || "2020-01-22 10:34";
|
date = date || "2020-01-22 10:34";
|
||||||
const newTimezone = timezone || PARIS;
|
const newTimezone = timezone || PARIS;
|
||||||
const previousZone = moment.tz.guess();
|
const previousZone = moment.tz.guess();
|
||||||
const now = moment.tz(date, newTimezone).valueOf();
|
const now = moment.tz(date, newTimezone).valueOf();
|
||||||
|
|
||||||
sandbox.useFakeTimers(now);
|
sinon.useFakeTimers(now);
|
||||||
sandbox.stub(moment.tz, "guess");
|
sinon.stub(moment.tz, "guess");
|
||||||
moment.tz.guess.returns(newTimezone);
|
moment.tz.guess.returns(newTimezone);
|
||||||
moment.tz.setDefault(newTimezone);
|
moment.tz.setDefault(newTimezone);
|
||||||
|
|
||||||
|
@ -28,7 +26,7 @@ function freezeTime({ date, timezone }, cb) {
|
||||||
|
|
||||||
moment.tz.guess.returns(previousZone);
|
moment.tz.guess.returns(previousZone);
|
||||||
moment.tz.setDefault(previousZone);
|
moment.tz.setDefault(previousZone);
|
||||||
sandbox.restore();
|
sinon.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUnit.assert.buildsCorrectDate = function (options, expected, message) {
|
QUnit.assert.buildsCorrectDate = function (options, expected, message) {
|
||||||
|
|
Loading…
Reference in New Issue