Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

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

Merged
merged 1 commit into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
57 changes: 38 additions & 19 deletions test/javascripts/acceptance/discourse-solved-test.js.es6
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down Expand Up @@ -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");
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(() => {
assert.ok(exists('.quote blockquote:contains("this is an excerpt")'));
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"));
});
});

visit("/t/without-excerpt/12");
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");

andThen(() => {
assert.notOk(exists(".quote blockquote"));
assert.ok(exists(".quote .title.title-only"));
assert.ok(
queryAll(".topic-status .solved").length === 1,
"shows the right icon"
);
});
});