Skip to content

Commit a2106bf

Browse files
committed
Update workflow to add frontend tests && handle deprecations
1 parent a19a1fa commit a2106bf

16 files changed

+82
-58
lines changed

.github/workflows/plugin-tests.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,6 @@ jobs:
7373
ref: "${{ github.base_ref }}"
7474
fetch-depth: 1
7575

76-
- name: Check spec existence
77-
id: check_spec
78-
uses: andstor/file-existence-action@v1
79-
with:
80-
files: "plugins/${{ steps.repo-name.outputs.value }}/spec"
81-
82-
- name: Check qunit existence
83-
id: check_qunit
84-
uses: andstor/file-existence-action@v1
85-
with:
86-
files: "plugins/${{ steps.repo-name.outputs.value }}/test/javascripts"
87-
8876
- name: Setup Git
8977
run: |
9078
git config --global user.email "ci@ci.invalid"
@@ -140,7 +128,7 @@ jobs:
140128
bin/rake db:migrate
141129
142130
- name: Plugin RSpec with Coverage
143-
if: matrix.build_type == 'backend' && steps.check_spec.outputs.files_exists == 'true'
131+
if: matrix.build_type == 'backend'
144132
run: |
145133
if [ -e plugins/${{ steps.repo-name.outputs.value }}/.simplecov ]
146134
then
@@ -150,6 +138,6 @@ jobs:
150138
bin/rake plugin:spec[${{ steps.repo-name.outputs.value }}]
151139
152140
- name: Plugin QUnit
153-
if: matrix.build_type == 'frontend' && steps.check_qunit.outputs.files_exists == 'true'
141+
if: matrix.build_type == 'frontend'
154142
run: bundle exec rake plugin:qunit['${{ steps.repo-name.outputs.value }}','1200000']
155143
timeout-minutes: 30

assets/javascripts/wizard/components/custom-user-selector.js.es6

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import userSearch from "../lib/user-search";
77
import WizardI18n from "../lib/wizard-i18n";
88
import Handlebars from "handlebars";
99
import { isEmpty } from "@ember/utils";
10+
import TextField from "@ember/component/text-field";
1011

1112
const template = function (params) {
1213
const options = params.options;
@@ -31,7 +32,7 @@ const template = function (params) {
3132
return new Handlebars.SafeString(html).string;
3233
};
3334

34-
export default Ember.TextField.extend({
35+
export default TextField.extend({
3536
attributeBindings: ["autofocus", "maxLength"],
3637
autocorrect: false,
3738
autocapitalize: false,

assets/javascripts/wizard/components/wizard-field-category.js.es6

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { observes } from "discourse-common/utils/decorators";
22
import Category from "discourse/models/category";
3+
import Component from "@ember/component";
34

4-
export default Ember.Component.extend({
5-
layoutName: 'wizard/templates/components/wizard-field-category',
5+
export default Component.extend({
6+
layoutName: "wizard/templates/components/wizard-field-category",
67

78
didInsertElement() {
89
const property = this.field.property || "id";

assets/javascripts/wizard/components/wizard-field-composer.js.es6

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import {
33
observes,
44
} from "discourse-common/utils/decorators";
55
import EmberObject from "@ember/object";
6+
import Component from "@ember/component";
67

7-
export default Ember.Component.extend({
8-
layoutName: 'wizard/templates/components/wizard-field-composer',
8+
export default Component.extend({
9+
layoutName: "wizard/templates/components/wizard-field-composer",
910

1011
showPreview: false,
1112
classNameBindings: [

assets/javascripts/wizard/components/wizard-step.js.es6

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default Component.extend({
8787
@observes("step.message")
8888
_handleMessage: function () {
8989
const message = this.get("step.message");
90-
this.sendAction("showMessage", message);
90+
this.showMessage(message);
9191
},
9292
9393
keyPress(event) {
@@ -162,7 +162,7 @@ export default Component.extend({
162162
if (response["final"]) {
163163
CustomWizard.finished(response);
164164
} else {
165-
this.sendAction("goNext", response);
165+
this.goNext(response);
166166
}
167167
})
168168
.catch(() => this.animateInvalidFields())
@@ -181,7 +181,7 @@ export default Component.extend({
181181
},
182182
183183
showMessage(message) {
184-
this.sendAction("showMessage", message);
184+
this.sendAction(message);
185185
},
186186
187187
stylingDropdownChanged(id, value) {

assets/javascripts/wizard/components/wizard-text-field.js.es6

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import computed from "discourse-common/utils/decorators";
22
import { isLTR, isRTL, siteDir } from "discourse/lib/text-direction";
33
import WizardI18n from "../lib/wizard-i18n";
4+
import TextField from "@ember/component/text-field";
45

5-
export default Ember.TextField.extend({
6+
export default TextField.extend({
67
attributeBindings: [
78
"autocorrect",
89
"autocapitalize",

assets/javascripts/wizard/lib/initialize/inject-objects.js.es6

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
export default {
2-
run(app, container) {
2+
run(app) {
3+
// siteSettings must always be registered first
4+
if (!app.hasRegistration("site-settings:main")) {
5+
const siteSettings = app.SiteSettings;
6+
app.register("site-settings:main", siteSettings, { instantiate: false });
7+
}
8+
39
const Store = requirejs("discourse/services/store").default;
410
const Site = requirejs(
511
"discourse/plugins/discourse-custom-wizard/wizard/models/site"
612
).default;
713
const Session = requirejs("discourse/models/session").default;
814
const RestAdapter = requirejs("discourse/adapters/rest").default;
915
const messageBus = requirejs("message-bus-client").default;
10-
const sniffCapabilites = requirejs("discourse/pre-initializers/sniff-capabilities").default;
16+
const sniffCapabilites = requirejs(
17+
"discourse/pre-initializers/sniff-capabilities"
18+
).default;
19+
1120
const site = Site.current();
1221
const session = Session.current();
13-
1422
const registrations = [
15-
["site-settings:main", app.SiteSettings, false],
1623
["message-bus:main", messageBus, false],
1724
["site:main", site, false],
1825
["session:main", session, false],
@@ -26,18 +33,18 @@ export default {
2633
}
2734
});
2835

29-
const targets = ["controller", "component", "route", "model", "adapter", "mixin"];
30-
const injections = [
31-
["siteSettings", "site-settings:main"],
32-
["messageBus", "message-bus:main"],
33-
["site", "site:main"],
34-
["session", "session:main"],
35-
["store", "service:store"],
36-
["appEvents", "service:app-events"]
37-
];
36+
const targets = ["controller", "component", "route", "model", "adapter"];
37+
38+
targets.forEach((t) => {
39+
app.inject(t, "appEvents", "service:app-events");
40+
app.inject(t, "store", "service:store");
41+
app.inject(t, "site", "site:main");
42+
});
3843

39-
injections.forEach(injection => {
40-
targets.forEach((t) => app.inject(t, injection[0], injection[1]));
44+
targets.concat("service").forEach((t) => {
45+
app.inject(t, "session", "session:main");
46+
app.inject(t, "messageBus", "message-bus:main");
47+
app.inject(t, "siteSettings", "site-settings:main");
4148
});
4249

4350
if (!app.hasRegistration("capabilities:main")) {

assets/javascripts/wizard/lib/initialize/patch-components.js.es6

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ export default {
2020
const DEditor = requirejs("discourse/components/d-editor").default;
2121
const { clipboardHelpers } = requirejs("discourse/lib/utilities");
2222
const toMarkdown = requirejs("discourse/lib/to-markdown").default;
23+
const discourseComputed = requirejs("discourse-common/utils/decorators")
24+
.default;
25+
const WizardI18n = requirejs(
26+
"discourse/plugins/discourse-custom-wizard/wizard/lib/wizard-i18n"
27+
).default;
2328
const isInside = (text, regex) => {
2429
const matches = text.match(regex);
2530
return matches && matches.length % 2;
@@ -44,6 +49,17 @@ export default {
4449
}
4550
},
4651

52+
@discourseComputed("placeholder", "placeholderOverride")
53+
placeholderTranslated(placeholder, placeholderOverride) {
54+
if (placeholderOverride) {
55+
return placeholderOverride;
56+
}
57+
if (placeholder) {
58+
return WizardI18n(placeholder);
59+
}
60+
return null;
61+
},
62+
4763
_wizardInsertText(args = {}) {
4864
if (args.fieldId === this.fieldId) {
4965
this.insertText(args.text, args.options);

assets/javascripts/wizard/lib/initialize/wizard.js.es6

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default {
3535
const Session = requirejs("discourse/models/session").default;
3636
const session = Session.current();
3737
session.set("highlightJsPath", setupData.highlightJsPath);
38+
session.set("markdownItUrl", setupData.markdownItUrl);
3839

3940
[
4041
'register-files',

assets/javascripts/wizard/lib/load-script.js.es6

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { ajax } from "wizard/lib/ajax";
2-
import getURL from "discourse-common/lib/get-url";
2+
import getURL, { getURLWithCDN } from "discourse-common/lib/get-url";
3+
import { run } from "@ember/runloop";
4+
import { Promise } from "rsvp";
35

46
const _loaded = {};
57
const _loading = {};
@@ -25,7 +27,7 @@ function loadWithTag(path, cb) {
2527
) {
2628
s = s.onload = s.onreadystatechange = null;
2729
if (!abort) {
28-
Ember.run(null, cb);
30+
run(null, cb);
2931
}
3032
}
3133
};
@@ -38,7 +40,7 @@ export function loadCSS(url) {
3840
export default function loadScript(url, opts) {
3941
// TODO: Remove this once plugins have been updated not to use it:
4042
if (url === "defer/html-sanitizer-bundle") {
41-
return Ember.RSVP.Promise.resolve();
43+
return Promise.resolve();
4244
}
4345

4446
opts = opts || {};
@@ -51,7 +53,7 @@ export default function loadScript(url, opts) {
5153
}
5254
});
5355

54-
return new Ember.RSVP.Promise(function (resolve) {
56+
return new Promise(function (resolve) {
5557
url = getURL(url);
5658

5759
// If we already loaded this url
@@ -63,7 +65,7 @@ export default function loadScript(url, opts) {
6365
}
6466

6567
let done;
66-
_loading[url] = new Ember.RSVP.Promise(function (_done) {
68+
_loading[url] = new Promise(function (_done) {
6769
done = _done;
6870
});
6971

@@ -84,8 +86,8 @@ export default function loadScript(url, opts) {
8486

8587
// Scripts should always load from CDN
8688
// CSS is type text, to accept it from a CDN we would need to handle CORS
87-
if (!opts.css && Discourse.CDN && url[0] === "/" && url[1] !== "/") {
88-
cdnUrl = Discourse.CDN.replace(/\/$/, "") + url;
89+
if (!opts.css) {
90+
cdnUrl = getURLWithCDN(url);
8991
}
9092

9193
// Some javascript depends on the path of where it is loaded (ace editor)

0 commit comments

Comments
 (0)