From 151d51acfa643c625f1207b1e70842019e5fc2b7 Mon Sep 17 00:00:00 2001 From: Lalit Date: Fri, 27 Oct 2023 21:59:03 +0530 Subject: [PATCH] input_pill: Remove over defensive if checks for `create` function. We should remove this overly defensive code and remove the `undefined` type from the return type of this function to avoid handling unexpected `undefined` values in the downstream code. --- web/src/input_pill.ts | 17 +---------------- web/tests/input_pill.test.js | 26 ++++++++------------------ 2 files changed, 9 insertions(+), 34 deletions(-) diff --git a/web/src/input_pill.ts b/web/src/input_pill.ts index 76de9ff196..e73b88c563 100644 --- a/web/src/input_pill.ts +++ b/web/src/input_pill.ts @@ -75,22 +75,7 @@ export type InputPillContainer = { _get_pills_for_testing: () => InputPill[]; }; -export function create(opts: InputPillCreateOptions): InputPillContainer | undefined { - if (!opts.$container) { - blueslip.error("Pill needs container."); - return undefined; - } - - if (!opts.create_item_from_text) { - blueslip.error("Pill needs create_item_from_text"); - return undefined; - } - - if (!opts.get_text_from_item) { - blueslip.error("Pill needs get_text_from_item"); - return undefined; - } - +export function create(opts: InputPillCreateOptions): InputPillContainer { // a stateful object of this `pill_container` instance. // all unique instance information is stored in here. const store: InputPillStore = { diff --git a/web/tests/input_pill.test.js b/web/tests/input_pill.test.js index a6bfd206b4..84bfe23345 100644 --- a/web/tests/input_pill.test.js +++ b/web/tests/input_pill.test.js @@ -51,28 +51,18 @@ run_test("basics", ({mock_template}) => { return html; }); - const config = {}; - - blueslip.expect("error", "Pill needs container."); - input_pill.create(config); - const $pill_input = $.create("pill_input"); const $container = $.create("container"); $container.set_find_results(".input", $pill_input); - blueslip.expect("error", "Pill needs create_item_from_text"); - config.$container = $container; - input_pill.create(config); - - blueslip.expect("error", "Pill needs get_text_from_item"); - config.create_item_from_text = noop; - input_pill.create(config); - - config.get_text_from_item = noop; - config.pill_config = { - show_user_status_emoji: true, - }; - const widget = input_pill.create(config); + const widget = input_pill.create({ + $container, + create_item_from_text: noop, + get_text_from_item: noop, + pill_config: { + show_user_status_emoji: true, + }, + }); const status_emoji_info = {emoji_code: 5}; // type for a pill can be any string but it needs to be