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:
parent
50f8782def
commit
11e6e9cca2
|
@ -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"
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
|
@ -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"
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
|
@ -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"
|
|
||||||
);
|
|
||||||
});
|
|
|
@ -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");
|
|
||||||
});
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
import componentTest, {
|
||||||
|
setupRenderingTest,
|
||||||
|
} from "discourse/tests/helpers/component-test";
|
||||||
|
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
|
||||||
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||||
|
import hbs from "htmlbars-inline-precompile";
|
||||||
|
|
||||||
|
discourseModule(
|
||||||
|
"Integration | Component | group-list site-setting",
|
||||||
|
function (hooks) {
|
||||||
|
setupRenderingTest(hooks);
|
||||||
|
|
||||||
|
componentTest("default", {
|
||||||
|
template: hbs`{{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"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
|
@ -0,0 +1,111 @@
|
||||||
|
import I18n from "I18n";
|
||||||
|
import Theme from "admin/models/theme";
|
||||||
|
import componentTest, {
|
||||||
|
setupRenderingTest,
|
||||||
|
} from "discourse/tests/helpers/component-test";
|
||||||
|
import {
|
||||||
|
discourseModule,
|
||||||
|
queryAll,
|
||||||
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
import hbs from "htmlbars-inline-precompile";
|
||||||
|
|
||||||
|
discourseModule("Integration | Component | themes-list-item", function (hooks) {
|
||||||
|
setupRenderingTest(hooks);
|
||||||
|
componentTest("default theme", {
|
||||||
|
template: hbs`{{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: hbs`{{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: hbs`{{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: hbs`{{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"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,154 @@
|
||||||
|
import Theme, { COMPONENTS, THEMES } from "admin/models/theme";
|
||||||
|
import I18n from "I18n";
|
||||||
|
import componentTest, {
|
||||||
|
setupRenderingTest,
|
||||||
|
} from "discourse/tests/helpers/component-test";
|
||||||
|
import {
|
||||||
|
discourseModule,
|
||||||
|
queryAll,
|
||||||
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
import hbs from "htmlbars-inline-precompile";
|
||||||
|
|
||||||
|
discourseModule("Integration | Component | themes-list", function (hooks) {
|
||||||
|
setupRenderingTest(hooks);
|
||||||
|
componentTest("current tab is themes", {
|
||||||
|
template: hbs`{{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: hbs`{{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"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
|
@ -85,7 +85,7 @@ discourseModule("Integration | Component | Widget | button", function (hooks) {
|
||||||
});
|
});
|
||||||
|
|
||||||
componentTest("translatedTitle", {
|
componentTest("translatedTitle", {
|
||||||
template: '{{mount-widget widget="button" args=args}}',
|
template: hbs`{{mount-widget widget="button" args=args}}`,
|
||||||
|
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
this.set("args", { label: "topic.create", translatedTitle: "foo bar" });
|
this.set("args", { label: "topic.create", translatedTitle: "foo bar" });
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
//= require_tree ./acceptance
|
//= require_tree ./acceptance
|
||||||
//= require_tree ./integration
|
//= require_tree ./integration
|
||||||
//= require_tree ./unit
|
//= require_tree ./unit
|
||||||
//= require_tree ../../admin/tests/admin
|
|
||||||
//= require plugin_tests
|
//= require plugin_tests
|
||||||
//= require setup-tests
|
//= require setup-tests
|
||||||
//= require test-shims
|
//= require test-shims
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
import Theme from "admin/models/theme";
|
||||||
|
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
import { test } from "qunit";
|
||||||
|
|
||||||
|
discourseModule("Unit | Controller | admin-customize-themes-show", function () {
|
||||||
|
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.getController("admin-customize-themes-show", {
|
||||||
|
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.getController("admin-customize-themes-show", {
|
||||||
|
model: remoteTheme,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
controller.get("remoteThemeLink"),
|
||||||
|
"https://github.com/discourse/discourse-brand-header/tree/beta",
|
||||||
|
"returns theme's repo URL to branch"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,49 @@
|
||||||
|
import Theme from "admin/models/theme";
|
||||||
|
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
import { test } from "qunit";
|
||||||
|
|
||||||
|
discourseModule("Unit | Controller | admin-customize-themes", function () {
|
||||||
|
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.getController("admin-customize-themes", {
|
||||||
|
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"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,57 @@
|
||||||
|
import Badge from "discourse/models/badge";
|
||||||
|
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
import { test } from "qunit";
|
||||||
|
|
||||||
|
discourseModule("Unit | Controller | admin-user-badges", function () {
|
||||||
|
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.getController("admin-user-badges", {
|
||||||
|
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,7 +1,7 @@
|
||||||
import { module, test } from "qunit";
|
import { module, test } from "qunit";
|
||||||
import Theme from "admin/models/theme";
|
import Theme from "admin/models/theme";
|
||||||
|
|
||||||
module("model:theme");
|
module("Unit | Model | theme");
|
||||||
|
|
||||||
test("can add an upload correctly", function (assert) {
|
test("can add an upload correctly", function (assert) {
|
||||||
let theme = Theme.create();
|
let theme = Theme.create();
|
Loading…
Reference in New Issue