import os

os.environ["RUNNING_TEST"] = 'True'
import unittest
from tests.helpers import AppWindowTestCase

from qtpy.QtGui import QIcon

from finalcif.appwindow import AppWindow
from finalcif.tools.statusbar import StatusBar
from finalcif import VERSION


class TestStausBarWithGraphics(AppWindowTestCase):

    def setUp(self) -> None:
        self.app = AppWindow()
        self.app.setWindowIcon(QIcon('./icon/multitable.png'))
        self.app.setWindowTitle(f'FinalCif v{VERSION}')
        self.status = StatusBar(self.app.ui)
        self.app.hide()

    def tearDown(self) -> None:
        self.app.close()
        super().tearDown()

    def test_show_hello(self):
        self.status.show_message('Hello!')
        self.assertEqual('Hello!', self.status.current_message)

    def test_show_list(self):
        self.status.show_message(['Hello', 'world!'])
        self.assertEqual('Hello world!', self.status.current_message)

    def test_show_2s(self):
        self.status.show_message('foobar', timeout=1)
        self.assertEqual('foobar', self.status.current_message)
        # I am not sure how to test this really


class TestStausBarConsole(AppWindowTestCase):

    def setUp(self) -> None:
        self.status = StatusBar()

    def test_show_hello(self):
        self.status.show_message('Hello!')
        self.assertEqual('Hello!', self.status.current_message)

    def test_show_list(self):
        self.status.show_message(['Hello', 'world!'])
        self.assertEqual('Hello world!', self.status.current_message)
