From be0af6f919a708d1044f8d44e01b41230da3acdd Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 20 Jun 2024 13:06:02 +0200 Subject: [PATCH] Tests and linting --- .../custom-wizard-field-topic.js.es6 | 7 ++----- .../custom-wizard-topic-selector.js.es6 | 16 +++++---------- .../components/wizard-custom-field.js.es6 | 9 ++++++++- .../models/custom-wizard-step.js.es6 | 2 +- assets/stylesheets/common/wizard/field.scss | 6 ++++++ plugin.rb | 2 +- spec/components/custom_wizard/mapper_spec.rb | 20 +++++++++++++++++++ .../plugin_spec.rb | 1 + 8 files changed, 44 insertions(+), 19 deletions(-) diff --git a/assets/javascripts/discourse/components/custom-wizard-field-topic.js.es6 b/assets/javascripts/discourse/components/custom-wizard-field-topic.js.es6 index 0d791db6..ac28aee0 100644 --- a/assets/javascripts/discourse/components/custom-wizard-field-topic.js.es6 +++ b/assets/javascripts/discourse/components/custom-wizard-field-topic.js.es6 @@ -1,5 +1,3 @@ -import { observes } from "discourse-common/utils/decorators"; -import Topic from "discourse/models/topic"; import Component from "@ember/component"; export default Component.extend({ @@ -11,14 +9,13 @@ export default Component.extend({ if (value) { this.set("topics", value); } - console.log(this.field) }, actions: { - setValue(topicIds, topics) { + setValue(_, topics) { if (topics.length) { this.set("field.value", topics); } }, - } + }, }); diff --git a/assets/javascripts/discourse/components/custom-wizard-topic-selector.js.es6 b/assets/javascripts/discourse/components/custom-wizard-topic-selector.js.es6 index afbb3feb..8f3ac98f 100644 --- a/assets/javascripts/discourse/components/custom-wizard-topic-selector.js.es6 +++ b/assets/javascripts/discourse/components/custom-wizard-topic-selector.js.es6 @@ -1,6 +1,4 @@ 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 { searchForTerm } from "discourse/lib/search"; import { makeArray } from "discourse-common/lib/helpers"; @@ -23,7 +21,7 @@ export default MultiSelectComponent.extend({ didReceiveAttrs() { 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); this.selectKit.change(values, content); } @@ -44,10 +42,7 @@ export default MultiSelectComponent.extend({ searchParams.restrictToArchetype = "regular"; searchParams.searchForId = true; - return searchForTerm( - filter, - searchParams - ).then((results) => { + return searchForTerm(filter, searchParams).then((results) => { if (results?.posts?.length > 0) { return results.posts.mapBy("topic"); } @@ -56,15 +51,14 @@ export default MultiSelectComponent.extend({ actions: { onChange(value, items) { - const content = items.map(t => { + const content = items.map((t) => { return { id: t.id, title: t.title, fancy_title: t.fancy_title, - url: t.url - } + url: t.url, + }; }); - console.log("onChange: ", value, content) this.setProperties({ value, content }); this.onChange(value, content); }, diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 index 8a6cd804..6990cf9f 100644 --- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 @@ -22,7 +22,14 @@ export default Component.extend(UndoChanges, { isTextarea: equal("field.type", "textarea"), isUrl: equal("field.type", "url"), 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"), showLimit: or("isCategory", "isTag", "isTopic"), isTextType: or("isText", "isTextarea", "isComposer"), diff --git a/assets/javascripts/discourse/models/custom-wizard-step.js.es6 b/assets/javascripts/discourse/models/custom-wizard-step.js.es6 index 9c8f6f99..24733950 100644 --- a/assets/javascripts/discourse/models/custom-wizard-step.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard-step.js.es6 @@ -64,7 +64,7 @@ export default EmberObject.extend(ValidState, { url: `/w/${wizardId}/steps/${this.get("id")}`, type: "PUT", contentType: "application/json", - data: JSON.stringify({ fields }) + data: JSON.stringify({ fields }), }).catch((response) => { if (response.jqXHR) { response = response.jqXHR; diff --git a/assets/stylesheets/common/wizard/field.scss b/assets/stylesheets/common/wizard/field.scss index 37bb45e2..f4cf3e26 100644 --- a/assets/stylesheets/common/wizard/field.scss +++ b/assets/stylesheets/common/wizard/field.scss @@ -186,4 +186,10 @@ body.custom-wizard { .wizard-topic-selector { width: 500px; } + + .wizard-topic-selector .topic-row { + .topic-title { + margin-right: 10px; + } + } } diff --git a/plugin.rb b/plugin.rb index db0dd9be..f68d31c2 100644 --- a/plugin.rb +++ b/plugin.rb @@ -8,7 +8,7 @@ # subscription_url: https://coop.pavilion.tech # 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_plugin_statistics', '0.1.0.pre7', require: true register_asset 'stylesheets/common/admin.scss' diff --git a/spec/components/custom_wizard/mapper_spec.rb b/spec/components/custom_wizard/mapper_spec.rb index 2e18cabd..7ebdcb32 100644 --- a/spec/components/custom_wizard/mapper_spec.rb +++ b/spec/components/custom_wizard/mapper_spec.rb @@ -63,6 +63,11 @@ describe CustomWizard::Mapper do "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) CustomWizard::Mapper.new( @@ -500,6 +505,21 @@ describe CustomWizard::Mapper do expect(result).to eq("Incorrect") 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 it "gives first non empty element from list" do template = <<-LIQUID.strip diff --git a/spec/components/discourse_plugin_statistics/plugin_spec.rb b/spec/components/discourse_plugin_statistics/plugin_spec.rb index bf3635c2..984bf2ce 100644 --- a/spec/components/discourse_plugin_statistics/plugin_spec.rb +++ b/spec/components/discourse_plugin_statistics/plugin_spec.rb @@ -57,6 +57,7 @@ describe DiscoursePluginStatistics::Plugin do tag: 0, category: 0, group: 0, + topic: 0, user_selector: 0, }, realtime_validations: 0