aboutsummaryrefslogtreecommitdiffstats
path: root/_pytest/test_render_message.py
blob: f336a0513accd17cdc4e64013fae82b1004e43f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import pytest

import wee_slack


@pytest.mark.parametrize(
    "case",
    [
        {
            "input_message": {
                "blocks": [
                    {
                        "type": "rich_text",
                        "block_id": "5Cg6",
                        "elements": [
                            {
                                "type": "rich_text_section",
                                "elements": [
                                    {
                                        "type": "emoji",
                                        "name": "smile",
                                        "unicode": "1f604",
                                    }
                                ],
                            },
                        ],
                    },
                ],
                "reactions": [{"name": "eyes", "users": ["U01E8P3JKM1"], "count": 1}],
            },
            "rendered": (
                # Should be just <emoji>
                "\U0001f604 <[color darkgray]>[\U0001f4401]<[color reset]>"
            ),
        },
        {
            "input_message": {
                "blocks": [
                    {
                        "type": "rich_text",
                        "block_id": "5Cg6",
                        "elements": [
                            {
                                "type": "rich_text_section",
                                "elements": [
                                    {
                                        "type": "emoji",
                                        "name": "smile",
                                        "unicode": "1f604",
                                    }
                                ],
                            },
                        ],
                    },
                ],
                "reactions": [{"name": "eyes", "users": ["U01E8P3JKM1"], "count": 1}],
            },
            "rendered": (
                # Should be just :<emoji name>:
                ":smile: <[color darkgray]>[:eyes:1]<[color reset]>"
            ),
            "render_emoji_as_string": True,
        },
        {
            "input_message": {
                "blocks": [
                    {
                        "type": "rich_text",
                        "block_id": "5Cg6",
                        "elements": [
                            {
                                "type": "rich_text_section",
                                "elements": [
                                    {
                                        "type": "emoji",
                                        "name": "smile",
                                        "unicode": "1f604",
                                    }
                                ],
                            },
                        ],
                    },
                ],
                "reactions": [{"name": "eyes", "users": ["U01E8P3JKM1"], "count": 1}],
            },
            "rendered": (
                # Should be <emoji> (:<emoji name>:)
                "\U0001f604 (:smile:) <[color darkgray]>[\U0001f440 (:eyes:)1]<[color reset]>"
            ),
            "render_emoji_as_string": "both",
        },
        {
            "input_message": {
                "text": "test",
                "reactions": [{"name": "custom", "users": ["U01E8P3JKM1"], "count": 2}],
            },
            "rendered": "test <[color darkgray]>[:custom:2]<[color reset]>",
        },
        {
            "input_message": {
                "text": "test",
                "reactions": [{"name": "custom", "users": ["U407ABLLW"], "count": 1}],
            },
            "rendered": "test <[color darkgray]>[:custom:(@alice)]<[color reset]>",
            "show_reaction_nicks": True,
        },
        {
            "input_message": {
                "text": "test",
                "reactions": [{"name": "custom", "users": ["U407ABLLW"], "count": 2}],
            },
            "rendered": "test <[color darkgray]>[:custom:(@alice, and others)]<[color reset]>",
            "show_reaction_nicks": True,
        },
        {
            "input_message": {
                "blocks": [
                    {
                        "type": "rich_text",
                        "block_id": "ASgLI",
                        "elements": [
                            {
                                "type": "rich_text_section",
                                "elements": [
                                    {"type": "text", "text": "<text> & "},
                                    {
                                        "type": "link",
                                        "url": "https://text.link?x=<x>&z=z",
                                    },
                                    {"type": "text", "text": " "},
                                    {
                                        "type": "text",
                                        "text": "<code> & ",
                                        "style": {"code": True},
                                    },
                                    {
                                        "type": "link",
                                        "url": "https://code.link?x=<x>&z=z",
                                        "style": {"code": True},
                                    },
                                    {"type": "text", "text": "\n"},
                                ],
                            },
                            {
                                "type": "rich_text_preformatted",
                                "elements": [
                                    {"type": "text", "text": "<code block> & "},
                                    {
                                        "type": "link",
                                        "url": "https://codeblock.link?x=<x>&z=z",
                                    },
                                ],
                                "border": 0,
                            },
                        ],
                    }
                ],
            },
            "rendered": (
                "<text> & https://text.link?x=<x>&z=z `<code> & https://code.link?x=<x>&z=z`\n"
                "```\n<code block> & https://codeblock.link?x=<x>&z=z\n```"
            ),
            "render_emoji_as_string": "both",
        },
    ],
)
def test_render_message(case, channel_general):
    wee_slack.EMOJI, wee_slack.EMOJI_WITH_SKIN_TONES_REVERSE = wee_slack.load_emoji()
    wee_slack.config.render_emoji_as_string = case.get("render_emoji_as_string")
    wee_slack.config.show_reaction_nicks = case.get("show_reaction_nicks", False)
    message_json = {"ts": str(wee_slack.SlackTS()), **case["input_message"]}
    message = wee_slack.SlackMessage("normal", message_json, channel_general)
    result = message.render()
    assert result == case["rendered"]