mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Replace ok(true)
assertions (#29555)
…with `verifySteps`, `expect(0)`, or by removing it
This commit is contained in:
parent
584a9d98ed
commit
693a4e691b
@ -1,6 +1,6 @@
|
|||||||
import { render } from "@ember/test-helpers";
|
import { render } from "@ember/test-helpers";
|
||||||
import { hbs } from "ember-cli-htmlbars";
|
|
||||||
import { module, test } from "qunit";
|
import { module, test } from "qunit";
|
||||||
|
import AvatarUploader from "discourse/components/avatar-uploader";
|
||||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||||
import { createFile } from "discourse/tests/helpers/qunit-helpers";
|
import { createFile } from "discourse/tests/helpers/qunit-helpers";
|
||||||
@ -8,23 +8,22 @@ import { createFile } from "discourse/tests/helpers/qunit-helpers";
|
|||||||
module("Integration | Component | avatar-uploader", function (hooks) {
|
module("Integration | Component | avatar-uploader", function (hooks) {
|
||||||
setupRenderingTest(hooks);
|
setupRenderingTest(hooks);
|
||||||
|
|
||||||
hooks.beforeEach(function () {
|
test("uploading", async function (assert) {
|
||||||
pretender.post("/uploads.json", () => response({}));
|
|
||||||
});
|
|
||||||
|
|
||||||
test("default", async function (assert) {
|
|
||||||
const done = assert.async();
|
const done = assert.async();
|
||||||
this.set("done", () => {
|
|
||||||
assert.ok(true, "action is called after avatar is uploaded");
|
pretender.post("/uploads.json", () => {
|
||||||
done();
|
assert.step("avatar is uploaded");
|
||||||
|
return response({});
|
||||||
});
|
});
|
||||||
|
|
||||||
await render(hbs`
|
const callback = () => {
|
||||||
<AvatarUploader
|
assert.verifySteps(["avatar is uploaded"]);
|
||||||
@id="avatar-uploader"
|
done();
|
||||||
@done={{this.done}}
|
};
|
||||||
/>
|
|
||||||
`);
|
await render(<template>
|
||||||
|
<AvatarUploader @id="avatar-uploader" @done={{callback}} />
|
||||||
|
</template>);
|
||||||
|
|
||||||
await this.container
|
await this.container
|
||||||
.lookup("service:app-events")
|
.lookup("service:app-events")
|
@ -67,9 +67,5 @@ module(
|
|||||||
"scrolls carousel to center of active item (vertical)"
|
"scrolls carousel to center of active item (vertical)"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("test scroll animation", async function (assert) {
|
|
||||||
assert.ok(true);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -136,10 +136,10 @@ module("Unit | Model | user", function (hooks) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("attempt to stop tracking status if status wasn't tracked doesn't throw", function (assert) {
|
test("attempt to stop tracking status if status wasn't tracked doesn't throw", function (assert) {
|
||||||
|
assert.expect(0);
|
||||||
const store = getOwner(this).lookup("service:store");
|
const store = getOwner(this).lookup("service:store");
|
||||||
const user = store.createRecord("user");
|
const user = store.createRecord("user");
|
||||||
user.statusManager.stopTrackingStatus();
|
user.statusManager.stopTrackingStatus();
|
||||||
assert.ok(true);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("clears statuses of several users correctly when receiving status updates via appEvents", function (assert) {
|
test("clears statuses of several users correctly when receiving status updates via appEvents", function (assert) {
|
||||||
|
@ -8,77 +8,73 @@ import {
|
|||||||
generateLightboxMarkup,
|
generateLightboxMarkup,
|
||||||
generateLightboxObject,
|
generateLightboxObject,
|
||||||
} from "discourse/tests/helpers/lightbox-helpers";
|
} from "discourse/tests/helpers/lightbox-helpers";
|
||||||
import domFromString from "discourse-common/lib/dom-from-string";
|
|
||||||
|
|
||||||
module("Unit | Service | Experimental Lightbox", function (hooks) {
|
module("Unit | Service | Experimental Lightbox", function (hooks) {
|
||||||
setupTest(hooks);
|
setupTest(hooks);
|
||||||
|
|
||||||
const wrap = domFromString(generateLightboxMarkup())[0];
|
|
||||||
const selector = ".lightbox";
|
|
||||||
|
|
||||||
hooks.beforeEach(function () {
|
hooks.beforeEach(function () {
|
||||||
this.lightbox = getOwner(this).lookup("service:lightbox");
|
this.lightbox = getOwner(this).lookup("service:lightbox");
|
||||||
this.appEvents = getOwner(this).lookup("service:app-events");
|
this.appEvents = getOwner(this).lookup("service:app-events");
|
||||||
|
|
||||||
|
document.querySelector("#ember-testing").innerHTML =
|
||||||
|
generateLightboxMarkup();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Lightbox Service has appEvents", async function (assert) {
|
hooks.afterEach(function () {
|
||||||
assert.ok(this.lightbox.appEvents);
|
document.querySelector("#ember-testing").innerHTML = "";
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Does not add event listener if no lightboxes are found", async function (assert) {
|
test("Does not add event listener if no lightboxes are found", async function (assert) {
|
||||||
const container = document.createElement("div");
|
const container = document.createElement("div");
|
||||||
const addEventListenerSpy = sinon.spy(container, "addEventListener");
|
const addEventListenerSpy = sinon.spy(container, "addEventListener");
|
||||||
|
|
||||||
await this.lightbox.setupLightboxes({ container, selector });
|
await this.lightbox.setupLightboxes({ container, selector: ".lightbox" });
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.false(addEventListenerSpy.called, "does not add event listener");
|
||||||
addEventListenerSpy.called,
|
|
||||||
false,
|
|
||||||
"does not add event listener"
|
|
||||||
);
|
|
||||||
|
|
||||||
addEventListenerSpy.restore();
|
addEventListenerSpy.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Adds event listener if lightboxes are found", async function (assert) {
|
test("Adds event listener if lightboxes are found", async function (assert) {
|
||||||
const container = wrap.cloneNode(true);
|
const container = document.querySelector(".lightbox-wrapper");
|
||||||
const addEventListenerSpy = sinon.spy(container, "addEventListener");
|
const addEventListenerSpy = sinon.spy(container, "addEventListener");
|
||||||
|
|
||||||
await this.lightbox.setupLightboxes({ container, selector });
|
await this.lightbox.setupLightboxes({ container, selector: ".lightbox" });
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.true(addEventListenerSpy.calledOnce, "adds event listener");
|
||||||
addEventListenerSpy.calledOnce,
|
|
||||||
true,
|
|
||||||
"adds event listener"
|
|
||||||
);
|
|
||||||
|
|
||||||
addEventListenerSpy.restore();
|
addEventListenerSpy.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Correctly sets event listeners", async function (assert) {
|
test("Correctly sets event listeners", async function (assert) {
|
||||||
const container = wrap.cloneNode(true);
|
const container = document.querySelector(".lightbox-wrapper");
|
||||||
|
|
||||||
const openLightboxSpy = sinon.spy(this.lightbox, "openLightbox");
|
const openLightboxSpy = sinon.spy(this.lightbox, "openLightbox");
|
||||||
const removeEventListenerSpy = sinon.spy(container, "removeEventListener");
|
const removeEventListenerSpy = sinon.spy(container, "removeEventListener");
|
||||||
const clickTarget = container.querySelector(selector);
|
const clickTarget = container.querySelector(".lightbox");
|
||||||
|
|
||||||
await this.lightbox.setupLightboxes({ container, selector, clickTarget });
|
await this.lightbox.setupLightboxes({
|
||||||
|
container,
|
||||||
|
selector: ".lightbox",
|
||||||
|
clickTarget,
|
||||||
|
});
|
||||||
|
|
||||||
await click(container.querySelector(selector));
|
await click(".lightbox");
|
||||||
|
|
||||||
container.appendChild(document.createElement("p"));
|
container.appendChild(document.createElement("p"));
|
||||||
|
|
||||||
await click(container.querySelector("p"));
|
await click(container.querySelector("p"));
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.true(
|
||||||
openLightboxSpy.calledWith({ container, selector, clickTarget }),
|
openLightboxSpy.calledWith({
|
||||||
true,
|
container,
|
||||||
|
selector: ".lightbox",
|
||||||
|
clickTarget,
|
||||||
|
}),
|
||||||
"calls openLightbox on lightboxed element click"
|
"calls openLightbox on lightboxed element click"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.true(
|
||||||
openLightboxSpy.calledOnce,
|
openLightboxSpy.calledOnce,
|
||||||
true,
|
|
||||||
"only calls open lightbox when lightboxed element is clicked"
|
"only calls open lightbox when lightboxed element is clicked"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -90,9 +86,8 @@ module("Unit | Service | Experimental Lightbox", function (hooks) {
|
|||||||
|
|
||||||
await this.lightbox.cleanupLightboxes();
|
await this.lightbox.cleanupLightboxes();
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.true(
|
||||||
removeEventListenerSpy.calledOnce,
|
removeEventListenerSpy.calledOnce,
|
||||||
true,
|
|
||||||
"removes event listener from element on cleanup"
|
"removes event listener from element on cleanup"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -108,11 +103,11 @@ module("Unit | Service | Experimental Lightbox", function (hooks) {
|
|||||||
removeEventListenerSpy.restore();
|
removeEventListenerSpy.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
test(`correctly calls the lightbox:open event`, async function (assert) {
|
test("correctly calls the lightbox:open event", async function (assert) {
|
||||||
const done = assert.async();
|
const done = assert.async();
|
||||||
const container = wrap.cloneNode(true);
|
const container = document.querySelector(".lightbox-wrapper");
|
||||||
|
|
||||||
await this.lightbox.setupLightboxes({ container, selector });
|
await this.lightbox.setupLightboxes({ container, selector: ".lightbox" });
|
||||||
|
|
||||||
const appEventsTriggerSpy = sinon.spy(this.appEvents, "trigger");
|
const appEventsTriggerSpy = sinon.spy(this.appEvents, "trigger");
|
||||||
|
|
||||||
@ -129,35 +124,34 @@ module("Unit | Service | Experimental Lightbox", function (hooks) {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
await click(container.querySelector(selector));
|
await click(".lightbox");
|
||||||
|
|
||||||
assert.ok(appEventsTriggerSpy.calledWith(expectedEvent));
|
assert.true(appEventsTriggerSpy.calledWith(expectedEvent));
|
||||||
|
|
||||||
appEventsTriggerSpy.restore();
|
appEventsTriggerSpy.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
test(`correctly calls the lightbox:close event`, async function (assert) {
|
test("correctly calls the lightbox:close event", async function (assert) {
|
||||||
const done = assert.async();
|
const container = document.querySelector(".lightbox-wrapper");
|
||||||
const container = wrap.cloneNode(true);
|
|
||||||
|
|
||||||
await this.lightbox.setupLightboxes({ container, selector });
|
await this.lightbox.setupLightboxes({ container, selector: ".lightbox" });
|
||||||
|
|
||||||
this.appEvents.on(LIGHTBOX_APP_EVENT_NAMES.CLOSE, () => {
|
this.appEvents.on(LIGHTBOX_APP_EVENT_NAMES.CLOSE, () => {
|
||||||
assert.ok(true);
|
assert.step("lightbox closed");
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await click(container.querySelector(selector));
|
await click(".lightbox");
|
||||||
|
|
||||||
await this.lightbox.closeLightbox();
|
await this.lightbox.closeLightbox();
|
||||||
|
assert.verifySteps(["lightbox closed"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test(`correctly responds to the lightbox:clean event`, async function (assert) {
|
test("correctly responds to the lightbox:clean event", async function (assert) {
|
||||||
const container = wrap.cloneNode(true);
|
const container = document.querySelector(".lightbox-wrapper");
|
||||||
|
|
||||||
await this.lightbox.setupLightboxes({ container, selector });
|
await this.lightbox.setupLightboxes({ container, selector: ".lightbox" });
|
||||||
|
|
||||||
await click(container.querySelector(".lightbox"));
|
await click(".lightbox");
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
this.lightbox.lightboxClickElements.length,
|
this.lightbox.lightboxClickElements.length,
|
||||||
@ -165,11 +159,7 @@ module("Unit | Service | Experimental Lightbox", function (hooks) {
|
|||||||
"correctly stores lightbox click elements for cleanup"
|
"correctly stores lightbox click elements for cleanup"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.true(this.lightbox.lightboxIsOpen, "sets lightboxIsOpen to true");
|
||||||
this.lightbox.lightboxIsOpen,
|
|
||||||
true,
|
|
||||||
"sets lightboxIsOpen to true"
|
|
||||||
);
|
|
||||||
|
|
||||||
this.appEvents.trigger(LIGHTBOX_APP_EVENT_NAMES.CLEAN);
|
this.appEvents.trigger(LIGHTBOX_APP_EVENT_NAMES.CLEAN);
|
||||||
|
|
||||||
@ -179,10 +169,6 @@ module("Unit | Service | Experimental Lightbox", function (hooks) {
|
|||||||
"correctly removes stored entry from lightboxClickElements on cleanup"
|
"correctly removes stored entry from lightboxClickElements on cleanup"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.false(this.lightbox.lightboxIsOpen, "sets lightboxIsOpen to false");
|
||||||
this.lightbox.lightboxIsOpen,
|
|
||||||
false,
|
|
||||||
"sets lightboxIsOpen to false"
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user