aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_unfurl.py
blob: 94948d905c27d453a1f583346795f12b2a592b6b (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
from __future__ import annotations

from typing import TYPE_CHECKING, List

import pytest

from slack.slack_message import SlackMessage
from tests.conftest import (
    channel_public_id,
    color_channel_mention,
    color_reset,
    color_user_mention,
    color_usergroup_mention,
    resolve_pending_message_item,
    user_test1_id,
)

if TYPE_CHECKING:
    from typing_extensions import TypedDict
else:
    TypedDict = object


class Case(TypedDict):
    input: str
    output: str


cases: List[Case] = [
    {
        "input": "foo",
        "output": "foo",
    },
    {
        "input": "<!channel>",
        "output": f"{color_usergroup_mention}@channel{color_reset}",
    },
    {
        "input": "<!here>",
        "output": f"{color_usergroup_mention}@here{color_reset}",
    },
    {
        "input": f"<@{user_test1_id}|@othernick>: foo",
        "output": f"{color_user_mention}@Test_1{color_reset}: foo",
    },
    {
        "input": f"foo <#{channel_public_id}|otherchannel> bar",
        "output": f"foo {color_channel_mention}#channel1{color_reset} bar",
    },
]


@pytest.mark.parametrize("case", cases)
def test_unfurl_refs(case: Case, message1_in_channel_public: SlackMessage):
    parsed = (
        message1_in_channel_public._unfurl_refs(  # pyright: ignore [reportPrivateUsage]
            case["input"]
        )
    )
    resolved = "".join(resolve_pending_message_item(item) for item in parsed)
    assert resolved == case["output"]