import unittest
from .events import Events
from .windows import WindowDocumentHandler
from .sessions import create_session
from .test_windows import TestWindow, TestView
from .test_session import test_config, TestClient
import unittest.mock
from . import test_sublime as test_sublime
from .test_rpc import TestSettings

try:
    from typing import Any, Dict
    assert Any and Dict
except ImportError:
    pass


class WindowDocumentHandlerTests(unittest.TestCase):

    def test_sends_did_open_to_session(self):

        events = Events()
        view = TestView(__file__)
        window = TestWindow([[view]])
        view.set_window(window)
        handler = WindowDocumentHandler(test_sublime, TestSettings(), window, events)
        client = TestClient()
        session = create_session(test_config, "", dict(), TestSettings(),
                                 bootstrap_client=client)
        handler.add_session(session)
        events.publish("view.on_activated_async", view)
        self.assertTrue(handler.has_document_state(__file__))
        self.assertEqual(len(client._notifications), 1)

    def test_ignores_views_from_other_window(self):
        events = Events()
        window = TestWindow()
        view = TestView(__file__)
        handler = WindowDocumentHandler(test_sublime, TestSettings(), window, events)
        client = TestClient()
        session = create_session(test_config, "", dict(), TestSettings(),
                                 bootstrap_client=client)
        handler.add_session(session)
        events.publish("view.on_activated_async", view)
        self.assertFalse(handler.has_document_state(__file__))
        self.assertEqual(len(client._notifications), 0)

@@ -311,16 +311,48 @@
 Settings
+%0Afrom .types import ClientConfig
 %0A%0Atry:%0A 
@@ -1731,8 +1731,1022 @@
 ns), 0)%0A
+%0A    def test_sends_did_open_to_multiple_sessions(self):%0A        events = Events()%0A        view = TestView(__file__)%0A        window = TestWindow(%5B%5Bview%5D%5D)%0A        view.set_window(window)%0A        handler = WindowDocumentHandler(test_sublime, TestSettings(), window, events)%0A        client = TestClient()%0A        session = create_session(test_config, %22%22, dict(), TestSettings(),%0A                                 bootstrap_client=client)%0A        client2 = TestClient()%0A        test_config2 = ClientConfig(%22test2%22, %5B%5D, None, %5B%22source.test%22%5D, %5B%22Test.sublime-syntax%22%5D, %22test%22)%0A        session2 = create_session(test_config2, %22%22, dict(), TestSettings(),%0A                                  bootstrap_client=client2)%0A%0A        handler.add_session(session)%0A        handler.add_session(session2)%0A        events.publish(%22view.on_activated_async%22, view)%0A        self.assertTrue(handler.has_document_state(__file__))%0A        self.assertEqual(len(client._notifications), 1)%0A        self.assertEqual(len(client2._notifications), 1)%0A

Add test for multi-session document sync