diff --git a/app/assets/javascripts/admin/tests/admin/integration/components/group-list-setting-test.js b/app/assets/javascripts/admin/tests/admin/integration/components/group-list-setting-test.js deleted file mode 100644 index 025f868e989..00000000000 --- a/app/assets/javascripts/admin/tests/admin/integration/components/group-list-setting-test.js +++ /dev/null @@ -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" - ); - }, -}); diff --git a/app/assets/javascripts/admin/tests/admin/integration/components/themes-list-item-test.js b/app/assets/javascripts/admin/tests/admin/integration/components/themes-list-item-test.js deleted file mode 100644 index 0fe76fe463f..00000000000 --- a/app/assets/javascripts/admin/tests/admin/integration/components/themes-list-item-test.js +++ /dev/null @@ -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" - ); - }, -}); diff --git a/app/assets/javascripts/admin/tests/admin/integration/components/themes-list-test.js b/app/assets/javascripts/admin/tests/admin/integration/components/themes-list-test.js deleted file mode 100644 index cd6ab79551d..00000000000 --- a/app/assets/javascripts/admin/tests/admin/integration/components/themes-list-test.js +++ /dev/null @@ -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" - ); - }, -}); diff --git a/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-customize-themes-show-test.js b/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-customize-themes-show-test.js deleted file mode 100644 index 9dca803f172..00000000000 --- a/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-customize-themes-show-test.js +++ /dev/null @@ -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" - ); -}); diff --git a/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-customize-themes-test.js b/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-customize-themes-test.js deleted file mode 100644 index 22c072c766e..00000000000 --- a/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-customize-themes-test.js +++ /dev/null @@ -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" - ); -}); diff --git a/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-user-badges-test.js b/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-user-badges-test.js deleted file mode 100644 index 48e2586496d..00000000000 --- a/app/assets/javascripts/admin/tests/admin/unit/controllers/admin-user-badges-test.js +++ /dev/null @@ -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"); -}); diff --git a/app/assets/javascripts/admin/tests/admin/acceptance/admin-install-theme-modal-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-install-theme-modal-test.js similarity index 100% rename from app/assets/javascripts/admin/tests/admin/acceptance/admin-install-theme-modal-test.js rename to app/assets/javascripts/discourse/tests/acceptance/admin-install-theme-modal-test.js diff --git a/app/assets/javascripts/discourse/tests/integration/components/group-list-setting-test.js b/app/assets/javascripts/discourse/tests/integration/components/group-list-setting-test.js new file mode 100644 index 00000000000..ef1340f54fb --- /dev/null +++ b/app/assets/javascripts/discourse/tests/integration/components/group-list-setting-test.js @@ -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" + ); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/components/themes-list-item-test.js b/app/assets/javascripts/discourse/tests/integration/components/themes-list-item-test.js new file mode 100644 index 00000000000..0dc7fea9c44 --- /dev/null +++ b/app/assets/javascripts/discourse/tests/integration/components/themes-list-item-test.js @@ -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" + ); + }, + }); +}); diff --git a/app/assets/javascripts/discourse/tests/integration/components/themes-list-test.js b/app/assets/javascripts/discourse/tests/integration/components/themes-list-test.js new file mode 100644 index 00000000000..3ab035c5f3d --- /dev/null +++ b/app/assets/javascripts/discourse/tests/integration/components/themes-list-test.js @@ -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" + ); + }, + }); +}); diff --git a/app/assets/javascripts/discourse/tests/integration/widgets/button-test.js b/app/assets/javascripts/discourse/tests/integration/widgets/button-test.js index e280f5f0836..5451f393c76 100644 --- a/app/assets/javascripts/discourse/tests/integration/widgets/button-test.js +++ b/app/assets/javascripts/discourse/tests/integration/widgets/button-test.js @@ -85,7 +85,7 @@ discourseModule("Integration | Component | Widget | button", function (hooks) { }); componentTest("translatedTitle", { - template: '{{mount-widget widget="button" args=args}}', + template: hbs`{{mount-widget widget="button" args=args}}`, beforeEach() { this.set("args", { label: "topic.create", translatedTitle: "foo bar" }); diff --git a/app/assets/javascripts/discourse/tests/test_helper.js b/app/assets/javascripts/discourse/tests/test_helper.js index ac4d8e868f7..aa2aacd65aa 100644 --- a/app/assets/javascripts/discourse/tests/test_helper.js +++ b/app/assets/javascripts/discourse/tests/test_helper.js @@ -37,7 +37,6 @@ //= require_tree ./acceptance //= require_tree ./integration //= require_tree ./unit -//= require_tree ../../admin/tests/admin //= require plugin_tests //= require setup-tests //= require test-shims diff --git a/app/assets/javascripts/discourse/tests/unit/controllers/admin-customize-themes-show-test.js b/app/assets/javascripts/discourse/tests/unit/controllers/admin-customize-themes-show-test.js new file mode 100644 index 00000000000..d3a311787c3 --- /dev/null +++ b/app/assets/javascripts/discourse/tests/unit/controllers/admin-customize-themes-show-test.js @@ -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" + ); + }); +}); diff --git a/app/assets/javascripts/discourse/tests/unit/controllers/admin-customize-themes-test.js b/app/assets/javascripts/discourse/tests/unit/controllers/admin-customize-themes-test.js new file mode 100644 index 00000000000..bdd9136f093 --- /dev/null +++ b/app/assets/javascripts/discourse/tests/unit/controllers/admin-customize-themes-test.js @@ -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" + ); + }); +}); diff --git a/app/assets/javascripts/discourse/tests/unit/controllers/admin-user-badges-test.js b/app/assets/javascripts/discourse/tests/unit/controllers/admin-user-badges-test.js new file mode 100644 index 00000000000..529cc342520 --- /dev/null +++ b/app/assets/javascripts/discourse/tests/unit/controllers/admin-user-badges-test.js @@ -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"); + }); +}); diff --git a/app/assets/javascripts/admin/tests/admin/unit/models/theme-test.js b/app/assets/javascripts/discourse/tests/unit/models/theme-test.js similarity index 95% rename from app/assets/javascripts/admin/tests/admin/unit/models/theme-test.js rename to app/assets/javascripts/discourse/tests/unit/models/theme-test.js index 058db729215..94c360d58d1 100644 --- a/app/assets/javascripts/admin/tests/admin/unit/models/theme-test.js +++ b/app/assets/javascripts/discourse/tests/unit/models/theme-test.js @@ -1,7 +1,7 @@ import { module, test } from "qunit"; import Theme from "admin/models/theme"; -module("model:theme"); +module("Unit | Model | theme"); test("can add an upload correctly", function (assert) { let theme = Theme.create();