This commit is contained in:
Jarek Radosz 2023-06-21 02:57:30 +02:00
parent 995f8b7130
commit 6d3e7c11ed
No known key found for this signature in database
GPG Key ID: 62D0FBAE5BF9B953
11 changed files with 172 additions and 184 deletions

View File

@ -14,6 +14,6 @@ acceptance("Discourse Assign | Assign disabled mobile", function (needs) {
const menu = selectKit(".topic-footer-mobile-dropdown");
await menu.expand();
assert.notOk(menu.rowByValue("assign").exists());
assert.false(menu.rowByValue("assign").exists());
});
});

View File

@ -3,7 +3,6 @@ import { cloneJSON } from "discourse-common/lib/object";
import userFixtures from "discourse/tests/fixtures/user-fixtures";
import {
acceptance,
exists,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import { click, visit } from "@ember/test-helpers";
@ -43,9 +42,9 @@ acceptance("Discourse Assign | Assign mobile", function (needs) {
const menu = selectKit(".topic-footer-mobile-dropdown");
await menu.expand();
assert.ok(menu.rowByValue("assign").exists());
assert.true(menu.rowByValue("assign").exists());
await menu.selectRowByValue("assign");
assert.ok(exists(".assign.modal-body"), "assign modal opens");
assert.dom(".assign.modal-body").exists("assign modal opens");
});
});
@ -81,25 +80,23 @@ acceptance("Discourse Assign | Assign desktop", function (needs) {
test("Post contains hidden assign button", async function (assert) {
await visit("/t/internationalization-localization/280");
assert.ok(
!exists("#post_2 .extra-buttons .d-icon-user-plus"),
"assign to post button is hidden"
);
assert
.dom("#post_2 .extra-buttons .d-icon-user-plus")
.doesNotExist("assign to post button is hidden");
await click("#post_2 button.show-more-actions");
assert.ok(
exists("#post_2 .extra-buttons .d-icon-user-plus"),
"assign to post button exists"
);
assert
.dom("#post_2 .extra-buttons .d-icon-user-plus")
.exists("assign to post button exists");
await click("#post_2 .extra-buttons .d-icon-user-plus");
assert.ok(exists(".assign.modal-body"), "assign modal opens");
assert.dom(".assign.modal-body").exists("assign modal opens");
});
test("Footer dropdown contains button", async function (assert) {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-button-assign");
assert.ok(exists(".assign.modal-body"), "assign modal opens");
assert.dom(".assign.modal-body").exists("assign modal opens");
});
});
@ -140,10 +137,9 @@ acceptance("Discourse Assign | Assign Status enabled", function (needs) {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-button-assign");
assert.ok(
exists(".assign.modal-body #assign-status"),
"assign status dropdown exists"
);
assert
.dom(".assign.modal-body #assign-status")
.exists("assign status dropdown exists");
});
});
@ -180,10 +176,9 @@ acceptance("Discourse Assign | Assign Status disabled", function (needs) {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-button-assign");
assert.notOk(
exists(".assign.modal-body #assign-status"),
"assign status dropdown doesn't exists"
);
assert
.dom(".assign.modal-body #assign-status")
.doesNotExist("assign status dropdown doesn't exists");
});
});

View File

@ -1,7 +1,6 @@
import { test } from "qunit";
import {
acceptance,
exists,
query,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
@ -99,62 +98,59 @@ acceptance("Discourse Assign | Assigned topic", function (needs) {
updateCurrentUser({ can_assign: true });
await visit("/t/assignment-topic/44");
assert.strictEqual(
query("#topic-title .assigned-to").innerText.trim(),
"eviltrout",
"shows assignment in the header"
);
assert.strictEqual(
query("#post_1 .assigned-to").innerText,
"Assigned topic to eviltrout#2 to Developers",
"shows assignment and indirect assignments in the first post"
);
assert.ok(exists("#post_1 .assigned-to svg.d-icon-user-plus"));
assert.strictEqual(
query(".discourse-tags .assigned-to[href='/t/28830'] span").title,
"Shark Doododooo",
"shows topic assign notes"
);
assert.strictEqual(
query(".discourse-tags .assigned-to[href='/p/2'] span").title,
'<script>alert("xss")</script>',
"shows indirect assign notes"
);
assert.ok(
exists("#topic-footer-dropdown-reassign"),
"shows reassign dropdown at the bottom of the topic"
);
assert
.dom("#topic-title .assigned-to")
.hasText("eviltrout", "shows assignment in the header");
assert
.dom("#post_1 .assigned-to")
.hasText(
"Assigned topic to eviltrout#2 to Developers",
"shows assignment and indirect assignments in the first post"
);
assert.dom("#post_1 .assigned-to svg.d-icon-user-plus").exists();
assert
.dom(".discourse-tags .assigned-to[href='/t/28830'] span")
.hasAttribute("title", "Shark Doododooo", "shows topic assign notes");
assert
.dom(".discourse-tags .assigned-to[href='/p/2'] span")
.hasAttribute(
"title",
'<script>alert("xss")</script>',
"shows indirect assign notes"
);
assert
.dom("#topic-footer-dropdown-reassign")
.exists("shows reassign dropdown at the bottom of the topic");
});
test("Shows group assignment info", async function (assert) {
updateCurrentUser({ can_assign: true });
await visit("/t/assignment-topic/45");
assert.strictEqual(
query("#topic-title .assigned-to").innerText.trim(),
"Developers",
"shows assignment in the header"
);
assert.strictEqual(
query("#post_1 .assigned-to--group").innerText.trim(),
"Assigned topic to Developers",
"shows assignment in the first post"
);
assert.ok(exists("#post_1 .assigned-to svg.d-icon-group-plus"));
assert.ok(
exists("#topic-footer-dropdown-reassign"),
"shows reassign dropdown at the bottom of the topic"
);
assert
.dom("#topic-title .assigned-to")
.hasText("Developers", "shows assignment in the header");
assert
.dom("#post_1 .assigned-to--group")
.hasText(
"Assigned topic to Developers",
"shows assignment in the first post"
);
assert.dom("#post_1 .assigned-to svg.d-icon-group-plus").exists();
assert
.dom("#topic-footer-dropdown-reassign")
.exists("shows reassign dropdown at the bottom of the topic");
});
test("User without assign ability cannot see footer button", async function (assert) {
updateCurrentUser({ can_assign: false, admin: false, moderator: false });
await visit("/t/assignment-topic/45");
assert.notOk(
exists("#topic-footer-dropdown-reassign"),
"does not show reassign dropdown at the bottom of the topic"
);
assert
.dom("#topic-footer-dropdown-reassign")
.doesNotExist(
"does not show reassign dropdown at the bottom of the topic"
);
});
test("Shows assignment notification", async function (assert) {
@ -166,7 +162,7 @@ acceptance("Discourse Assign | Assigned topic", function (needs) {
"section.user-content ul.notifications li.item.notification"
);
assert.ok(
assert.true(
notification.children[0].classList.contains("assigned"),
"with correct assigned class"
);
@ -201,9 +197,9 @@ acceptance("Discourse Assign | Reassign topic", function (needs) {
await visit("/t/assignment-topic/44");
await menu.expand();
assert.ok(menu.rowByValue("unassign").exists());
assert.ok(menu.rowByValue("reassign").exists());
assert.ok(menu.rowByValue("reassign-self").exists());
assert.true(menu.rowByValue("unassign").exists());
assert.true(menu.rowByValue("reassign").exists());
assert.true(menu.rowByValue("reassign-self").exists());
});
});
@ -225,9 +221,9 @@ acceptance("Discourse Assign | Reassign topic | mobile", function (needs) {
await visit("/t/assignment-topic/44");
await menu.expand();
assert.ok(menu.rowByValue("unassign-mobile").exists());
assert.ok(menu.rowByValue("reassign-mobile").exists());
assert.ok(menu.rowByValue("reassign-self-mobile").exists());
assert.true(menu.rowByValue("unassign-mobile").exists());
assert.true(menu.rowByValue("reassign-mobile").exists());
assert.true(menu.rowByValue("reassign-self-mobile").exists());
});
});
@ -248,6 +244,6 @@ acceptance("Discourse Assign | Reassign topic conditionals", function (needs) {
await visit("/t/assignment-topic/44");
await menu.expand();
assert.notOk(menu.rowByValue("reassign-self").exists());
assert.false(menu.rowByValue("reassign-self").exists());
});
});

View File

@ -1,6 +1,5 @@
import {
acceptance,
exists,
query,
queryAll,
updateCurrentUser,
@ -211,7 +210,7 @@ acceptance(
test("the assigns tab is not shown", async function (assert) {
await visit("/");
await click(".d-header-icons .current-user");
assert.notOk(exists("#user-menu-button-assign-list"));
assert.dom("#user-menu-button-assign-list").doesNotExist();
});
}
);
@ -229,7 +228,7 @@ acceptance(
test("the assigns tab is not shown", async function (assert) {
await visit("/");
await click(".d-header-icons .current-user");
assert.notOk(exists("#user-menu-button-assign-list"));
assert.dom("#user-menu-button-assign-list").doesNotExist();
});
}
);
@ -284,31 +283,24 @@ acceptance("Discourse Assign | user menu", function (needs) {
test("assigns tab", async function (assert) {
await visit("/");
await click(".d-header-icons .current-user");
assert.ok(exists("#user-menu-button-assign-list"), "assigns tab exists");
assert.ok(
exists("#user-menu-button-assign-list .d-icon-user-plus"),
"assigns tab has the user-plus icon"
);
assert.strictEqual(
query(
"#user-menu-button-assign-list .badge-notification"
).textContent.trim(),
"173",
"assigns tab has a count badge"
);
assert.dom("#user-menu-button-assign-list").exists("assigns tab exists");
assert
.dom("#user-menu-button-assign-list .d-icon-user-plus")
.exists("assigns tab has the user-plus icon");
assert
.dom("#user-menu-button-assign-list .badge-notification")
.hasText("173", "assigns tab has a count badge");
updateCurrentUser({
grouped_unread_notifications: {},
});
assert.notOk(
exists("#user-menu-button-assign-list .badge-notification"),
"badge count disappears when it goes to zero"
);
assert.ok(
exists("#user-menu-button-assign-list"),
"assigns tab still exists"
);
assert
.dom("#user-menu-button-assign-list .badge-notification")
.doesNotExist("badge count disappears when it goes to zero");
assert
.dom("#user-menu-button-assign-list")
.exists("assigns tab still exists");
});
test("clicking on the assign tab when it's already selected navigates to the user's assignments page", async function (assert) {
@ -335,11 +327,11 @@ acceptance("Discourse Assign | user menu", function (needs) {
1,
"there is one unread notification"
);
assert.ok(
assert.true(
notifications[0].classList.contains("unread"),
"the notification is unread"
);
assert.ok(
assert.true(
notifications[0].classList.contains("assigned"),
"the notification is of type assigned"
);
@ -358,13 +350,13 @@ acceptance("Discourse Assign | user menu", function (needs) {
"group assign has the right icon"
);
assert.ok(
assert.true(
userAssign
.querySelector("a")
.href.endsWith("/t/howdy-this-a-test-topic/209/3"),
"user assign links to the first unread post (last read post + 1)"
);
assert.ok(
assert.true(
groupAssign
.querySelector("a")
.href.endsWith(
@ -382,7 +374,7 @@ acceptance("Discourse Assign | user menu", function (needs) {
userAssign.querySelector(".item-description img.emoji"),
"emojis are rendered in user assign"
);
assert.ok(
assert.strictEqual(
userAssign.querySelector(".item-description b").textContent.trim(),
"my test topic",
"user assign topic title is trusted"
@ -423,13 +415,12 @@ acceptance("Discourse Assign | user menu", function (needs) {
await click(".d-header-icons .current-user");
await click("#user-menu-button-assign-list");
assert.ok(
exists("#user-menu-button-assign-list .badge-notification"),
"badge count is visible before dismissing"
);
assert
.dom("#user-menu-button-assign-list .badge-notification")
.exists("badge count is visible before dismissing");
await click(".notifications-dismiss");
assert.notOk(markRead, "mark-read request isn't sent");
assert.false(markRead, "mark-read request isn't sent");
assert.strictEqual(
query(".dismiss-notification-confirmation.modal-body").textContent.trim(),
I18n.t("notifications.dismiss_confirmation.body.assigns", { count: 173 }),
@ -437,12 +428,11 @@ acceptance("Discourse Assign | user menu", function (needs) {
);
await click(".modal-footer .btn-primary");
assert.ok(markRead, "mark-read request is sent");
assert.notOk(exists(".notifications-dismiss"), "dismiss button is gone");
assert.notOk(
exists("#user-menu-button-assign-list .badge-notification"),
"badge count is gone after dismissing"
);
assert.true(markRead, "mark-read request is sent");
assert.dom(".notifications-dismiss").doesNotExist("dismiss button is gone");
assert
.dom("#user-menu-button-assign-list .badge-notification")
.doesNotExist("badge count is gone after dismissing");
assert.strictEqual(
requestBody,
"dismiss_types=assigned",
@ -456,21 +446,20 @@ acceptance("Discourse Assign | user menu", function (needs) {
await click(".d-header-icons .current-user");
await click("#user-menu-button-assign-list");
assert.strictEqual(
query(".empty-state-title").textContent.trim(),
I18n.t("user.no_assignments_title"),
"empty state title is rendered"
);
const emptyStateBody = query(".empty-state-body");
assert.ok(emptyStateBody, "empty state body exists");
assert.ok(
emptyStateBody.querySelector(".d-icon-user-plus"),
"empty state body has user-plus icon"
);
assert.ok(
emptyStateBody
.querySelector("a")
.href.endsWith("/my/preferences/notifications"),
assert
.dom(".empty-state-title")
.hasText(
I18n.t("user.no_assignments_title"),
"empty state title is rendered"
);
assert.dom(".empty-state-body").exists("empty state body exists");
assert
.dom(".empty-state-body .d-icon-user-plus")
.exists("empty state body has user-plus icon");
assert.true(
query(".empty-state-body a").href.endsWith(
"/my/preferences/notifications"
),
"empty state body has user-plus icon"
);
});

View File

@ -1,4 +1,4 @@
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import I18n from "I18n";
@ -40,7 +40,7 @@ acceptance(
await visit("/c/test");
const title = I18n.t("filters.unassigned.help");
assert.ok(exists(`#navigation-bar li[title='${title}']`));
assert.dom(`#navigation-bar li[title='${title}']`).exists();
});
}
);
@ -60,7 +60,7 @@ acceptance(
await visit("/c/test");
const title = I18n.t("filters.unassigned.help");
assert.ok(!exists(`#navigation-bar li[title='${title}']`));
assert.dom(`#navigation-bar li[title='${title}']`).doesNotExist();
});
}
);
@ -80,7 +80,7 @@ acceptance(
await visit("/c/test");
const title = I18n.t("filters.unassigned.help");
assert.ok(exists(`#navigation-bar li[title='${title}']`));
assert.dom(`#navigation-bar li[title='${title}']`).exists();
});
}
);
@ -100,7 +100,7 @@ acceptance(
await visit("/c/test");
const title = I18n.t("filters.unassigned.help");
assert.ok(!exists(`#navigation-bar li[title='${title}']`));
assert.dom(`#navigation-bar li[title='${title}']`).doesNotExist();
});
}
);

View File

@ -1,4 +1,4 @@
import { acceptance, count } from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { visit } from "@ember/test-helpers";
import AssignedTopics from "../fixtures/assigned-group-assignments-fixtures";
import GroupMembers from "../fixtures/group-members-fixtures";
@ -21,11 +21,11 @@ acceptance("Discourse Assign | GroupAssignments", function (needs) {
test("Group Assignments Everyone", async function (assert) {
await visit("/g/discourse/assigned");
assert.strictEqual(count(".topic-list-item"), 1);
assert.dom(".topic-list-item").exists({ count: 1 });
});
test("Group Assignments Ahmedgagan", async function (assert) {
await visit("/g/discourse/assigned/ahmedgagan6");
assert.strictEqual(count(".topic-list-item"), 1);
assert.dom(".topic-list-item").exists({ count: 1 });
});
});

View File

@ -1,7 +1,6 @@
import { test } from "qunit";
import {
acceptance,
query,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import { visit } from "@ember/test-helpers";
@ -48,10 +47,11 @@ acceptance(
await visit("/t/assignment-topic/44");
assert.strictEqual(
query(".topic-notifications-button .reason span.text").innerText,
"You will receive notifications because you are watching this topic."
);
assert
.dom(".topic-notifications-button .reason span.text")
.hasText(
"You will receive notifications because you are watching this topic."
);
});
test("Show user assign reason when user never tracks topics", async function (assert) {
@ -61,10 +61,11 @@ acceptance(
await visit("/t/assignment-topic/45");
assert.strictEqual(
query(".topic-notifications-button .reason span.text").innerText,
"You will see a count of new replies because this topic was assigned to you."
);
assert
.dom(".topic-notifications-button .reason span.text")
.hasText(
"You will see a count of new replies because this topic was assigned to you."
);
});
}
);

View File

@ -1,5 +1,5 @@
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit";
@ -28,11 +28,12 @@ acceptance("Discourse Assign | Search - Full Page", function (needs) {
await fillIn(".search-query", "none");
await inSelector.expand();
await inSelector.selectRowByValue("assigned");
assert.strictEqual(
query(".search-query").value,
"none in:assigned",
'has updated search term to "none in:assigned"'
);
assert
.dom(".search-query")
.hasValue(
"none in:assigned",
'has updated search term to "none in:assigned"'
);
});
test("update in:unassigned filter through advanced search ui", async function (assert) {
@ -43,11 +44,12 @@ acceptance("Discourse Assign | Search - Full Page", function (needs) {
await fillIn(".search-query", "none");
await inSelector.expand();
await inSelector.selectRowByValue("unassigned");
assert.strictEqual(
query(".search-query").value,
"none in:unassigned",
'has updated search term to "none in:unassigned"'
);
assert
.dom(".search-query")
.hasValue(
"none in:unassigned",
'has updated search term to "none in:unassigned"'
);
});
test("update assigned to through advanced search ui", async function (assert) {
@ -67,10 +69,11 @@ acceptance("Discourse Assign | Search - Full Page", function (needs) {
'has "admin" filled in'
);
assert.strictEqual(
query(".search-query").value,
"none assigned:admin",
'has updated search term to "none assigned:admin"'
);
assert
.dom(".search-query")
.hasValue(
"none assigned:admin",
'has updated search term to "none assigned:admin"'
);
});
});

View File

@ -1,9 +1,5 @@
import selectKit from "discourse/tests/helpers/select-kit-helper";
import {
acceptance,
count,
exists,
} from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { visit } from "@ember/test-helpers";
import AssignedTopics from "../fixtures/assigned-topics-fixtures";
import { cloneJSON } from "discourse-common/lib/object";
@ -26,8 +22,8 @@ acceptance(
await visit("/u/eviltrout/activity/assigned");
await options.expand();
assert.strictEqual(count("li[data-value='unassign']"), 1);
assert.strictEqual(count("li[data-value='reassign']"), 1);
assert.dom("li[data-value='unassign']").exists({ count: 1 });
assert.dom("li[data-value='reassign']").exists({ count: 1 });
});
}
);
@ -49,12 +45,12 @@ acceptance(
test("It renders the empty state panel", async function (assert) {
await visit("/u/eviltrout/activity/assigned");
assert.ok(exists("div.empty-state"));
assert.dom("div.empty-state").exists();
});
test("It does not render the search form", async function (assert) {
await visit("/u/eviltrout/activity/assigned");
assert.notOk(exists("div.topic-search-div"));
assert.dom("div.topic-search-div").doesNotExist();
});
}
);

View File

@ -1,9 +1,12 @@
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import EmberObject from "@ember/object";
import pretender, { response } from "discourse/tests/helpers/create-pretender";
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { getOwner } from "discourse-common/lib/get-owner";
module("Unit | Controller | assign-user", function (hooks) {
setupRenderingTest(hooks);
discourseModule("Unit | Controller | assign-user", function () {
test("assigning a user via suggestions makes API call and closes the modal", async function (assert) {
pretender.get("/assign/suggestions", () =>
response({
@ -16,7 +19,8 @@ discourseModule("Unit | Controller | assign-user", function () {
pretender.put("/assign/assign", () => response({}));
let modalClosed = false;
const controller = this.getController("assign-user", {
const controller = getOwner(this).lookup("controller:assign-user");
controller.setProperties({
model: {
target: EmberObject.create({}),
},
@ -29,7 +33,7 @@ discourseModule("Unit | Controller | assign-user", function () {
await controller.assignUser("nat");
assert.strictEqual(modalClosed, true);
assert.true(modalClosed);
});
test("assigning a user by selector does not close the modal", async function (assert) {
@ -42,7 +46,8 @@ discourseModule("Unit | Controller | assign-user", function () {
);
let modalClosed = false;
const controller = this.getController("assign-user", {
const controller = getOwner(this).lookup("controller:assign-user");
controller.setProperties({
model: {
target: EmberObject.create({}),
},
@ -55,6 +60,6 @@ discourseModule("Unit | Controller | assign-user", function () {
await controller.assignUsername("nat");
assert.strictEqual(modalClosed, false);
assert.false(modalClosed);
});
});

View File

@ -1,13 +1,16 @@
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { module, test } from "qunit";
import { setupTest } from "ember-qunit";
import sinon from "sinon";
import * as showModal from "discourse/lib/show-modal";
import pretender, { response } from "discourse/tests/helpers/create-pretender";
import { getOwner } from "discourse-common/lib/get-owner";
module("Unit | Service | task-actions", function (hooks) {
setupTest(hooks);
discourseModule("Unit | Service | task-actions", function () {
test("assign", function (assert) {
const stub = sinon.stub(showModal, "default").returns("the modal");
const service = this.container.lookup("service:task-actions");
const service = getOwner(this).lookup("service:task-actions");
const target = {
assigned_to_user: { username: "tomtom" },
assigned_to_group: { name: "cats" },
@ -17,7 +20,7 @@ discourseModule("Unit | Service | task-actions", function () {
const modalCall = stub.getCall(0).args;
assert.strictEqual(modal, "the modal");
assert.deepEqual(modalCall[0], "assign-user");
assert.strictEqual(modalCall[0], "assign-user");
assert.deepEqual(modalCall[1], {
title: "discourse_assign.assign_modal.title",
model: {
@ -32,7 +35,7 @@ discourseModule("Unit | Service | task-actions", function () {
});
test("reassignUserToTopic", async function (assert) {
const service = this.container.lookup("service:task-actions");
const service = getOwner(this).lookup("service:task-actions");
const target = { id: 1 };
const user = { username: "tomtom" };
let assignRequest;