DEV: Add acceptance tests for solved icon in full page search. (#105)

This commit is contained in:
Alan Guo Xiang Tan 2020-12-23 15:37:06 +08:00 committed by GitHub
parent 37b432732a
commit 160faf9f6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 20 deletions

View File

@ -246,6 +246,7 @@ export default {
closeTag: "span",
title: I18n.t("topic_statuses.solved.help"),
icon: "far-check-square",
key: "solved",
});
} else if (
this.topic.can_have_answer &&

View File

@ -1,12 +1,13 @@
import { acceptance } from "helpers/qunit-helpers";
import { acceptance, queryAll } from "helpers/qunit-helpers";
import {
fixturesByUrl,
response,
} from "discourse/tests/helpers/create-pretender";
acceptance("Discourse Solved Plugin", {
loggedIn: true,
beforeEach() {
const response = (object) => {
return [200, { "Content-Type": "application/json" }, object];
};
acceptance("Discourse Solved Plugin", function (needs) {
needs.user();
needs.pretender((server, helper) => {
const postStreamWithAcceptedAnswerExcerpt = (excerpt) => {
return {
post_stream: {
@ -217,21 +218,24 @@ acceptance("Discourse Solved Plugin", {
};
};
// eslint-disable-next-line no-undef
server.get("/t/11.json", () => {
return response(
postStreamWithAcceptedAnswerExcerpt("this is an excerpt")
);
});
// eslint-disable-next-line no-undef
server.get("/t/12.json", () => {
return response(postStreamWithAcceptedAnswerExcerpt(null));
});
},
});
test("A topic with an accepted answer shows an excerpt of the answer, if provided", (assert) => {
server.get("/search", () => {
const fixtures = fixturesByUrl["/search.json"];
fixtures.topics.firstObject.has_accepted_answer = true;
return response(fixtures);
});
});
test("A topic with an accepted answer shows an excerpt of the answer, if provided", (assert) => {
visit("/t/with-excerpt/11");
andThen(() => {
@ -244,4 +248,19 @@ test("A topic with an accepted answer shows an excerpt of the answer, if provide
assert.notOk(exists(".quote blockquote"));
assert.ok(exists(".quote .title.title-only"));
});
});
test("Full page search displays solved status", async function (assert) {
await visit("/search");
await fillIn(".search-query", "discourse");
await click(".search-cta");
assert.ok(queryAll(".fps-topic").length === 1, "has one post");
assert.ok(
queryAll(".topic-status .solved").length === 1,
"shows the right icon"
);
});
});