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/user-status-message-test.js
Andrei Prigorshnev 9f5ba2db90
DEV: Make it possible to hide tooltip on the user status (#17808)
Sometimes status appears on popovers, and we may not want to show a tooltip in that case. But by default, tooltip is enabled.
2022-08-05 16:53:28 +04:00

145 lines
4.1 KiB
JavaScript

import { module, test } from "qunit";
import { render, triggerEvent } from "@ember/test-helpers";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { hbs } from "ember-cli-htmlbars";
import { exists, fakeTime, query } from "discourse/tests/helpers/qunit-helpers";
async function mouseenter() {
await triggerEvent(query(".user-status-message"), "mouseenter");
}
module("Integration | Component | user-status-message", function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
this.currentUser.timezone = "UTC";
});
hooks.afterEach(function () {
if (this.clock) {
this.clock.restore();
}
});
test("it renders user status emoji", async function (assert) {
this.set("status", { emoji: "tooth", description: "off to dentist" });
await render(hbs`<UserStatusMessage @status={{this.status}} />`);
assert.ok(exists("img.emoji[alt='tooth']"), "the status emoji is shown");
});
test("it doesn't render status description by default", async function (assert) {
this.set("status", { emoji: "tooth", description: "off to dentist" });
await render(hbs`<UserStatusMessage @status={{this.status}} />`);
assert.notOk(exists(".user-status-message-description"));
});
test("it renders status description if enabled", async function (assert) {
this.set("status", { emoji: "tooth", description: "off to dentist" });
await render(hbs`
<UserStatusMessage
@status={{this.status}}
@showDescription=true/>
`);
assert.equal(
query(".user-status-message-description").innerText.trim(),
"off to dentist"
);
});
test("it shows the until TIME on the tooltip if status will expire today", async function (assert) {
this.clock = fakeTime(
"2100-02-01T08:00:00.000Z",
this.currentUser.timezone,
true
);
this.set("status", {
emoji: "tooth",
description: "off to dentist",
ends_at: "2100-02-01T12:30:00.000Z",
});
await render(hbs`<UserStatusMessage @status={{this.status}} />`);
await mouseenter();
assert.equal(
document
.querySelector("[data-tippy-root] .user-status-tooltip-until")
.textContent.trim(),
"Until: 12:30 PM"
);
});
test("it shows the until DATE on the tooltip if status will expire tomorrow", async function (assert) {
this.clock = fakeTime(
"2100-02-01T08:00:00.000Z",
this.currentUser.timezone,
true
);
this.set("status", {
emoji: "tooth",
description: "off to dentist",
ends_at: "2100-02-02T12:30:00.000Z",
});
await render(hbs`<UserStatusMessage @status={{this.status}} />`);
await mouseenter();
assert.equal(
document
.querySelector("[data-tippy-root] .user-status-tooltip-until")
.textContent.trim(),
"Until: Feb 2"
);
});
test("it doesn't show until datetime on the tooltip if status doesn't have expiration date", async function (assert) {
this.clock = fakeTime(
"2100-02-01T08:00:00.000Z",
this.currentUser.timezone,
true
);
this.set("status", {
emoji: "tooth",
description: "off to dentist",
ends_at: null,
});
await render(hbs`<UserStatusMessage @status={{this.status}} />`);
await mouseenter();
assert.notOk(
document.querySelector("[data-tippy-root] .user-status-tooltip-until")
);
});
test("it shows tooltip by default", async function (assert) {
this.set("status", {
emoji: "tooth",
description: "off to dentist",
});
await render(hbs`<UserStatusMessage @status={{this.status}} />`);
await mouseenter();
assert.ok(
document.querySelector("[data-tippy-root] .user-status-message-tooltip")
);
});
test("it doesn't show tooltip if disabled", async function (assert) {
this.set("status", {
emoji: "tooth",
description: "off to dentist",
});
await render(
hbs`<UserStatusMessage @status={{this.status}} @showTooltip={{false}} />`
);
await mouseenter();
assert.notOk(
document.querySelector("[data-tippy-root] .user-status-message-tooltip")
);
});
});