js: Convert static/js/poll_widget.js to ES6 module.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-02-27 15:45:58 -08:00 committed by Tim Abbott
parent cfacf68fb8
commit 472f3bc478
6 changed files with 14 additions and 15 deletions

View File

@ -249,7 +249,6 @@
"upload": false,
"upload_widget": false,
"user_events": false,
"poll_widget": false,
"widgetize": false,
"zxcvbn": false
}

View File

@ -2,16 +2,21 @@
const {strict: assert} = require("assert");
const rewiremock = require("rewiremock/node");
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
const poll_widget = set_global("poll_widget", {});
const poll_widget = {__esModule: true};
rewiremock("../../static/js/poll_widget").with(poll_widget);
set_global("document", "document-stub");
const narrow_state = set_global("narrow_state", {});
set_global("current_msg_list", {});
rewiremock.enable();
const widgetize = zrequire("widgetize");
run_test("activate", (override) => {
@ -176,3 +181,4 @@ run_test("activate", (override) => {
});
widgetize.set_widgets_for_list();
});
rewiremock.disable();

View File

@ -20,7 +20,6 @@ import "../setup";
import "../unread_ops";
import "../unread";
import "../stream_list";
import "../poll_widget";
import "../widgetize";
import "../submessage";
import "../message_list_view";

View File

@ -63,7 +63,6 @@ declare let padded_widget: any;
declare let page_params: any;
declare let panels: any;
declare let pointer: any;
declare let poll_widget: any;
declare let popovers: any;
declare let presence: any;
declare let reactions: any;

View File

@ -1,11 +1,9 @@
"use strict";
import render_widgets_poll_widget from "../templates/widgets/poll_widget.hbs";
import render_widgets_poll_widget_results from "../templates/widgets/poll_widget_results.hbs";
const render_widgets_poll_widget = require("../templates/widgets/poll_widget.hbs");
const render_widgets_poll_widget_results = require("../templates/widgets/poll_widget_results.hbs");
import * as people from "./people";
const people = require("./people");
class PollData {
export class PollData {
// This object just holds data for a poll, although it
// works closely with the widget's concept of how data
// should be represented for rendering, plus how the
@ -177,9 +175,8 @@ class PollData {
return data.some((el) => el.option === latest_option);
}
}
exports.PollData = PollData;
exports.activate = function (opts) {
export function activate(opts) {
const elem = opts.elem;
const callback = opts.callback;
@ -368,6 +365,4 @@ exports.activate = function (opts) {
build_widget();
render_question();
render_results();
};
window.poll_widget = exports;
}

View File

@ -1,5 +1,6 @@
"use strict";
const poll_widget = require("./poll_widget");
const todo_widget = require("./todo_widget");
const zform = require("./zform");