Skip to content

A platform for community discussion. Free, open, simple.

DEV: improves sk api (#9653)

Joffrey JAFFEUXc99ecba68f11
diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.js b/app/assets/javascripts/discourse/app/lib/plugin-api.js
index ab04e0e7119..342dce0a6d2 100644
--- a/app/assets/javascripts/discourse/app/lib/plugin-api.js
+++ b/app/assets/javascripts/discourse/app/lib/plugin-api.js
@@ -54,7 +54,7 @@ import { on } from "@ember/object/evented";
import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
// If you add any methods to the API ensure you bump up this number
-const PLUGIN_API_VERSION = "0.8.42";
+const PLUGIN_API_VERSION = "0.8.43";
class PluginApi {
constructor(version, container) {
diff --git a/app/assets/javascripts/select-kit/components/select-kit.js b/app/assets/javascripts/select-kit/components/select-kit.js
index 61e21beeeca..84f0fab35cb 100644
--- a/app/assets/javascripts/select-kit/components/select-kit.js
+++ b/app/assets/javascripts/select-kit/components/select-kit.js
@@ -16,12 +16,8 @@ import {
} from "@ember/runloop";
import { Promise } from "rsvp";
import {
- applyHeaderContentPluginApiCallbacks,
- applyModifyNoSelectionPluginApiCallbacks,
applyContentPluginApiCallbacks,
- applyOnOpenPluginApiCallbacks,
- applyOnClosePluginApiCallbacks,
- applyOnInputPluginApiCallbacks
+ applyOnChangePluginApiCallbacks
} from "select-kit/mixins/plugin-api";
export const MAIN_COLLECTION = "MAIN_COLLECTION";
@@ -379,15 +375,7 @@ export default Component.extend(
cancel(this._searchPromise);
}
- const input = applyOnInputPluginApiCallbacks(
- this.pluginApiIdentifiers,
- event,
- this.selectKit
- );
-
- if (input) {
- debounce(this, this._debouncedInput, event.target.value, 200);
- }
+ debounce(this, this._debouncedInput, event.target.value, 200);
},
_debouncedInput(filter) {
@@ -430,6 +418,9 @@ export default Component.extend(
}
this._boundaryActionHandler("onChange", value, items);
+
+ applyOnChangePluginApiCallbacks(value, items, this);
+
resolve(items);
}).finally(() => {
if (!this.isDestroying && !this.isDestroyed) {
@@ -448,11 +439,7 @@ export default Component.extend(
_modifyContentWrapper(content) {
content = this.modifyContent(content);
- return applyContentPluginApiCallbacks(
- this.pluginApiIdentifiers,
- content,
- this.selectKit
- );
+ return applyContentPluginApiCallbacks(content, this);
},
modifyContent(content) {
@@ -460,13 +447,7 @@ export default Component.extend(
},
_modifyNoSelectionWrapper() {
- let none = this.modifyNoSelection();
-
- return applyModifyNoSelectionPluginApiCallbacks(
- this.pluginApiIdentifiers,
- none,
- this.selectKit
- );
+ return this.modifyNoSelection();
},
modifyNoSelection() {
@@ -498,12 +479,6 @@ export default Component.extend(
},
_modifySelectionWrapper(item) {
- applyHeaderContentPluginApiCallbacks(
- this.pluginApiIdentifiers,
- item,
- this.selectKit
- );
-
return this.modifySelection(item);
},
@@ -731,30 +706,14 @@ export default Component.extend(
this.selectKit.change(null, null);
},
- _onOpenWrapper(event) {
- let boundaryAction = this._boundaryActionHandler("onOpen");
-
- boundaryAction = applyOnOpenPluginApiCallbacks(
- this.pluginApiIdentifiers,
- this.selectKit,
- event
- );
-
- return boundaryAction;
+ _onOpenWrapper() {
+ return this._boundaryActionHandler("onOpen");
},
- _onCloseWrapper(event) {
+ _onCloseWrapper() {
this.set("selectKit.highlighted", null);
- let boundaryAction = this._boundaryActionHandler("onClose");
-
- boundaryAction = applyOnClosePluginApiCallbacks(
- this.pluginApiIdentifiers,
- this.selectKit,
- event
- );
-
- return boundaryAction;
+ return this._boundaryActionHandler("onClose");
},
_toggle(event) {
@@ -772,9 +731,7 @@ export default Component.extend(
this.clearErrors();
- if (!this.selectKit.onClose(event)) {
- return;
- }
+ this.selectKit.onClose(event);
this.selectKit.setProperties({
isExpanded: false,
@@ -789,9 +746,7 @@ export default Component.extend(
this.clearErrors();
- if (!this.selectKit.onOpen(event)) {
- return;
- }
+ this.selectKit.onOpen(event);
if (!this.popper) {
const anchor = document.querySelector(
diff --git a/app/assets/javascripts/select-kit/mixins/plugin-api.js b/app/assets/javascripts/select-kit/mixins/plugin-api.js
index 370f301b152..22f446dca6b 100644
--- a/app/assets/javascripts/select-kit/mixins/plugin-api.js
+++ b/app/assets/javascripts/select-kit/mixins/plugin-api.js
@@ -12,257 +12,55 @@ function appendContent(pluginApiIdentifiers, contentFunction) {
}
let _prependContentCallbacks = {};
-function prependContent(pluginApiIdentifiers, contentFunction) {
- if (isNone(_prependContentCallbacks[pluginApiIdentifiers])) {
- _prependContentCallbacks[pluginApiIdentifiers] = [];
+function prependContent(targetedIdentifier, contentFunction) {
+ if (isNone(_prependContentCallbacks[targetedIdentifier])) {
+ _prependContentCallbacks[targetedIdentifier] = [];
}
- _prependContentCallbacks[pluginApiIdentifiers].push(contentFunction);
+ _prependContentCallbacks[targetedIdentifier].push(contentFunction);
}
-let _filterContentCallbacks = {};
-function filterContent(pluginApiIdentifiers, contentFunction) {
- if (isNone(_filterContentCallbacks[pluginApiIdentifiers])) {
- _filterContentCallbacks[pluginApiIdentifiers] = [];
+let _onChangeCallbacks = {};
+function onChange(pluginApiIdentifiers, mutationFunction) {
+ if (isNone(_onChangeCallbacks[pluginApiIdentifiers])) {
+ _onChangeCallbacks[pluginApiIdentifiers] = [];
}
- _filterContentCallbacks[pluginApiIdentifiers].push(contentFunction);
+ _onChangeCallbacks[pluginApiIdentifiers].push(mutationFunction);
}
-let _modifyContentCallbacks = {};
-function modifyContent(pluginApiIdentifiers, contentFunction) {
- if (isNone(_modifyContentCallbacks[pluginApiIdentifiers])) {
- _modifyContentCallbacks[pluginApiIdentifiers] = [];
- }
-
- _modifyContentCallbacks[pluginApiIdentifiers].push(contentFunction);
-}
-
-let _modifyHeaderComputedContentCallbacks = {};
-function modifyHeaderComputedContent(pluginApiIdentifiers, contentFunction) {
- if (isNone(_modifyHeaderComputedContentCallbacks[pluginApiIdentifiers])) {
- _modifyHeaderComputedContentCallbacks[pluginApiIdentifiers] = [];
- }
-
- _modifyHeaderComputedContentCallbacks[pluginApiIdentifiers].push(
- contentFunction
- );
-}
-
-let _modifyNoSelectionCallbacks = {};
-function modifyNoSelection(pluginApiIdentifiers, contentFunction) {
- if (isNone(_modifyNoSelectionCallbacks[pluginApiIdentifiers])) {
- _modifyNoSelectionCallbacks[pluginApiIdentifiers] = [];
- }
-
- _modifyNoSelectionCallbacks[pluginApiIdentifiers].push(contentFunction);
-}
-
-let _modifyCollectionHeaderCallbacks = {};
-function modifyCollectionHeader(pluginApiIdentifiers, contentFunction) {
- if (isNone(_modifyCollectionHeaderCallbacks[pluginApiIdentifiers])) {
- _modifyCollectionHeaderCallbacks[pluginApiIdentifiers] = [];
- }
-
- _modifyCollectionHeaderCallbacks[pluginApiIdentifiers].push(contentFunction);
-}
-
-let _onSelectCallbacks = {};
-function onSelect(pluginApiIdentifiers, mutationFunction) {
- if (isNone(_onSelectCallbacks[pluginApiIdentifiers])) {
- _onSelectCallbacks[pluginApiIdentifiers] = [];
- }
-
- _onSelectCallbacks[pluginApiIdentifiers].push(mutationFunction);
-}
-
-let _onOpenCallbacks = {};
-function onOpen(pluginApiIdentifiers, mutationFunction) {
- if (isNone(_onOpenCallbacks[pluginApiIdentifiers])) {
- _onOpenCallbacks[pluginApiIdentifiers] = [];
- }
-
- _onOpenCallbacks[pluginApiIdentifiers].push(mutationFunction);
-}
-
-let _onCloseCallbacks = {};
-function onClose(pluginApiIdentifiers, mutationFunction) {
- if (isNone(_onCloseCallbacks[pluginApiIdentifiers])) {
- _onCloseCallbacks[pluginApiIdentifiers] = [];
- }
-
- _onCloseCallbacks[pluginApiIdentifiers].push(mutationFunction);
-}
-
-let _onInputCallbacks = {};
-function onInput(pluginApiIdentifiers, mutationFunction) {
- if (isNone(_onInputCallbacks[pluginApiIdentifiers])) {
- _onInputCallbacks[pluginApiIdentifiers] = [];
- }
-
- _onInputCallbacks[pluginApiIdentifiers].push(mutationFunction);
-}
-
-export function applyContentPluginApiCallbacks(
- identifiers,
- content,
- selectKit
-) {
- identifiers.forEach(key => {
+export function applyContentPluginApiCallbacks(content, component) {
+ makeArray(component.pluginApiIdentifiers).forEach(key => {
(_prependContentCallbacks[key] || []).forEach(c => {
- content = makeArray(c(selectKit, content)).concat(content);
+ content = makeArray(c(component, content)).concat(content);
});
(_appendContentCallbacks[key] || []).forEach(c => {
- content = content.concat(makeArray(c(selectKit, content)));
- });
- const filterCallbacks = _filterContentCallbacks[key] || [];
- if (filterCallbacks.length) {
- content = content.filter(c => {
- let kept = true;
- filterCallbacks.forEach(cb => {
- kept = cb(selectKit, c);
- });
- return kept;
- });
- }
- (_modifyContentCallbacks[key] || []).forEach(c => {
- content = c(selectKit, content);
+ content = content.concat(makeArray(c(component, content)));
});
});
return content;
}
-export function applyHeaderContentPluginApiCallbacks(
- identifiers,
- content,
- context
-) {
- identifiers.forEach(key => {
- (_modifyHeaderComputedContentCallbacks[key] || []).forEach(c => {
- content = c(context, content);
- });
+export function applyOnChangePluginApiCallbacks(value, items, component) {
+ makeArray(component.pluginApiIdentifiers).forEach(key => {
+ (_onChangeCallbacks[key] || []).forEach(c => c(component, value, items));
});
-
- return content;
-}
-export function applyModifyNoSelectionPluginApiCallbacks(
- identifiers,
- content,
- context
-) {
- identifiers.forEach(key => {
- (_modifyNoSelectionCallbacks[key] || []).forEach(c => {
- content = c(context, content);
- });
- });
-
- return content;
-}
-
-export function applyCollectionHeaderCallbacks(
- identifiers,
- content,
- selectKit
-) {
- identifiers.forEach(key => {
- (_modifyCollectionHeaderCallbacks[key] || []).forEach(c => {
- content = c(selectKit, content);
- });
- });
-
- return content;
-}
-
-export function applyOnSelectPluginApiCallbacks(identifiers, val, selectKit) {
- identifiers.forEach(key => {
- (_onSelectCallbacks[key] || []).forEach(c => c(selectKit, val));
- });
-}
-
-export function applyOnOpenPluginApiCallbacks(identifiers, selectKit, event) {
- let keepBubbling = true;
- identifiers.forEach(key => {
- (_onOpenCallbacks[key] || []).forEach(
- c => (keepBubbling = c(selectKit, event))
- );
- });
- return keepBubbling;
-}
-
-export function applyOnClosePluginApiCallbacks(identifiers, selectKit, event) {
- let keepBubbling = true;
- identifiers.forEach(key => {
- (_onCloseCallbacks[key] || []).forEach(
- c => (keepBubbling = c(selectKit, event))
- );
- });
- return keepBubbling;
}
-export function applyOnInputPluginApiCallbacks(identifiers, event, selectKit) {
- let keepBubbling = true;
- identifiers.forEach(key => {
- (_onInputCallbacks[key] || []).forEach(
- c => (keepBubbling = c(selectKit, event))
- );
- });
- return keepBubbling;
-}
-
-export function modifySelectKit(pluginApiIdentifiers) {
+export function modifySelectKit(targetedIdentifier) {
return {
- appendContent: content => {
- appendContent(pluginApiIdentifiers, () => {
- return content;
- });
- return modifySelectKit(pluginApiIdentifiers);
- },
- prependContent: content => {
- prependContent(pluginApiIdentifiers, () => {
- return content;
- });
- return modifySelectKit(pluginApiIdentifiers);
- },
- filterContent: filterFunction => {
- filterContent(pluginApiIdentifiers, filterFunction);
- return modifySelectKit(pluginApiIdentifiers);
- },
- modifyContent: callback => {
- modifyContent(pluginApiIdentifiers, callback);
- return modifySelectKit(pluginApiIdentifiers);
- },
- modifyHeaderComputedContent: callback => {
- modifyHeaderComputedContent(pluginApiIdentifiers, callback);
- return modifySelectKit(pluginApiIdentifiers);
- },
- modifySelection: callback => {
- modifyHeaderComputedContent(pluginApiIdentifiers, callback);
- return modifySelectKit(pluginApiIdentifiers);
- },
- modifyNoSelection: callback => {
- modifyNoSelection(pluginApiIdentifiers, callback);
- return modifySelectKit(pluginApiIdentifiers);
- },
- modifyCollectionHeader: callback => {
- modifyCollectionHeader(pluginApiIdentifiers, callback);
- return modifySelectKit(pluginApiIdentifiers);
- },
- onSelect: callback => {
- onSelect(pluginApiIdentifiers, callback);
- return modifySelectKit(pluginApiIdentifiers);
- },
- onClose: callback => {
- onClose(pluginApiIdentifiers, callback);
- return modifySelectKit(pluginApiIdentifiers);
+ appendContent: callback => {
+ appendContent(targetedIdentifier, callback);
+ return modifySelectKit(targetedIdentifier);
},
- onOpen: callback => {
- onOpen(pluginApiIdentifiers, callback);
- return modifySelectKit(pluginApiIdentifiers);
+ prependContent: callback => {
+ prependContent(targetedIdentifier, callback);
+ return modifySelectKit(targetedIdentifier);
},
- onInput: callback => {
- onInput(pluginApiIdentifiers, callback);
- return modifySelectKit(pluginApiIdentifiers);
+ onChange: callback => {
+ onChange(targetedIdentifier, callback);
+ return modifySelectKit(targetedIdentifier);
}
};
}
@@ -270,15 +68,7 @@ export function modifySelectKit(pluginApiIdentifiers) {
export function clearCallbacks() {
_appendContentCallbacks = {};
_prependContentCallbacks = {};
- _filterContentCallbacks = {};
- _modifyNoSelectionCallbacks = {};
- _modifyContentCallbacks = {};
- _modifyHeaderComputedContentCallbacks = {};
- _modifyCollectionHeaderCallbacks = {};
- _onSelectCallbacks = {};
- _onCloseCallbacks = {};
- _onOpenCallbacks = {};
- _onInputCallbacks = {};
+ _onChangeCallbacks = {};
}
const EMPTY_ARRAY = Object.freeze([]);
diff --git a/test/javascripts/components/select-kit/api-test.js b/test/javascripts/components/select-kit/api-test.js
new file mode 100644
index 00000000000..db17590ede3
--- /dev/null
+++ b/test/javascripts/components/select-kit/api-test.js
@@ -0,0 +1,109 @@
+import componentTest from "helpers/component-test";
+import selectKit, {
+ testSelectKitModule,
+ setDefaultState,
+ DEFAULT_CONTENT
+} from "helpers/select-kit-helper";
+import { withPluginApi } from "discourse/lib/plugin-api";
+import { clearCallbacks } from "select-kit/mixins/plugin-api";
+
+testSelectKitModule("select-kit:api", {
+ beforeEach() {
+ this.setProperties({
+ comboBox: selectKit(".combo-box"),
+ singleSelect: selectKit(".single-select:not(.combo-box)")
+ });
+ },
+
+ afterEach() {
+ clearCallbacks();
+ }
+});
+
+componentTest("modifySelectKit(identifier).appendContent", {
+ template: `
+ {{combo-box value=value content=content onChange=onChange}}
+ {{single-select value=value content=content onChange=onChange}}
+ `,
+
+ beforeEach() {
+ setDefaultState(this, null, { content: DEFAULT_CONTENT });
+
+ withPluginApi("0.8.43", api => {
+ api.modifySelectKit("combo-box").appendContent(() => {
+ return {
+ id: "alpaca",
+ name: "Alpaca"
+ };
+ });
+ });
+ },
+
+ async test(assert) {
+ await this.comboBox.expand();
+ const row = this.comboBox.rowByIndex(3);
+ assert.ok(row.exists());
+ assert.equal(row.value(), "alpaca");
+
+ await this.comboBox.collapse();
+
+ assert.notOk(this.singleSelect.rowByValue("alpaca").exists());
+ }
+});
+
+componentTest("modifySelectKit(identifier).prependContent", {
+ template: `
+ {{combo-box value=value content=content onChange=onChange}}
+ {{single-select value=value content=content onChange=onChange}}
+ `,
+
+ beforeEach() {
+ setDefaultState(this, null, { content: DEFAULT_CONTENT });
+
+ withPluginApi("0.8.43", api => {
+ api.modifySelectKit("combo-box").prependContent(() => {
+ return {
+ id: "alpaca",
+ name: "Alpaca"
+ };
+ });
+ });
+ },
+
+ afterEach() {},
+
+ async test(assert) {
+ await this.comboBox.expand();
+ const row = this.comboBox.rowByIndex(0);
+ assert.ok(row.exists());
+ assert.equal(row.value(), "alpaca");
+
+ await this.comboBox.collapse();
+
+ assert.notOk(this.singleSelect.rowByValue("alpaca").exists());
+ }
+});
+
+componentTest("modifySelectKit(identifier).onChange", {
+ template: `
+ <div id="test"></div>
+ {{combo-box value=value content=content onChange=onChange}}
+ `,
+
+ beforeEach() {
+ setDefaultState(this, null, { content: DEFAULT_CONTENT });
+
+ withPluginApi("0.8.43", api => {
+ api.modifySelectKit("combo-box").onChange((component, value, item) => {
+ find("#test").text(item.name);
+ });
+ });
+ },
+
+ async test(assert) {
+ await this.comboBox.expand();
+ await this.comboBox.selectRowByIndex(0);
+
+ assert.equal(find("#test").text(), "foo");
+ }
+});
diff --git a/test/javascripts/components/select-kit/category-chooser-test.js b/test/javascripts/components/select-kit/category-chooser-test.js
index 196f692e3c5..19146cb3b46 100644
--- a/test/javascripts/components/select-kit/category-chooser-test.js
+++ b/test/javascripts/components/select-kit/category-chooser-test.js
@@ -1,5 +1,5 @@
import componentTest from "helpers/component-test";
-import { testSelectKitModule } from "./select-kit-test-helper";
+import { testSelectKitModule } from "helpers/select-kit-helper";
testSelectKitModule("category-chooser");
diff --git a/test/javascripts/components/select-kit/category-drop-test.js b/test/javascripts/components/select-kit/category-drop-test.js
index 5c45042cb93..923bd93bbc9 100644
--- a/test/javascripts/components/select-kit/category-drop-test.js
+++ b/test/javascripts/components/select-kit/category-drop-test.js
@@ -1,7 +1,7 @@
import DiscourseURL from "discourse/lib/url";
import Category from "discourse/models/category";
import componentTest from "helpers/component-test";
-import { testSelectKitModule } from "./select-kit-test-helper";
+import { testSelectKitModule } from "helpers/select-kit-helper";
import {
NO_CATEGORIES_ID,
ALL_CATEGORIES_ID
diff --git a/test/javascripts/components/select-kit/list-setting-test.js b/test/javascripts/components/select-kit/list-setting-test.js
index 37e08081d23..5fddc9ea56d 100644
--- a/test/javascripts/components/select-kit/list-setting-test.js
+++ b/test/javascripts/components/select-kit/list-setting-test.js
@@ -1,5 +1,5 @@
import componentTest from "helpers/component-test";
-import { testSelectKitModule } from "./select-kit-test-helper";
+import { testSelectKitModule } from "helpers/select-kit-helper";
testSelectKitModule("list-setting");
diff --git a/test/javascripts/components/select-kit/mini-tag-chooser-test.js b/test/javascripts/components/select-kit/mini-tag-chooser-test.js
index 4c230212724..f929cb99d49 100644
--- a/test/javascripts/components/select-kit/mini-tag-chooser-test.js
+++ b/test/javascripts/components/select-kit/mini-tag-chooser-test.js
@@ -1,5 +1,5 @@
import componentTest from "helpers/component-test";
-import { testSelectKitModule } from "./select-kit-test-helper";
+import { testSelectKitModule } from "helpers/select-kit-helper";
testSelectKitModule("mini-tag-chooser");
diff --git a/test/javascripts/components/select-kit/multi-select-test.js b/test/javascripts/components/select-kit/multi-select-test.js
index 7e636904856..d3d022273e1 100644
--- a/test/javascripts/components/select-kit/multi-select-test.js
+++ b/test/javascripts/components/select-kit/multi-select-test.js
@@ -1,5 +1,5 @@
import componentTest from "helpers/component-test";
-import { testSelectKitModule } from "./select-kit-test-helper";
+import { testSelectKitModule } from "helpers/select-kit-helper";
testSelectKitModule("multi-select");
diff --git a/test/javascripts/components/select-kit/notifications-button-test.js b/test/javascripts/components/select-kit/notifications-button-test.js
index 44f9cf39747..7da1f8002fa 100644
--- a/test/javascripts/components/select-kit/notifications-button-test.js
+++ b/test/javascripts/components/select-kit/notifications-button-test.js
@@ -1,5 +1,8 @@
import componentTest from "helpers/component-test";
-import { testSelectKitModule, setDefaultState } from "./select-kit-test-helper";
+import {
+ testSelectKitModule,
+ setDefaultState
+} from "helpers/select-kit-helper";
testSelectKitModule("notifications-button");
diff --git a/test/javascripts/components/select-kit/select-kit-test-helper.js b/test/javascripts/components/select-kit/select-kit-test-helper.js
deleted file mode 100644
index 828b656e5d5..00000000000
--- a/test/javascripts/components/select-kit/select-kit-test-helper.js
+++ /dev/null
@@ -1,35 +0,0 @@
-import selectKit from "helpers/select-kit-helper";
-
-export function testSelectKitModule(moduleName, options = {}) {
- moduleForComponent(`select-kit/${moduleName}`, {
- integration: true,
-
- beforeEach() {
- this.set("subject", selectKit());
- options.beforeEach && options.beforeEach.call(this);
- },
-
- afterEach() {
- options.afterEach && options.afterEach.call(this);
- }
- });
-}
-
-export const DEFAULT_CONTENT = [
- { id: 1, name: "foo" },
- { id: 2, name: "bar" },
- { id: 3, name: "baz" }
-];
-
-export function setDefaultState(ctx, value, options = {}) {
- const properties = Object.assign(
- {
- onChange: v => {
- this.set("value", v);
- }
- },
- options || {}
- );
-
- ctx.setProperties(properties);
-}
diff --git a/test/javascripts/components/select-kit/single-select-test.js b/test/javascripts/components/select-kit/single-select-test.js
index ac53d73bf7d..66bd9403284 100644
--- a/test/javascripts/components/select-kit/single-select-test.js
+++ b/test/javascripts/components/select-kit/single-select-test.js
@@ -1,5 +1,5 @@
import componentTest from "helpers/component-test";
-import { testSelectKitModule } from "./select-kit-test-helper";
+import { testSelectKitModule } from "helpers/select-kit-helper";
testSelectKitModule("single-select");
diff --git a/test/javascripts/components/select-kit/tag-drop-test.js b/test/javascripts/components/select-kit/tag-drop-test.js
index 2c6d156052d..39ab21187f7 100644
--- a/test/javascripts/components/select-kit/tag-drop-test.js
+++ b/test/javascripts/components/select-kit/tag-drop-test.js
@@ -1,5 +1,5 @@
import componentTest from "helpers/component-test";
-import { testSelectKitModule } from "./select-kit-test-helper";
+import { testSelectKitModule } from "helpers/select-kit-helper";
import Site from "discourse/models/site";
import { set } from "@ember/object";
import pretender from "helpers/create-pretender";
diff --git a/test/javascripts/components/select-kit/user-chooser-test.js b/test/javascripts/components/select-kit/user-chooser-test.js
index c59d7cb5713..d54da015d5b 100644
--- a/test/javascripts/components/select-kit/user-chooser-test.js
+++ b/test/javascripts/components/select-kit/user-chooser-test.js
@@ -1,5 +1,5 @@
import componentTest from "helpers/component-test";
-import { testSelectKitModule } from "./select-kit-test-helper";
+import { testSelectKitModule } from "helpers/select-kit-helper";
import pretender from "helpers/create-pretender";
testSelectKitModule("user-chooser");
diff --git a/test/javascripts/helpers/select-kit-helper.js b/test/javascripts/helpers/select-kit-helper.js
index c103c4371c5..5d80b8f0b37 100644
--- a/test/javascripts/helpers/select-kit-helper.js
+++ b/test/javascripts/helpers/select-kit-helper.js
@@ -276,3 +276,38 @@ export default function selectKit(selector) {
}
};
}
+
+export function testSelectKitModule(moduleName, options = {}) {
+ moduleForComponent(`select-kit/${moduleName}`, {
+ integration: true,
+
+ beforeEach() {
+ this.set("subject", selectKit());
+ options.beforeEach && options.beforeEach.call(this);
+ },
+
+ afterEach() {
+ options.afterEach && options.afterEach.call(this);
+ }
+ });
+}
+
+export const DEFAULT_CONTENT = [
+ { id: 1, name: "foo" },
+ { id: 2, name: "bar" },
+ { id: 3, name: "baz" }
+];
+
+export function setDefaultState(ctx, value, options = {}) {
+ const properties = Object.assign(
+ {
+ value,
+ onChange: v => {
+ ctx.set("value", v);
+ }
+ },
+ options || {}
+ );
+
+ ctx.setProperties(properties);
+}