From 44001e259bfe27c9c30d1e004cd408d3b349b87d Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 12 Sep 2018 16:16:18 +0100 Subject: [PATCH] DEV: Apply prettier to JS and SCSS files --- .../javascripts/admin/adapters/channel.js.es6 | 4 +- .../admin/adapters/provider.js.es6 | 4 +- assets/javascripts/admin/adapters/rule.js.es6 | 4 +- .../javascripts/admin/chat-route-map.js.es6 | 14 +- .../admin/components/channel-data.js.es6 | 4 +- .../admin/components/rule-row.js.es6 | 31 ++- .../controllers/admin-plugins-chat.js.es6 | 4 +- .../admin-plugins-chat-edit-channel.js.es6 | 89 ++++--- .../admin-plugins-chat-edit-rule.js.es6 | 32 ++- .../modals/admin-plugins-chat-test.js.es6 | 41 +-- .../javascripts/admin/models/channel.js.es6 | 6 +- .../javascripts/admin/models/provider.js.es6 | 6 +- assets/javascripts/admin/models/rule.js.es6 | 73 ++++-- .../routes/admin-plugins-chat-index.js.es6 | 5 +- .../routes/admin-plugins-chat-provider.js.es6 | 31 ++- .../admin/routes/admin-plugins-chat.js.es6 | 6 +- .../discourse/public-route-map.js.es6 | 4 +- .../discourse/routes/transcript.js.es6 | 19 +- .../acceptance/chat-integration-test.js.es6 | 242 ++++++++++++------ 19 files changed, 394 insertions(+), 225 deletions(-) diff --git a/assets/javascripts/admin/adapters/channel.js.es6 b/assets/javascripts/admin/adapters/channel.js.es6 index ae28a13..e100dde 100644 --- a/assets/javascripts/admin/adapters/channel.js.es6 +++ b/assets/javascripts/admin/adapters/channel.js.es6 @@ -1,3 +1,3 @@ -import buildPluginAdapter from 'admin/adapters/build-plugin'; +import buildPluginAdapter from "admin/adapters/build-plugin"; -export default buildPluginAdapter('chat'); +export default buildPluginAdapter("chat"); diff --git a/assets/javascripts/admin/adapters/provider.js.es6 b/assets/javascripts/admin/adapters/provider.js.es6 index ae28a13..e100dde 100644 --- a/assets/javascripts/admin/adapters/provider.js.es6 +++ b/assets/javascripts/admin/adapters/provider.js.es6 @@ -1,3 +1,3 @@ -import buildPluginAdapter from 'admin/adapters/build-plugin'; +import buildPluginAdapter from "admin/adapters/build-plugin"; -export default buildPluginAdapter('chat'); +export default buildPluginAdapter("chat"); diff --git a/assets/javascripts/admin/adapters/rule.js.es6 b/assets/javascripts/admin/adapters/rule.js.es6 index ae28a13..e100dde 100644 --- a/assets/javascripts/admin/adapters/rule.js.es6 +++ b/assets/javascripts/admin/adapters/rule.js.es6 @@ -1,3 +1,3 @@ -import buildPluginAdapter from 'admin/adapters/build-plugin'; +import buildPluginAdapter from "admin/adapters/build-plugin"; -export default buildPluginAdapter('chat'); +export default buildPluginAdapter("chat"); diff --git a/assets/javascripts/admin/chat-route-map.js.es6 b/assets/javascripts/admin/chat-route-map.js.es6 index b666749..ff6a520 100644 --- a/assets/javascripts/admin/chat-route-map.js.es6 +++ b/assets/javascripts/admin/chat-route-map.js.es6 @@ -1,11 +1,9 @@ export default { - resource: 'admin.adminPlugins', - path: '/plugins', + resource: "admin.adminPlugins", + path: "/plugins", map() { - this.route('chat', function(){ - this.route('provider', {path: '/:provider'}); - }); - - + this.route("chat", function() { + this.route("provider", { path: "/:provider" }); + }); } -}; \ No newline at end of file +}; diff --git a/assets/javascripts/admin/components/channel-data.js.es6 b/assets/javascripts/admin/components/channel-data.js.es6 index 259fb6c..ece9cf5 100644 --- a/assets/javascripts/admin/components/channel-data.js.es6 +++ b/assets/javascripts/admin/components/channel-data.js.es6 @@ -1,3 +1,3 @@ export default Ember.Component.extend({ - classNames: ['channel-info'], -}); \ No newline at end of file + classNames: ["channel-info"] +}); diff --git a/assets/javascripts/admin/components/rule-row.js.es6 b/assets/javascripts/admin/components/rule-row.js.es6 index 3d3cc38..140d69b 100644 --- a/assets/javascripts/admin/components/rule-row.js.es6 +++ b/assets/javascripts/admin/components/rule-row.js.es6 @@ -1,37 +1,40 @@ -import { popupAjaxError } from 'discourse/lib/ajax-error'; -import computed from 'ember-addons/ember-computed-decorators'; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import computed from "ember-addons/ember-computed-decorators"; export default Ember.Component.extend({ - tagName: 'tr', + tagName: "tr", - @computed('rule.type') + @computed("rule.type") isCategory(type) { - return type === 'normal'; + return type === "normal"; }, - @computed('rule.type') + @computed("rule.type") isMessage(type) { - return type === 'group_message'; + return type === "group_message"; }, - @computed('rule.type') + @computed("rule.type") isMention(type) { - return type === 'group_mention'; + return type === "group_mention"; }, actions: { edit() { - this.sendAction('edit', this.get('rule')); + this.sendAction("edit", this.get("rule")); }, delete(rule) { - rule.destroyRecord().then(() => { - this.send('refresh'); - }).catch(popupAjaxError); + rule + .destroyRecord() + .then(() => { + this.send("refresh"); + }) + .catch(popupAjaxError); }, refresh() { - this.sendAction('refresh'); + this.sendAction("refresh"); } } }); diff --git a/assets/javascripts/admin/controllers/admin-plugins-chat.js.es6 b/assets/javascripts/admin/controllers/admin-plugins-chat.js.es6 index 4ee344f..2d3f960 100644 --- a/assets/javascripts/admin/controllers/admin-plugins-chat.js.es6 +++ b/assets/javascripts/admin/controllers/admin-plugins-chat.js.es6 @@ -1,3 +1 @@ -export default Ember.Controller.extend({ - -}); \ No newline at end of file +export default Ember.Controller.extend({}); diff --git a/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-channel.js.es6 b/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-channel.js.es6 index dedd94e..d8d8a42 100644 --- a/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-channel.js.es6 +++ b/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-channel.js.es6 @@ -1,26 +1,39 @@ -import ModalFunctionality from 'discourse/mixins/modal-functionality'; -import { popupAjaxError } from 'discourse/lib/ajax-error'; -import InputValidation from 'discourse/models/input-validation'; -import { default as computed, observes, on } from 'ember-addons/ember-computed-decorators'; +import ModalFunctionality from "discourse/mixins/modal-functionality"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import InputValidation from "discourse/models/input-validation"; +import { + default as computed, + observes, + on +} from "ember-addons/ember-computed-decorators"; export default Ember.Controller.extend(ModalFunctionality, { - @on('init') + @on("init") setupKeydown() { - Ember.run.schedule('afterRender', () => { - $('#chat-integration-edit-channel-modal').keydown(e => { + Ember.run.schedule("afterRender", () => { + $("#chat-integration-edit-channel-modal").keydown(e => { if (e.keyCode === 13) { - this.send('save'); + this.send("save"); } }); }); }, // The validation property must be defined at runtime since the possible parameters vary by provider - @observes('model') + @observes("model") setupValidations() { - if (this.get('model.provider')) { - const theKeys = this.get('model.provider.channel_parameters').map( ( param ) => param['key'] ); - Ember.defineProperty(this,'paramValidation', Ember.computed(`model.channel.data.{${theKeys.join(',')}}`, this._paramValidation)); + if (this.get("model.provider")) { + const theKeys = this.get("model.provider.channel_parameters").map( + param => param["key"] + ); + Ember.defineProperty( + this, + "paramValidation", + Ember.computed( + `model.channel.data.{${theKeys.join(",")}}`, + this._paramValidation + ) + ); } }, @@ -33,31 +46,38 @@ export default Ember.Controller.extend(ModalFunctionality, { val = ""; } - if (val === "") { // Fail silently if field blank + if (val === "") { + // Fail silently if field blank return InputValidation.create({ - failed: true, + failed: true }); - } else if (!regString) { // Pass silently if no regex available for provider + } else if (!regString) { + // Pass silently if no regex available for provider + return InputValidation.create({ + ok: true + }); + } else if (regex.test(val)) { + // Test against regex return InputValidation.create({ ok: true, + reason: I18n.t( + "chat_integration.edit_channel_modal.channel_validation.ok" + ) }); - } else if (regex.test(val)) { // Test against regex - return InputValidation.create({ - ok: true, - reason: I18n.t('chat_integration.edit_channel_modal.channel_validation.ok') - }); - } else { // Failed regex + } else { + // Failed regex return InputValidation.create({ failed: true, - reason: I18n.t('chat_integration.edit_channel_modal.channel_validation.fail') + reason: I18n.t( + "chat_integration.edit_channel_modal.channel_validation.fail" + ) }); } - }, _paramValidation() { const response = {}; - const parameters = this.get('model.provider.channel_parameters'); + const parameters = this.get("model.provider.channel_parameters"); parameters.forEach(parameter => { response[parameter.key] = this.validate(parameter); @@ -66,19 +86,19 @@ export default Ember.Controller.extend(ModalFunctionality, { return response; }, - @computed('paramValidation') + @computed("paramValidation") saveDisabled(paramValidation) { if (!paramValidation) return true; let invalid = false; - Object.keys(paramValidation).forEach(key =>{ + Object.keys(paramValidation).forEach(key => { if (!paramValidation[key]) { invalid = true; } - if (!paramValidation[key]['ok']) { - invalid = true; + if (!paramValidation[key]["ok"]) { + invalid = true; } }); @@ -87,15 +107,18 @@ export default Ember.Controller.extend(ModalFunctionality, { actions: { cancel() { - this.send('closeModal'); + this.send("closeModal"); }, save() { - if (this.get('saveDisabled')) return; + if (this.get("saveDisabled")) return; - this.get('model.channel').save().then(() => { - this.send('closeModal'); - }).catch(popupAjaxError); + this.get("model.channel") + .save() + .then(() => { + this.send("closeModal"); + }) + .catch(popupAjaxError); } } }); diff --git a/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-rule.js.es6 b/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-rule.js.es6 index 80a4224..6d14632 100644 --- a/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-rule.js.es6 +++ b/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-rule.js.es6 @@ -1,37 +1,43 @@ -import ModalFunctionality from 'discourse/mixins/modal-functionality'; -import { popupAjaxError } from 'discourse/lib/ajax-error'; -import { default as computed, on } from "ember-addons/ember-computed-decorators"; +import ModalFunctionality from "discourse/mixins/modal-functionality"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import { + default as computed, + on +} from "ember-addons/ember-computed-decorators"; export default Ember.Controller.extend(ModalFunctionality, { saveDisabled: false, - @on('init') + @on("init") setupKeydown() { - Ember.run.schedule('afterRender', () => { - $('#chat-integration-edit-channel-modal').keydown(e => { + Ember.run.schedule("afterRender", () => { + $("#chat-integration-edit-channel-modal").keydown(e => { if (e.keyCode === 13) { - this.send('save'); + this.send("save"); } }); }); }, - @computed('model.rule.type') + @computed("model.rule.type") showCategory(type) { return type === "normal"; }, actions: { cancel() { - this.send('closeModal'); + this.send("closeModal"); }, save() { - if (this.get('saveDisabled')) return; + if (this.get("saveDisabled")) return; - this.get('model.rule').save().then(() => { - this.send('closeModal'); - }).catch(popupAjaxError); + this.get("model.rule") + .save() + .then(() => { + this.send("closeModal"); + }) + .catch(popupAjaxError); } } }); diff --git a/assets/javascripts/admin/controllers/modals/admin-plugins-chat-test.js.es6 b/assets/javascripts/admin/controllers/modals/admin-plugins-chat-test.js.es6 index b027c31..68009b5 100644 --- a/assets/javascripts/admin/controllers/modals/admin-plugins-chat-test.js.es6 +++ b/assets/javascripts/admin/controllers/modals/admin-plugins-chat-test.js.es6 @@ -1,40 +1,45 @@ -import ModalFunctionality from 'discourse/mixins/modal-functionality'; -import { ajax } from 'discourse/lib/ajax'; -import { popupAjaxError } from 'discourse/lib/ajax-error'; -import { default as computed, on } from "ember-addons/ember-computed-decorators"; +import ModalFunctionality from "discourse/mixins/modal-functionality"; +import { ajax } from "discourse/lib/ajax"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import { + default as computed, + on +} from "ember-addons/ember-computed-decorators"; export default Ember.Controller.extend(ModalFunctionality, { - @on('init') + @on("init") setupKeydown() { - Ember.run.schedule('afterRender', () => { - $('#chat_integration_test_modal').keydown(e => { + Ember.run.schedule("afterRender", () => { + $("#chat_integration_test_modal").keydown(e => { if (e.keyCode === 13) { - this.send('send'); + this.send("send"); } }); }); }, - @computed('model.topic_id') + @computed("model.topic_id") sendDisabled(topicId) { return !topicId; }, actions: { send() { - if (this.get('sendDisabled')) return; - this.set('loading', true); + if (this.get("sendDisabled")) return; + this.set("loading", true); ajax("/admin/plugins/chat/test", { data: { - channel_id: this.get('model.channel.id'), - topic_id: this.get('model.topic_id') + channel_id: this.get("model.channel.id"), + topic_id: this.get("model.topic_id") }, - type: 'POST' - }).then(() => { - this.set('loading', false); - this.flash(I18n.t('chat_integration.test_modal.success'), 'success'); - }).catch(popupAjaxError); + type: "POST" + }) + .then(() => { + this.set("loading", false); + this.flash(I18n.t("chat_integration.test_modal.success"), "success"); + }) + .catch(popupAjaxError); } } }); diff --git a/assets/javascripts/admin/models/channel.js.es6 b/assets/javascripts/admin/models/channel.js.es6 index 4d32062..c503a39 100644 --- a/assets/javascripts/admin/models/channel.js.es6 +++ b/assets/javascripts/admin/models/channel.js.es6 @@ -1,11 +1,11 @@ -import RestModel from 'discourse/models/rest'; +import RestModel from "discourse/models/rest"; export default RestModel.extend({ updateProperties() { - return this.getProperties(['data']); + return this.getProperties(["data"]); }, createProperties() { - return this.getProperties(['provider','data']); + return this.getProperties(["provider", "data"]); } }); diff --git a/assets/javascripts/admin/models/provider.js.es6 b/assets/javascripts/admin/models/provider.js.es6 index 41d886a..0c432d3 100644 --- a/assets/javascripts/admin/models/provider.js.es6 +++ b/assets/javascripts/admin/models/provider.js.es6 @@ -1,5 +1,3 @@ -import RestModel from 'discourse/models/rest'; +import RestModel from "discourse/models/rest"; -export default RestModel.extend({ - -}); +export default RestModel.extend({}); diff --git a/assets/javascripts/admin/models/rule.js.es6 b/assets/javascripts/admin/models/rule.js.es6 index 9773417..4fd6413 100644 --- a/assets/javascripts/admin/models/rule.js.es6 +++ b/assets/javascripts/admin/models/rule.js.es6 @@ -1,57 +1,88 @@ -import RestModel from 'discourse/models/rest'; -import Category from 'discourse/models/category'; -import { default as computed, observes } from "ember-addons/ember-computed-decorators"; +import RestModel from "discourse/models/rest"; +import Category from "discourse/models/category"; +import { + default as computed, + observes +} from "ember-addons/ember-computed-decorators"; export default RestModel.extend({ available_filters: [ - { id: 'watch', name: I18n.t('chat_integration.filter.watch'), icon: 'exclamation-circle' }, - { id: 'follow', name: I18n.t('chat_integration.filter.follow'), icon: 'circle'}, - { id: 'mute', name: I18n.t('chat_integration.filter.mute'), icon: 'times-circle' } + { + id: "watch", + name: I18n.t("chat_integration.filter.watch"), + icon: "exclamation-circle" + }, + { + id: "follow", + name: I18n.t("chat_integration.filter.follow"), + icon: "circle" + }, + { + id: "mute", + name: I18n.t("chat_integration.filter.mute"), + icon: "times-circle" + } ], available_types: [ - { id: 'normal', name: I18n.t('chat_integration.type.normal')}, - { id: 'group_message', name: I18n.t('chat_integration.type.group_message')}, - { id: 'group_mention', name: I18n.t('chat_integration.type.group_mention')} + { id: "normal", name: I18n.t("chat_integration.type.normal") }, + { + id: "group_message", + name: I18n.t("chat_integration.type.group_message") + }, + { id: "group_mention", name: I18n.t("chat_integration.type.group_mention") } ], category_id: null, tags: null, channel_id: null, - filter: 'watch', - type: 'normal', + filter: "watch", + type: "normal", error_key: null, - @observes('type') + @observes("type") removeUnneededInfo() { - const type = this.get('type'); + const type = this.get("type"); - if (type === 'normal') { - this.set('group_id', null); + if (type === "normal") { + this.set("group_id", null); } else { - this.set('category_id', null); + this.set("category_id", null); } }, - @computed('category_id') + @computed("category_id") category(categoryId) { - if (categoryId){ + if (categoryId) { return Category.findById(categoryId); } else { return false; } }, - @computed('filter') + @computed("filter") filterName(filter) { return I18n.t(`chat_integration.filter.${filter}`); }, updateProperties() { - return this.getProperties(['type','category_id','group_id','tags','filter']); + return this.getProperties([ + "type", + "category_id", + "group_id", + "tags", + "filter" + ]); }, createProperties() { - return this.getProperties(['type','channel_id', 'category_id','group_id','tags','filter']); + return this.getProperties([ + "type", + "channel_id", + "category_id", + "group_id", + "tags", + "filter" + ]); } }); diff --git a/assets/javascripts/admin/routes/admin-plugins-chat-index.js.es6 b/assets/javascripts/admin/routes/admin-plugins-chat-index.js.es6 index 0a09c33..5755953 100644 --- a/assets/javascripts/admin/routes/admin-plugins-chat-index.js.es6 +++ b/assets/javascripts/admin/routes/admin-plugins-chat-index.js.es6 @@ -1,7 +1,10 @@ export default Discourse.Route.extend({ afterModel(model) { if (model.totalRows > 0) { - this.transitionTo('adminPlugins.chat.provider', model.get('firstObject').name); + this.transitionTo( + "adminPlugins.chat.provider", + model.get("firstObject").name + ); } } }); diff --git a/assets/javascripts/admin/routes/admin-plugins-chat-provider.js.es6 b/assets/javascripts/admin/routes/admin-plugins-chat-provider.js.es6 index 6992b11..69bdd0f 100644 --- a/assets/javascripts/admin/routes/admin-plugins-chat-provider.js.es6 +++ b/assets/javascripts/admin/routes/admin-plugins-chat-provider.js.es6 @@ -1,21 +1,26 @@ -import Group from 'discourse/models/group'; +import Group from "discourse/models/group"; export default Discourse.Route.extend({ - model(params) { return Ember.RSVP.hash({ - channels: this.store.findAll('channel', {provider: params.provider}), - provider: this.modelFor("admin-plugins-chat").findBy('id',params.provider), + channels: this.store.findAll("channel", { provider: params.provider }), + provider: this.modelFor("admin-plugins-chat").findBy( + "id", + params.provider + ), groups: Group.findAll().then(groups => { - return groups.filter(g => !g.get('automatic')); + return groups.filter(g => !g.get("automatic")); }) }).then(value => { value.channels.forEach(channel => { - channel.set('rules', channel.rules.map(rule => { - rule = this.store.createRecord('rule', rule); - rule.channel = channel; - return rule; - })); + channel.set( + "rules", + channel.rules.map(rule => { + rule = this.store.createRecord("rule", rule); + rule.channel = channel; + return rule; + }) + ); }); return value; @@ -23,14 +28,14 @@ export default Discourse.Route.extend({ }, serialize(model) { - return { provider: model['provider'].get('id') }; + return { provider: model["provider"].get("id") }; }, actions: { closeModal() { - if (this.get('controller.modalShowing')) { + if (this.get("controller.modalShowing")) { this.refresh(); - this.set('controller.modalShowing', false); + this.set("controller.modalShowing", false); } return true; // Continue bubbling up, so the modal actually closes diff --git a/assets/javascripts/admin/routes/admin-plugins-chat.js.es6 b/assets/javascripts/admin/routes/admin-plugins-chat.js.es6 index 26ea770..2c61d62 100644 --- a/assets/javascripts/admin/routes/admin-plugins-chat.js.es6 +++ b/assets/javascripts/admin/routes/admin-plugins-chat.js.es6 @@ -1,12 +1,12 @@ export default Discourse.Route.extend({ model() { - return this.store.findAll('provider'); + return this.store.findAll("provider"); }, actions: { showSettings() { - this.transitionTo('adminSiteSettingsCategory', 'plugins', { - queryParams: { filter: 'chat_integration'} + this.transitionTo("adminSiteSettingsCategory", "plugins", { + queryParams: { filter: "chat_integration" } }); } } diff --git a/assets/javascripts/discourse/public-route-map.js.es6 b/assets/javascripts/discourse/public-route-map.js.es6 index fd4b9dd..6ea6208 100644 --- a/assets/javascripts/discourse/public-route-map.js.es6 +++ b/assets/javascripts/discourse/public-route-map.js.es6 @@ -1,3 +1,3 @@ export default function() { - this.route('transcript', { path: '/chat-transcript/:secret' }); -}; + this.route("transcript", { path: "/chat-transcript/:secret" }); +} diff --git a/assets/javascripts/discourse/routes/transcript.js.es6 b/assets/javascripts/discourse/routes/transcript.js.es6 index ac2e803..ed38c77 100644 --- a/assets/javascripts/discourse/routes/transcript.js.es6 +++ b/assets/javascripts/discourse/routes/transcript.js.es6 @@ -1,23 +1,30 @@ -import { ajax } from 'discourse/lib/ajax'; -import { popupAjaxError } from 'discourse/lib/ajax-error'; +import { ajax } from "discourse/lib/ajax"; +import { popupAjaxError } from "discourse/lib/ajax-error"; export default Discourse.Route.extend({ beforeModel(transition) { if (this.currentUser) { const secret = transition.params.transcript.secret; - this.replaceWith('discovery.latest').then(e => { - if (this.controllerFor('navigation/default').get('canCreateTopic')) { + this.replaceWith("discovery.latest").then(e => { + if (this.controllerFor("navigation/default").get("canCreateTopic")) { Ember.run.next(() => { ajax(`chat-transcript/${secret}`).then(result => { - e.send('createNewTopicViaParams', null, result['content'], null, null, null); + e.send( + "createNewTopicViaParams", + null, + result["content"], + null, + null, + null + ); }, popupAjaxError); }); } }); } else { this.session.set("shouldRedirectToUrl", window.location.href); - this.replaceWith('login'); + this.replaceWith("login"); } } }); diff --git a/test/javascripts/acceptance/chat-integration-test.js.es6 b/test/javascripts/acceptance/chat-integration-test.js.es6 index 0ef5610..2a46e52 100644 --- a/test/javascripts/acceptance/chat-integration-test.js.es6 +++ b/test/javascripts/acceptance/chat-integration-test.js.es6 @@ -3,53 +3,85 @@ acceptance("Chat Integration", { loggedIn: true, beforeEach() { - const response = (object) => { - return [ - 200, - {"Content-Type": "text/html; charset=utf-8"}, - object - ]; + const response = object => { + return [200, { "Content-Type": "text/html; charset=utf-8" }, object]; }; - server.get('/admin/plugins/chat/providers', () => { // eslint-disable-line no-undef - return response({ providers: [{name: 'dummy', id:'dummy',channel_parameters:[{key:'somekey', regex:"^\\S+$"}]}] }); + server.get("/admin/plugins/chat/providers", () => { + // eslint-disable-line no-undef + return response({ + providers: [ + { + name: "dummy", + id: "dummy", + channel_parameters: [{ key: "somekey", regex: "^\\S+$" }] + } + ] + }); }); - server.get('/admin/plugins/chat/channels', () => { // eslint-disable-line no-undef - return response({"channels":[{"id":97,"provider":"dummy","data":{somekey:"#general"},"rules":[ - {"id":98,"channel_id":97,"category_id":null,"team_id":null,"type":"normal","tags":[],"filter":"watch","error_key":null} - ]}]}); + server.get("/admin/plugins/chat/channels", () => { + // eslint-disable-line no-undef + return response({ + channels: [ + { + id: 97, + provider: "dummy", + data: { somekey: "#general" }, + rules: [ + { + id: 98, + channel_id: 97, + category_id: null, + team_id: null, + type: "normal", + tags: [], + filter: "watch", + error_key: null + } + ] + } + ] + }); }); - server.post('/admin/plugins/chat/channels', () => { // eslint-disable-line no-undef - return response({ }); + server.post("/admin/plugins/chat/channels", () => { + // eslint-disable-line no-undef + return response({}); }); - server.put('/admin/plugins/chat/channels/:id', () => { // eslint-disable-line no-undef - return response({ }); + server.put("/admin/plugins/chat/channels/:id", () => { + // eslint-disable-line no-undef + return response({}); }); - server.delete('/admin/plugins/chat/channels/:id', () => { // eslint-disable-line no-undef - return response({ }); + server.delete("/admin/plugins/chat/channels/:id", () => { + // eslint-disable-line no-undef + return response({}); }); - server.post('/admin/plugins/chat/rules', () => { // eslint-disable-line no-undef - return response({ }); + server.post("/admin/plugins/chat/rules", () => { + // eslint-disable-line no-undef + return response({}); }); - server.put('/admin/plugins/chat/rules/:id', () => { // eslint-disable-line no-undef - return response({ }); + server.put("/admin/plugins/chat/rules/:id", () => { + // eslint-disable-line no-undef + return response({}); }); - server.delete('/admin/plugins/chat/rules/:id', () => { // eslint-disable-line no-undef - return response({ }); + server.delete("/admin/plugins/chat/rules/:id", () => { + // eslint-disable-line no-undef + return response({}); }); - server.post('/admin/plugins/chat/test', () => { // eslint-disable-line no-undef - return response({ }); + server.post("/admin/plugins/chat/test", () => { + // eslint-disable-line no-undef + return response({}); }); - server.get('/groups/search.json', () => { // eslint-disable-line no-undef + server.get("/groups/search.json", () => { + // eslint-disable-line no-undef return response([]); }); } @@ -59,8 +91,18 @@ test("Rules load successfully", assert => { visit("/admin/plugins/chat"); andThen(() => { - assert.ok(exists('#admin-plugin-chat table'), "it shows the table of rules"); - assert.equal(find('#admin-plugin-chat table tr td').eq(0).text().trim(), 'All posts and replies', 'rule displayed'); + assert.ok( + exists("#admin-plugin-chat table"), + "it shows the table of rules" + ); + assert.equal( + find("#admin-plugin-chat table tr td") + .eq(0) + .text() + .trim(), + "All posts and replies", + "rule displayed" + ); }); }); @@ -68,78 +110,108 @@ test("Create channel works", assert => { visit("/admin/plugins/chat"); andThen(() => { - click('#create-channel'); + click("#create-channel"); }); andThen(() => { - assert.ok(exists('#chat-integration-edit-channel-modal'), 'it displays the modal'); - assert.ok(find('#save-channel').prop('disabled'), 'it disables the save button'); - fillIn('#chat-integration-edit-channel-modal input', '#general'); + assert.ok( + exists("#chat-integration-edit-channel-modal"), + "it displays the modal" + ); + assert.ok( + find("#save-channel").prop("disabled"), + "it disables the save button" + ); + fillIn("#chat-integration-edit-channel-modal input", "#general"); }); andThen(() => { - assert.ok(find('#save-channel').prop('disabled') === false, 'it enables the save button'); + assert.ok( + find("#save-channel").prop("disabled") === false, + "it enables the save button" + ); }); andThen(() => { - click('#save-channel'); + click("#save-channel"); }); andThen(() => { - assert.ok(!exists('#chat-integration-edit-channel-modal'), 'modal closes on save'); + assert.ok( + !exists("#chat-integration-edit-channel-modal"), + "modal closes on save" + ); }); - }); test("Edit channel works", assert => { visit("/admin/plugins/chat"); andThen(() => { - click('.channel-header button:first'); + click(".channel-header button:first"); }); andThen(() => { - assert.ok(exists('#chat-integration-edit-channel-modal'), 'it displays the modal'); - assert.ok(!find('#save-channel').prop('disabled'), 'save is enabled'); - fillIn('#chat-integration-edit-channel-modal input', ' general'); + assert.ok( + exists("#chat-integration-edit-channel-modal"), + "it displays the modal" + ); + assert.ok(!find("#save-channel").prop("disabled"), "save is enabled"); + fillIn("#chat-integration-edit-channel-modal input", " general"); }); andThen(() => { - assert.ok(find('#save-channel').prop('disabled'), 'it disables the save button'); + assert.ok( + find("#save-channel").prop("disabled"), + "it disables the save button" + ); }); andThen(() => { - fillIn('#chat-integration-edit-channel-modal input', '#random'); + fillIn("#chat-integration-edit-channel-modal input", "#random"); }); andThen(() => { - $("#chat-integration-edit-channel-modal input").trigger( $.Event( "keydown", { keyCode: 13 } ) ); // Press enter + $("#chat-integration-edit-channel-modal input").trigger( + $.Event("keydown", { keyCode: 13 }) + ); // Press enter }); andThen(() => { - assert.ok(!exists('#chat-integration-edit-channel-modal'), 'modal saves on enter'); + assert.ok( + !exists("#chat-integration-edit-channel-modal"), + "modal saves on enter" + ); }); - }); test("Create rule works", assert => { visit("/admin/plugins/chat"); andThen(() => { - assert.ok(exists('.channel-footer button:first'), 'create button is displayed'); + assert.ok( + exists(".channel-footer button:first"), + "create button is displayed" + ); }); - click('.channel-footer button:first'); + click(".channel-footer button:first"); andThen(() => { - assert.ok(exists('#chat-integration-edit-rule_modal'), 'modal opens on edit'); - assert.ok(find('#save-rule').prop('disabled') === false, 'save is enabled'); + assert.ok( + exists("#chat-integration-edit-rule_modal"), + "modal opens on edit" + ); + assert.ok(find("#save-rule").prop("disabled") === false, "save is enabled"); }); - click('#save-rule'); + click("#save-rule"); andThen(() => { - assert.ok(!exists('#chat-integration-edit-rule_modal'), 'modal closes on save'); + assert.ok( + !exists("#chat-integration-edit-rule_modal"), + "modal closes on save" + ); }); }); @@ -147,20 +219,29 @@ test("Edit rule works", assert => { visit("/admin/plugins/chat"); andThen(() => { - assert.ok(exists('.edit:first'), 'edit button is displayed'); + assert.ok(exists(".edit:first"), "edit button is displayed"); }); - click('.edit:first'); + click(".edit:first"); andThen(() => { - assert.ok(exists('#chat-integration-edit-rule_modal'), 'modal opens on edit'); - assert.ok(find('#save-rule').prop('disabled') === false, 'it enables the save button'); + assert.ok( + exists("#chat-integration-edit-rule_modal"), + "modal opens on edit" + ); + assert.ok( + find("#save-rule").prop("disabled") === false, + "it enables the save button" + ); }); - click('#save-rule'); + click("#save-rule"); andThen(() => { - assert.ok(!exists('#chat-integration-edit-rule_modal'), 'modal closes on save'); + assert.ok( + !exists("#chat-integration-edit-rule_modal"), + "modal closes on save" + ); }); }); @@ -168,17 +249,17 @@ test("Delete channel works", function(assert) { visit("/admin/plugins/chat"); andThen(() => { - assert.ok(exists('.channel-header button:last'), "delete button exists"); - click('.channel-header button:last'); + assert.ok(exists(".channel-header button:last"), "delete button exists"); + click(".channel-header button:last"); }); andThen(() => { - assert.ok(exists('div.bootbox'), "modal is displayed"); - click('div.bootbox .btn-primary'); + assert.ok(exists("div.bootbox"), "modal is displayed"); + click("div.bootbox .btn-primary"); }); andThen(() => { - assert.ok(exists('div.bootbox')===false, "modal has closed"); + assert.ok(exists("div.bootbox") === false, "modal has closed"); }); }); @@ -186,8 +267,8 @@ test("Delete rule works", function(assert) { visit("/admin/plugins/chat"); andThen(() => { - assert.ok(exists('.delete:first')); - click('.delete:first'); + assert.ok(exists(".delete:first")); + click(".delete:first"); }); }); @@ -195,30 +276,41 @@ test("Test channel works", assert => { visit("/admin/plugins/chat"); andThen(() => { - click('.fa-rocket'); + click(".fa-rocket"); }); andThen(() => { - assert.ok(exists('#chat_integration_test_modal'), 'it displays the modal'); - assert.ok(find('#send-test').prop('disabled'), 'it disables the send button'); - fillIn('#choose-topic-title', '9318'); + assert.ok(exists("#chat_integration_test_modal"), "it displays the modal"); + assert.ok( + find("#send-test").prop("disabled"), + "it disables the send button" + ); + fillIn("#choose-topic-title", "9318"); }); andThen(() => { - click('#chat_integration_test_modal .radio:first'); + click("#chat_integration_test_modal .radio:first"); }); andThen(() => { - assert.ok(find('#send-test').prop('disabled') === false, 'it enables the send button'); + assert.ok( + find("#send-test").prop("disabled") === false, + "it enables the send button" + ); }); andThen(() => { - click('#send-test'); + click("#send-test"); }); andThen(() => { - assert.ok(exists('#chat_integration_test_modal'), 'modal doesn\'t close on send'); - assert.ok(exists('#modal-alert.alert-success'), 'success message displayed'); + assert.ok( + exists("#chat_integration_test_modal"), + "modal doesn't close on send" + ); + assert.ok( + exists("#modal-alert.alert-success"), + "success message displayed" + ); }); - });