0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-09 11:52:54 +01:00

Tests and linting

Dieser Commit ist enthalten in:
Angus McLeod 2024-06-20 13:06:02 +02:00
Ursprung 057b3f989f
Commit be0af6f919
8 geänderte Dateien mit 44 neuen und 19 gelöschten Zeilen

Datei anzeigen

@ -1,5 +1,3 @@
import { observes } from "discourse-common/utils/decorators";
import Topic from "discourse/models/topic";
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({ export default Component.extend({
@ -11,14 +9,13 @@ export default Component.extend({
if (value) { if (value) {
this.set("topics", value); this.set("topics", value);
} }
console.log(this.field)
}, },
actions: { actions: {
setValue(topicIds, topics) { setValue(_, topics) {
if (topics.length) { if (topics.length) {
this.set("field.value", topics); this.set("field.value", topics);
} }
}, },
} },
}); });

Datei anzeigen

@ -1,6 +1,4 @@
import MultiSelectComponent from "select-kit/components/multi-select"; import MultiSelectComponent from "select-kit/components/multi-select";
import { computed } from "@ember/object";
import { mapBy } from "@ember/object/computed";
import { isEmpty } from "@ember/utils"; import { isEmpty } from "@ember/utils";
import { searchForTerm } from "discourse/lib/search"; import { searchForTerm } from "discourse/lib/search";
import { makeArray } from "discourse-common/lib/helpers"; import { makeArray } from "discourse-common/lib/helpers";
@ -23,7 +21,7 @@ export default MultiSelectComponent.extend({
didReceiveAttrs() { didReceiveAttrs() {
if (this.topics && !this.selectKit.hasSelection) { if (this.topics && !this.selectKit.hasSelection) {
const values = makeArray(this.topics.map(t => t.id)); const values = makeArray(this.topics.map((t) => t.id));
const content = makeArray(this.topics); const content = makeArray(this.topics);
this.selectKit.change(values, content); this.selectKit.change(values, content);
} }
@ -44,10 +42,7 @@ export default MultiSelectComponent.extend({
searchParams.restrictToArchetype = "regular"; searchParams.restrictToArchetype = "regular";
searchParams.searchForId = true; searchParams.searchForId = true;
return searchForTerm( return searchForTerm(filter, searchParams).then((results) => {
filter,
searchParams
).then((results) => {
if (results?.posts?.length > 0) { if (results?.posts?.length > 0) {
return results.posts.mapBy("topic"); return results.posts.mapBy("topic");
} }
@ -56,15 +51,14 @@ export default MultiSelectComponent.extend({
actions: { actions: {
onChange(value, items) { onChange(value, items) {
const content = items.map(t => { const content = items.map((t) => {
return { return {
id: t.id, id: t.id,
title: t.title, title: t.title,
fancy_title: t.fancy_title, fancy_title: t.fancy_title,
url: t.url url: t.url,
} };
}); });
console.log("onChange: ", value, content)
this.setProperties({ value, content }); this.setProperties({ value, content });
this.onChange(value, content); this.onChange(value, content);
}, },

Datei anzeigen

@ -22,7 +22,14 @@ export default Component.extend(UndoChanges, {
isTextarea: equal("field.type", "textarea"), isTextarea: equal("field.type", "textarea"),
isUrl: equal("field.type", "url"), isUrl: equal("field.type", "url"),
isComposer: equal("field.type", "composer"), isComposer: equal("field.type", "composer"),
showPrefill: or("isText", "isCategory", "isTag", "isGroup", "isDropdown", "isTopic"), showPrefill: or(
"isText",
"isCategory",
"isTag",
"isGroup",
"isDropdown",
"isTopic"
),
showContent: or("isCategory", "isTag", "isGroup", "isDropdown", "isTopic"), showContent: or("isCategory", "isTag", "isGroup", "isDropdown", "isTopic"),
showLimit: or("isCategory", "isTag", "isTopic"), showLimit: or("isCategory", "isTag", "isTopic"),
isTextType: or("isText", "isTextarea", "isComposer"), isTextType: or("isText", "isTextarea", "isComposer"),

Datei anzeigen

@ -64,7 +64,7 @@ export default EmberObject.extend(ValidState, {
url: `/w/${wizardId}/steps/${this.get("id")}`, url: `/w/${wizardId}/steps/${this.get("id")}`,
type: "PUT", type: "PUT",
contentType: "application/json", contentType: "application/json",
data: JSON.stringify({ fields }) data: JSON.stringify({ fields }),
}).catch((response) => { }).catch((response) => {
if (response.jqXHR) { if (response.jqXHR) {
response = response.jqXHR; response = response.jqXHR;

Datei anzeigen

@ -186,4 +186,10 @@ body.custom-wizard {
.wizard-topic-selector { .wizard-topic-selector {
width: 500px; width: 500px;
} }
.wizard-topic-selector .topic-row {
.topic-title {
margin-right: 10px;
}
}
} }

Datei anzeigen

@ -8,7 +8,7 @@
# subscription_url: https://coop.pavilion.tech # subscription_url: https://coop.pavilion.tech
# meta_topic_id: 73345 # meta_topic_id: 73345
gem 'liquid', '5.0.1', require: true gem 'liquid', '5.5.0', require: true
gem "discourse_subscription_client", "0.1.2", require_name: "discourse_subscription_client" gem "discourse_subscription_client", "0.1.2", require_name: "discourse_subscription_client"
gem 'discourse_plugin_statistics', '0.1.0.pre7', require: true gem 'discourse_plugin_statistics', '0.1.0.pre7', require: true
register_asset 'stylesheets/common/admin.scss' register_asset 'stylesheets/common/admin.scss'

Datei anzeigen

@ -63,6 +63,11 @@ describe CustomWizard::Mapper do
"step_1_field_1": get_wizard_fixture("field/upload") "step_1_field_1": get_wizard_fixture("field/upload")
} }
} }
let(:template_params_object_array) {
{
"step_1_field_1" => [{ text: "Hello" }, { text: "World" }]
}
}
def create_template_mapper(data, user) def create_template_mapper(data, user)
CustomWizard::Mapper.new( CustomWizard::Mapper.new(
@ -500,6 +505,21 @@ describe CustomWizard::Mapper do
expect(result).to eq("Incorrect") expect(result).to eq("Incorrect")
end end
it "iterates over an interpolated list of objects" do
template = <<-LIQUID.strip
{% for object in step_1_field_1 %}{{object.text}} {% endfor %}
LIQUID
mapper = create_template_mapper(template_params_object_array, user1)
result = mapper.interpolate(
template.dup,
template: true,
user: true,
wizard: true,
value: true
)
expect(result).to eq("Hello World ")
end
context "custom filter: 'first_non_empty'" do context "custom filter: 'first_non_empty'" do
it "gives first non empty element from list" do it "gives first non empty element from list" do
template = <<-LIQUID.strip template = <<-LIQUID.strip

Datei anzeigen

@ -57,6 +57,7 @@ describe DiscoursePluginStatistics::Plugin do
tag: 0, tag: 0,
category: 0, category: 0,
group: 0, group: 0,
topic: 0,
user_selector: 0, user_selector: 0,
}, },
realtime_validations: 0 realtime_validations: 0