discourse-solved/test/javascripts/acceptance/discourse-solved-test.js

54 lines
1.7 KiB
JavaScript
Raw Normal View History

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";
import { postStreamWithAcceptedAnswerExcerpt } from "../helpers/discourse-solved-helpers";
acceptance("Discourse Solved Plugin", function (needs) {
needs.user();
needs.pretender((server, helper) => {
2018-10-22 15:13:46 -04:00
server.get("/t/11.json", () => {
return helper.response(
2018-10-22 15:13:46 -04:00
postStreamWithAcceptedAnswerExcerpt("this is an excerpt")
);
});
2018-10-22 15:13:46 -04:00
server.get("/t/12.json", () => {
return helper.response(postStreamWithAcceptedAnswerExcerpt(null));
});
server.get("/search", () => {
2022-03-10 11:34:11 -05:00
const fixtures = cloneJSON(fixturesByUrl["/search.json"]);
fixtures.topics[0].has_accepted_answer = true;
return helper.response(fixtures);
});
});
test("A topic with an accepted answer shows an excerpt of the answer, if provided", async function (assert) {
await visit("/t/with-excerpt/11");
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
);
await visit("/t/without-excerpt/12");
2024-11-28 11:14:00 -05:00
assert.notStrictEqual(queryAll(".quote blockquote").length, 1);
assert.strictEqual(queryAll(".quote .title.title-only").length, 1);
});
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");
2021-01-27 04:38:37 -05:00
assert.ok(queryAll(".topic-status .solved").length, "shows the right icon");
});
});