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";
|
2024-12-02 17:13:34 -05:00
|
|
|
import pretender, {
|
|
|
|
fixturesByUrl,
|
|
|
|
response,
|
|
|
|
} from "discourse/tests/helpers/create-pretender";
|
|
|
|
import { acceptance } 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 13:41:07 -05:00
|
|
|
test("A topic with an accepted answer shows an excerpt of the answer, if provided", async function (assert) {
|
2024-12-02 17:13:34 -05:00
|
|
|
pretender.get("/t/11.json", () =>
|
|
|
|
response(postStreamWithAcceptedAnswerExcerpt("this is an excerpt"))
|
|
|
|
);
|
2017-08-09 14:20:44 -04:00
|
|
|
|
2024-12-02 17:13:34 -05:00
|
|
|
pretender.get("/t/12.json", () =>
|
|
|
|
response(postStreamWithAcceptedAnswerExcerpt(null))
|
2021-01-27 04:38:37 -05:00
|
|
|
);
|
2020-12-23 02:37:06 -05:00
|
|
|
|
2024-12-02 17:13:34 -05:00
|
|
|
await visit("/t/with-excerpt/11");
|
|
|
|
assert.dom(".quote blockquote").hasText("this is an excerpt");
|
2020-12-23 02:37:06 -05:00
|
|
|
|
2024-12-02 17:13:34 -05:00
|
|
|
await visit("/t/without-excerpt/12");
|
|
|
|
assert.dom(".quote blockquote").doesNotExist();
|
|
|
|
assert.dom(".quote .title.title-only").exists();
|
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) {
|
2024-12-02 17:13:34 -05:00
|
|
|
pretender.get("/search", () => {
|
|
|
|
const fixtures = cloneJSON(fixturesByUrl["/search.json"]);
|
|
|
|
fixtures.topics[0].has_accepted_answer = true;
|
|
|
|
return response(fixtures);
|
|
|
|
});
|
2020-12-23 02:37:06 -05:00
|
|
|
|
2024-12-02 17:13:34 -05:00
|
|
|
await visit("/search");
|
2020-12-23 02:37:06 -05:00
|
|
|
await fillIn(".search-query", "discourse");
|
|
|
|
await click(".search-cta");
|
|
|
|
|
2024-12-02 17:13:34 -05:00
|
|
|
assert.dom(".fps-topic").exists({ count: 1 }, "has one post");
|
|
|
|
assert.dom(".topic-status .solved").exists("shows the right icon");
|
2017-08-09 14:20:44 -04:00
|
|
|
});
|
|
|
|
});
|