123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- # Copyright 2021-2024 Avaiga Private Limited
- #
- # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
- # the License. You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
- # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
- # specific language governing permissions and limitations under the License.
- from taipy.gui import Gui, Icon
- def test_chat_md_1(gui: Gui, test_client, helpers):
- gui._bind_var_val(
- "messages",
- [
- ["1", "msg 1", "Fred"],
- ["2", "msg From Another unknown User", "Fredo"],
- ["3", "This from the sender User", "taipy"],
- ["4", "And from another known one", "Fredi"],
- ],
- )
- gui._bind_var_val(
- "chat_properties",
- {
- "users": [
- ["Fred", Icon("/images/favicon.png", "Fred.png")],
- ["Fredi", Icon("/images/fred.png", "Fred.png")],
- ],
- "sender_id": "sender",
- "on_action": "on_action",
- "with_input": False,
- "height": "50vh",
- },
- )
- md_string = "<|{messages}|chat|properties=chat_properties|>"
- expected_list = [
- "<Chat",
- 'defaultUsers="[["Fred", {"path": "/images/favicon.png", "text": "Fred.png"}], ["Fredi", {"path": "/images/fred.png", "text": "Fred.png"}]]"', # noqa: E501
- "messages={_TpD_tpec_TpExPr_messages_TPMDL_0}",
- 'updateVarName="_TpD_tpec_TpExPr_messages_TPMDL_0"',
- 'senderId="sender"',
- 'onAction="on_action"',
- "defaultWithInput={false}",
- 'height="50vh"',
- ]
- helpers.test_control_md(gui, md_string, expected_list)
- def test_chat_md_2(gui: Gui, test_client, helpers):
- gui._bind_var_val(
- "messages",
- [
- ["1", "msg 1", "Fred"],
- ["2", "msg From Another unknown User", "Fredo"],
- ["3", "This from the sender User", "taipy"],
- ["4", "And from another known one", "Fredi"],
- ],
- )
- gui._bind_var_val(
- "users", [["Fred", Icon("/images/favicon.png", "Fred.png")], ["Fredi", Icon("/images/fred.png", "Fred.png")]]
- )
- gui._bind_var_val("winp", False)
- md_string = "<|{messages}|chat|users={users}|with_input={winp}|show_sender|>"
- expected_list = [
- "<Chat",
- 'defaultUsers="[["Fred", {"path": "/images/favicon.png", "text": "Fred.png"}], ["Fredi", {"path": "/images/fred.png", "text": "Fred.png"}]]"', # noqa: E501
- "messages={_TpD_tpec_TpExPr_messages_TPMDL_0}",
- 'updateVarName="_TpD_tpec_TpExPr_messages_TPMDL_0"',
- 'updateVars="users=_TpL_tp_TpExPr_gui_get_adapted_lov_users_list_TPMDL_0_0"',
- "users={_TpL_tp_TpExPr_gui_get_adapted_lov_users_list_TPMDL_0_0}",
- "withInput={_TpB_tpec_TpExPr_winp_TPMDL_0}>",
- "defaultWithInput={false}",
- "showSender={true}",
- ]
- helpers.test_control_md(gui, md_string, expected_list)
- def test_chat_html_1_1(gui: Gui, test_client, helpers):
- gui._bind_var_val(
- "messages",
- [
- ["1", "msg 1", "Fred"],
- ["2", "msg From Another unknown User", "Fredo"],
- ["3", "This from the sender User", "taipy"],
- ["4", "And from another known one", "Fredi"],
- ],
- )
- gui._bind_var_val(
- "chat_properties",
- {"users": [["Fred", Icon("/images/favicon.png", "Fred.png")], ["Fredi", Icon("/images/fred.png", "Fred.png")]]},
- )
- html_string = '<taipy:chat messages="{messages}" properties="chat_properties"/>'
- expected_list = [
- "<Chat",
- 'defaultUsers="[["Fred", {"path": "/images/favicon.png", "text": "Fred.png"}], ["Fredi", {"path": "/images/fred.png", "text": "Fred.png"}]]"', # noqa: E501
- "messages={_TpD_tpec_TpExPr_messages_TPMDL_0}",
- 'updateVarName="_TpD_tpec_TpExPr_messages_TPMDL_0"',
- ]
- helpers.test_control_html(gui, html_string, expected_list)
- def test_chat_html_1_2(gui: Gui, test_client, helpers):
- gui._bind_var_val(
- "messages",
- [
- ["1", "msg 1", "Fred"],
- ["2", "msg From Another unknown User", "Fredo"],
- ["3", "This from the sender User", "taipy"],
- ["4", "And from another known one", "Fredi"],
- ],
- )
- gui._bind_var_val(
- "chat_properties",
- {"users": [["Fred", Icon("/images/favicon.png", "Fred.png")], ["Fredi", Icon("/images/fred.png", "Fred.png")]]},
- )
- html_string = '<taipy:chat properties="chat_properties">{messages}</taipy:chat>'
- expected_list = [
- "<Chat",
- 'defaultUsers="[["Fred", {"path": "/images/favicon.png", "text": "Fred.png"}], ["Fredi", {"path": "/images/fred.png", "text": "Fred.png"}]]"', # noqa: E501
- "messages={_TpD_tpec_TpExPr_messages_TPMDL_0}",
- 'updateVarName="_TpD_tpec_TpExPr_messages_TPMDL_0"',
- ]
- helpers.test_control_html(gui, html_string, expected_list)
- def test_chat_html_2_1(gui: Gui, test_client, helpers):
- gui._bind_var_val(
- "messages",
- [
- ["1", "msg 1", "Fred"],
- ["2", "msg From Another unknown User", "Fredo"],
- ["3", "This from the sender User", "taipy"],
- ["4", "And from another known one", "Fredi"],
- ],
- )
- gui._bind_var_val(
- "users", [["Fred", Icon("/images/favicon.png", "Fred.png")], ["Fredi", Icon("/images/fred.png", "Fred.png")]]
- )
- html_string = '<taipy:chat messages="{messages}" users="{users}" />'
- expected_list = [
- "<Chat",
- 'defaultUsers="[["Fred", {"path": "/images/favicon.png", "text": "Fred.png"}], ["Fredi", {"path": "/images/fred.png", "text": "Fred.png"}]]"', # noqa: E501
- "messages={_TpD_tpec_TpExPr_messages_TPMDL_0}",
- 'updateVarName="_TpD_tpec_TpExPr_messages_TPMDL_0"',
- 'updateVars="users=_TpL_tp_TpExPr_gui_get_adapted_lov_users_list_TPMDL_0_0"',
- "users={_TpL_tp_TpExPr_gui_get_adapted_lov_users_list_TPMDL_0_0}",
- ]
- helpers.test_control_html(gui, html_string, expected_list)
- def test_chat_html_2_2(gui: Gui, test_client, helpers):
- gui._bind_var_val(
- "messages",
- [
- ["1", "msg 1", "Fred"],
- ["2", "msg From Another unknown User", "Fredo"],
- ["3", "This from the sender User", "taipy"],
- ["4", "And from another known one", "Fredi"],
- ],
- )
- gui._bind_var_val(
- "users", [["Fred", Icon("/images/favicon.png", "Fred.png")], ["Fredi", Icon("/images/fred.png", "Fred.png")]]
- )
- html_string = '<taipy:chat users="{users}">{messages}</taipy:chat>'
- expected_list = [
- "<Chat",
- 'defaultUsers="[["Fred", {"path": "/images/favicon.png", "text": "Fred.png"}], ["Fredi", {"path": "/images/fred.png", "text": "Fred.png"}]]"', # noqa: E501
- "messages={_TpD_tpec_TpExPr_messages_TPMDL_0}",
- 'updateVarName="_TpD_tpec_TpExPr_messages_TPMDL_0"',
- 'updateVars="users=_TpL_tp_TpExPr_gui_get_adapted_lov_users_list_TPMDL_0_0"',
- "users={_TpL_tp_TpExPr_gui_get_adapted_lov_users_list_TPMDL_0_0}",
- ]
- helpers.test_control_html(gui, html_string, expected_list)
|