DEV: Clean up tests (#388)

This commit is contained in:
Jarek Radosz 2022-10-07 10:51:37 +02:00 committed by GitHub
parent 17bcfde257
commit 5eee863d01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 94 additions and 118 deletions

View File

@ -1,23 +1,17 @@
import selectKit from "discourse/tests/helpers/select-kit-helper";
import {
acceptance,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { visit } from "@ember/test-helpers";
import { clearTopicFooterButtons } from "discourse/lib/register-topic-footer-button";
import { test } from "qunit";
acceptance("Discourse Assign | Assign disabled mobile", function (needs) {
needs.user();
needs.user({ can_assign: true });
needs.mobileView();
needs.settings({ assign_enabled: false });
needs.hooks.beforeEach(() => clearTopicFooterButtons());
test("Footer dropdown does not contain button", async (assert) => {
updateCurrentUser({ can_assign: true });
const menu = selectKit(".topic-footer-mobile-dropdown");
test("Footer dropdown does not contain button", async function (assert) {
await visit("/t/internationalization-localization/280");
const menu = selectKit(".topic-footer-mobile-dropdown");
await menu.expand();
assert.notOk(menu.rowByValue("assign").exists());

View File

@ -7,14 +7,12 @@ import {
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import { click, visit } from "@ember/test-helpers";
import { clearTopicFooterButtons } from "discourse/lib/register-topic-footer-button";
import { test } from "qunit";
acceptance("Discourse Assign | Assign mobile", function (needs) {
needs.user();
needs.mobileView();
needs.settings({ assign_enabled: true });
needs.hooks.beforeEach(() => clearTopicFooterButtons());
needs.pretender((server, helper) => {
server.get("/assign/suggestions", () => {
@ -39,7 +37,7 @@ acceptance("Discourse Assign | Assign mobile", function (needs) {
});
});
test("Footer dropdown contains button", async (assert) => {
test("Footer dropdown contains button", async function (assert) {
updateCurrentUser({ can_assign: true });
await visit("/t/internationalization-localization/280");
const menu = selectKit(".topic-footer-mobile-dropdown");
@ -58,7 +56,6 @@ acceptance("Discourse Assign | Assign desktop", function (needs) {
can_assign: true,
});
needs.settings({ assign_enabled: true });
needs.hooks.beforeEach(() => clearTopicFooterButtons());
needs.pretender((server, helper) => {
server.get("/assign/suggestions", () => {
@ -82,7 +79,8 @@ acceptance("Discourse Assign | Assign desktop", function (needs) {
return helper.response({ success: true });
});
});
test("Post contains hidden assign button", async (assert) => {
test("Post contains hidden assign button", async function (assert) {
await visit("/t/internationalization-localization/280");
assert.ok(
@ -99,7 +97,7 @@ acceptance("Discourse Assign | Assign desktop", function (needs) {
assert.ok(exists(".assign.modal-body"), "assign modal opens");
});
test("Footer dropdown contains button", async (assert) => {
test("Footer dropdown contains button", async function (assert) {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-button-assign");
@ -118,7 +116,6 @@ acceptance("Discourse Assign | Assign Status enabled", function (needs) {
enable_assign_status: true,
assign_statuses: "New|In Progress|Done",
});
needs.hooks.beforeEach(() => clearTopicFooterButtons());
needs.pretender((server, helper) => {
server.get("/assign/suggestions", () => {
@ -143,7 +140,7 @@ acceptance("Discourse Assign | Assign Status enabled", function (needs) {
});
});
test("Modal contains status dropdown", async (assert) => {
test("Modal contains status dropdown", async function (assert) {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-button-assign");
@ -159,7 +156,6 @@ acceptance("Discourse Assign | Assign Status disabled", function (needs) {
can_assign: true,
});
needs.settings({ assign_enabled: true, enable_assign_status: false });
needs.hooks.beforeEach(() => clearTopicFooterButtons());
needs.pretender((server, helper) => {
server.get("/assign/suggestions", () => {
@ -184,7 +180,7 @@ acceptance("Discourse Assign | Assign Status disabled", function (needs) {
});
});
test("Modal contains status dropdown", async (assert) => {
test("Modal contains status dropdown", async function (assert) {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-button-assign");
@ -226,36 +222,36 @@ acceptance("Discourse Assign | User preferences", function (needs) {
remind_assigns_frequency: 43200,
});
test("The frequency for assigned topic reminders defaults to the site setting", async (assert) => {
test("The frequency for assigned topic reminders defaults to the site setting", async function (assert) {
await visit("/u/eviltrout/preferences/notifications");
assert.equal(
assert.strictEqual(
selectKit("#remind-assigns-frequency").header().value(),
"43200",
"set frequency to default of Monthly"
);
});
test("The user can change the frequency to Never", async (assert) => {
test("The user can change the frequency to Never", async function (assert) {
await visit("/u/eviltrout/preferences/notifications");
await selectKit("#remind-assigns-frequency").expand();
await selectKit("#remind-assigns-frequency").selectRowByValue(0);
assert.equal(
assert.strictEqual(
selectKit("#remind-assigns-frequency").header().value(),
"0",
"set frequency to Never"
);
});
test("The user can change the frequency to some other non-default value", async (assert) => {
test("The user can change the frequency to some other non-default value", async function (assert) {
await visit("/u/eviltrout/preferences/notifications");
await selectKit("#remind-assigns-frequency").expand();
await selectKit("#remind-assigns-frequency").selectRowByValue(10080); // weekly
assert.equal(
assert.strictEqual(
selectKit("#remind-assigns-frequency").header().value(),
"10080",
"set frequency to Weekly"
@ -286,10 +282,10 @@ acceptance(
});
});
test("The user's previously selected value is loaded", async (assert) => {
test("The user's previously selected value is loaded", async function (assert) {
await visit("/u/eviltrout/preferences/notifications");
assert.equal(
assert.strictEqual(
selectKit("#remind-assigns-frequency").header().value(),
"10080",
"frequency is pre-selected to Weekly"

View File

@ -52,22 +52,22 @@ acceptance("Discourse Assign | Assignment notifications", function (needs) {
);
});
test("Shows the right icons", async (assert) => {
test("Shows the right icons", async function (assert) {
await visit("/");
await click("#current-user.header-dropdown-toggle");
const userAssignment = query(".quick-access-panel li:nth-child(1) a");
assert.ok(
[...userAssignment.querySelector(".d-icon").classList].includes(
"d-icon-user-plus"
)
userAssignment
.querySelector(".d-icon")
.classList.contains("d-icon-user-plus")
);
const groupAssignment = query(".quick-access-panel li:nth-child(2) a");
assert.ok(
[...groupAssignment.querySelector(".d-icon").classList].includes(
"d-icon-group-plus"
)
groupAssignment
.querySelector(".d-icon")
.classList.contains("d-icon-group-plus")
);
});
});

View File

@ -95,27 +95,27 @@ acceptance("Discourse Assign | Assigned topic", function (needs) {
assignCurrentUserToTopic(needs);
test("Shows user assignment info", async (assert) => {
test("Shows user assignment info", async function (assert) {
updateCurrentUser({ can_assign: true });
await visit("/t/assignment-topic/44");
assert.equal(
assert.strictEqual(
query("#topic-title .assigned-to").innerText.trim(),
"eviltrout",
"shows assignment in the header"
);
assert.equal(
assert.strictEqual(
query("#post_1 .assigned-to").innerText,
"Assigned toeviltrout#2 Developers",
"shows assignment and indirect assignments in the first post"
);
assert.ok(exists("#post_1 .assigned-to svg.d-icon-user-plus"));
assert.equal(
assert.strictEqual(
query(".discourse-tags .assigned-to[href='/t/28830'] span").title,
"Shark Doododooo",
"shows topic assign notes"
);
assert.equal(
assert.strictEqual(
query(".discourse-tags .assigned-to[href='/p/2'] span").title,
'<script>alert("xss")</script>',
"shows indirect assign notes"
@ -126,16 +126,16 @@ acceptance("Discourse Assign | Assigned topic", function (needs) {
);
});
test("Shows group assignment info", async (assert) => {
test("Shows group assignment info", async function (assert) {
updateCurrentUser({ can_assign: true });
await visit("/t/assignment-topic/45");
assert.equal(
assert.strictEqual(
query("#topic-title .assigned-to").innerText.trim(),
"Developers",
"shows assignment in the header"
);
assert.equal(
assert.strictEqual(
query("#post_1 .assigned-to-group").innerText.trim(),
"Developers",
"shows assignment in the first post"
@ -147,7 +147,7 @@ acceptance("Discourse Assign | Assigned topic", function (needs) {
);
});
test("User without assign ability cannot see footer button", async (assert) => {
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");
@ -166,18 +166,17 @@ acceptance("Discourse Assign | Assigned topic", function (needs) {
"section.user-content ul.notifications li.item.notification"
);
assert.equal(
notification.children[0].classList,
"assigned",
assert.ok(
notification.children[0].classList.contains("assigned"),
"with correct assigned class"
);
assert.equal(
assert.strictEqual(
notification.querySelector("a").title,
I18n.t("notifications.titles.assigned"),
"with correct title"
);
assert.equal(
assert.strictEqual(
notification.querySelector("svg use").href["baseVal"],
"#user-plus",
"with correct icon"
@ -185,7 +184,7 @@ acceptance("Discourse Assign | Assigned topic", function (needs) {
});
});
acceptance("Discourse Assign | Re-assign topic", function (needs) {
acceptance("Discourse Assign | Reassign topic", function (needs) {
needs.user();
needs.settings({
assign_enabled: true,
@ -195,7 +194,7 @@ acceptance("Discourse Assign | Re-assign topic", function (needs) {
assignNewUserToTopic(needs);
test("Re-assign Footer dropdown contains reassign buttons", async (assert) => {
test("Reassign Footer dropdown contains reassign buttons", async function (assert) {
updateCurrentUser({ can_assign: true });
const menu = selectKit("#topic-footer-dropdown-reassign");
@ -208,7 +207,7 @@ acceptance("Discourse Assign | Re-assign topic", function (needs) {
});
});
acceptance("Discourse Assign | Re-assign topic | mobile", function (needs) {
acceptance("Discourse Assign | Reassign topic | mobile", function (needs) {
needs.user();
needs.mobileView();
needs.settings({
@ -219,7 +218,7 @@ acceptance("Discourse Assign | Re-assign topic | mobile", function (needs) {
assignNewUserToTopic(needs);
test("Mobile Footer dropdown contains reassign buttons", async (assert) => {
test("Mobile Footer dropdown contains reassign buttons", async function (assert) {
updateCurrentUser({ can_assign: true });
const menu = selectKit(".topic-footer-mobile-dropdown");
@ -232,7 +231,7 @@ acceptance("Discourse Assign | Re-assign topic | mobile", function (needs) {
});
});
acceptance("Discourse Assign | Re-assign topic conditionals", function (needs) {
acceptance("Discourse Assign | Reassign topic conditionals", function (needs) {
needs.user();
needs.settings({
assign_enabled: true,
@ -242,7 +241,7 @@ acceptance("Discourse Assign | Re-assign topic conditionals", function (needs) {
assignCurrentUserToTopic(needs);
test("Reassign Footer dropdown won't display reassign-to-self button when already assigned to current user", async (assert) => {
test("Reassign Footer dropdown won't display reassign-to-self button when already assigned to current user", async function (assert) {
updateCurrentUser({ can_assign: true });
const menu = selectKit("#topic-footer-dropdown-reassign");

View File

@ -490,17 +490,15 @@ acceptance("Discourse Assign | experimental user menu", function (needs) {
await click(".d-header-icons .current-user");
await click("#user-menu-button-assign-list");
const notifications = queryAll(
"#quick-access-assign-list ul li.notification"
);
const notification = query("#quick-access-assign-list ul li.notification");
assert.strictEqual(
notifications[0].textContent.replace(/\s+/g, " ").trim(),
notification.textContent.replace(/\s+/g, " ").trim(),
"tony notificationModelTransformer Test poll topic please bear with me"
);
const assigns = queryAll("#quick-access-assign-list ul li.assign");
const assign = query("#quick-access-assign-list ul li.assign");
assert.strictEqual(
assigns[0].textContent.replace(/\s+/g, " ").trim(),
assign.textContent.replace(/\s+/g, " ").trim(),
"topicModelTransformer Howdy this my test topic with emoji !"
);
});

View File

@ -36,7 +36,7 @@ acceptance(
});
stubCategory(needs, { enable_unassigned_filter: "true" });
test("can see Unassigned button", async (assert) => {
test("can see Unassigned button", async function (assert) {
await visit("/c/test");
const title = I18n.t("filters.unassigned.help");
@ -56,7 +56,7 @@ acceptance(
});
stubCategory(needs, { enable_unassigned_filter: "false" });
test("cannot see Unassigned button", async (assert) => {
test("cannot see Unassigned button", async function (assert) {
await visit("/c/test");
const title = I18n.t("filters.unassigned.help");
@ -76,7 +76,7 @@ acceptance(
});
stubCategory(needs, { enable_unassigned_filter: "true" });
test("can see Unassigned button", async (assert) => {
test("can see Unassigned button", async function (assert) {
await visit("/c/test");
const title = I18n.t("filters.unassigned.help");
@ -96,7 +96,7 @@ acceptance(
});
stubCategory(needs, { enable_unassigned_filter: "true" });
test("cannot see Unassigned button", async (assert) => {
test("cannot see Unassigned button", async function (assert) {
await visit("/c/test");
const title = I18n.t("filters.unassigned.help");

View File

@ -19,13 +19,13 @@ acceptance("Discourse Assign | GroupAssignments", function (needs) {
server.get(getMembersPath, () => helper.response(getMembers));
});
test("Group Assignments Everyone", async (assert) => {
test("Group Assignments Everyone", async function (assert) {
await visit("/g/discourse/assigned");
assert.equal(count(".topic-list-item"), 1);
assert.strictEqual(count(".topic-list-item"), 1);
});
test("Group Assignments Ahmedgagan", async (assert) => {
test("Group Assignments Ahmedgagan", async function (assert) {
await visit("/g/discourse/assigned/ahmedgagan6");
assert.equal(count(".topic-list-item"), 1);
assert.strictEqual(count(".topic-list-item"), 1);
});
});

View File

@ -43,7 +43,7 @@ acceptance(
});
});
test("Show default assign reason when user tracks topics", async (assert) => {
test("Show default assign reason when user tracks topics", async function (assert) {
updateCurrentUser({ never_auto_track_topics: false });
await visit("/t/assignment-topic/44");
@ -54,7 +54,7 @@ acceptance(
);
});
test("Show user assign reason when user never tracks topics", async (assert) => {
test("Show user assign reason when user never tracks topics", async function (assert) {
updateCurrentUser({
never_auto_track_topics: true,
});

View File

@ -19,7 +19,7 @@ acceptance(
server.get(messagesPath, () => helper.response(assigns));
});
test("Quick access assignments panel", async (assert) => {
test("Quick access assignments panel", async function (assert) {
updateCurrentUser({ can_assign: true });
await visit("/");
@ -32,7 +32,7 @@ acceptance(
assert.ok(assignment.href.includes("/t/greetings/10/5"));
await click(".widget-button.assigned");
assert.equal(
assert.strictEqual(
currentURL(),
"/u/eviltrout/activity/assigned",
"a second click should redirect to the full assignments page"

View File

@ -20,7 +20,7 @@ acceptance("Discourse Assign | Search - Full Page", function (needs) {
});
});
test("update in:assigned filter through advanced search ui", async (assert) => {
test("update in:assigned filter through advanced search ui", async function (assert) {
const inSelector = selectKit(".search-advanced-options .select-kit#in");
await visit("/search");
@ -28,14 +28,14 @@ acceptance("Discourse Assign | Search - Full Page", function (needs) {
await fillIn(".search-query", "none");
await inSelector.expand();
await inSelector.selectRowByValue("assigned");
assert.equal(
assert.strictEqual(
query(".search-query").value,
"none in:assigned",
'has updated search term to "none in:assigned"'
);
});
test("update in:unassigned filter through advanced search ui", async (assert) => {
test("update in:unassigned filter through advanced search ui", async function (assert) {
const inSelector = selectKit(".search-advanced-options .select-kit#in");
await visit("/search");
@ -43,14 +43,14 @@ acceptance("Discourse Assign | Search - Full Page", function (needs) {
await fillIn(".search-query", "none");
await inSelector.expand();
await inSelector.selectRowByValue("unassigned");
assert.equal(
assert.strictEqual(
query(".search-query").value,
"none in:unassigned",
'has updated search term to "none in:unassigned"'
);
});
test("update assigned to through advanced search ui", async (assert) => {
test("update assigned to through advanced search ui", async function (assert) {
const assignedField = selectKit(".assigned-advanced-search .select-kit");
await visit("/search");
@ -61,13 +61,13 @@ acceptance("Discourse Assign | Search - Full Page", function (needs) {
await assignedField.fillInFilter("admin");
await assignedField.selectRowByValue("admin");
assert.equal(
assert.strictEqual(
assignedField.header().value(),
"admin",
'has "admin" filled in'
);
assert.equal(
assert.strictEqual(
query(".search-query").value,
"none assigned:admin",
'has updated search term to "none assigned:admin"'

View File

@ -10,7 +10,7 @@ import { cloneJSON } from "discourse-common/lib/object";
import { test } from "qunit";
acceptance(
"Discourse Assign | UnAssign/Re-assign from the topics list",
"Discourse Assign | Unassign/reassign from the topics list",
function (needs) {
needs.user();
needs.settings({ assign_enabled: true, assigns_user_url_path: "/" });
@ -20,14 +20,14 @@ acceptance(
server.get(messagesPath, () => helper.response(assigns));
});
test("Unassign/Re-assign options are visible", async (assert) => {
test("Unassign/reassign options are visible", async function (assert) {
const options = selectKit(".assign-actions-dropdown");
await visit("/u/eviltrout/activity/assigned");
await options.expand();
assert.equal(count("li[data-value='unassign']"), 1);
assert.equal(count("li[data-value='reassign']"), 1);
assert.strictEqual(count("li[data-value='unassign']"), 1);
assert.strictEqual(count("li[data-value='reassign']"), 1);
});
}
);

View File

@ -10,7 +10,7 @@ discourseModule(
setupRenderingTest(hooks);
componentTest("displays username and name", {
template: hbs`{{group-assigned-filter showAvatar=true filter=filter}}`,
template: hbs`<GroupAssignedFilter @showAvatar={{true}} @filter={{filter}} />`,
beforeEach() {
this.set("filter", {
@ -27,8 +27,8 @@ discourseModule(
},
test(assert) {
assert.equal(query(".assign-username").innerText, "Ahmed");
assert.equal(query(".assign-name").innerText, "Ahmed Gagan");
assert.strictEqual(query(".assign-username").innerText, "Ahmed");
assert.strictEqual(query(".assign-name").innerText, "Ahmed Gagan");
},
});
}

View File

@ -1,25 +1,19 @@
import EmberObject from "@ember/object";
import pretender from "discourse/tests/helpers/create-pretender";
import pretender, { response } from "discourse/tests/helpers/create-pretender";
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
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", () => {
return [
200,
{ "Content-Type": "application/json" },
{
suggestions: [],
assign_allowed_on_groups: ["nat"],
assign_allowed_for_groups: [],
},
];
});
pretender.get("/assign/suggestions", () =>
response({
suggestions: [],
assign_allowed_on_groups: ["nat"],
assign_allowed_for_groups: [],
})
);
pretender.put("/assign/assign", () => {
return [200, { "Content-Type": "application/json" }, {}];
});
pretender.put("/assign/assign", () => response({}));
let modalClosed = false;
const controller = this.getController("assign-user", {
@ -39,17 +33,13 @@ discourseModule("Unit | Controller | assign-user", function () {
});
test("assigning a user by selector does not close the modal", async function (assert) {
pretender.get("/assign/suggestions", () => {
return [
200,
{ "Content-Type": "application/json" },
{
suggestions: [],
assign_allowed_on_groups: ["nat"],
assign_allowed_for_groups: [],
},
];
});
pretender.get("/assign/suggestions", () =>
response({
suggestions: [],
assign_allowed_on_groups: ["nat"],
assign_allowed_for_groups: [],
})
);
let modalClosed = false;
const controller = this.getController("assign-user", {

View File

@ -2,7 +2,7 @@ import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import sinon from "sinon";
import * as showModal from "discourse/lib/show-modal";
import pretender from "discourse/tests/helpers/create-pretender";
import pretender, { response } from "discourse/tests/helpers/create-pretender";
discourseModule("Unit | Service | task-actions", function () {
test("assign", function (assert) {
@ -14,10 +14,9 @@ discourseModule("Unit | Service | task-actions", function () {
};
const modal = service.assign(target);
const modalCall = stub.getCall(0).args;
assert.equal(modal, "the modal");
assert.strictEqual(modal, "the modal");
assert.deepEqual(modalCall[0], "assign-user");
assert.deepEqual(modalCall[1], {
title: "discourse_assign.assign_modal.title",
@ -40,7 +39,7 @@ discourseModule("Unit | Service | task-actions", function () {
let assignRequest;
pretender.put("/assign/assign", (request) => {
assignRequest = request;
return [200];
return response({});
});
await service.reassignUserToTopic(user, target);