"""Tests for the Textual app and message routing."""
import pytest

from django_shreck.messages import (
    ShellResult,
    ShowDetail,
    ShowTable,
    ShowCompare,
    OpenAdmin,
)


class TestMessages:
    """Tests that custom Textual messages can be instantiated correctly."""

    def test_shell_result_message(self):
        msg = ShellResult(result=42, variable_name="x")
        assert msg.result == 42
        assert msg.variable_name == "x"

    def test_shell_result_without_variable(self):
        msg = ShellResult(result=[1, 2, 3])
        assert msg.result == [1, 2, 3]
        assert msg.variable_name is None

    def test_show_detail_message(self):
        msg = ShowDetail(instance="fake_instance", editable=True)
        assert msg.instance == "fake_instance"
        assert msg.editable is True

    def test_show_detail_default_not_editable(self):
        msg = ShowDetail(instance="fake_instance")
        assert msg.editable is False

    def test_show_table_message(self):
        msg = ShowTable(queryset="fake_queryset")
        assert msg.queryset == "fake_queryset"

    def test_show_compare_message(self):
        msg = ShowCompare(instances=["obj1", "obj2", "obj3"])
        assert msg.instances == ["obj1", "obj2", "obj3"]

    def test_open_admin_message(self):
        msg = OpenAdmin(target="some_target")
        assert msg.target == "some_target"


