DEV: Fix default pretenders (#22326)

Prevent state leakage and update `/tags` to match the server
This commit is contained in:
Jarek Radosz 2023-06-28 13:59:17 +02:00 committed by GitHub
parent 6fc62586a2
commit b74d0633d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 91 additions and 58 deletions

View File

@ -1,8 +1,4 @@
import {
acceptance,
exists,
query,
} from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { cloneJSON } from "discourse-common/lib/object";
@ -22,33 +18,28 @@ acceptance("User - Preferences - Profile - Featured topic", function (needs) {
test("setting featured topic on profile", async function (assert) {
await visit("/u/eviltrout/preferences/profile");
assert.ok(
!exists(".featured-topic-link"),
"no featured topic link to present"
);
assert.ok(
!exists(".clear-feature-topic-on-profile-btn"),
"clear button not present"
);
assert
.dom(".featured-topic-link")
.doesNotExist("no featured topic link to present");
assert
.dom(".clear-feature-topic-on-profile-btn")
.doesNotExist("clear button not present");
await click(".feature-topic-on-profile-btn");
assert.ok(
exists(".feature-topic-on-profile"),
"topic picker modal is open"
);
assert
.dom(".feature-topic-on-profile")
.exists("topic picker modal is open");
await click(query('input[name="choose_topic_id"]'));
await click('input[name="choose_topic_id"]');
await click(".save-featured-topic-on-profile");
assert.ok(
exists(".featured-topic-link"),
"link to featured topic is present"
);
assert.ok(
exists(".clear-feature-topic-on-profile-btn"),
"clear button is present"
);
assert
.dom(".featured-topic-link")
.exists("link to featured topic is present");
assert
.dom(".clear-feature-topic-on-profile-btn")
.exists("clear button is present");
});
test("focused item after closing feature topic modal", async function (assert) {
@ -56,11 +47,9 @@ acceptance("User - Preferences - Profile - Featured topic", function (needs) {
await click(".feature-topic-on-profile-btn");
await click(".modal-close");
assert.equal(
document.activeElement,
query(".feature-topic-on-profile-btn"),
"it keeps focus on the feature topic button"
);
assert
.dom(".feature-topic-on-profile-btn")
.isFocused("it keeps focus on the feature topic button");
});
});
@ -72,18 +61,18 @@ acceptance(
needs.pretender((server, helper) => {
server.get("/u/eviltrout.json", () => {
const cloned = cloneJSON(userFixtures["/u/eviltrout.json"]);
cloned.user.can_edit = true;
cloned.user.user_option.default_calendar = "none_selected";
return helper.response(200, cloned);
return helper.response(cloned);
});
});
test("default calendar option is not visible", async function (assert) {
await visit("/u/eviltrout/preferences/profile");
assert.ok(
!exists("#user-default-calendar"),
"option to change default calendar is hidden"
);
assert
.dom("#user-default-calendar")
.doesNotExist("option to change default calendar is hidden");
});
}
);
@ -96,18 +85,18 @@ acceptance(
needs.pretender((server, helper) => {
server.get("/u/eviltrout.json", () => {
const cloned = cloneJSON(userFixtures["/u/eviltrout.json"]);
cloned.user.can_edit = true;
cloned.user.user_option.default_calendar = "google";
return helper.response(200, cloned);
return helper.response(cloned);
});
});
test("default calendar can be changed", async function (assert) {
await visit("/u/eviltrout/preferences/profile");
assert.ok(
exists("#user-default-calendar"),
"option to change default calendar"
);
assert
.dom("#user-default-calendar")
.exists("option to change default calendar");
});
}
);

View File

@ -13,12 +13,6 @@ let deleteAndBlock = null;
acceptance("User Profile - Summary", function (needs) {
needs.user();
needs.pretender((server, helper) => {
server.get("/u/eviltrout.json", () => {
const response = cloneJSON(userFixtures["/u/eviltrout.json"]);
return helper.response(response);
});
});
test("Viewing Summary", async function (assert) {
await visit("/u/eviltrout/summary");

View File

@ -1,6 +1,7 @@
import Pretender from "pretender";
import User from "discourse/models/user";
import getURL from "discourse-common/lib/get-url";
import { cloneJSON } from "discourse-common/lib/object";
export function parsePostData(query) {
const result = {};
@ -81,17 +82,18 @@ export function applyDefaultHandlers(pretender) {
);
pretender.get("/latest.json", () => {
const json = fixturesByUrl["/latest.json"];
const json = cloneJSON(fixturesByUrl["/latest.json"]);
if (loggedIn()) {
// Stuff to let us post
json.topic_list.can_create_topic = true;
}
return response(json);
});
pretender.get("/c/bug/1/l/latest.json", () => {
const json = fixturesByUrl["/c/bug/1/l/latest.json"];
const json = cloneJSON(fixturesByUrl["/c/bug/1/l/latest.json"]);
if (loggedIn()) {
// Stuff to let us post
@ -104,8 +106,20 @@ export function applyDefaultHandlers(pretender) {
return response({
tags: [
{ id: "eviltrout", count: 1 },
{ id: "planned", text: "planned", count: 7, pm_only: false },
{ id: "private", text: "private", count: 0, pm_only: true },
{
id: "planned",
name: "planned",
text: "planned",
count: 7,
pm_only: false,
},
{
id: "private",
name: "private",
text: "private",
count: 0,
pm_only: true,
},
],
extras: {
tag_groups: [
@ -113,24 +127,60 @@ export function applyDefaultHandlers(pretender) {
id: 2,
name: "Ford Cars",
tags: [
{ id: "Escort", text: "Escort", count: 1, pm_only: false },
{ id: "focus", text: "focus", count: 3, pm_only: false },
{
id: "Escort",
name: "Escort",
text: "Escort",
count: 1,
pm_only: false,
},
{
id: "focus",
name: "focus",
text: "focus",
count: 3,
pm_only: false,
},
],
},
{
id: 1,
name: "Honda Cars",
tags: [
{ id: "civic", text: "civic", count: 4, pm_only: false },
{ id: "accord", text: "accord", count: 2, pm_only: false },
{
id: "civic",
name: "civic",
text: "civic",
count: 4,
pm_only: false,
},
{
id: "accord",
name: "accord",
text: "accord",
count: 2,
pm_only: false,
},
],
},
{
id: 1,
name: "Makes",
tags: [
{ id: "ford", text: "ford", count: 5, pm_only: false },
{ id: "honda", text: "honda", count: 6, pm_only: false },
{
id: "ford",
name: "ford",
text: "ford",
count: 5,
pm_only: false,
},
{
id: "honda",
name: "honda",
text: "honda",
count: 6,
pm_only: false,
},
],
},
],
@ -188,7 +238,7 @@ export function applyDefaultHandlers(pretender) {
);
pretender.get("/u/eviltrout.json", () => {
const json = fixturesByUrl["/u/eviltrout.json"];
const json = cloneJSON(fixturesByUrl["/u/eviltrout.json"]);
json.user.can_edit = loggedIn();
return response(json);
});