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", closeTag: "span",
title: I18n.t("topic_statuses.solved.help"), title: I18n.t("topic_statuses.solved.help"),
icon: "far-check-square", icon: "far-check-square",
key: "solved",
}); });
} else if ( } else if (
this.topic.can_have_answer && 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", { acceptance("Discourse Solved Plugin", function (needs) {
loggedIn: true, needs.user();
beforeEach() {
const response = (object) => {
return [200, { "Content-Type": "application/json" }, object];
};
needs.pretender((server, helper) => {
const postStreamWithAcceptedAnswerExcerpt = (excerpt) => { const postStreamWithAcceptedAnswerExcerpt = (excerpt) => {
return { return {
post_stream: { post_stream: {
@ -217,31 +218,49 @@ acceptance("Discourse Solved Plugin", {
}; };
}; };
// eslint-disable-next-line no-undef
server.get("/t/11.json", () => { server.get("/t/11.json", () => {
return response( return response(
postStreamWithAcceptedAnswerExcerpt("this is an excerpt") postStreamWithAcceptedAnswerExcerpt("this is an excerpt")
); );
}); });
// eslint-disable-next-line no-undef
server.get("/t/12.json", () => { server.get("/t/12.json", () => {
return response(postStreamWithAcceptedAnswerExcerpt(null)); return response(postStreamWithAcceptedAnswerExcerpt(null));
}); });
},
});
test("A topic with an accepted answer shows an excerpt of the answer, if provided", (assert) => { server.get("/search", () => {
visit("/t/with-excerpt/11"); const fixtures = fixturesByUrl["/search.json"];
fixtures.topics.firstObject.has_accepted_answer = true;
andThen(() => { return response(fixtures);
assert.ok(exists('.quote blockquote:contains("this is an excerpt")')); });
}); });
visit("/t/without-excerpt/12"); test("A topic with an accepted answer shows an excerpt of the answer, if provided", (assert) => {
visit("/t/with-excerpt/11");
andThen(() => { andThen(() => {
assert.notOk(exists(".quote blockquote")); assert.ok(exists('.quote blockquote:contains("this is an excerpt")'));
assert.ok(exists(".quote .title.title-only")); });
visit("/t/without-excerpt/12");
andThen(() => {
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"
);
}); });
}); });