2022-03-06 15:33:24 -05:00
|
|
|
import { click, fillIn, visit } from "@ember/test-helpers";
|
2024-01-16 11:50:43 -05:00
|
|
|
import { test } from "qunit";
|
|
|
|
import { fixturesByUrl } from "discourse/tests/helpers/create-pretender";
|
|
|
|
import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers";
|
2022-03-10 11:34:11 -05:00
|
|
|
import { cloneJSON } from "discourse-common/lib/object";
|
2024-11-12 18:45:17 -05:00
|
|
|
import { postStreamWithAcceptedAnswerExcerpt } from "../helpers/discourse-solved-helpers";
|
2017-08-09 14:20:44 -04:00
|
|
|
|
2020-12-23 02:37:06 -05:00
|
|
|
acceptance("Discourse Solved Plugin", function (needs) {
|
|
|
|
needs.user();
|
2017-08-09 14:20:44 -04:00
|
|
|
|
2020-12-23 02:37:06 -05:00
|
|
|
needs.pretender((server, helper) => {
|
2018-10-22 15:13:46 -04:00
|
|
|
server.get("/t/11.json", () => {
|
2020-12-23 13:41:07 -05:00
|
|
|
return helper.response(
|
2018-10-22 15:13:46 -04:00
|
|
|
postStreamWithAcceptedAnswerExcerpt("this is an excerpt")
|
|
|
|
);
|
2017-08-09 14:20:44 -04:00
|
|
|
});
|
|
|
|
|
2018-10-22 15:13:46 -04:00
|
|
|
server.get("/t/12.json", () => {
|
2020-12-23 13:41:07 -05:00
|
|
|
return helper.response(postStreamWithAcceptedAnswerExcerpt(null));
|
2017-08-09 14:20:44 -04:00
|
|
|
});
|
|
|
|
|
2020-12-23 02:37:06 -05:00
|
|
|
server.get("/search", () => {
|
2022-03-10 11:34:11 -05:00
|
|
|
const fixtures = cloneJSON(fixturesByUrl["/search.json"]);
|
2020-12-23 13:41:07 -05:00
|
|
|
fixtures.topics[0].has_accepted_answer = true;
|
|
|
|
return helper.response(fixtures);
|
2020-12-23 02:37:06 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-12-23 13:41:07 -05:00
|
|
|
test("A topic with an accepted answer shows an excerpt of the answer, if provided", async function (assert) {
|
|
|
|
await visit("/t/with-excerpt/11");
|
2017-08-09 14:20:44 -04:00
|
|
|
|
2024-11-28 11:14:00 -05:00
|
|
|
assert.strictEqual(
|
|
|
|
queryAll('.quote blockquote:contains("this is an excerpt")').length,
|
|
|
|
1
|
2021-01-27 04:38:37 -05:00
|
|
|
);
|
2020-12-23 02:37:06 -05:00
|
|
|
|
2020-12-23 13:41:07 -05:00
|
|
|
await visit("/t/without-excerpt/12");
|
2020-12-23 02:37:06 -05:00
|
|
|
|
2024-11-28 11:14:00 -05:00
|
|
|
assert.notStrictEqual(queryAll(".quote blockquote").length, 1);
|
|
|
|
assert.strictEqual(queryAll(".quote .title.title-only").length, 1);
|
2017-08-09 14:20:44 -04:00
|
|
|
});
|
|
|
|
|
2020-12-23 02:37:06 -05:00
|
|
|
test("Full page search displays solved status", async function (assert) {
|
|
|
|
await visit("/search");
|
|
|
|
|
|
|
|
await fillIn(".search-query", "discourse");
|
|
|
|
await click(".search-cta");
|
|
|
|
|
2024-11-28 11:14:00 -05:00
|
|
|
assert.strictEqual(queryAll(".fps-topic").length, 1, "has one post");
|
2017-08-09 14:20:44 -04:00
|
|
|
|
2021-01-27 04:38:37 -05:00
|
|
|
assert.ok(queryAll(".topic-status .solved").length, "shows the right icon");
|
2017-08-09 14:20:44 -04:00
|
|
|
});
|
|
|
|
});
|