REFACTOR: All remaining acceptance tests converted to new format

Also contains fixes to leaky state in pretender.
This commit is contained in:
Robin Ward
2020-10-20 13:56:52 -04:00
parent 88c5a37efa
commit 919f488358
87 changed files with 6699 additions and 6806 deletions

View File

@@ -1,119 +1,115 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import { Promise } from "rsvp";
acceptance("Poll breakdown", {
loggedIn: true,
settings: { poll_enabled: true, poll_groupable_user_fields: "something" },
beforeEach() {
clearPopupMenuOptionsCallback();
},
pretend(server, helper) {
server.get("/polls/grouped_poll_results.json", () => {
return new Promise((resolve) => {
resolve(
helper.response({
grouped_results: [
acceptance("Poll breakdown", function (needs) {
needs.user();
needs.settings({
poll_enabled: true,
poll_groupable_user_fields: "something",
});
needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback());
needs.pretender((server, helper) => {
server.get("/polls/grouped_poll_results.json", () =>
helper.response({
grouped_results: [
{
group: "Engineering",
options: [
{
group: "Engineering",
options: [
{
digest: "687a1ccf3c6a260f9aeeb7f68a1d463c",
html: "This Is",
votes: 1,
},
{
digest: "9377906763a1221d31d656ea0c4a4495",
html: "A test for sure",
votes: 1,
},
{
digest: "ecf47c65a85a0bb20029072b1b721977",
html: "Why not give it some more",
votes: 1,
},
],
digest: "687a1ccf3c6a260f9aeeb7f68a1d463c",
html: "This Is",
votes: 1,
},
{
group: "Marketing",
options: [
{
digest: "687a1ccf3c6a260f9aeeb7f68a1d463c",
html: "This Is",
votes: 1,
},
{
digest: "9377906763a1221d31d656ea0c4a4495",
html: "A test for sure",
votes: 1,
},
{
digest: "ecf47c65a85a0bb20029072b1b721977",
html: "Why not give it some more",
votes: 1,
},
],
digest: "9377906763a1221d31d656ea0c4a4495",
html: "A test for sure",
votes: 1,
},
{
digest: "ecf47c65a85a0bb20029072b1b721977",
html: "Why not give it some more",
votes: 1,
},
],
})
);
});
});
},
});
test("Displaying the poll breakdown modal", async (assert) => {
await visit("/t/-/topic_with_pie_chart_poll");
assert.equal(
find(".poll-show-breakdown").text(),
"Show breakdown",
"shows the breakdown button when poll_groupable_user_fields is non-empty"
);
await click(".poll-show-breakdown:first");
assert.equal(
find(".poll-breakdown-total-votes")[0].textContent.trim(),
"2 votes",
"display the correct total vote count"
);
assert.equal(
find(".poll-breakdown-chart-container").length,
2,
"renders a chart for each of the groups in group_results response"
);
assert.ok(
find(".poll-breakdown-chart-container > canvas")[0].$chartjs,
"$chartjs is defined on the pie charts"
);
});
test("Changing the display mode from percentage to count", async (assert) => {
await visit("/t/-/topic_with_pie_chart_poll");
await click(".poll-show-breakdown:first");
assert.equal(
find(".poll-breakdown-option-count:first")[0].textContent.trim(),
"40.0%",
"displays the correct vote percentage"
);
await click(".modal-tabs .count");
assert.equal(
find(".poll-breakdown-option-count:first")[0].textContent.trim(),
"2",
"displays the correct vote count"
);
await click(".modal-tabs .percentage");
assert.equal(
find(".poll-breakdown-option-count:last")[0].textContent.trim(),
"20.0%",
"displays the percentage again"
);
},
{
group: "Marketing",
options: [
{
digest: "687a1ccf3c6a260f9aeeb7f68a1d463c",
html: "This Is",
votes: 1,
},
{
digest: "9377906763a1221d31d656ea0c4a4495",
html: "A test for sure",
votes: 1,
},
{
digest: "ecf47c65a85a0bb20029072b1b721977",
html: "Why not give it some more",
votes: 1,
},
],
},
],
})
);
});
test("Displaying the poll breakdown modal", async (assert) => {
await visit("/t/-/topic_with_pie_chart_poll");
assert.equal(
find(".poll-show-breakdown").text(),
"Show breakdown",
"shows the breakdown button when poll_groupable_user_fields is non-empty"
);
await click(".poll-show-breakdown:first");
assert.equal(
find(".poll-breakdown-total-votes")[0].textContent.trim(),
"2 votes",
"display the correct total vote count"
);
assert.equal(
find(".poll-breakdown-chart-container").length,
2,
"renders a chart for each of the groups in group_results response"
);
assert.ok(
find(".poll-breakdown-chart-container > canvas")[0].$chartjs,
"$chartjs is defined on the pie charts"
);
});
test("Changing the display mode from percentage to count", async (assert) => {
await visit("/t/-/topic_with_pie_chart_poll");
await click(".poll-show-breakdown:first");
assert.equal(
find(".poll-breakdown-option-count:first")[0].textContent.trim(),
"40.0%",
"displays the correct vote percentage"
);
await click(".modal-tabs .count");
assert.equal(
find(".poll-breakdown-option-count:first")[0].textContent.trim(),
"2",
"displays the correct vote count"
);
await click(".modal-tabs .percentage");
assert.equal(
find(".poll-breakdown-option-count:last")[0].textContent.trim(),
"20.0%",
"displays the percentage again"
);
});
});

View File

@@ -1,47 +1,48 @@
import { acceptance, updateCurrentUser } from "discourse/tests/helpers/qunit-helpers";
import {
acceptance,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import { displayPollBuilderButton } from "discourse/plugins/poll/helpers/display-poll-builder-button";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
acceptance("Poll Builder - polls are disabled", {
loggedIn: true,
settings: {
acceptance("Poll Builder - polls are disabled", function (needs) {
needs.user();
needs.settings({
poll_enabled: false,
poll_minimum_trust_level_to_create: 2,
},
beforeEach: function () {
clearPopupMenuOptionsCallback();
},
});
test("regular user - sufficient trust level", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 3 });
await displayPollBuilderButton();
assert.ok(
!exists(".select-kit-row[title='Build Poll']"),
"it hides the builder button"
);
});
test("regular user - insufficient trust level", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
await displayPollBuilderButton();
assert.ok(
!exists(".select-kit-row[title='Build Poll']"),
"it hides the builder button"
);
});
test("staff", async (assert) => {
updateCurrentUser({ moderator: true });
await displayPollBuilderButton();
assert.ok(
!exists(".select-kit-row[title='Build Poll']"),
"it hides the builder button"
);
});
needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback());
test("regular user - sufficient trust level", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 3 });
await displayPollBuilderButton();
assert.ok(
!exists(".select-kit-row[title='Build Poll']"),
"it hides the builder button"
);
});
test("regular user - insufficient trust level", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
await displayPollBuilderButton();
assert.ok(
!exists(".select-kit-row[title='Build Poll']"),
"it hides the builder button"
);
});
test("staff", async (assert) => {
updateCurrentUser({ moderator: true });
await displayPollBuilderButton();
assert.ok(
!exists(".select-kit-row[title='Build Poll']"),
"it hides the builder button"
);
});
});

View File

@@ -1,60 +1,67 @@
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance, updateCurrentUser } from "discourse/tests/helpers/qunit-helpers";
import {
acceptance,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import { displayPollBuilderButton } from "discourse/plugins/poll/helpers/display-poll-builder-button";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
acceptance("Poll Builder - polls are enabled", {
loggedIn: true,
settings: {
acceptance("Poll Builder - polls are enabled", function (needs) {
needs.user();
needs.settings({
poll_enabled: true,
poll_minimum_trust_level_to_create: 1,
},
beforeEach() {
clearPopupMenuOptionsCallback();
},
});
test("regular user - sufficient trust level", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
await displayPollBuilderButton();
assert.ok(
exists(".select-kit-row[title='Build Poll']"),
"it shows the builder button"
);
});
test("regular user - insufficient trust level", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 0 });
await displayPollBuilderButton();
assert.ok(
!exists(".select-kit-row[title='Build Poll']"),
"it hides the builder button"
);
});
test("staff - with insufficient trust level", async (assert) => {
updateCurrentUser({ moderator: true, trust_level: 0 });
await displayPollBuilderButton();
assert.ok(
exists(".select-kit-row[title='Build Poll']"),
"it shows the builder button"
);
});
test("poll preview", async (assert) => {
await displayPollBuilderButton();
const popupMenu = selectKit(".toolbar-popup-menu-options");
await popupMenu.selectRowByValue("showPollBuilder");
await fillIn(".poll-textarea textarea", "First option\nSecond option");
assert.equal(find(".d-editor-preview li:first-child").text(), "First option");
assert.equal(find(".d-editor-preview li:last-child").text(), "Second option");
});
needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback());
test("regular user - sufficient trust level", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
await displayPollBuilderButton();
assert.ok(
exists(".select-kit-row[title='Build Poll']"),
"it shows the builder button"
);
});
test("regular user - insufficient trust level", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 0 });
await displayPollBuilderButton();
assert.ok(
!exists(".select-kit-row[title='Build Poll']"),
"it hides the builder button"
);
});
test("staff - with insufficient trust level", async (assert) => {
updateCurrentUser({ moderator: true, trust_level: 0 });
await displayPollBuilderButton();
assert.ok(
exists(".select-kit-row[title='Build Poll']"),
"it shows the builder button"
);
});
test("poll preview", async (assert) => {
await displayPollBuilderButton();
const popupMenu = selectKit(".toolbar-popup-menu-options");
await popupMenu.selectRowByValue("showPollBuilder");
await fillIn(".poll-textarea textarea", "First option\nSecond option");
assert.equal(
find(".d-editor-preview li:first-child").text(),
"First option"
);
assert.equal(
find(".d-editor-preview li:last-child").text(),
"Second option"
);
});
});

View File

@@ -1,36 +1,39 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Rendering polls with pie charts", {
loggedIn: true,
settings: { poll_enabled: true, poll_groupable_user_fields: "something" },
});
test("Displays the pie chart", async (assert) => {
await visit("/t/-/topic_with_pie_chart_poll");
const poll = find(".poll")[0];
assert.equal(
find(".info-number", poll)[0].innerHTML,
"2",
"it should display the right number of voters"
);
assert.equal(
find(".info-number", poll)[1].innerHTML,
"5",
"it should display the right number of votes"
);
assert.equal(
poll.classList.contains("pie"),
true,
"pie class is present on poll div"
);
assert.equal(
find(".poll-results-chart", poll).length,
1,
"Renders the chart div instead of bar container"
);
acceptance("Rendering polls with pie charts", function (needs) {
needs.user();
needs.settings({
poll_enabled: true,
poll_groupable_user_fields: "something",
});
test("Displays the pie chart", async (assert) => {
await visit("/t/-/topic_with_pie_chart_poll");
const poll = find(".poll")[0];
assert.equal(
find(".info-number", poll)[0].innerHTML,
"2",
"it should display the right number of voters"
);
assert.equal(
find(".info-number", poll)[1].innerHTML,
"5",
"it should display the right number of votes"
);
assert.equal(
poll.classList.contains("pie"),
true,
"pie class is present on poll div"
);
assert.equal(
find(".poll-results-chart", poll).length,
1,
"Renders the chart div instead of bar container"
);
});
});

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,13 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
acceptance("Rendering polls with bar charts - desktop", {
loggedIn: true,
settings: { poll_enabled: true },
beforeEach() {
acceptance("Rendering polls with bar charts - desktop", function (needs) {
needs.user();
needs.settings({ poll_enabled: true });
needs.hooks.beforeEach(() => {
clearPopupMenuOptionsCallback();
},
pretend(server) {
});
needs.pretender((server, helper) => {
server.get("/polls/voters.json", (request) => {
let body = {};
if (
@@ -35,78 +35,78 @@ acceptance("Rendering polls with bar charts - desktop", {
})),
};
}
return [200, { "Content-Type": "application/json" }, body];
return helper.response(body);
});
},
});
test("Polls", async (assert) => {
await visit("/t/-/15");
const polls = find(".poll");
assert.equal(polls.length, 2, "it should render the polls correctly");
assert.equal(
find(".info-number", polls[0]).text(),
"2",
"it should display the right number of votes"
);
assert.equal(
find(".info-number", polls[1]).text(),
"3",
"it should display the right number of votes"
);
});
test("Public poll", async (assert) => {
await visit("/t/-/14");
const polls = find(".poll");
assert.equal(polls.length, 1, "it should render the poll correctly");
await click("button.toggle-results");
assert.equal(
find(".poll-voters:first li").length,
25,
"it should display the right number of voters"
);
await click(".poll-voters-toggle-expand:first a");
assert.equal(
find(".poll-voters:first li").length,
26,
"it should display the right number of voters"
);
});
test("Public number poll", async (assert) => {
await visit("/t/-/13");
const polls = find(".poll");
assert.equal(polls.length, 1, "it should render the poll correctly");
await click("button.toggle-results");
assert.equal(
find(".poll-voters:first li").length,
25,
"it should display the right number of voters"
);
assert.notOk(
find(".poll-voters:first li:first a").attr("href"),
"user URL does not exist"
);
await click(".poll-voters-toggle-expand:first a");
assert.equal(
find(".poll-voters:first li").length,
30,
"it should display the right number of voters"
);
});
test("Polls", async (assert) => {
await visit("/t/-/15");
const polls = find(".poll");
assert.equal(polls.length, 2, "it should render the polls correctly");
assert.equal(
find(".info-number", polls[0]).text(),
"2",
"it should display the right number of votes"
);
assert.equal(
find(".info-number", polls[1]).text(),
"3",
"it should display the right number of votes"
);
});
test("Public poll", async (assert) => {
await visit("/t/-/14");
const polls = find(".poll");
assert.equal(polls.length, 1, "it should render the poll correctly");
await click("button.toggle-results");
assert.equal(
find(".poll-voters:first li").length,
25,
"it should display the right number of voters"
);
await click(".poll-voters-toggle-expand:first a");
assert.equal(
find(".poll-voters:first li").length,
26,
"it should display the right number of voters"
);
});
test("Public number poll", async (assert) => {
await visit("/t/-/13");
const polls = find(".poll");
assert.equal(polls.length, 1, "it should render the poll correctly");
await click("button.toggle-results");
assert.equal(
find(".poll-voters:first li").length,
25,
"it should display the right number of voters"
);
assert.notOk(
find(".poll-voters:first li:first a").attr("href"),
"user URL does not exist"
);
await click(".poll-voters-toggle-expand:first a");
assert.equal(
find(".poll-voters:first li").length,
30,
"it should display the right number of voters"
);
});
});

View File

@@ -1,54 +1,51 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
acceptance("Rendering polls with bar charts - mobile", {
loggedIn: true,
mobileView: true,
settings: { poll_enabled: true },
beforeEach() {
clearPopupMenuOptionsCallback();
},
pretend(server) {
// eslint-disable-next-line
acceptance("Rendering polls with bar charts - mobile", function (needs) {
needs.user();
needs.mobileView();
needs.settings({ poll_enabled: true });
needs.pretender((server, helper) => {
server.get("/polls/voters.json", () => {
const body = {
return helper.response({
voters: Array.from(new Array(10), (_, i) => ({
id: 500 + i,
username: `bruce${500 + i}`,
avatar_template: "/images/avatar.png",
name: "Bruce Wayne",
})),
};
return [200, { "Content-Type": "application/json" }, body];
});
});
},
});
test("Public number poll", async (assert) => {
await visit("/t/-/13");
const polls = find(".poll");
assert.equal(polls.length, 1, "it should render the poll correctly");
await click("button.toggle-results");
assert.equal(
find(".poll-voters:first li").length,
25,
"it should display the right number of voters"
);
assert.notOk(
find(".poll-voters:first li:first a").attr("href"),
"user URL does not exist"
);
await click(".poll-voters-toggle-expand:first a");
assert.equal(
find(".poll-voters:first li").length,
35,
"it should display the right number of voters"
);
});
needs.hooks.beforeEach(() => {
clearPopupMenuOptionsCallback();
});
test("Public number poll", async (assert) => {
await visit("/t/-/13");
const polls = find(".poll");
assert.equal(polls.length, 1, "it should render the poll correctly");
await click("button.toggle-results");
assert.equal(
find(".poll-voters:first li").length,
25,
"it should display the right number of voters"
);
assert.notOk(
find(".poll-voters:first li:first a").attr("href"),
"user URL does not exist"
);
await click(".poll-voters-toggle-expand:first a");
assert.equal(
find(".poll-voters:first li").length,
35,
"it should display the right number of voters"
);
});
});