From 160faf9f6cd78afd7109e5afb005299999f26fb8 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Wed, 23 Dec 2020 15:37:06 +0800 Subject: [PATCH] DEV: Add acceptance tests for solved icon in full page search. (#105) --- .../extend-for-solved-button.js.es6 | 1 + .../acceptance/discourse-solved-test.js.es6 | 59 ++++++++++++------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 b/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 index 59c7ca6..5c714fd 100644 --- a/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 +++ b/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 @@ -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 && diff --git a/test/javascripts/acceptance/discourse-solved-test.js.es6 b/test/javascripts/acceptance/discourse-solved-test.js.es6 index 8c60ecf..fd37347 100644 --- a/test/javascripts/acceptance/discourse-solved-test.js.es6 +++ b/test/javascripts/acceptance/discourse-solved-test.js.es6 @@ -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,31 +218,49 @@ 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) => { - visit("/t/with-excerpt/11"); - - andThen(() => { - assert.ok(exists('.quote blockquote:contains("this is an excerpt")')); + server.get("/search", () => { + const fixtures = fixturesByUrl["/search.json"]; + fixtures.topics.firstObject.has_accepted_answer = true; + return response(fixtures); + }); }); - 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(() => { - assert.notOk(exists(".quote blockquote")); - assert.ok(exists(".quote .title.title-only")); + andThen(() => { + assert.ok(exists('.quote blockquote:contains("this is an excerpt")')); + }); + + 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" + ); }); });