Mercurial > libervia-web
annotate tests/browser/unit/test_chat.py @ 1637:29dd52585984 default tip
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
fix 461
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 04 Jul 2025 18:15:48 +0200 |
parents | |
children |
rev | line source |
---|---|
1637
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Libervia Web |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2025 Jérôme Poisson (goffi@goffi.org) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 from collections import defaultdict |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 import sys |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 import pytest |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from unittest.mock import MagicMock, AsyncMock, patch |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 # We mock all non-stdlib modules, so the module can be imported. |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 sys.modules["bridge"] = MagicMock(AsyncBridge=AsyncMock) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 sys.modules["cache"] = MagicMock(cache=MagicMock()) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 sys.modules["dialog"] = MagicMock(Confirm=MagicMock()) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 sys.modules["errors"] = MagicMock() |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 sys.modules["file_uploader"] = MagicMock(FileUploader=MagicMock()) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 sys.modules["javascript"] = MagicMock() |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 sys.modules["jid"] = MagicMock(JID=MagicMock()) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 sys.modules["jid_search"] = MagicMock(JidSearch=MagicMock()) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 sys.modules["loading"] = MagicMock() |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 sys.modules["popup"] = MagicMock(create_popup=MagicMock()) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 sys.modules["js_modules"] = MagicMock() |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 sys.modules["js_modules.emoji_picker_element"] = MagicMock() |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 sys.modules["js_modules.tippy_js"] = MagicMock() |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 sys.modules["js_modules.quill"] = MagicMock(Quill=MagicMock()) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 sys.modules["tools"] = MagicMock() |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 sys.modules["interpreter"] = MagicMock(Inspector=MagicMock()) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 sys.modules["components"] = MagicMock(init_collapsible_cards=MagicMock()) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 class FakeElement: |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 """FakeElement, with methods to similuate child appending and some attributes.""" |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 scrollHeight = 0 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 scrollTop = 0 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 clientHeight = 0 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 def __init__(self): |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 self.attrs = defaultdict(MagicMock) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 self.children = [] |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 def __getattr__(self, attr) -> MagicMock: |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 return self.attrs[attr] |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 def __le__(self, child): |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 child.parent = self |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 self.children.append(child) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 return True |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 class FakeDocument: |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 def __init__(self): |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 self.attrs = defaultdict(MagicMock) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 self.items = defaultdict(FakeElement) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 def __getattr__(self, attr) -> MagicMock: |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 return self.attrs[attr] |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 def __getitem__(self, item) -> FakeElement: |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 return self.items[item] |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 def __setitem__(self, key, item) -> None: |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 self.items[key] = item |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 document = FakeDocument() |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 browser = sys.modules["browser"] = MagicMock( |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 aio=MagicMock(), |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 console=MagicMock(), |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 document=document, |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 window=MagicMock(), |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 navigator=MagicMock(mediaDevices=MagicMock(getDisplayMedia=MagicMock())), |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 ) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 class FakeTemplate(MagicMock): |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 def get_elt(self, *args, **kwargs): |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 return FakeElement() |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 sys.modules["template"] = MagicMock(Template=FakeTemplate) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 # We can now import the actual module |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 from libervia.web.pages.chat import _browser as chat_module |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 class TestLiberviaWebChat: |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 @pytest.fixture |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 def chat(self) -> chat_module.LiberviaWebChat: |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 """Fixture to create a LiberviaWebChat instance with mocks.""" |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 chat = chat_module.LiberviaWebChat() |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 chat.rich_editor = MagicMock( |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 getSelection=MagicMock(return_value=MagicMock(index=0, length=1)), |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 getFormat=MagicMock(return_value={}), |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 format=MagicMock(), |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 getContents=MagicMock(return_value={"ops": []}), |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 ) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 return chat |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 @pytest.fixture |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 def bridge(self, monkeypatch) -> AsyncMock: |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 bridge = AsyncMock() |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 monkeypatch.setattr(chat_module, "bridge", bridge) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 return bridge |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 @pytest.fixture |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 def message_elt(self) -> MagicMock: |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 """Fixture to create a mock message element.""" |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 msg_mock = MagicMock() |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 msg_mock.__getitem__.side_effect = lambda key: "msg123" if key == "id" else None |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 return msg_mock |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 @pytest.mark.asyncio |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 async def test_forward_action(self, chat, bridge, message_elt) -> None: |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 """Forward action launches bridge.message_forward with correct parameters.""" |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 message_elt.classList.contains.return_value = True |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 with patch("browser.window.prompt", return_value="recipient@example.org"): |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 await chat.on_action_forward(None, message_elt) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 bridge.message_forward.assert_awaited_once_with("msg123", "recipient@example.org") |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 @pytest.mark.asyncio |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 async def test_rich_editor_actions(self, chat) -> None: |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 """Rich editor formatting actions modify editor state correctly.""" |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 test_cases = [ |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 ("bold", ["bold", True]), |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 ("italic", ["italic", True]), |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 ("underline", ["underline", True]), |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 ("link", ["link", "https://example.org"]), |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 ] |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 for action, expected_call in test_cases: |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 evt = MagicMock() |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 evt.currentTarget.dataset = {"action": action} |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 if action == "link": |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 with patch("browser.window.prompt", return_value="https://example.org"): |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 chat.on_rich_action(evt) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 else: |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 chat.on_rich_action(evt) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 chat.rich_editor.format.assert_called_with(*expected_call) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 @pytest.mark.asyncio |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 async def test_extra_recipients(self, monkeypatch, chat) -> None: |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 """Adding extra recipient calls "insertBefore".""" |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 toolbar_elt = MagicMock() |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 monkeypatch.setitem(document, "rich-edit-toolbar", toolbar_elt) |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 await chat.on_action_extra_recipients(selected="to") |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 await chat.on_action_extra_recipients(selected="cc") |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 |
29dd52585984
tests (browser/unit/chat): Add tests for forwarding, rich editing and extra recipients:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 assert toolbar_elt.parent.insertBefore.call_count == 2 |