mirror of
https://github.com/discourse/discourse.git
synced 2026-07-29 23:58:12 -05:00
FIX: Tests in admin/tests were not running (#12391)
Since we want to run them in the core app they've been moved into the `tests` directory for discourse, and updated to the latest format.
This commit is contained in:
-108
@@ -1,108 +0,0 @@
|
||||
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import { click, fillIn, visit } from "@ember/test-helpers";
|
||||
import { test } from "qunit";
|
||||
import I18n from "I18n";
|
||||
|
||||
acceptance("Admin - Themes - Install modal", function (needs) {
|
||||
needs.user();
|
||||
test("closing the modal resets the modal inputs", async function (assert) {
|
||||
const urlInput = ".install-theme-content .repo input";
|
||||
const branchInput = ".install-theme-content .branch input";
|
||||
const privateRepoCheckbox = ".install-theme-content .check-private input";
|
||||
const publicKey = ".install-theme-content .public-key textarea";
|
||||
|
||||
const themeUrl = "git@github.com:discourse/discourse.git";
|
||||
await visit("/admin/customize/themes");
|
||||
|
||||
await click(".create-actions .btn-primary");
|
||||
await click("#remote");
|
||||
await fillIn(urlInput, themeUrl);
|
||||
await click(".install-theme-content .inputs .advanced-repo");
|
||||
await fillIn(branchInput, "tests-passed");
|
||||
await click(privateRepoCheckbox);
|
||||
assert.equal(query(urlInput).value, themeUrl, "url input is filled");
|
||||
assert.equal(
|
||||
query(branchInput).value,
|
||||
"tests-passed",
|
||||
"branch input is filled"
|
||||
);
|
||||
assert.ok(
|
||||
query(privateRepoCheckbox).checked,
|
||||
"private repo checkbox is checked"
|
||||
);
|
||||
assert.ok(query(publicKey), "shows public key");
|
||||
|
||||
await click(".modal-footer .d-modal-cancel");
|
||||
|
||||
await click(".create-actions .btn-primary");
|
||||
await click("#remote");
|
||||
assert.equal(query(urlInput).value, "", "url input is reset");
|
||||
assert.equal(query(branchInput).value, "", "branch input is reset");
|
||||
assert.ok(
|
||||
!query(privateRepoCheckbox).checked,
|
||||
"private repo checkbox unchecked"
|
||||
);
|
||||
assert.notOk(query(publicKey), "hide public key");
|
||||
});
|
||||
|
||||
test("show public key for valid ssh theme urls", async function (assert) {
|
||||
const urlInput = ".install-theme-content .repo input";
|
||||
const privateRepoCheckbox = ".install-theme-content .check-private input";
|
||||
const publicKey = ".install-theme-content .public-key textarea";
|
||||
|
||||
// Supports backlog repo ssh url format
|
||||
const themeUrl =
|
||||
"discourse@discourse.git.backlog.com:/TEST_THEME/test-theme.git";
|
||||
await visit("/admin/customize/themes");
|
||||
|
||||
await click(".create-actions .btn-primary");
|
||||
await click("#remote");
|
||||
await fillIn(urlInput, themeUrl);
|
||||
await click(".install-theme-content .inputs .advanced-repo");
|
||||
await click(privateRepoCheckbox);
|
||||
assert.equal(query(urlInput).value, themeUrl, "url input is filled");
|
||||
assert.ok(
|
||||
query(privateRepoCheckbox).checked,
|
||||
"private repo checkbox is checked"
|
||||
);
|
||||
assert.ok(query(publicKey), "shows public key");
|
||||
|
||||
await fillIn(urlInput, "https://github.com/discourse/discourse.git");
|
||||
assert.notOk(query(publicKey), "does not shows public key for https urls");
|
||||
});
|
||||
|
||||
test("modal can be auto-opened with the right query params", async function (assert) {
|
||||
await visit("/admin/customize/themes?repoUrl=testUrl&repoName=testName");
|
||||
assert.ok(query(".admin-install-theme-modal"), "modal is visible");
|
||||
assert.equal(
|
||||
query(".install-theme code").textContent.trim(),
|
||||
"testUrl",
|
||||
"repo url is visible"
|
||||
);
|
||||
});
|
||||
|
||||
test("installed themes are matched with the popular list by URL", async function (assert) {
|
||||
await visit("/admin/customize/themes");
|
||||
await click(".create-actions .btn-primary");
|
||||
|
||||
assert.notOk(
|
||||
query(
|
||||
'.popular-theme-item[data-name="Graceful"] .popular-theme-buttons button'
|
||||
),
|
||||
"no install button is shown for installed themes"
|
||||
);
|
||||
assert.equal(
|
||||
query(
|
||||
'.popular-theme-item[data-name="Graceful"] .popular-theme-buttons'
|
||||
).textContent.trim(),
|
||||
I18n.t("admin.customize.theme.installed")
|
||||
);
|
||||
|
||||
assert.ok(
|
||||
query(
|
||||
'.popular-theme-item[data-name="Minima"] .popular-theme-buttons button'
|
||||
),
|
||||
"install button is shown for not installed themes"
|
||||
);
|
||||
});
|
||||
});
|
||||
-60
@@ -1,60 +0,0 @@
|
||||
import EmberObject from "@ember/object";
|
||||
import componentTest from "discourse/tests/helpers/component-test";
|
||||
import { moduleForComponent } from "ember-qunit";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
|
||||
moduleForComponent("group-list", { integration: true });
|
||||
|
||||
componentTest("default", {
|
||||
template: "{{site-setting setting=setting}}",
|
||||
|
||||
beforeEach() {
|
||||
this.site.groups = [
|
||||
{
|
||||
id: 1,
|
||||
name: "Donuts",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "Cheese cake",
|
||||
},
|
||||
];
|
||||
|
||||
this.set(
|
||||
"setting",
|
||||
EmberObject.create({
|
||||
allowsNone: undefined,
|
||||
category: "foo",
|
||||
default: "",
|
||||
description: "Choose groups",
|
||||
overridden: false,
|
||||
placeholder: null,
|
||||
preview: null,
|
||||
secret: false,
|
||||
setting: "foo_bar",
|
||||
type: "group_list",
|
||||
validValues: undefined,
|
||||
value: "1",
|
||||
})
|
||||
);
|
||||
},
|
||||
|
||||
async test(assert) {
|
||||
const subject = selectKit(".list-setting");
|
||||
|
||||
assert.equal(
|
||||
subject.header().value(),
|
||||
"1",
|
||||
"it selects the setting's value"
|
||||
);
|
||||
|
||||
await subject.expand();
|
||||
await subject.selectRowByValue("2");
|
||||
|
||||
assert.equal(
|
||||
subject.header().value(),
|
||||
"1,2",
|
||||
"it allows to select a setting from the list of choices"
|
||||
);
|
||||
},
|
||||
});
|
||||
-105
@@ -1,105 +0,0 @@
|
||||
import I18n from "I18n";
|
||||
import Theme from "admin/models/theme";
|
||||
import componentTest from "discourse/tests/helpers/component-test";
|
||||
import { moduleForComponent } from "ember-qunit";
|
||||
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
|
||||
|
||||
moduleForComponent("themes-list-item", { integration: true });
|
||||
|
||||
componentTest("default theme", {
|
||||
template: "{{themes-list-item theme=theme}}",
|
||||
beforeEach() {
|
||||
this.set("theme", Theme.create({ name: "Test", default: true }));
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.expect(1);
|
||||
assert.equal(
|
||||
queryAll(".d-icon-check").length,
|
||||
1,
|
||||
"shows default theme icon"
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
componentTest("pending updates", {
|
||||
template: "{{themes-list-item theme=theme}}",
|
||||
beforeEach() {
|
||||
this.set(
|
||||
"theme",
|
||||
Theme.create({ name: "Test", remote_theme: { commits_behind: 6 } })
|
||||
);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.expect(1);
|
||||
assert.equal(
|
||||
queryAll(".d-icon-sync").length,
|
||||
1,
|
||||
"shows pending update icon"
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
componentTest("broken theme", {
|
||||
template: "{{themes-list-item theme=theme}}",
|
||||
beforeEach() {
|
||||
this.set(
|
||||
"theme",
|
||||
Theme.create({
|
||||
name: "Test",
|
||||
theme_fields: [{ name: "scss", type_id: 1, error: "something" }],
|
||||
})
|
||||
);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.expect(1);
|
||||
assert.equal(
|
||||
queryAll(".d-icon-exclamation-circle").length,
|
||||
1,
|
||||
"shows broken theme icon"
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
componentTest("with children", {
|
||||
template: "{{themes-list-item theme=theme}}",
|
||||
|
||||
beforeEach() {
|
||||
this.childrenList = [1, 2, 3, 4, 5].map((num) =>
|
||||
Theme.create({ name: `Child ${num}`, component: true })
|
||||
);
|
||||
|
||||
this.set(
|
||||
"theme",
|
||||
Theme.create({
|
||||
name: "Test",
|
||||
childThemes: this.childrenList,
|
||||
default: true,
|
||||
})
|
||||
);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.expect(2);
|
||||
assert.deepEqual(
|
||||
queryAll(".components")
|
||||
.text()
|
||||
.trim()
|
||||
.split(",")
|
||||
.map((n) => n.trim())
|
||||
.join(","),
|
||||
this.childrenList
|
||||
.splice(0, 4)
|
||||
.map((theme) => theme.get("name"))
|
||||
.join(","),
|
||||
"lists the first 4 children"
|
||||
);
|
||||
assert.deepEqual(
|
||||
queryAll(".others-count").text().trim(),
|
||||
I18n.t("admin.customize.theme.and_x_more", { count: 1 }),
|
||||
"shows count of remaining children"
|
||||
);
|
||||
},
|
||||
});
|
||||
@@ -1,150 +0,0 @@
|
||||
import Theme, { COMPONENTS, THEMES } from "admin/models/theme";
|
||||
import I18n from "I18n";
|
||||
import componentTest from "discourse/tests/helpers/component-test";
|
||||
import { moduleForComponent } from "ember-qunit";
|
||||
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
|
||||
|
||||
moduleForComponent("themes-list", { integration: true });
|
||||
|
||||
componentTest("current tab is themes", {
|
||||
template:
|
||||
"{{themes-list themes=themes components=components currentTab=currentTab}}",
|
||||
beforeEach() {
|
||||
this.themes = [1, 2, 3, 4, 5].map((num) =>
|
||||
Theme.create({ name: `Theme ${num}` })
|
||||
);
|
||||
this.components = [1, 2, 3, 4, 5].map((num) =>
|
||||
Theme.create({
|
||||
name: `Child ${num}`,
|
||||
component: true,
|
||||
parentThemes: [this.themes[num - 1]],
|
||||
parent_themes: [1, 2, 3, 4, 5],
|
||||
})
|
||||
);
|
||||
this.setProperties({
|
||||
themes: this.themes,
|
||||
components: this.components,
|
||||
currentTab: THEMES,
|
||||
});
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.equal(
|
||||
queryAll(".themes-tab").hasClass("active"),
|
||||
true,
|
||||
"themes tab is active"
|
||||
);
|
||||
assert.equal(
|
||||
queryAll(".components-tab").hasClass("active"),
|
||||
false,
|
||||
"components tab is not active"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
queryAll(".inactive-indicator").index(),
|
||||
-1,
|
||||
"there is no inactive themes separator when all themes are inactive"
|
||||
);
|
||||
assert.equal(
|
||||
queryAll(".themes-list-item").length,
|
||||
5,
|
||||
"displays all themes"
|
||||
);
|
||||
|
||||
[2, 3].forEach((num) => this.themes[num].set("user_selectable", true));
|
||||
this.themes[4].set("default", true);
|
||||
this.set("themes", this.themes);
|
||||
const names = [4, 2, 3, 0, 1].map((num) => this.themes[num].get("name")); // default theme always on top, followed by user-selectable ones and then the rest
|
||||
assert.deepEqual(
|
||||
Array.from(queryAll(".themes-list-item .name")).map((node) =>
|
||||
node.innerText.trim()
|
||||
),
|
||||
names,
|
||||
"sorts themes correctly"
|
||||
);
|
||||
assert.equal(
|
||||
queryAll(".inactive-indicator").index(),
|
||||
3,
|
||||
"the separator is in the right location"
|
||||
);
|
||||
|
||||
this.themes.forEach((theme) => theme.set("user_selectable", true));
|
||||
this.set("themes", this.themes);
|
||||
assert.equal(
|
||||
queryAll(".inactive-indicator").index(),
|
||||
-1,
|
||||
"there is no inactive themes separator when all themes are user-selectable"
|
||||
);
|
||||
|
||||
this.set("themes", []);
|
||||
assert.equal(
|
||||
queryAll(".themes-list-item").length,
|
||||
1,
|
||||
"shows one entry with a message when there is nothing to display"
|
||||
);
|
||||
assert.equal(
|
||||
queryAll(".themes-list-item span.empty").text().trim(),
|
||||
I18n.t("admin.customize.theme.empty"),
|
||||
"displays the right message"
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
componentTest("current tab is components", {
|
||||
template:
|
||||
"{{themes-list themes=themes components=components currentTab=currentTab}}",
|
||||
beforeEach() {
|
||||
this.themes = [1, 2, 3, 4, 5].map((num) =>
|
||||
Theme.create({ name: `Theme ${num}` })
|
||||
);
|
||||
this.components = [1, 2, 3, 4, 5].map((num) =>
|
||||
Theme.create({
|
||||
name: `Child ${num}`,
|
||||
component: true,
|
||||
parentThemes: [this.themes[num - 1]],
|
||||
parent_themes: [1, 2, 3, 4, 5],
|
||||
})
|
||||
);
|
||||
this.setProperties({
|
||||
themes: this.themes,
|
||||
components: this.components,
|
||||
currentTab: COMPONENTS,
|
||||
});
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.equal(
|
||||
queryAll(".components-tab").hasClass("active"),
|
||||
true,
|
||||
"components tab is active"
|
||||
);
|
||||
assert.equal(
|
||||
queryAll(".themes-tab").hasClass("active"),
|
||||
false,
|
||||
"themes tab is not active"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
queryAll(".inactive-indicator").index(),
|
||||
-1,
|
||||
"there is no separator"
|
||||
);
|
||||
assert.equal(
|
||||
queryAll(".themes-list-item").length,
|
||||
5,
|
||||
"displays all components"
|
||||
);
|
||||
|
||||
this.set("components", []);
|
||||
assert.equal(
|
||||
queryAll(".themes-list-item").length,
|
||||
1,
|
||||
"shows one entry with a message when there is nothing to display"
|
||||
);
|
||||
assert.equal(
|
||||
queryAll(".themes-list-item span.empty").text().trim(),
|
||||
I18n.t("admin.customize.theme.empty"),
|
||||
"displays the right message"
|
||||
);
|
||||
},
|
||||
});
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
import Theme from "admin/models/theme";
|
||||
import { moduleFor } from "ember-qunit";
|
||||
import { registerRouter } from "discourse/mapping-router";
|
||||
import { test } from "qunit";
|
||||
|
||||
moduleFor("controller:admin-customize-themes-show", {
|
||||
beforeEach() {
|
||||
registerRouter(this.registry);
|
||||
},
|
||||
needs: ["controller:adminUser"],
|
||||
});
|
||||
|
||||
test("can display source url for remote themes", function (assert) {
|
||||
const repoUrl = "https://github.com/discourse/discourse-brand-header.git";
|
||||
const remoteTheme = Theme.create({
|
||||
id: 2,
|
||||
default: true,
|
||||
name: "default",
|
||||
remote_theme: {
|
||||
remote_url: repoUrl,
|
||||
},
|
||||
});
|
||||
const controller = this.subject({
|
||||
model: remoteTheme,
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
controller.get("remoteThemeLink"),
|
||||
repoUrl,
|
||||
"returns theme's repo URL"
|
||||
);
|
||||
});
|
||||
|
||||
test("can display source url for remote theme branches", function (assert) {
|
||||
const remoteTheme = Theme.create({
|
||||
id: 2,
|
||||
default: true,
|
||||
name: "default",
|
||||
remote_theme: {
|
||||
remote_url: "https://github.com/discourse/discourse-brand-header.git",
|
||||
branch: "beta",
|
||||
},
|
||||
});
|
||||
const controller = this.subject({
|
||||
model: remoteTheme,
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
controller.get("remoteThemeLink"),
|
||||
"https://github.com/discourse/discourse-brand-header/tree/beta",
|
||||
"returns theme's repo URL to branch"
|
||||
);
|
||||
});
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
import Theme from "admin/models/theme";
|
||||
import { moduleFor } from "ember-qunit";
|
||||
import { registerRouter } from "discourse/mapping-router";
|
||||
import { test } from "qunit";
|
||||
|
||||
moduleFor("controller:admin-customize-themes", {
|
||||
beforeEach() {
|
||||
registerRouter(this.registry);
|
||||
},
|
||||
needs: ["controller:adminUser"],
|
||||
});
|
||||
|
||||
test("can list themes correctly", function (assert) {
|
||||
const defaultTheme = Theme.create({ id: 2, default: true, name: "default" });
|
||||
const userTheme = Theme.create({
|
||||
id: 3,
|
||||
user_selectable: true,
|
||||
name: "name",
|
||||
});
|
||||
const strayTheme1 = Theme.create({ id: 4, name: "stray1" });
|
||||
const strayTheme2 = Theme.create({ id: 5, name: "stray2" });
|
||||
const componentTheme = Theme.create({
|
||||
id: 6,
|
||||
name: "component",
|
||||
component: true,
|
||||
});
|
||||
|
||||
const controller = this.subject({
|
||||
model: [strayTheme2, strayTheme1, userTheme, defaultTheme, componentTheme],
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
controller.get("fullThemes").map((t) => t.get("name")),
|
||||
[strayTheme2, strayTheme1, userTheme, defaultTheme].map((t) =>
|
||||
t.get("name")
|
||||
),
|
||||
"returns a list of themes without components"
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
controller.get("childThemes").map((t) => t.get("name")),
|
||||
[componentTheme].map((t) => t.get("name")),
|
||||
"separate components from themes"
|
||||
);
|
||||
});
|
||||
@@ -1,57 +0,0 @@
|
||||
import Badge from "discourse/models/badge";
|
||||
import { moduleFor } from "ember-qunit";
|
||||
import { registerRouter } from "discourse/mapping-router";
|
||||
import { test } from "qunit";
|
||||
|
||||
moduleFor("controller:admin-user-badges", {
|
||||
beforeEach() {
|
||||
registerRouter(this.registry);
|
||||
},
|
||||
needs: ["controller:adminUser"],
|
||||
});
|
||||
|
||||
test("grantableBadges", function (assert) {
|
||||
const badgeFirst = Badge.create({
|
||||
id: 3,
|
||||
name: "A Badge",
|
||||
enabled: true,
|
||||
manually_grantable: true,
|
||||
});
|
||||
const badgeMiddle = Badge.create({
|
||||
id: 1,
|
||||
name: "My Badge",
|
||||
enabled: true,
|
||||
manually_grantable: true,
|
||||
});
|
||||
const badgeLast = Badge.create({
|
||||
id: 2,
|
||||
name: "Zoo Badge",
|
||||
enabled: true,
|
||||
manually_grantable: true,
|
||||
});
|
||||
const badgeDisabled = Badge.create({
|
||||
id: 4,
|
||||
name: "Disabled Badge",
|
||||
enabled: false,
|
||||
manually_grantable: true,
|
||||
});
|
||||
const badgeAutomatic = Badge.create({
|
||||
id: 5,
|
||||
name: "Automatic Badge",
|
||||
enabled: true,
|
||||
manually_grantable: false,
|
||||
});
|
||||
|
||||
const controller = this.subject({
|
||||
model: [],
|
||||
badges: [badgeLast, badgeFirst, badgeMiddle, badgeDisabled, badgeAutomatic],
|
||||
});
|
||||
|
||||
const sortedNames = [badgeFirst.name, badgeMiddle.name, badgeLast.name];
|
||||
const badgeNames = controller.get("grantableBadges").map(function (badge) {
|
||||
return badge.name;
|
||||
});
|
||||
|
||||
assert.not(badgeNames.includes(badgeDisabled), "excludes disabled badges");
|
||||
assert.deepEqual(badgeNames, sortedNames, "sorts badges by name");
|
||||
});
|
||||
@@ -1,22 +0,0 @@
|
||||
import { module, test } from "qunit";
|
||||
import Theme from "admin/models/theme";
|
||||
|
||||
module("model:theme");
|
||||
|
||||
test("can add an upload correctly", function (assert) {
|
||||
let theme = Theme.create();
|
||||
|
||||
assert.equal(
|
||||
theme.get("uploads.length"),
|
||||
0,
|
||||
"uploads should be an empty array"
|
||||
);
|
||||
|
||||
theme.setField("common", "bob", "", 999, 2);
|
||||
let fields = theme.get("theme_fields");
|
||||
assert.equal(fields.length, 1, "expecting 1 theme field");
|
||||
assert.equal(fields[0].upload_id, 999, "expecting upload id to be set");
|
||||
assert.equal(fields[0].type_id, 2, "expecting type id to be set");
|
||||
|
||||
assert.equal(theme.get("uploads.length"), 1, "expecting an upload");
|
||||
});
|
||||
Reference in New Issue
Block a user