diff --git a/.eslintrc.json b/.eslintrc.json index a5c4528616..26f90de473 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -142,7 +142,6 @@ "compose": false, "compose_actions": false, "compose_fade": false, - "compose_pm_pill": false, "compose_state": false, "compose_ui": false, "composebox_typeahead": false, diff --git a/frontend_tests/node_tests/compose_actions.js b/frontend_tests/node_tests/compose_actions.js index 4fb19da60f..bc25924420 100644 --- a/frontend_tests/node_tests/compose_actions.js +++ b/frontend_tests/node_tests/compose_actions.js @@ -17,7 +17,9 @@ set_global("document", { to_$: () => $("document-stub"), }); -const compose_pm_pill = set_global("compose_pm_pill", {}); +const compose_pm_pill = {__esModule: true}; + +rewiremock("../../static/js/compose_pm_pill").with(compose_pm_pill); const hash_util = set_global("hash_util", {}); diff --git a/frontend_tests/node_tests/compose_pm_pill.js b/frontend_tests/node_tests/compose_pm_pill.js index 1df459d48b..5336ec982c 100644 --- a/frontend_tests/node_tests/compose_pm_pill.js +++ b/frontend_tests/node_tests/compose_pm_pill.js @@ -166,27 +166,27 @@ run_test("pills", (override) => { }); run_test("has_unconverted_data", () => { - compose_pm_pill.widget = { + compose_pm_pill.__Rewire__("widget", { is_pending: () => true, - }; + }); // If the pill itself has pending data, we have unconverted // data. assert.equal(compose_pm_pill.has_unconverted_data(), true); - compose_pm_pill.widget = { + compose_pm_pill.__Rewire__("widget", { is_pending: () => false, items: () => [{user_id: 99}], - }; + }); // Our pill is complete and all items contain user_id, so // we do NOT have unconverted data. assert.equal(compose_pm_pill.has_unconverted_data(), false); - compose_pm_pill.widget = { + compose_pm_pill.__Rewire__("widget", { is_pending: () => false, items: () => [{user_id: 99}, {email: "random@mit.edu"}], - }; + }); // One of our items only knows email (as in a bridge-with-zephyr // scenario where we might not have registered the user yet), so diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.js index 6bcca83a28..f5e422f299 100644 --- a/frontend_tests/node_tests/composebox_typeahead.js +++ b/frontend_tests/node_tests/composebox_typeahead.js @@ -786,9 +786,9 @@ run_test("initialize", () => { }; let appended_name; - compose_pm_pill.set_from_typeahead = (item) => { + compose_pm_pill.__Rewire__("set_from_typeahead", (item) => { appended_name = item.full_name; - }; + }); // options.updater() options.query = "othello"; @@ -808,15 +808,15 @@ run_test("initialize", () => { let appended_names = []; - compose_pm_pill.set_from_typeahead = (item) => { + compose_pm_pill.__Rewire__("set_from_typeahead", (item) => { appended_names.push(item.full_name); - }; + }); let cleared = false; function fake_clear() { cleared = true; } - compose_pm_pill.widget = {clear_text: fake_clear}; + compose_pm_pill.__Rewire__("widget", {clear_text: fake_clear}); options.query = "hamletchar"; options.updater(hamletcharacters, event); diff --git a/frontend_tests/node_tests/typing_status.js b/frontend_tests/node_tests/typing_status.js index f5da551873..d31602e60e 100644 --- a/frontend_tests/node_tests/typing_status.js +++ b/frontend_tests/node_tests/typing_status.js @@ -263,7 +263,7 @@ run_test("basics", () => { // test that we correctly detect if worker.get_recipient // and typing_status.state.current_recipient are the same - compose_pm_pill.get_user_ids_string = () => "1,2,3"; + compose_pm_pill.__Rewire__("get_user_ids_string", () => "1,2,3"); typing_status.state.current_recipient = typing.get_recipient(); const call_count = { @@ -294,14 +294,14 @@ run_test("basics", () => { // change in recipient and new_recipient should make us // call typing_status.stop_last_notification - compose_pm_pill.get_user_ids_string = () => "2,3,4"; + compose_pm_pill.__Rewire__("get_user_ids_string", () => "2,3,4"); typing_status.update(worker, typing.get_recipient()); assert.deepEqual(call_count.maybe_ping_server, 2); assert.deepEqual(call_count.start_or_extend_idle_timer, 3); assert.deepEqual(call_count.stop_last_notification, 1); // Stream messages are represented as get_user_ids_string being empty - compose_pm_pill.get_user_ids_string = () => ""; + compose_pm_pill.__Rewire__("get_user_ids_string", () => ""); typing_status.update(worker, typing.get_recipient()); assert.deepEqual(call_count.maybe_ping_server, 2); assert.deepEqual(call_count.start_or_extend_idle_timer, 3); diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js index c2112c22cb..8c2e28a4b6 100644 --- a/frontend_tests/node_tests/ui_init.js +++ b/frontend_tests/node_tests/ui_init.js @@ -67,7 +67,7 @@ page_params.presences = []; set_global("activity", {initialize() {}}); set_global("click_handlers", {initialize() {}}); -set_global("compose_pm_pill", {initialize() {}}); +rewiremock("../../static/js/compose_pm_pill").with({initialize() {}}); rewiremock("../../static/js/drafts").with({initialize() {}}); set_global("emoji_picker", {initialize() {}}); set_global("gear_menu", {initialize() {}}); diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js index c5c3ac677a..fe3af92f6b 100644 --- a/static/js/bundles/app.js +++ b/static/js/bundles/app.js @@ -16,7 +16,6 @@ import "flatpickr/dist/plugins/confirmDate/confirmDate"; import "../i18n"; import "../fold_dict"; import "../input_pill"; -import "../compose_pm_pill"; import "../channel"; import "../setup"; import "../unread_ui"; diff --git a/static/js/compose.js b/static/js/compose.js index d7ab61c2fb..fe39486a0e 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -10,6 +10,7 @@ const render_compose_not_subscribed = require("../templates/compose_not_subscrib const render_compose_private_stream_alert = require("../templates/compose_private_stream_alert.hbs"); const common = require("./common"); +const compose_pm_pill = require("./compose_pm_pill"); const drafts = require("./drafts"); const echo = require("./echo"); const loading = require("./loading"); diff --git a/static/js/compose_actions.js b/static/js/compose_actions.js index 3488b68df7..109105f419 100644 --- a/static/js/compose_actions.js +++ b/static/js/compose_actions.js @@ -5,6 +5,7 @@ const autosize = require("autosize"); const fenced_code = require("../shared/js/fenced_code"); const common = require("./common"); +const compose_pm_pill = require("./compose_pm_pill"); const drafts = require("./drafts"); const people = require("./people"); diff --git a/static/js/compose_pm_pill.js b/static/js/compose_pm_pill.js index 5c83d24117..207a6aa4f4 100644 --- a/static/js/compose_pm_pill.js +++ b/static/js/compose_pm_pill.js @@ -1,10 +1,10 @@ -"use strict"; +import * as people from "./people"; +import * as user_pill from "./user_pill"; +import * as util from "./util"; -const people = require("./people"); -const user_pill = require("./user_pill"); -const util = require("./util"); +export let widget; -exports.initialize_pill = function () { +export function initialize_pill() { const container = $("#private_message_recipient").parent(); const pill = input_pill.create({ @@ -14,62 +14,60 @@ exports.initialize_pill = function () { }); return pill; -}; +} -exports.initialize = function () { - exports.widget = exports.initialize_pill(); +export function initialize() { + widget = initialize_pill(); - exports.widget.onPillCreate(() => { + widget.onPillCreate(() => { compose_actions.update_placeholder_text(); }); - exports.widget.onPillRemove(() => { + widget.onPillRemove(() => { compose_actions.update_placeholder_text(); }); -}; +} -exports.clear = function () { - exports.widget.clear(); -}; +export function clear() { + widget.clear(); +} -exports.set_from_typeahead = function (person) { +export function set_from_typeahead(person) { // We expect person to be an object returned from people.js. user_pill.append_person({ - pill_widget: exports.widget, + pill_widget: widget, person, }); -}; +} -exports.set_from_emails = function (value) { +export function set_from_emails(value) { // value is something like "alice@example.com,bob@example.com" - exports.clear(); - exports.widget.appendValue(value); -}; + clear(); + widget.appendValue(value); +} -exports.get_user_ids = function () { - return user_pill.get_user_ids(exports.widget); -}; +export function get_user_ids() { + return user_pill.get_user_ids(widget); +} -exports.has_unconverted_data = function () { - return user_pill.has_unconverted_data(exports.widget); -}; +export function has_unconverted_data() { + return user_pill.has_unconverted_data(widget); +} -exports.get_user_ids_string = function () { - const user_ids = exports.get_user_ids(); +export function get_user_ids_string() { + const user_ids = get_user_ids(); const sorted_user_ids = util.sorted_ids(user_ids); const user_ids_string = sorted_user_ids.join(","); return user_ids_string; -}; +} -exports.get_emails = function () { +export function get_emails() { // return something like "alice@example.com,bob@example.com" - const user_ids = exports.get_user_ids(); + const user_ids = get_user_ids(); const emails = user_ids.map((id) => people.get_by_user_id(id).email).join(","); return emails; -}; +} -exports.filter_taken_users = function (persons) { - return user_pill.filter_taken_users(persons, exports.widget); -}; - -window.compose_pm_pill = exports; +export function filter_taken_users(persons) { + return user_pill.filter_taken_users(persons, widget); +} diff --git a/static/js/compose_state.js b/static/js/compose_state.js index 33f907e8c0..ffaf084b3b 100644 --- a/static/js/compose_state.js +++ b/static/js/compose_state.js @@ -1,5 +1,7 @@ "use strict"; +const compose_pm_pill = require("./compose_pm_pill"); + let message_type = false; // 'stream', 'private', or false-y exports.set_message_type = function (msg_type) { diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js index 4a37295c8c..1d9ad3dbbb 100644 --- a/static/js/composebox_typeahead.js +++ b/static/js/composebox_typeahead.js @@ -9,6 +9,7 @@ const pygments_data = require("../generated/pygments_data.json"); const emoji = require("../shared/js/emoji"); const typeahead = require("../shared/js/typeahead"); +const compose_pm_pill = require("./compose_pm_pill"); const people = require("./people"); const settings_data = require("./settings_data"); const user_pill = require("./user_pill"); diff --git a/static/js/global.d.ts b/static/js/global.d.ts index 7663619505..d45010d9f4 100644 --- a/static/js/global.d.ts +++ b/static/js/global.d.ts @@ -21,7 +21,6 @@ declare let compose: any; declare let compose_actions: any; declare let composebox_typeahead: any; declare let compose_fade: any; -declare let compose_pm_pill: any; declare let compose_state: any; declare let compose_ui: any; declare let condense: any; diff --git a/static/js/typing.js b/static/js/typing.js index 37dc14a066..81e95c89f3 100644 --- a/static/js/typing.js +++ b/static/js/typing.js @@ -1,5 +1,6 @@ import * as typing_status from "../shared/js/typing_status"; +import * as compose_pm_pill from "./compose_pm_pill"; import * as people from "./people"; // This module handles the outbound side of typing indicators. diff --git a/static/js/ui_init.js b/static/js/ui_init.js index e86f7f7d89..c9e1c06b58 100644 --- a/static/js/ui_init.js +++ b/static/js/ui_init.js @@ -9,6 +9,7 @@ const fenced_code = require("../shared/js/fenced_code"); const render_edit_content_button = require("../templates/edit_content_button.hbs"); const alert_words = require("./alert_words"); +const compose_pm_pill = require("./compose_pm_pill"); const copy_and_paste = require("./copy_and_paste"); const drafts = require("./drafts"); const echo = require("./echo");